TupleAccessor.h

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/tuple/TupleAccessor.h#17 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #ifndef Fennel_TupleAccessor_Included
00025 #define Fennel_TupleAccessor_Included
00026 
00027 #include "fennel/tuple/TupleFormat.h"
00028 
00029 #include <boost/dynamic_bitset.hpp>
00030 #include <boost/utility.hpp>
00031 #include <vector>
00032 
00033 FENNEL_BEGIN_NAMESPACE
00034 
00035 class TupleData;
00036 class TupleDescriptor;
00037 class AttributeAccessor;
00038 
00039 // NOTE: see comments on struct StoredNode before modifying the way tuples are
00040 // stored.
00041 
00048 class FENNEL_TUPLE_EXPORT TupleAccessor
00049     : public boost::noncopyable
00050 {
00054     std::vector<AttributeAccessor *> ppAttributeAccessors;
00055 
00059     VectorOfUint pVarWidthAttrIndices;
00060 
00066     VectorOfUint marshalOrder;
00067 
00071     uint cbMaxStorage;
00072 
00076     uint cbMinStorage;
00077 
00081     uint nBitFields;
00082 
00086     uint iBitFieldOffset;
00087 
00092     uint iFirstVarEndIndirectOffset;
00093 
00098     uint iLastVarEndIndirectOffset;
00099 
00104     uint iFirstVarOffset;
00105 
00111     bool bAlignedVar;
00112 
00116     PConstBuffer pTupleBuf;
00117 
00121     boost::dynamic_bitset<FixedBuffer> bitFields;
00122 
00123     TupleFormat format;
00124 
00125     // private helpers
00126     void initFixedAccessors(TupleDescriptor const &,VectorOfUint &);
00127     void clear();
00128 
00129 public:
00130     typedef uint16_t StoredValueOffset;
00131 
00137     static const bool BOOL_TRUE;
00138 
00144     static const bool BOOL_FALSE;
00145 
00146     explicit TupleAccessor();
00147 
00148     virtual ~TupleAccessor();
00149 
00158     void compute(
00159         TupleDescriptor const &tuple,
00160         TupleFormat format = TUPLE_FORMAT_STANDARD);
00161 
00165     uint getMaxByteCount() const
00166     {
00167         return cbMaxStorage;
00168     }
00169 
00173     uint getMinByteCount() const
00174     {
00175         return cbMinStorage;
00176     }
00177 
00181     bool isFixedWidth() const
00182     {
00183         return isMAXU(iFirstVarOffset);
00184     }
00185 
00190     uint getBitFieldOffset() const
00191     {
00192         return iBitFieldOffset;
00193     }
00194 
00200     PConstBuffer getCurrentTupleBuf() const
00201     {
00202         return pTupleBuf;
00203     }
00204 
00216     void setCurrentTupleBuf(PConstBuffer pTupleBuf, bool valid = true);
00217 
00221     void resetCurrentTupleBuf();
00222 
00230     inline uint getCurrentByteCount() const;
00231 
00240     uint getBufferByteCount(PConstBuffer pBuf) const;
00241 
00250     uint getByteCount(TupleData const &tuple) const;
00251 
00261     bool isBufferSufficient(TupleData const &tuple,uint cbBuffer) const;
00262 
00263     // TODO:  come up with a common interface for TupleProjectionAccessor, and
00264     // add an additional virtual interface
00276     void unmarshal(TupleData &tuple,uint iFirstDatum = 0) const;
00277 
00284     AttributeAccessor const &getAttributeAccessor(uint iAttribute) const
00285     {
00286         return *(ppAttributeAccessors[iAttribute]);
00287     }
00288 
00297     void marshal(TupleData const &tuple,PBuffer pTupleBuf);
00298 
00302     uint size() const
00303     {
00304         return ppAttributeAccessors.size();
00305     }
00306 
00307     // TODO:  private
00308 
00312     boost::dynamic_bitset<FixedBuffer> const &getBitFields() const
00313     {
00314         return bitFields;
00315     }
00316 
00324     StoredValueOffset const *referenceIndirectOffset(uint iIndirectOffset) const
00325     {
00326         return referenceIndirectOffset(
00327             const_cast<PBuffer>(pTupleBuf),
00328             iIndirectOffset);
00329     }
00330 
00340     static StoredValueOffset *referenceIndirectOffset(
00341         PBuffer pTupleBuf,uint iIndirectOffset)
00342     {
00343         return reinterpret_cast<StoredValueOffset *>(
00344             pTupleBuf + iIndirectOffset);
00345     }
00346 };
00347 
00348 inline uint TupleAccessor::getCurrentByteCount() const
00349 {
00350     assert(pTupleBuf);
00351     return getBufferByteCount(pTupleBuf);
00352 }
00353 
00354 FENNEL_END_NAMESPACE
00355 
00356 #endif
00357 
00358 // End TupleAccessor.h

Generated on Mon Jun 22 04:00:21 2009 for Fennel by  doxygen 1.5.1