00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _LTI_STL_IO_INTERFACE_H_
00034 #define _LTI_STL_IO_INTERFACE_H_
00035
00036 #include "ltiIoHandler.h"
00037 #include <list>
00038 #include <vector>
00039 #include <map>
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 namespace lti {
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 template<class T,class U>
00081 bool read(ioHandler& handler,std::pair<T,U>& data,const bool complete=true) {
00082 bool b = true;
00083
00084 if (complete) {
00085 b = handler.readBegin();
00086 }
00087
00088 b = b && lti::read(handler,data.first);
00089 b = b && handler.readDataSeparator();
00090 b = b && lti::read(handler,data.second);
00091
00092 if (complete) {
00093 b = b && handler.readEnd();
00094 }
00095
00096 return b;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106 template<class T,class U>
00107 bool write(ioHandler& handler,const std::pair<T,U>& data,
00108 const bool complete=true){
00109 bool b = true;
00110
00111 if (complete) {
00112 b = handler.writeBegin();
00113 }
00114
00115 b = b && lti::write(handler,data.first);
00116 b = b && handler.writeDataSeparator();
00117 b = b && lti::write(handler,data.second);
00118
00119 if (complete) {
00120 b = b && handler.writeEnd();
00121 }
00122
00123 return b;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 template <class T>
00138 bool read(ioHandler& handler,std::list<T>& data,const bool complete=true) {
00139 int i,size;
00140 bool b = true;
00141
00142 if (complete) {
00143 b = handler.readBegin();
00144 }
00145
00146 b = b && handler.read("size",size);
00147 std::string str;
00148
00149 int level = handler.getLevel();
00150
00151 b = b && handler.readBegin();
00152 b = b && handler.readSymbol(str);
00153
00154 if (str == "data") {
00155 b = b && handler.readKeyValueSeparator();
00156 b = b && handler.readBegin();
00157 data.clear();
00158 if (size > 0) {
00159 size--;
00160 T tmp;
00161 for (i=0;i<size;++i) {
00162 b = b && read(handler,tmp);
00163 data.push_back(tmp);
00164 b = b && handler.readDataSeparator();
00165 }
00166 b = b && read(handler,tmp);
00167 data.push_back(tmp);
00168 }
00169 }
00170
00171
00172 while (handler.readEnd() && (handler.getLevel() > level));
00173
00174 if (complete) {
00175 b = b && handler.readEnd();
00176 }
00177 return b;
00178 }
00179
00180
00181
00182
00183
00184
00185 template <class T>
00186 bool write(ioHandler& handler,
00187 const std::list<T>& data,
00188 const bool complete=true) {
00189 int i;
00190 const int theSize = static_cast<int>(data.size());
00191 bool b = true;
00192
00193 if (complete) {
00194 b = handler.writeBegin();
00195 }
00196
00197 b = b && handler.write("size",theSize);
00198
00199 b = b && handler.writeBegin();
00200 b = b && handler.writeSymbol(std::string("data"));
00201 b = b && handler.writeKeyValueSeparator();
00202 b = b && handler.writeBegin();
00203 if (theSize > 0) {
00204 typename std::list<T>::const_iterator it;
00205
00206
00207 for (i=1,it=data.begin();i<theSize;++it,++i) {
00208 b = b && write(handler,(*it));
00209 b = b && handler.writeDataSeparator();
00210 }
00211 b = b && write(handler,(*it));
00212 }
00213 b = b && handler.writeEnd();
00214 b = b && handler.writeEnd();
00215
00216 if (complete) {
00217 b = b && handler.writeEnd();
00218 }
00219
00220 return b;
00221 }
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 template <class T>
00234 bool read(ioHandler& handler,
00235 std::vector<T>& data,
00236 const bool complete=true) {
00237
00238 int i,size;
00239 bool b = true;
00240
00241 if (complete) {
00242 b = handler.readBegin();
00243 }
00244
00245 b = b && handler.read("size",size);
00246 std::string str;
00247
00248 int level = handler.getLevel();
00249
00250 b = b && handler.readBegin();
00251 b = b && handler.readSymbol(str);
00252
00253 if (str == "data") {
00254 b = b && handler.readKeyValueSeparator();
00255 b = b && handler.readBegin();
00256 data.resize(size);
00257 if (size > 0) {
00258 size--;
00259 for (i=0;i<size;++i) {
00260 b = b && read(handler,data[i]);
00261 b = b && handler.readDataSeparator();
00262 }
00263 b = b && read(handler,data[i]);
00264 }
00265 }
00266
00267
00268 while (handler.readEnd() && (handler.getLevel() > level));
00269
00270 if (complete) {
00271 b = b && handler.readEnd();
00272 }
00273
00274 return b;
00275 }
00276
00277
00278
00279
00280
00281
00282 template <class T>
00283 bool write(ioHandler& handler,
00284 const std::vector<T>& data,
00285 const bool complete=true) {
00286 int i;
00287 const int theSize = static_cast<int>(data.size());
00288 bool b = true;
00289
00290 if (complete) {
00291 b = handler.writeBegin();
00292 }
00293
00294 b = b && handler.write("size",theSize);
00295
00296 b = b && handler.writeBegin();
00297 b = b && handler.writeSymbol(std::string("data"));
00298 b = b && handler.writeKeyValueSeparator();
00299 b = b && handler.writeBegin();
00300 if (theSize > 0) {
00301 typename std::vector<T>::const_iterator it;
00302
00303
00304 for (i=1,it=data.begin();i<theSize;++it,++i) {
00305 b = b && write(handler,(*it));
00306 b = b && handler.writeDataSeparator();
00307 }
00308 b = b && write(handler,(*it));
00309 }
00310 b = b && handler.writeEnd();
00311 b = b && handler.writeEnd();
00312
00313 if (complete) {
00314 b = b && handler.writeEnd();
00315 }
00316
00317 return b;
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 template <class T,class U>
00332 bool read(ioHandler& handler,std::map<T,U>& data,const bool complete=true) {
00333 int i,size;
00334 bool b = true;
00335
00336 if (complete) {
00337 b = handler.readBegin();
00338 }
00339
00340 b = b && handler.read("size",size);
00341 std::string str;
00342
00343 int level = handler.getLevel();
00344
00345 b = b && handler.readBegin();
00346 b = b && handler.readSymbol(str);
00347
00348 if (str == "data") {
00349 b = b && handler.readKeyValueSeparator();
00350 b = b && handler.readBegin();
00351 data.clear();
00352 if (size > 0) {
00353 size--;
00354 std::pair<T,U> tmp;
00355 for (i=0;i<size;++i) {
00356 b = b && read(handler,tmp);
00357 data.insert(tmp);
00358 b = b && handler.readDataSeparator();
00359 }
00360 b = b && read(handler,tmp);
00361 data.insert(tmp);
00362 }
00363 }
00364
00365
00366 while (handler.readEnd() && (handler.getLevel() > level));
00367
00368 if (complete) {
00369 b = b && handler.readEnd();
00370 }
00371 return b;
00372 }
00373
00374
00375
00376
00377
00378
00379 template <class T,class U>
00380 bool write(ioHandler& handler,
00381 const std::map<T,U>& data,
00382 const bool complete=true) {
00383 int i;
00384 const int theSize = static_cast<int>(data.size());
00385 bool b = true;
00386
00387 if (complete) {
00388 b = handler.writeBegin();
00389 }
00390
00391 b = b && handler.write("size",theSize);
00392
00393 b = b && handler.writeBegin();
00394 b = b && handler.writeSymbol(std::string("data"));
00395 b = b && handler.writeKeyValueSeparator();
00396 b = b && handler.writeBegin();
00397 if (theSize > 0) {
00398 typename std::map<T,U>::const_iterator it;
00399
00400
00401 for (i=1,it=data.begin();i<theSize;++it,++i) {
00402 b = b && write(handler,(*it));
00403 b = b && handler.writeDataSeparator();
00404 }
00405 b = b && write(handler,(*it));
00406 }
00407 b = b && handler.writeEnd();
00408 b = b && handler.writeEnd();
00409
00410 if (complete) {
00411 b = b && handler.writeEnd();
00412 }
00413
00414 return b;
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 template <class T,class U>
00429 bool read(ioHandler& handler,std::multimap<T,U>& data,
00430 const bool complete=true) {
00431 int i,size;
00432 bool b = true;
00433
00434 if (complete) {
00435 b = handler.readBegin();
00436 }
00437
00438 b = b && handler.read("size",size);
00439 std::string str;
00440
00441 int level = handler.getLevel();
00442
00443 b = b && handler.readBegin();
00444 b = b && handler.readSymbol(str);
00445
00446 if (str == "data") {
00447 b = b && handler.readKeyValueSeparator();
00448 b = b && handler.readBegin();
00449 data.clear();
00450 if (size > 0) {
00451 size--;
00452 std::pair<T,U> tmp;
00453 for (i=0;i<size;++i) {
00454 b = b && read(handler,tmp);
00455 data.insert(tmp);
00456 b = b && handler.readDataSeparator();
00457 }
00458 b = b && read(handler,tmp);
00459 data.insert(tmp);
00460 }
00461 }
00462
00463
00464 while (handler.readEnd() && (handler.getLevel() > level));
00465
00466 if (complete) {
00467 b = b && handler.readEnd();
00468 }
00469 return b;
00470 }
00471
00472
00473
00474
00475
00476
00477 template <class T,class U>
00478 bool write(ioHandler& handler,const std::multimap<T,U>& data,
00479 const bool complete=true) {
00480 int i;
00481 const int theSize = data.size();
00482 bool b = true;
00483
00484 if (complete) {
00485 b = handler.writeBegin();
00486 }
00487
00488 b = b && handler.write("size",theSize);
00489
00490 b = b && handler.writeBegin();
00491 b = b && handler.writeSymbol(std::string("data"));
00492 b = b && handler.writeKeyValueSeparator();
00493 b = b && handler.writeBegin();
00494 if (theSize > 0) {
00495 typename std::map<T,U>::const_iterator it;
00496
00497
00498 for (i=1,it=data.begin();i<theSize;++it,++i) {
00499 b = b && write(handler,(*it));
00500 b = b && handler.writeDataSeparator();
00501 }
00502 b = b && write(handler,(*it));
00503 }
00504 b = b && handler.writeEnd();
00505 b = b && handler.writeEnd();
00506
00507 if (complete) {
00508 b = b && handler.writeEnd();
00509 }
00510
00511 return b;
00512 }
00513
00514
00515 }
00516
00517 #endif