Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

Read.h

Go to the documentation of this file.
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     // ignore: column is empty
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     // ignore: column is empty
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         delete tmp;
00048     }
00049 }
00050 
00051 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00052 inline void
00053 Read(ColumnTem<Int32>* col, String fileName, Util::Database* db)
00054 {
00055     Array::Array2dScalarInt32* tmp = 0;
00056     Array::ReadRaw(tmp, fileName, db);
00057     if (tmp)
00058     {
00059         col->SetData(tmp->CPB(), tmp->CW());
00060         delete tmp;
00061     }
00062 }
00063 #endif // REPOSITORY_USED
00064 
00066 
00067 inline void
00068 Read(ColumnTem<UInt64>* col, Util::IOBuffer* buffer)
00069 {
00070     Array::Array2dScalarUInt64* tmp = 0;
00071     Array::ReadRaw(tmp, buffer);
00072     if (tmp)
00073     {
00074         col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00075         delete tmp;
00076     }
00077 }
00078 
00079 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00080 inline void
00081 Read(ColumnTem<UInt64>* col, String fileName, Util::Database* db)
00082 {
00083     Array::Array2dScalarUInt64* tmp = 0;
00084     Array::ReadRaw(tmp, fileName, db);
00085     if (tmp)
00086     {
00087         col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00088         delete tmp;
00089     }
00090 }
00091 #endif // REPOSITORY_USED
00092 
00094 
00095 inline void
00096 Read(ColumnTem<Real64>* col, Util::IOBuffer* buffer)
00097 {
00098     Array::Array2dScalarReal64* tmp = 0;
00099     Array::ReadRaw(tmp, buffer);
00100     if (tmp)
00101     {
00102         col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00103         delete tmp;
00104     }
00105 }
00106 
00107 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00108 inline void
00109 Read(ColumnTem<Real64>* col, String fileName, Util::Database* db)
00110 {
00111     Array::Array2dScalarReal64* tmp = 0;
00112     Array::ReadRaw(tmp, fileName, db);
00113     if (tmp)
00114     {
00115         col->SetData(tmp->CPB(), tmp->CW()*tmp->CH());
00116         delete tmp;
00117     }
00118 }
00119 #endif // REPOSITORY_USED
00120 
00122 
00123 inline void
00124 Read(ColumnTem<String>* col, Util::IOBuffer* buffer)
00125 {
00126     if (! (buffer && buffer->Valid()))
00127     {
00128         return;
00129     }
00130     int nrElem;
00131     int byteSize;
00132     //fscanf(f.Fp(), "nr strings : %d\n", &nrElem);
00133     std::istringstream iss(buffer->ReadLine() + " 0");
00134     String dummy;
00135     iss >> dummy >> dummy >> dummy >> nrElem >> byteSize;
00136     col->Reserve(nrElem, false);
00137     String* data = col->GetData();
00138     if(byteSize > 0)
00139     {
00140         char* binaryData = new char[byteSize];
00141         buffer->Read(binaryData, byteSize);
00142         int j = 0;
00143         for (int i=0 ; i<nrElem ; i++)
00144         {
00145             int start = j;
00146             while((j<byteSize) && (binaryData[j] != '\n'))
00147                 j++;
00148             data[i] = String(&(binaryData[start]), j - start);
00149             j++;
00150         }
00151         delete binaryData;
00152     }
00153     else
00154     {
00155         for (int i=0 ; i<nrElem ; i++)
00156             data[i] = buffer->ReadLine();
00157     }
00158 }
00159 
00160 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00161 inline void
00162 Read(ColumnTem<String>* col, String fileName, Util::Database* db)
00163 {
00164     Util::IOBuffer* buf = db->GetIOBuffer(fileName, true, true, "");
00165     Read(col, buf);
00166     delete buf;
00167 }
00168 #endif // REPOSITORY_USED
00169 
00171 
00172 inline void
00173 Read(ColumnTem<Geometry::Rectangle>* col, Util::IOBuffer* buffer)
00174 {
00175     ILOG_VAR(Impala.Core.Column.Read);
00176     String s,nr;
00177     int nrElem;
00178     s=buffer->ReadLine();
00179     String subs=s.substr(0,11);
00180     if (subs=="nr rects : ")
00181     {
00182         nr=s.substr(10);
00183         std::istringstream iss(nr);
00184         iss>>nrElem;
00185         col->Reserve(nrElem, false);
00186         Geometry::Rectangle* data = col->GetData();
00187         for (int i=0 ; i<nrElem ; i++)
00188         {
00189            buffer->NativeTypeRead(&data[i].mLeft);
00190            buffer->NativeTypeRead(&data[i].mTop);
00191            buffer->NativeTypeRead(&data[i].mRight);
00192            buffer->NativeTypeRead(&data[i].mBottom);
00193         }
00194     }
00195     else
00196     {
00197         ILOG_ERROR("Parsing error");
00198     }
00199 }
00200 
00201 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00202 inline void
00203 Read(ColumnTem<Geometry::Rectangle>* col, String fileName, Util::Database* db)
00204 {
00205     ILOG_VAR(Impala.Core.Column.Read);
00206     std::ifstream f(fileName.c_str());
00207     if (!f.is_open())
00208         return;
00209     String s1,s2,s3;
00210     f >> s1 >> s2 >> s3;
00211     if (s1 == "nr" && s2 == "rects" && s3 == ":")
00212     {
00213         int nrElem;
00214         f >> nrElem;
00215         col->Reserve(nrElem, false);
00216         Geometry::Rectangle* data = col->GetData();
00217         for (int i=0 ; i<nrElem ; i++)
00218             f >> data[i];
00219     }
00220     else
00221     {
00222         ILOG_ERROR("Parsing error in " << fileName);
00223     }
00224     f.close();
00225 }
00226 #endif // REPOSITORY_USED
00227 
00229 
00230 inline void
00231 Read(Vector::VectorSet<Array::Array2dScalarInt8>* col, Util::IOBuffer* buffer)
00232 {
00233     // todo: only works for set with constVecSize and is a dirty hack
00234     Array::Array2dScalarInt8* tmp = 0;
00235     Array::ReadRaw(tmp, buffer);
00236     if (tmp)
00237     {
00238         col->SetStorage(tmp);
00239         col->SetSize(tmp->CH());
00240     }
00241 }
00242 
00243 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00244 inline void
00245 Read(Vector::VectorSet<Array::Array2dScalarInt8>* col, String fileName,
00246      Util::Database* db)
00247 {
00248     // todo: only works for set with constVecSize and is a dirty hack
00249     Array::Array2dScalarInt8* tmp = 0;
00250     Array::ReadRaw(tmp, fileName, db);
00251     if (tmp)
00252     {
00253         col->SetStorage(tmp);
00254         col->SetSize(tmp->CH());
00255     }
00256 }
00257 #endif // REPOSITORY_USED
00258 
00260 
00261 inline void
00262 Read(Vector::VectorSet<Array::Array2dScalarReal64>* col, Util::IOBuffer* buffer)
00263 {
00264     // todo: only works for set with constVecSize and is a dirty hack
00265     Array::Array2dScalarReal64* tmp = 0;
00266     Array::ReadRaw(tmp, buffer);
00267     if (tmp)
00268     {
00269         col->SetStorage(tmp);
00270         col->SetSize(tmp->CH());
00271     }
00272 }
00273 
00274 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00275 inline void
00276 Read(Vector::VectorSet<Array::Array2dScalarReal64>* col, String fileName,
00277      Util::Database* db)
00278 {
00279     // todo: only works for set with constVecSize and is a dirty hack
00280     Array::Array2dScalarReal64* tmp = 0;
00281     Array::ReadRaw(tmp, fileName, db);
00282     if (tmp)
00283     {
00284         col->SetStorage(tmp);
00285         col->SetSize(tmp->CH());
00286     }
00287 }
00288 #endif // REPOSITORY_USED
00289 
00290 } // namespace Column
00291 } // namespace Core
00292 } // namespace Impala
00293 
00294 #endif

Generated on Thu Jan 13 09:04:23 2011 for ImpalaSrc by  doxygen 1.5.1