00001 #ifndef Impala_Core_Column_Write_h
00002 #define Impala_Core_Column_Write_h
00003
00004 #include <fstream>
00005 #include "Util/Database.h"
00006 #include "Core/Geometry/Rectangle.h"
00007 #include "Core/Array/Arrays.h"
00008 #include "Core/Column/ColumnTem.h"
00009 #include "Core/Column/InvalidColumn.h"
00010 #include "Core/Vector/VectorSet.h"
00011 #include "Core/Array/WriteRaw.h"
00012
00013 namespace Impala
00014 {
00015 namespace Core
00016 {
00017 namespace Column
00018 {
00019
00020
00021 inline void
00022 Write(InvalidColumn* col, int nrElem, Util::IOBuffer* buf, bool binary)
00023 {
00024
00025 }
00026
00027 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00028 inline void
00029 Write(InvalidColumn* col, int nrElem, String fileName, Util::Database* db,
00030 bool binary)
00031 {
00032
00033 }
00034 #endif // REPOSITORY_USED
00035
00037
00038 inline void
00039 Write(ColumnTem<Int32>* col, int nrElem, Util::IOBuffer* buf, bool binary)
00040 {
00041 Array::Array2dScalarInt32 wrapper(nrElem, 1, 0, 0, col->GetData(), true);
00042 Array::WriteRaw(&wrapper, buf, binary);
00043 }
00044
00045 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00046 inline void
00047 Write(ColumnTem<Int32>* col, int nrElem, String fileName, Util::Database* db,
00048 bool binary)
00049 {
00050 Array::Array2dScalarInt32 wrapper(nrElem, 1, 0, 0, col->GetData(), true);
00051 Array::WriteRaw(&wrapper, fileName, db, binary);
00052 }
00053 #endif // REPOSITORY_USED
00054
00056
00057 inline void
00058 Write(ColumnTem<UInt64>* col, int nrElem, Util::IOBuffer* buf, bool binary)
00059 {
00060 Array::Array2dScalarUInt64 wrapper(nrElem, 1, 0, 0, col->GetData(), true);
00061 Array::WriteRaw(&wrapper, buf, binary);
00062 }
00063
00064 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00065 inline void
00066 Write(ColumnTem<UInt64>* col, int nrElem, String fileName, Util::Database* db,
00067 bool binary)
00068 {
00069 Array::Array2dScalarUInt64 wrapper(nrElem, 1, 0, 0, col->GetData(), true);
00070 Array::WriteRaw(&wrapper, fileName, db, binary);
00071 }
00072 #endif // REPOSITORY_USED
00073
00075
00076 inline void
00077 Write(ColumnTem<Real64>* col, int nrElem, Util::IOBuffer* buf, bool binary)
00078 {
00079 Array::Array2dScalarReal64 wrapper(nrElem, 1, 0, 0, col->GetData(), true);
00080 Array::WriteRaw(&wrapper, buf, binary);
00081 }
00082
00083 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00084 inline void
00085 Write(ColumnTem<Real64>* col, int nrElem, String fileName, Util::Database* db,
00086 bool binary)
00087 {
00088 Array::Array2dScalarReal64 wrapper(nrElem, 1, 0, 0, col->GetData(), true);
00089 Array::WriteRaw(&wrapper, fileName, db, binary);
00090 }
00091 #endif // REPOSITORY_USED
00092
00094
00095 inline void
00096 Write(ColumnTem<String>* col, int nrElem, Util::IOBuffer* buf, bool binary)
00097 {
00098 if (! (buf && buf->Valid()))
00099 {
00100 return;
00101 }
00102 String* data = col->GetData();
00103 int byteSize = nrElem;
00104 for (int i=0 ; i<nrElem ; i++) byteSize += data[i].size();
00105 buf->Puts("nr strings : " + MakeString(nrElem) + " " +
00106 MakeString(byteSize));
00107 for (int i=0 ; i<nrElem ; i++)
00108
00109 buf->Puts(data[i]);
00110 }
00111
00112 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00113 inline void
00114 Write(ColumnTem<String>* col, int nrElem, String fileName, Util::Database* db,
00115 bool binary)
00116 {
00117 Util::IOBuffer* buf = db->GetIOBuffer(fileName, false, false, "tmp");
00118 if (! buf)
00119 {
00120 delete buf;
00121 return;
00122 }
00123 Write(col, nrElem, buf, binary);
00124 delete buf;
00125 }
00126 #endif // REPOSITORY_USED
00127
00129
00130 inline void
00131 Write(ColumnTem<Geometry::Rectangle>* col, int nrElem, Util::IOBuffer* buf,
00132 bool binary)
00133 {
00134 if (! (buf && buf->Valid()))
00135 {
00136 return;
00137 }
00138
00139 buf->Write("nr rects : ",11);
00140 buf->NativeTypeWrite(nrElem);
00141 buf->Puts("");
00142 Geometry::Rectangle* data = col->GetData();
00143 for (int i=0 ; i<nrElem ; i++)
00144 {
00145 buf->NativeTypeWrite(data[i].mLeft);
00146 buf->NativeTypeWrite(data[i].mTop);
00147 buf->NativeTypeWrite(data[i].mRight);
00148 buf->NativeTypeWrite(data[i].mBottom);
00149 buf->Puts("");
00150 }
00151 }
00152
00153 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00154 inline void
00155 Write(ColumnTem<Geometry::Rectangle>* col, int nrElem, String fileName,
00156 Util::Database* db, bool binary)
00157 {
00158 std::ofstream f(fileName.c_str());
00159 if (!f.is_open())
00160 return;
00161 f << "nr rects : " << nrElem << "\n";
00162 Geometry::Rectangle* data = col->GetData();
00163 for (int i=0 ; i<nrElem ; i++)
00164 f << data[i] << "\n";
00165 f.close();
00166 }
00167 #endif // REPOSITORY_USED
00168
00170
00171 inline void
00172 Write(Vector::VectorSet<Array::Array2dScalarInt8>* col, int nrElem,
00173 Util::IOBuffer* buf, bool binary)
00174 {
00175
00176 Array::Array2dScalarInt8* data = col->GetStorage();
00177 Array::Array2dScalarInt8 wrapper(data->CW(), nrElem, 0, 0, data->PB(),
00178 true);
00179 Array::WriteRaw(&wrapper, buf, binary);
00180 }
00181
00182 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00183 inline void
00184 Write(Vector::VectorSet<Array::Array2dScalarInt8>* col, int nrElem,
00185 String fileName, Util::Database* db, bool binary)
00186 {
00187
00188 Array::Array2dScalarInt8* data = col->GetStorage();
00189 Array::Array2dScalarInt8 wrapper(data->CW(), nrElem, 0, 0, data->PB(),
00190 true);
00191 Array::WriteRaw(&wrapper, fileName, db, binary);
00192 }
00193 #endif // REPOSITORY_USED
00194
00196
00197 inline void
00198 Write(Vector::VectorSet<Array::Array2dScalarReal64>* col, int nrElem,
00199 Util::IOBuffer* buf, bool binary)
00200 {
00201
00202 Array::Array2dScalarReal64* data = col->GetStorage();
00203 Array::Array2dScalarReal64 wrapper(data->CW(), nrElem, 0, 0, data->PB(),
00204 true);
00205 Array::WriteRaw(&wrapper, buf, binary);
00206 }
00207
00208 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00209 inline void
00210 Write(Vector::VectorSet<Array::Array2dScalarReal64>* col, int nrElem,
00211 String fileName, Util::Database* db, bool binary)
00212 {
00213
00214 Array::Array2dScalarReal64* data = col->GetStorage();
00215 Array::Array2dScalarReal64 wrapper(data->CW(), nrElem, 0, 0, data->PB(),
00216 true);
00217 Array::WriteRaw(&wrapper, fileName, db, binary);
00218 }
00219 #endif // REPOSITORY_USED
00220
00221
00222 }
00223 }
00224 }
00225
00226 #endif