Fennel: /home/pub/open/dev/fennel/calctest/tuple.cpp File Reference (original) (raw)

Definition at line 45 of file tuple.cpp.

References bufferlen, TupleAccessor::compute(), FixedBuffer, TupleAccessor::getMaxByteCount(), StandardTypeDescriptorFactory::newDataType(), num, TupleDatum::pData, TuplePrinter::print(), TupleAccessor::setCurrentTupleBuf(), STANDARD_TYPE_INT_32, STANDARD_TYPE_REAL, STANDARD_TYPE_UINT_8, STANDARD_TYPE_VARCHAR, TUPLE_FORMAT_ALL_FIXED, and TupleAccessor::unmarshal().

Referenced by main().

00046 { 00047 bool isNullable = true;
00048 int i; 00049 00050 TupleDescriptor tupleDesc; 00051 tupleDesc.clear(); 00052 00053
00054 StandardTypeDescriptorFactory typeFactory; 00055 for (i = 0; i < num; i++) { 00056 StoredTypeDescriptor const &typeDesc = 00057 typeFactory.newDataType(STANDARD_TYPE_VARCHAR); 00058 tupleDesc.push_back( 00059 TupleAttributeDescriptor( 00060 typeDesc, 00061 isNullable, 00062 bufferlen)); 00063 } 00064 for (i = 0; i < num; i++) { 00065 StoredTypeDescriptor const &typeDesc = 00066 typeFactory.newDataType(STANDARD_TYPE_INT_32); 00067 tupleDesc.push_back(TupleAttributeDescriptor(typeDesc, isNullable)); 00068 } 00069 for (i = 0; i < num; i++) { 00070 StoredTypeDescriptor const &typeDesc = 00071 typeFactory.newDataType(STANDARD_TYPE_UINT_8); 00072 tupleDesc.push_back(TupleAttributeDescriptor(typeDesc, isNullable)); 00073 } 00074 for (i = 0; i < num; i++) { 00075 StoredTypeDescriptor const &typeDesc = 00076 typeFactory.newDataType(STANDARD_TYPE_REAL); 00077 tupleDesc.push_back(TupleAttributeDescriptor(typeDesc, isNullable)); 00078 } 00079 00080
00081
00082
00083
00084
00085
00086 TupleAccessor tupleAccessorFixed; 00087 tupleAccessorFixed.compute(tupleDesc, TUPLE_FORMAT_ALL_FIXED); 00088 00089
00090 boost::scoped_array 00091 pTupleBufFixed(new FixedBuffer[tupleAccessorFixed.getMaxByteCount()]); 00092 00093
00094 tupleAccessorFixed.setCurrentTupleBuf(pTupleBufFixed.get(), false); 00095 00096
00097 TupleData tupleDataFixed(tupleDesc); 00098 00099
00100
00101 tupleAccessorFixed.unmarshal(tupleDataFixed); 00102 00103 TupleData::iterator itr = tupleDataFixed.begin(); 00104 00105 TupleDatum pDatum; 00106 PBuffer pData; 00107 00108 for (i = 0; i < num; i++, itr++) { 00109 char buf[bufferlen * 10]; 00110 sprintf(buf,"%d-A-%d-B-%d-C-", i, i, i); 00111 strncpy( 00112 (reinterpret_cast<char *>(const_cast(itr->pData))), 00113 buf, bufferlen); 00114 } 00115 for (i = 0; i < num; i++, itr++) { 00116
00117 pDatum = *itr; 00118 pData = const_cast(pDatum.pData); 00119 (reinterpret_cast<int32_t *>(pData)) = i; 00120 } 00121 for (i = 0; i < num; i++, itr++) { 00122
00123 *(reinterpret_cast<uint8_t *>(const_cast(itr->pData))) = i; 00124 } 00125 for (i = 0; i < num; i++, itr++) { 00126 *(reinterpret_cast<float *>(const_cast(itr->pData))) = i * 0.5; 00127 } 00128 00129
00130 TuplePrinter tuplePrinter; 00131 tuplePrinter.print(cout, tupleDesc, tupleDataFixed); 00132 cout << endl; 00133 00134
00135 TupleData tupleDataNullable = tupleDataFixed; 00136 00137
00138 for (i = 1; i <= 3; i++) { 00139 tupleDataNullable[(i
num)-1].pData = NULL; 00140 } 00141 00142
00143 tuplePrinter.print(cout, tupleDesc, tupleDataNullable); 00144 cout << endl; 00145 00146
00147 tupleDataNullable[1].pData = tupleDataNullable[0].pData; 00148 00149
00150 tupleDataNullable[2].pData = (tupleDataNullable[0].pData + 1); 00151 00152
00153 tuplePrinter.print(cout, tupleDesc, tupleDataNullable); 00154 cout << endl; 00155 00156 }