Fennel: /home/pub/open/dev/fennel/tuple/TupleAccessor.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 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 00032 00033 FENNEL_BEGIN_NAMESPACE 00034 00035 class TupleData; 00036 class TupleDescriptor; 00037 class AttributeAccessor; 00038 00039 00040 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 bitFields; 00122 00123 TupleFormat format; 00124 00125
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
00264
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
00308 00312 boost::dynamic_bitset const &getBitFields() const 00313 { 00314 return bitFields; 00315 } 00316 00324 StoredValueOffset const *referenceIndirectOffset(uint iIndirectOffset) const 00325 { 00326 return referenceIndirectOffset( 00327 const_cast(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