00001 #ifndef Impala_Core_Column_Read_h
00002 #define Impala_Core_Column_Read_h
00003
00004 #include <iostream>
00005 #include <fstream>
00006
00007 #include "Util/Database.h"
00008 #include "Core/Geometry/Rectangle.h"
00009 #include "Core/Array/Arrays.h"
00010 #include "Core/Column/ColumnTem.h"
00011 #include "Core/Column/InvalidColumn.h"
00012 #include "Core/Vector/VectorSet.h"
00013 #include "Core/Array/ReadRaw.h"
00014
00015 namespace Impala
00016 {
00017 namespace Core
00018 {
00019 namespace Column
00020 {
00021
00022
00023 inline void
00024 Read(InvalidColumn* col, Util::IOBuffer* buffer)
00025 {
00026
00027 }
00028
00029 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00030 inline void
00031 Read(InvalidColumn* col, String fileName, Util::Database* db)
00032 {
00033
00034 }
00035 #endif // REPOSITORY_USED
00036
00038
00039 inline void
00040 Read(ColumnTem<Int32>* col, Util::IOBuffer* buffer)
00041 {
00042 Array::Array2dScalarInt32* tmp = 0;
00043 Array::ReadRaw(tmp, buffer);
00044 if (tmp)
00045 {
00046 col->SetData(tmp->CPB(), tmp->CW());
00047 tmp->mIsWrapper = true;
00048 delete tmp;
00049 }
00050 }
00051
00052 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00053 inline void
00054 Read(ColumnTem<Int32>* col, String fileName, Util::Database* db)
00055 {
00056 Array::Array2dScalarInt32* tmp = 0;
00057 Array::ReadRaw(tmp, fileName, db);
00058 if (tmp)
00059 {
00060 col->SetData(tmp->CPB(), tmp->CW());
00061 tmp->mIsWrapper = true;
00062 delete tmp;
00063 }
00064 }
00065 #endif // REPOSITORY_USED
00066
00068
00069 inline void
00070 Read(ColumnTem<UInt64>* col, Util::IOBuffer* buffer)
00071 {
00072 Array::Array2dScalarUInt64* tmp = 0;
00073 Array::ReadRaw(tmp, buffer);
00074 if (tmp)
00075 {
00076 col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00077 tmp->mIsWrapper = true;
00078 delete tmp;
00079 }
00080 }
00081
00082 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00083 inline void
00084 Read(ColumnTem<UInt64>* col, String fileName, Util::Database* db)
00085 {
00086 Array::Array2dScalarUInt64* tmp = 0;
00087 Array::ReadRaw(tmp, fileName, db);
00088 if (tmp)
00089 {
00090 col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00091 tmp->mIsWrapper = true;
00092 delete tmp;
00093 }
00094 }
00095 #endif // REPOSITORY_USED
00096
00098
00099 inline void
00100 Read(ColumnTem<Real64>* col, Util::IOBuffer* buffer)
00101 {
00102 Array::Array2dScalarReal64* tmp = 0;
00103 Array::ReadRaw(tmp, buffer);
00104 if (tmp)
00105 {
00106 col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00107 tmp->mIsWrapper = true;
00108 delete tmp;
00109 }
00110 }
00111
00112 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00113 inline void
00114 Read(ColumnTem<Real64>* col, String fileName, Util::Database* db)
00115 {
00116 Array::Array2dScalarReal64* tmp = 0;
00117 Array::ReadRaw(tmp, fileName, db);
00118 if (tmp)
00119 {
00120 col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00121 tmp->mIsWrapper = true;
00122 delete tmp;
00123 }
00124 }
00125 #endif // REPOSITORY_USED
00126
00128
00129 inline void
00130 Read(ColumnTem<String>* col, Util::IOBuffer* buffer)
00131 {
00132 if (! (buffer && buffer->Valid()))
00133 {
00134 return;
00135 }
00136 int nrElem;
00137 int byteSize;
00138
00139 std::istringstream iss(buffer->ReadLine() + " 0");
00140 String dummy;
00141 iss >> dummy >> dummy >> dummy >> nrElem >> byteSize;
00142 col->Reserve(nrElem, false);
00143 String* data = col->GetData();
00144 if(byteSize > 0)
00145 {
00146 char* binaryData = new char[byteSize];
00147 buffer->Read(binaryData, byteSize);
00148 int j = 0;
00149 for (int i=0 ; i<nrElem ; i++)
00150 {
00151 int start = j;
00152 while((j<byteSize) && (binaryData[j] != '\n'))
00153 j++;
00154 data[i] = String(&(binaryData[start]), j - start);
00155 j++;
00156 }
00157 delete binaryData;
00158 }
00159 else
00160 {
00161 for (int i=0 ; i<nrElem ; i++)
00162 data[i] = buffer->ReadLine();
00163 }
00164 }
00165
00166 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00167 inline void
00168 Read(ColumnTem<String>* col, String fileName, Util::Database* db)
00169 {
00170 Util::IOBuffer* buf = db->GetIOBuffer(fileName, true, true, "");
00171 Read(col, buf);
00172 delete buf;
00173 }
00174 #endif // REPOSITORY_USED
00175
00177
00178 inline void
00179 Read(ColumnTem<Geometry::Rectangle>* col, Util::IOBuffer* buffer)
00180 {
00181 String s,nr;
00182 int nrElem;
00183 s=buffer->ReadLine();
00184 String subs=s.substr(0,11);
00185 if (subs=="nr rects : ")
00186 {
00187 nr=s.substr(10);
00188 std::istringstream iss(nr);
00189 iss>>nrElem;
00190 col->Reserve(nrElem, false);
00191 Geometry::Rectangle* data = col->GetData();
00192 for (int i=0 ; i<nrElem ; i++)
00193 {
00194 buffer->NativeTypeRead(&data[i].mLeft);
00195 buffer->NativeTypeRead(&data[i].mTop);
00196 buffer->NativeTypeRead(&data[i].mRight);
00197 buffer->NativeTypeRead(&data[i].mBottom);
00198 }
00199 }
00200 else
00201 {
00202 std::cout << "[Read<column<rectangles>>] parsing error"<< std::endl;
00203 }
00204 }
00205
00206 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00207 inline void
00208 Read(ColumnTem<Geometry::Rectangle>* col, String fileName, Util::Database* db)
00209 {
00210 std::ifstream f(fileName.c_str());
00211 if (!f.is_open())
00212 return;
00213 String s1,s2,s3;
00214 f >> s1 >> s2 >> s3;
00215 if (s1 == "nr" && s2 == "rects" && s3 == ":")
00216 {
00217 int nrElem;
00218 f >> nrElem;
00219 col->Reserve(nrElem, false);
00220 Geometry::Rectangle* data = col->GetData();
00221 for (int i=0 ; i<nrElem ; i++)
00222 f >> data[i];
00223 }
00224 else
00225 {
00226 std::cout << "[Read<column<rectangles>>] parsing error in " << fileName
00227 << std::endl;
00228 }
00229 f.close();
00230 }
00231 #endif // REPOSITORY_USED
00232
00234
00235 inline void
00236 Read(Vector::VectorSet<Array::Array2dScalarInt8>* col, Util::IOBuffer* buffer)
00237 {
00238
00239 Array::Array2dScalarInt8* tmp = 0;
00240 Array::ReadRaw(tmp, buffer);
00241 if (tmp)
00242 {
00243 col->SetStorage(tmp);
00244 col->SetSize(tmp->CH());
00245 }
00246 }
00247
00248 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00249 inline void
00250 Read(Vector::VectorSet<Array::Array2dScalarInt8>* col, String fileName,
00251 Util::Database* db)
00252 {
00253
00254 Array::Array2dScalarInt8* tmp = 0;
00255 Array::ReadRaw(tmp, fileName, db);
00256 if (tmp)
00257 {
00258 col->SetStorage(tmp);
00259 col->SetSize(tmp->CH());
00260 }
00261 }
00262 #endif // REPOSITORY_USED
00263
00265
00266 inline void
00267 Read(Vector::VectorSet<Array::Array2dScalarReal64>* col, Util::IOBuffer* buffer)
00268 {
00269
00270 Array::Array2dScalarReal64* tmp = 0;
00271 Array::ReadRaw(tmp, buffer);
00272 if (tmp)
00273 {
00274 col->SetStorage(tmp);
00275 col->SetSize(tmp->CH());
00276 }
00277 }
00278
00279 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00280 inline void
00281 Read(Vector::VectorSet<Array::Array2dScalarReal64>* col, String fileName,
00282 Util::Database* db)
00283 {
00284
00285 Array::Array2dScalarReal64* tmp = 0;
00286 Array::ReadRaw(tmp, fileName, db);
00287 if (tmp)
00288 {
00289 col->SetStorage(tmp);
00290 col->SetSize(tmp->CH());
00291 }
00292 }
00293 #endif // REPOSITORY_USED
00294
00295 }
00296 }
00297 }
00298
00299 #endif