Go to the source code of this file.
Functions | |
void | tupleFiddle () |
int | main (int argc, char *argv[]) |
boost::unit_test_framework::test_suite * | init_unit_test_suite (int, char **) |
Variables | |
int const | bufferlen = 8 |
int const | num = 5 |
boost::unit_test_framework::test_suite* init_unit_test_suite | ( | int | , | |
char ** | ||||
) |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 159 of file tuple.cpp.
References tupleFiddle().
00160 { 00161 tupleFiddle(); 00162 return 0; 00163 }
void tupleFiddle | ( | ) |
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; // Can tuple contain nulls? 00048 int i; 00049 00050 TupleDescriptor tupleDesc; 00051 tupleDesc.clear(); 00052 00053 // Build up a description of what we'd like the tuple to look like 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 // Create a tuple accessor from the description 00081 // 00082 // Note: Must use an ALL_FIXED accessor when creating a tuple out of 00083 // the air like this, otherwise unmarshal() does not know what to 00084 // do. If you need a STANDARD type tuple with variable-lengty 00085 // fields, it has to be built as a copy. 00086 TupleAccessor tupleAccessorFixed; 00087 tupleAccessorFixed.compute(tupleDesc, TUPLE_FORMAT_ALL_FIXED); 00088 00089 // Allocate memory for the tuple 00090 boost::scoped_array<FixedBuffer> 00091 pTupleBufFixed(new FixedBuffer[tupleAccessorFixed.getMaxByteCount()]); 00092 00093 // Link memory to accessor 00094 tupleAccessorFixed.setCurrentTupleBuf(pTupleBufFixed.get(), false); 00095 00096 // Create a vector of TupleDatum objects based on the description we built 00097 TupleData tupleDataFixed(tupleDesc); 00098 00099 // Do something mysterious. Probably binding pointers in the accessor to 00100 // items in the TupleData vector 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); // longer than buflen 00111 strncpy( 00112 (reinterpret_cast<char *>(const_cast<PBuffer>(itr->pData))), 00113 buf, bufferlen); 00114 } 00115 for (i = 0; i < num; i++, itr++) { 00116 // exploded form 00117 pDatum = *itr; 00118 pData = const_cast<PBuffer>(pDatum.pData); 00119 *(reinterpret_cast<int32_t *>(pData)) = i; 00120 } 00121 for (i = 0; i < num; i++, itr++) { 00122 // condensed form 00123 *(reinterpret_cast<uint8_t *>(const_cast<PBuffer>(itr->pData))) = i; 00124 } 00125 for (i = 0; i < num; i++, itr++) { 00126 *(reinterpret_cast<float *>(const_cast<PBuffer>(itr->pData))) = i * 0.5; 00127 } 00128 00129 // Print out the tuple 00130 TuplePrinter tuplePrinter; 00131 tuplePrinter.print(cout, tupleDesc, tupleDataFixed); 00132 cout << endl; 00133 00134 // Create another TupleData object that will be nullable 00135 TupleData tupleDataNullable = tupleDataFixed; 00136 00137 // null out last element of each type 00138 for (i = 1; i <= 3; i++) { 00139 tupleDataNullable[(i*num)-1].pData = NULL; 00140 } 00141 00142 // Print out the nullable tuple 00143 tuplePrinter.print(cout, tupleDesc, tupleDataNullable); 00144 cout << endl; 00145 00146 // Re-point second string to first string 00147 tupleDataNullable[1].pData = tupleDataNullable[0].pData; 00148 00149 // Re-point third string to part way into first string 00150 tupleDataNullable[2].pData = (tupleDataNullable[0].pData + 1); 00151 00152 // Print out the modified nullable tuple 00153 tuplePrinter.print(cout, tupleDesc, tupleDataNullable); 00154 cout << endl; 00155 00156 }
int const bufferlen = 8 |
Definition at line 41 of file tuple.cpp.
Referenced by tupleFiddle(), unitTestNullableLocal(), and unitTestPointer().
int const num = 5 |
Definition at line 42 of file tuple.cpp.
Referenced by tupleFiddle(), unitTestNullableLocal(), and unitTestPointer().