Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

dataio.h

Go to the documentation of this file.
00001 
00002 // dataio 0.5 (beta) - Copyright (C) 2001, by Sadao Massago              //
00003 // file: dataio.h (dataio header file)                                   //
00004 // requires: stringutil.h                                                //
00005 // ----------------------------------------------------------------------//
00006 // The dataio library and related files is licenced under the term of    //
00007 // GNU Lesser General Public License version 2.1 or latter               //
00008 // (see lesser.txt for detail).                                          //
00009 // For information over GNU or GNU compatible license, visit the site    //
00010 // http://www.gnu.org.                                                   //
00012 
00014 // javadoc style documentation in way to generate class documentation   //
00015 // using GNU GPL licensed doxygen utility. For doxygen, see the         //
00016 // http://www.doxygen.org                                               //
00018 
00020 // TO DEVELOPER: Caution for using template class.
00021 // The inline methods will not speciallyzed correctly
00022 // (if split into two files, each of one generate one and can not link it)
00023 // Thus, all of methos that will specialize, use as non inline version
00024 // (define outside of class) independent of their code size (one line, for example)
00025 // !!!
00027 
00028 #ifndef  _DATAIO_H_
00029 // #ifdef __cplusplus
00030 #define _DATAIO_H_
00031 
00032 
00033 #ifndef DOXYGEN_SHOULD_SKIP_THIS // doxygen skip this...
00034 
00035 // #define _DEBUG_
00036 
00037 #ifdef _DEBUG_ // _DEBUG_ activate debugging mod for this...
00038    #define _DATAIODEBUG_
00039 #endif
00040 
00041 // #define _DATAIONOMESSAGE_ // if error occur, do not emit error message 
00042 // #define _DATAIONOTHROW_ // (don't throw exception)
00043 
00044 // #ifdef _DATAIODEBUG_ // in debug mode, activate message
00045 //   #undef _DATAIONOMESSAGE_ // if error occur, do not emit error message 
00046 // #endif
00047 
00048 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS // doxygen skip this...
00049 
00050 // defining group for dataio (for doxygen)
00051 // need only if want to list in module section.
00052 // doxygen bug???: it make the template class member listed as public functions???
00053 // there are member itemtostring() and stringtoitem() of _dataiorec
00054 // template class
00055 
00056 // for dxygen usage only (skip or not some part of code)
00057 // use: PREDEFINED = DOXYGEN_SHOULD_SKIP_THIS in doxygen config file
00058 
00060 // starting group (for doxygen)
00064 
00065 #define _DATAIODEFAULTCOLUMNSEPARATOR '\t'
00070 #define  _DATAIODEFAULTAUTOLINESEPARATOR '\0'
00071 
00072 #define _DATAIODEFAULTLINESEPARATOR  _DATAIODEFAULTAUTOLINESEPARATOR
00078 #define _DATAIODEFAULTATTRIBSEPARATOR '\0'
00079 
00080 #define _DATAIODEFAULTDECIMAL         '.'
00081 
00082 #define _DATAIODEFAULTIGNORECASE      false
00083 
00084 #define _DATAIODEFAULTCOMMENTLINE     "//"
00085 
00086 #define _DATAIODEFAULTCOMMENTOPEN     "/*" 
00088 #define _DATAIODEFAULTCOMMENTCLOSE    "*/"
00089 
00091 #define _DATAIODEFAULTSTDCOMMENTOPEN     "/*" 
00093 #define _DATAIODEFAULTSTDCOMMENTCLOSE    "*/"
00094 
00096 #define _DATAIODEFAULTLINEWRAP     ""
00100 #define _DATAIODEFAULTMAXCOLUMNONLINE  (~0U)
00101 
00102 #define _DATAIODEFAULTCOLUMNORIENTED  false
00103 
00104 #define _DATAIODEFAULTISTABLE         false
00105 
00106 #define _DATAIODEFAULTEMPTYISVALID    true
00107 
00108 #define _DATAIODEFAULTEXTENDEDMODE    true
00109 // / default value of mapflagstomember flag (the flag is applied inside their membes)
00110 // #define _DATAIODEFAULTMAPFLAGSTOMEMBER    true
00111 // / default value of includemapflagstomemberflag parameter in the 
00112 // / calling of mapflagstomember()
00113 // #define _DATAIODEFAULTINCLUDEMAPFLAGSTOMEMBERFLAG true
00115 #define _DATAIODEFAULTVALIDATEALL    true
00116 
00118 #define  _DATAIODEFAULTCLEAREMPTYTAIL true
00119 
00120 #define _DATAIODEFAULTSTRINGDELIMITER    '\"'
00121 
00122 #define _DATAIODEFAULTSCAPECHAR    '\0'
00123 
00125 #define _DATAIODEFAULTTHROWEXCEPTION   false
00126 
00127 #define _DATAIODEFAULTPRINTERROR   true
00128 
00129 
00132 #define _DATAIODEFAULTCOLLECTNAMES  true
00133 
00134 #define _DATAIODEFAULTPARSEALLINPUTSTRING false
00135 
00137 #define _DATAIODEFAULTSECTIONNAMEOPEN '\0' /* '[' */
00138 
00139 #define _DATAIODEFAULTSECTIONNAMECLOSE '\0' /* ']' */
00140 
00142 #define _DATAIODEFAULTSTDSECTIONNAMEOPEN '['
00143 
00144 #define _DATAIODEFAULTSTDSECTIONNAMECLOSE ']'
00145 
00148 #define _DATAIODEFAULTREVERSEBYTEORDER false
00149 
00150 // for boolean recognition
00153 #define _DATAIODEFAULTYESLIST {"true", "on", "yes", 0} // null terminated list
00156 #define _DATAIODEFAULTNOLIST {"false", "off", "no", 0} // null terminated list
00158 #define _DATAIODEFAULTYESVALUE "yes"
00160 #define _DATAIODEFAULTNOVALUE "no"
00161 
00162 
00164 // For developer (caution):
00165 // will not use inline methods (defined inside of class, or specified by inline)
00166 // for specialized methods (define special handle for some T)
00167 // it cause linking problem for multiple file modules
00168 // it's can not find symbol (it defined only on one file)
00169 // ir duplicate symbol (if defined on more one files)
00171 // Does not know how to solve this problem, without using non inline versions.
00172 // Thus, all method that pretend specialize in future, use
00173 // non inline version.
00174 //
00175 // In this module, several small methods of _dataiorec
00176 // such as ignorecase, decimal, itentostring, stringtoitem
00177 // are  defined as non inline
00178 // because use some specilization for dataio class:
00179 // Do not try to define theses (and other specialized method)
00180 // as inline version!!
00182 
00183 // #define MAXUINT ((unsigned) ~0)
00184 
00185 #include <string>
00186 #include <iostream>
00187 #include <strstream>
00188 #include <vector>
00189 #include <errno.h> // for C routine error handle
00190 
00191 // to use parsestring()
00192 // in debug mode, use putline too??
00193 #include "stringutil.h" 
00194 
00195 
00197 // dataio class
00199 // forward definition
00200    class dataio;
00201 
00204    class _dataiorecbase {
00205    
00206    // Atributes and member of this class does not documentes
00207    // to doxygen skip this for documentation
00208    #ifndef DOXYGEN_SHOULD_SKIP_THIS
00209    protected:
00210       void *var; // used by dataio
00211       unsigned dim;
00212       unsigned long *size1, *size2, *strsize;
00213       vector <vector <string> > datalist; // used by getvalue
00214       vector <string> commentlist; // item comment list
00215       bool valuesetted; // true if value is setted
00216       // it will deleted, if change setvalue.
00217       // bool columnoriented; // used only by dataio
00218       // dataio that include this
00219       dataio *base;
00220       // char decimalchar; // used by _dataiorec members: stringtoitem and itemtostring
00221       // char stringdelimiterchar; // used by _dataiorec members: stringtoitem and itemtostring
00222       // bool emptyisvaliddata; // used by _dataiorec members: stringtoitem and itemtostring
00223       string name;
00224       // to check if is dataio member
00225       // used only by dataio to detect if the member is dataio type
00226       // if it is true, will overrride several parameter settings, as
00227       // decimal, ignorecase, commentopen, commentclose, etc.
00228       // used only to make prety print of sectioned data
00229       // mixed by non sectioned data
00230       bool isdataio;
00231       // long int read/writer to read/write size of vector
00232       static bool readsize(istream &is, unsigned long int &n, bool reverseorder);
00233       static void writesize(ostream &os, unsigned long int n, bool reverseorder);
00234       // used by setvalue/read
00235       virtual void clearitemvalue(){}
00236       virtual void addrowtoitemvalue(){}
00237       // used by setvalue
00238       virtual bool addtoitemvalue(string &s){return false;}
00239       // used by read
00240       virtual bool readtoitemvalue(istream &is){return false;}
00241       // used to getvalue/write
00242       virtual unsigned long getitemrownumber(){return 1;}
00243       virtual unsigned long getitemlistsize(unsigned long i) {return 1;}
00244       // used by getvalue
00245       virtual void getstringvalue(string &s, unsigned long i, unsigned long j){}
00246       // used by write
00247       virtual void writeitemvalue(ostream &os, unsigned long i, unsigned long j){}
00248    public:
00249       void setvalue(vector <vector <string> > &valuelist);
00250       // {  blockcount++;}
00251       vector <vector <string> > &getvalue(bool includecomment);
00252       // {    return datalist;    }
00253       // binary input/output
00254       istream &read(istream &is);
00255       ostream &write(ostream &os);
00256       unsigned blockcount; // to count number of inputed block
00257       // multiple block data: prepare next output block
00258       // only for named data
00259       // virtual void startinblock(unsigned i){return true;}  // used only for dataio
00260       virtual void startinblock(unsigned i);
00261       // used only for dataio
00262       // virtual bool nextinblock(){return true;}  // used only for dataio
00263       // method for data validator calling.
00264       void validate();  // used only for dataio
00265       // method for multi block out put. It will implemented
00266       // to make adjust in end of readding.
00267       // For exaple, will initialize unread variable, or make data range cheking...
00268       // n is number of readded block
00269       virtual bool startoutblock(unsigned i);
00270       //{ return (i==0);}
00271       // used only by dataio to detect if the member is dataio type
00272       // if it is true, will overrride several parameter settings, as
00273       // decimal, ignorecase, commentopen, commentclose, etc.
00274       // used only to make prety print of sectioned data
00275       // ixed by non sectioned data
00276    
00277 
00278       // empty member
00279       _dataiorecbase(){
00280          dim = 0; base = 0; var = 0; size1 = size2 = strsize = 0;
00281          valuesetted = isdataio = false; blockcount = 0;
00282       } 
00283 
00284       // dataio member  
00285       _dataiorecbase(dataio *_base, string const &_name, dataio *_var){
00286          dim = 0;  base = _base; name = _name; var = _var; 
00287          size1 = size2 = strsize = 0; blockcount = 0;
00288          valuesetted = false;
00289          isdataio = true;
00290       } 
00291 
00292       // 0 dimensional member
00293       _dataiorecbase(dataio *_base, string const &_name, void * _var, unsigned long *_strsize){
00294          dim = 0;  base = _base; name = _name; var = _var; 
00295          size1 = size2 = 0; strsize = _strsize;
00296          valuesetted = isdataio = false; blockcount = 0;
00297       } 
00298 
00299       // 1 dimensional member
00300       _dataiorecbase(dataio *_base, string const &_name, void * _var, unsigned long *_size1, unsigned long *_strsize){
00301          dim = 1; base = _base; name = _name; var = _var; 
00302          size1 = _size1;
00303          size2 = 0; strsize = _strsize;
00304          valuesetted = isdataio = false; blockcount = 0;
00305       } 
00306 
00307       // 2 dimensional member
00308       _dataiorecbase(dataio *_base, string const &_name, void * _var, unsigned long *_size1, 
00309                              unsigned long *_size2, unsigned long *_strsize){
00310          dim = 2; base = _base; name = _name; var = _var; 
00311          size1 = _size1;
00312          size2 = _size2; strsize = _strsize;
00313          valuesetted = isdataio = false; blockcount = 0;
00314       } 
00315 
00316       // empty destructor
00317       virtual ~_dataiorecbase(){
00318       }
00319       // friend class
00320       friend dataio;
00321       // to acess the name
00322       friend istream &operator>>(istream &is, dataio &data);
00323       friend ostream &operator<<(ostream &os, dataio &data);
00324    
00325    // to doxygen skip this for documentation
00326    #endif //#ifndef DOXYGEN_SHOULD_SKIP_THIS
00327    }; // _dataiorecbase
00328 
00337    template <class T>
00338    class _dataiorec : public _dataiorecbase {
00339    // most of atributes and member of this class does not documentes
00340    // to doxygen skip this for documentation
00341    #ifndef DOXYGEN_SHOULD_SKIP_THIS
00342       // used by setvalue/read
00343       void clearitemvalue()
00344       {if(dim == 1) ((vector <T> *)var)->clear();
00345        else if(dim == 2) ((vector <vector <T> > *)var)->clear(); }
00346       void addrowtoitemvalue()
00347       { if(dim == 2) ((vector <vector <T> >*)var)->push_back(vector <T>());}
00348       bool addtoitemvalue(string &s)
00349       {  bool status;
00350          T itemvalue; 
00351          if(dim ==0) {
00352             #ifdef _DATAIODEBUG_
00353                 cout << "addtoitemvalue:value = ";
00354                 cout << *(T *)var << endl;
00355             #endif
00356             status = stringtoitem(s, *((T *)var));
00357          }
00358          else if(dim == 1) {
00359             status = stringtoitem(s, itemvalue);
00360             ((vector <T>*)var)->push_back(itemvalue);       
00361          } 
00362          else {
00363            status = stringtoitem(s, itemvalue);  
00364            (*(vector <vector <T> >*)var)[((vector <vector <T> >*)var)->size()-1].push_back(itemvalue);      
00365         }
00366         return status;
00367       }
00368 
00369       // used by read
00370       bool readtoitemvalue(istream &is)
00371       {  bool status;
00372          T itemvalue; 
00373          if(dim ==0)
00374             status = readitem(is, *(T *)var);
00375          else if(dim == 1) {
00376             status = readitem(is, itemvalue);
00377             ((vector <T>*)var)->push_back(itemvalue);       
00378          } 
00379          else {
00380            status = readitem(is, itemvalue);  
00381            (*(vector <vector <T> >*)var)[((vector <vector <T> >*)var)->size()-1].push_back(itemvalue);      
00382         }
00383         return status;
00384       }
00385 
00386       // used by getvalue/write
00387       unsigned long getitemrownumber()
00388       {   // if(dim == 1)
00389           //   return ((vector <T> *)var)->size();
00390           // else 
00391           if(dim == 2)
00392              return ((vector <vector <T> >*)var)->size();
00393           return 1;
00394       }
00395       unsigned long getitemlistsize(unsigned long i)
00396       {
00397           if(dim == 1)
00398                return ((vector <T> *)var)->size();
00399           else if((dim == 2) && (i < (*(vector <vector <T> >*)var).size()))
00400                return (*(vector <vector <T> >*)var)[i].size();
00401           return 1; 
00402       }
00403       // used by getvalue
00404       void getstringvalue(string &s, unsigned long i, unsigned long j)
00405       {
00406           if(dim == 0) itemtostring(*(T *)var, s);
00407           else if((dim == 1) && (i < (*(vector <T> *)var).size()))
00408                itemtostring((*(vector <T> *)var)[i], s);
00409           else if((dim == 2) && (i < (*(vector <vector <T> >*)var).size())
00410                              && (j < (*(vector <vector <T> >*)var)[i].size()))
00411                itemtostring((*(vector <vector <T> >*)var)[i][j], s);
00412           else s.erase();          
00413       }
00414       // used by write
00415       void writeitemvalue(ostream &os, unsigned long i, unsigned long j)
00416       {
00417           if(dim == 0) writeitem(os, *(T *)var);
00418           else if((dim == 1) && (i < (*(vector <T> *)var).size()))
00419                writeitem(os, (*(vector <T> *)var)[i]);
00420           else if((dim == 2) && (i < (*(vector <vector <T> >*)var).size())
00421                              && (j < (*(vector <vector <T> >*)var)[i].size()))
00422                writeitem(os, (*(vector <vector <T> >*)var)[i][j]);
00423       }
00424       // virtual bool additemvalue(string &s)
00425       // {return stringtoitem(s, *(T *)item);}
00426       // virtual void itemvaluetostring(void *item, string &s)
00427       // {itemtostring(*(T *)item, s);}
00428       
00429    public:
00430       // void startinblock(unsigned i);
00431       // void validate();
00432       // bool startoutblock(unsigned i);
00433 
00434       _dataiorec(dataio *_base, string const &_name, dataio *item) :
00435              _dataiorecbase(_base, _name, item){}
00436       _dataiorec(dataio *_base, string const &_name, T *item, unsigned long *_strsize) : 
00437              _dataiorecbase(_base, _name, item, _strsize){}
00438       _dataiorec(dataio *_base, string const &_name, vector <T> *item, 
00439              unsigned long *m, unsigned long *_strsize) :
00440              _dataiorecbase(_base, _name, item, m, _strsize){}
00441       _dataiorec(dataio *_base, string const &_name, vector <vector <T> > *item, 
00442              unsigned long *m, unsigned long *n, unsigned long *_strsize) :
00443              _dataiorecbase(_base, _name, item, m, n, _strsize){}
00444 
00445       // void setvalue(vector <vector <string> > &item);
00446       // vector <vector <string> > &getvalue(bool includecomment);
00447    
00448       // istream &read(istream &is);
00449       // ostream &write(ostream &os);
00450       // Atributes and member of this class does not documentes
00451       // to doxygen skip this for documentation
00452    #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00453    
00454    public: // arleady public, but for doxygen... (for doxygen, above public is hidden)
00455       // stringtoitem/itemtostring methods is virtual in way to add your own
00456       // if error occur, return the false
00457       // in way to obtain finally status
00458       // 
00463       bool stringtoitem(string &s, T &item);
00468       void itemtostring(T const &item, string &s);
00474       bool readitem(istream &is, T &item);
00480       void writeitem(ostream &os, T const &item);
00481 
00482       // friend dataio;
00483    }; // _dataiorec
00484 
00497    class dataio {
00498    private:
00499       vector <vector <string> > datalist; // used by getvalue()
00500       vector <string>commentlist; // comment string list.]
00501 
00502       vector <_dataiorecbase *> unnamed;
00503       vector <_dataiorecbase *> named;  
00504       vector <bool> isnamedvar; // used by binary input/output to determine order 
00505       // fstream f;
00506       // store names refered in the databese 
00507       vector <string> referednameslist;
00508       // store names that do not refered in the databese 
00509       // used by unreferednames()
00510       vector <string> unreferednameslist;
00511    
00512       // bool commentopened;
00513       bool casesensive;
00514       char decimalchar;
00516       // char stringdelimiterchar;
00517 
00518       // true if the value is setted correctly
00519       bool valuesetted;
00520       // Comment line marker.
00521       // Default is _DATAIODEFAULTCOMMENTLINE
00522       string commentlinemark; 
00523       // Comment block start marker. Ignore until commentclose occur. 
00524       // Default is _DATAIODEFAULTCOMMENTOPEN
00525       // \sa _DATAIODEFAULTCOMMENTOPEN, commentclose, commentline     
00526       string commentopenmark; 
00527       // Comment block endding marker. End the comment started by commentopen.
00528       // Default is _DATAIODEFAULTCOMMENTCLOSE
00529       // \sa _DATAIODEFAULTCOMMENTCLOSE, commentopen, commentline
00530       string commentclosemark;    
00531       // line wrap marker;
00532       string linewrapmark; 
00533       // if this flag is true, consider empty value as valid value
00534       // inside of several stringtoitem() conversion
00535       // Default is _DATAIODEFAULTEMPTYISVALID
00536       bool emptyisvaliddata;
00537       // if this flag is true, all item string is parsed in the 
00538       // input process. atenpt to evit double parsing
00539       // in the string to item...
00540       // bool parseallitemstring;
00541       // if this flag, collect refered names in the set value stage 
00542       // (inclusive in the dataio classes that is not directly loaded)
00543       bool collectreferednames;
00544       // validate unrefered member ??  
00545       bool validateunreferedmember;
00546 
00547       // if this flag is true, throw exception on error
00548       // default value is _DATAIOTHROWEXCEPTION
00549       // \sa errormessage,  _DATAIOTHROWEXCEPTION
00550       bool throwonerror;
00551       // if this flag is true, coutput error message on error
00552       // default value is _DATAIODEFAULTPRINTERROR
00553       // \sa throwexception, _DATAIODEFAULTPRINTERROR
00554       bool printerrormessage;
00555 
00556       // map recomended flags that member need to same, in way to perform i/o.
00557       // the required flags is not copied, because it will setted during i/o
00558       void maprecomendedflagsto(dataio &dest);
00559       // map minimal required flags that member need to same, in way to perform i/o.
00560       void maprequiredflagsto(dataio &dest);
00561 
00562       // map minimun required flags to their members. This flags are:
00563       // used by delimiterrecomended (for correct output):
00564       //    columnseparator, lineseparator, attribseparator,
00565       //   commentopenmark, commentclosemark, commentline, stringdelimiter, linewrap,
00566       //  
00567       void maprecomendedflagstomember();
00568       void maprequiredflagstomember();
00569       // CAUTION: no type checking!!
00570       // use isdataio() to check validate and check the i range
00571       dataio * unnamedmember(unsigned i) {return (dataio *)(unnamed[i]->var);}
00572       dataio * namedmember(unsigned i) {return (dataio *)(named[i]->var);}
00573    public:
00576       void addcomment(string const &rem) {addcommenttolist(rem, commentlist);}
00579       void clearcomment(bool includemember=false);
00583       vector <string> &comment() {return commentlist;}
00584        
00585 
00589       bool addcomment(string const &name, string const &rem);
00592       bool additemcomment(void *item, string const &rem);
00595       void clearcomment(string const &name, bool includemember=false);
00598       void clearitemcomment(void *item, bool includemember=false);
00601       void clearitemcomment(bool includemember=false);
00605       vector <string> &comment(string const &name);
00609       vector <string> &itemcomment(void *item);
00610 
00611       // comment markers
00615       string &commentline() {return commentlinemark;}
00616       string &commentline(string const &com) 
00617       {return parsestring(commentlinemark = com, stringdelimiter, scapechar);} 
00624       string &linewrap() { return linewrapmark;}; 
00625       string &linewrap(string const &wrap)
00626       {return parsestring(linewrapmark=wrap, stringdelimiter, scapechar);}
00630       unsigned maxcolumnonline;
00634       bool istable; 
00635    
00643       char sectionnameopen;
00651       char sectionnameclose; 
00656       void disablesection()
00657       { sectionnameopen = '\0';
00658         sectionnameclose = '\0';
00659       }
00663       void enablestdsection()
00664       { sectionnameopen = _DATAIODEFAULTSTDSECTIONNAMEOPEN;
00665         sectionnameclose = _DATAIODEFAULTSTDSECTIONNAMECLOSE;
00666       }
00667 
00671       bool columnoriented; 
00675       char columnseparator;
00679       char lineseparator;
00692       char attribseparator;
00698       bool extendedmode;
00702       bool clearemptytail;
00710       bool parseallinputstring;
00711 
00715       bool throwexception() {
00716         return throwonerror; }
00717       bool throwexception(bool dec, bool includemember=true);
00721       bool printerror() {
00722         return printerrormessage; }
00723       bool printerror(bool dec, bool includemember=true);
00724 
00729       bool emptyisvalid(){
00730          return emptyisvaliddata;}
00731       bool emptyisvalid(bool flag, bool includemember=true);
00732 
00733       bool ignorecase() { 
00734          return !casesensive;}  
00735 
00736 
00737 
00738       bool ignorecase(bool status, bool includemember=true);
00739       char decimal() { 
00740          return decimalchar;}  
00741 
00742 
00743 
00744       char decimal(char dec, bool includemember=true);
00745 
00749       char stringdelimiter;
00750 
00754       char scapechar;
00760 
00764       bool reversebyteorder;
00765 
00766       bool validateall() { 
00767          return validateunreferedmember;}  
00768 
00769 
00770 
00771       bool validateall(bool status, bool includemember=true);
00772    
00773       string &commentopen() { 
00774          return commentopenmark;} 
00775 
00776 
00777       // */ disapar... how to insert it on document file??
00779       string &commentopen(string const &s) {
00780          return parsestring(commentopenmark = s, stringdelimiter, scapechar);} //(s, mapthisflagstomember); }
00784    
00785       string &commentclose() { 
00786          return commentclosemark;} 
00787 
00788 
00789 
00790       string &commentclose(string const &s) {
00791          return parsestring(commentclosemark = s, stringdelimiter, scapechar);} //(s, mapthisflagstomember); }
00792       // string &commentclose(string const &s, bool includemember);
00793    
00795       void disablecommentblock()
00796       { commentopen("");
00797         commentclose("");
00798       }
00802       void enablestdcommentblock()
00803       { commentopen(_DATAIODEFAULTSTDCOMMENTOPEN);
00804         commentclose(_DATAIODEFAULTSTDCOMMENTCLOSE);
00805       }
00806       // check if the values is correctly setted (return false, if not refered in database)
00807       bool setted() { 
00808          return valuesetted;}  
00809       bool setted(string const &name); 
00810       // /< \sa refered, itemsetted, itemrefered 
00811       bool itemsetted(void *item); 
00812       // /< \sa refered, setted, itemsetted 
00813 
00814       // / CAUTION: name of this methods will change!
00815       // / \return the flag for name collector.
00816       bool collectnames() { 
00817          return collectreferednames;} 
00826       bool collectnames(bool flag, bool includemember=true);
00830       bool refered(string const &name){  
00831          string key = name;
00832          return keysearch(key, referednameslist) != referednameslist.size();} 
00836       bool itemrefered(void *item) {  
00837          return (finditem(item, unnamed) != unnamed.size()) || (finditem(item, named) != named.size()); }
00838 
00839       vector <string> &referednames(){
00840          return referednameslist;} 
00841       vector <string> &unreferednames(); 
00842    
00846       void add(string const &name, dataio *item)
00847       {  named.push_back(new _dataiorec <dataio>(this, name, item)); 
00848          // named[named.size()-1]->base = this;
00849          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
00850          #ifdef _DATAIODEBUG_
00851            cerr << "dataio::add(): adding named dataio item: " 
00852                 << named[named.size()-1]->name << endl;
00853          #endif
00854          // named[named.size()-1]->isdataio = true;
00855          item->ignorecase(!casesensive); 
00856          item->decimal(decimalchar);
00857          item->emptyisvalid(emptyisvaliddata); 
00858          item->collectnames(collectreferednames); 
00859          isnamedvar.push_back(true);
00860       }
00863       void add(dataio *item)
00864       {  unnamed.push_back(new _dataiorec <dataio>(this, "", item)); 
00865          // unnamed[unnamed.size()-1]->base = this;
00866          // unnamed[unnamed.size()-1]->isdataio = true;
00867          #ifdef _DATAIODEBUG_
00868            cerr << "dataio:add(): adding unnamed dataio item\n";
00869          #endif
00870          item->ignorecase(!casesensive);  
00871          item->decimal(decimalchar);          
00872          item->emptyisvalid(emptyisvaliddata); 
00873          item->collectnames(collectreferednames); 
00874          isnamedvar.push_back(false);
00875       }
00876 
00880       template <class T>
00881       void add(string const &name, T *item)
00882       {  named.push_back(new _dataiorec<T>(this, name, item, (unsigned long *)0)); 
00883          // named[named.size()-1]->base = this;
00884          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
00885          #ifdef _DATAIODEBUG_
00886            cerr << "dataio::add(): adding named template item:"
00887                 << named[named.size()-1]->name << endl;
00888          #endif         
00889 
00890          isnamedvar.push_back(true);
00891       }
00895       template <class T>
00896       void add(T *item)
00897       {  unnamed.push_back(new _dataiorec <T>(this, "", item, (unsigned long *)0)); 
00898          #ifdef _DATAIODEBUG_
00899            cerr << "dataio::add(): adding unnamed template item\n";
00900          #endif         // unnamed[unnamed.size()-1]->base = this;
00901          isnamedvar.push_back(false);
00902       }
00903       // one dimensional
00907       template <class T>
00908       void add(string const &name, vector <T> *item)
00909       {  named.push_back(new _dataiorec <T>(this, name, item, (unsigned long *)0, (unsigned long *)0)); 
00910          // named[named.size()-1]->base = this;
00911          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
00912          isnamedvar.push_back(true);
00913       }
00917       template <class T>
00918       void add(vector <T> *item)
00919       {  unnamed.push_back(new _dataiorec <T>(this, "", item, (unsigned long *)0, (unsigned long *)0)); 
00920          // unnamed[unnamed.size()-1]->base = this;
00921          isnamedvar.push_back(false);
00922       }
00923       // 2 dimensional
00927       template <class T>
00928       void add(string const &name, vector <vector <T> > *item)
00929       {  named.push_back(new _dataiorec <T>(this, name, item, (unsigned long *)0, (unsigned long *)0, (unsigned long *)0)); 
00930          // named[named.size()-1]->base = this;
00931          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
00932          isnamedvar.push_back(true);
00933       }
00938       template <class T>
00939       void add(vector < vector <T> > *item)
00940       {  unnamed.push_back(new _dataiorec <T>(this, "", item, (unsigned long *)0, (unsigned long *)0, (unsigned long *)0)); 
00941          // unnamed[unnamed.size()-1]->base = this;
00942          isnamedvar.push_back(false);
00943       }
00944 
00946       // for fixed size data type
00948       // The named and unnamed type is treated separatelly (using different names for 
00949       // adding methods, to solve conflict).
00962       template <class T>
00963       void addnamed(string const &name, T *item, unsigned long &strsize=*(unsigned long *)0)
00964       {  named.push_back(new _dataiorec<T>(this, name, item, &strsize)); 
00965          // named[named.size()-1]->base = this;
00966          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
00967          isnamedvar.push_back(true);
00968       }
00981       template <class T>
00982       void addunnamed(T *item, unsigned long &strsize=*(unsigned long *)0)
00983       {  unnamed.push_back(new _dataiorec <T>(this, "", item, &strsize)); 
00984          // unnamed[unnamed.size()-1]->base = this;
00985          isnamedvar.push_back(false);
00986       }
01001       // one dimensional
01002       template <class T>
01003       void addnamed(string const &name, vector <T> *item, unsigned long &m = *(unsigned long *)0, 
01004            unsigned long &strsize=*(unsigned long *)0)
01005       {  named.push_back(new _dataiorec <T>(this, name, item, &m, &strsize)); 
01006          // named[named.size()-1]->base = this;
01007          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
01008          isnamedvar.push_back(true);
01009       }
01024       // one dimensional
01025       template <class T>
01026       void addunnamed(vector <T> *item, unsigned long &m=*(unsigned long *)0, 
01027              unsigned long &strsize=*(unsigned long *)0)
01028       {  unnamed.push_back(new _dataiorec <T>(this, "", item, &m, &strsize)); 
01029          // unnamed[unnamed.size()-1]->base = this;
01030          isnamedvar.push_back(false);
01031       }
01048       template <class T>
01049       void addnamed(string const &name, vector <vector <T> > *item, unsigned long &m=*(unsigned long *)0,
01050            unsigned long &n=*(unsigned long *)0, unsigned long &strsize=*(unsigned long *)0)
01051       {  named.push_back(new _dataiorec <T>(this, name, item, &m, &n, &strsize)); 
01052          // named[named.size()-1]->base = this;
01053          parsestring(named[named.size()-1]->name, stringdelimiter, scapechar);
01054          isnamedvar.push_back(true);
01055       }
01072       template <class T>
01073       void addunnamed(vector < vector <T> > *item, unsigned long &m=0, unsigned long &n=*(unsigned long *)0,
01074            unsigned long strsize=*(unsigned long *)0)
01075       {  unnamed.push_back(new _dataiorec <T>(this, "", item, &m, &n, &strsize)); 
01076          // unnamed[unnamed.size()-1]->base = this;
01077          isnamedvar.push_back(false);
01078       }
01079 
01080    // protected:
01081    private:
01082       // find item on the (un)named variable list
01083       unsigned finditem(void const *item, vector<_dataiorecbase *> &list);
01084       // find name index
01085       unsigned findname(string const &key);
01086       // find key on string list
01087       unsigned keysearch(string const &key, vector<string> &list);
01088       // find name and add to refered name list
01089       unsigned findrefername(string const &key);
01090       bool unnamedsetted();
01091       bool namedsetted();
01092    
01093       // add comment to comment list
01094       void addcommenttolist(string const &rem, vector <string> &remlist);
01095       // get comment list as vector <string>, delimiting each item by comment markers
01096       // used by gettablevalue() and getvalue()
01097       vector <string> &dataio::commentlisttoblockmode(vector <string> &rem, vector<string> &remlist);
01098 
01099       // get the line with comment, used by getdataline
01100       istream &getlinewithcomment(istream &f, string &datalinelist);
01101       // delete the line wrap marker. return false if not found on end of line
01102       // Do not call this, if linewrap is inactive
01103       // used by getdataline()
01104       bool deletelinewrapmarker(string &line);
01105       // delete the section marker. return false if not section mark, 
01106       // or section mark is inactive
01107       // used by operator>>()
01108       bool deletesectionnamemarker(string &s);
01109 
01110       // return true if section like name (do not apply parsestring inside)
01111       // for operator<<()
01112       bool sectionnamelike(string const &s);
01113       // get one line of data as string
01114       // istream &getdatatextline(istream &f, string &line);
01115       // get one line of data and break into list
01116       istream &getdataline(istream &f, vector <string> &datalinelist);
01117    
01118       // read table or column oriente data
01119       // required by
01120       //  friend istream &operator>>(istream &is, dataio &data);
01121       istream &readtableorcolumnoriented(istream &is);
01122       // return true if s need to delimited.
01123       // used by output
01124       bool delimiterrecomended(string const &s);
01125       // write table or column oriente data
01126       // required by
01127       //  friend ostream &operator<<(ostream &os, dataio &data);
01128       ostream &writetableorcolumnoriented(ostream &os);
01129       // write comment
01130       ostream &writecomment(ostream &os, vector <string> const &rem);
01131       // write line separator in apropriate way
01132       ostream &writelineseparator(ostream &os);
01133       // getvalue when is table
01134       vector <vector <string> > &gettablevalue(bool includecomment);
01135 
01136       // read/write buffer 
01137       // read buffer. return number of bytes readed
01138       // if reverse byte order is active and eof is found before end input,
01139       // the data is on right of buffer (end to first)
01140       unsigned long dataio::readbuffer(istream &is, unsigned char *buff, unsigned long n);
01141       // write buffer. Return none
01142       void dataio::writebuffer(ostream &os, unsigned char *buff, unsigned long n);
01143        
01144        // clear only the member input status
01145        // will analise way to clear it?
01146        void clearmemberinputstatus();
01147        // set valuesetted as false and clear referednameslist
01148        // clear input status of member and this
01149        void clearinputstatus(bool includemember=true);
01150        // validate the current class. If validateunrefered is true,
01151        // validate unrefered members too.
01152        void validatethis(unsigned n);
01153    public:
01154       //  set/get value
01155       // void setvalue(vector <vector <string> > &item, bool refernames = false);
01158       void setvalue(vector <vector <string> > &item);
01162       vector <vector <string> > &getvalue(bool includecomment=false);
01165       friend istream &operator>>(istream &is, dataio &data);
01168       friend ostream &operator<<(ostream &os,dataio &data);
01169 
01173       istream &read(istream &is);
01177       ostream &write(ostream &os);
01178    
01190       virtual void startinblock(unsigned i){
01191       }
01192 
01207       virtual void validate(unsigned n){
01208       }
01209    
01214       virtual bool startoutblock(unsigned i){
01215          return (i == 0);}
01216    
01218       dataio()
01219       {  resetflags();
01220          valuesetted=false; 
01221       }
01225       void clearinputbuffer();
01226 
01236       void resetflags(bool maprecomendedflagsintomember=true);
01242       void clear();
01246       void reset()
01247       {
01248          clear();
01249          resetflags();
01250          valuesetted = false;
01251       } // reset()
01253       virtual ~dataio()
01254       { unsigned i;
01255          for(i=0; i< unnamed.size(); i++)  delete unnamed[i];
01256          for(i=0; i< named.size(); i++)    delete named[i];
01257       } // ~dataio
01258 
01259       template <class T>
01260       friend _dataiorec<T>;
01261    };   // class dataio
01262 
01263 // for doxygen usage only (skip or not this part of code)
01264 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01265 
01266 
01268 // misc  _dataiorec methods that overrrided
01270    // template<class T>
01271    // bool _dataiorec<T>::isdataio()
01272    // {return false;} // to check is the data is dataio. used only when section is active.
01273 
01274 
01275    // template <class T>
01276    // void _dataiorec<T>::startinblock(unsigned i){
01277    // };
01278 
01279 //   template <class T>
01280 //   void _dataiorec<T>::validate(){
01281 //   };
01282 
01283    // template <class T>
01284    // bool _dataiorec<T>::startoutblock(unsigned i){
01285    //   return (i ==0);}
01286 
01287    template <class T>
01288    // T _dataiorec<T>::stringtoitem(string const &s)
01289    bool _dataiorec<T>::stringtoitem(string &s, T &item)
01290    {  
01291       cerr << "_dataiorec<T>::stringtoitem() not implemented" << endl;
01292       return false;
01293    }
01294 
01295    template <class T>
01296    void _dataiorec<T>::itemtostring(T const &item, string &s)
01297    {
01298       cerr << "_dataiorec<T>::itemtostring not implemented" << endl;
01299       s = "_dataiorec<T>::itemtostring not implemented";   
01300    }
01301 
01302    // binary input/output
01303    template <class T>
01304    bool _dataiorec<T>::readitem(istream &is, T &item)
01305    {  
01306       cerr << "_dataiorec<T>::readitem() not implemented" << endl;
01307       return false;
01308    }
01309 
01310    template <class T>
01311    void _dataiorec<T>::writeitem(ostream &os, T const &item)
01312    {
01313       cerr << "_dataiorec<T>::itemtostring not implemented" << endl;
01314       os << "_dataiorec<T>::itemtostring not implemented";   
01315    }
01316 
01318 // _dataiorec main methods implementation
01319 // generic implementation, using itemtostring and stringtoitem method
01321 
01322 
01324 // data dependency _dataiorec methods implementations
01326 
01328 // data conversion methods
01331 // string type
01333 // the string coincides with original method ???
01334 // string _dataiorec <string>::stringtoitem(string const &s);
01335    bool _dataiorec<string>::stringtoitem(string &s, string &item);
01336    void _dataiorec<string>::itemtostring(string const &item, string &s);
01337 
01338    bool _dataiorec<string>::readitem(istream &is, string &item);
01339    void _dataiorec<string>::writeitem(ostream &os, string const &item);
01340 
01342 // char and wchar_t
01344    // char _dataiorec <char>::stringtoitem(string const &s);
01345    bool _dataiorec<char>::stringtoitem(string &s, char &item);
01346    void _dataiorec<char>::itemtostring(char const &item, string &s);
01347 
01348    bool _dataiorec<char>::readitem(istream &is, char &item);
01349    void _dataiorec<char>::writeitem(ostream &os, char const &item);
01350 
01351 // unsigned char
01352    // unsigned char _dataiorec <unsigned char>::stringtoitem(string const &s);
01353    bool _dataiorec<unsigned char>::stringtoitem(string &s, unsigned char &item);
01354    void _dataiorec<unsigned char>::itemtostring(unsigned char const &item, string  &s);
01355 
01356    bool _dataiorec<unsigned char>::readitem(istream &is, unsigned char &item);
01357    void _dataiorec<unsigned char>::writeitem(ostream &os, unsigned char const &item);
01358 
01359 // wchar_t
01360    // wchar_t _dataiorec <wchar_t>::stringtoitem(string const &s);
01361    bool _dataiorec<wchar_t>::stringtoitem(string &s, wchar_t  &item);
01362    void _dataiorec<wchar_t>::itemtostring(wchar_t const &item, string &s);
01363 
01364    bool _dataiorec<wchar_t>::readitem(istream &is, wchar_t &item);
01365    void _dataiorec<wchar_t>::writeitem(ostream &os, wchar_t const &item);
01366 
01368 // int, unsigned, long, unsigned long
01370 // int
01371 // int _dataiorec <int>::stringtoitem(string const &s);
01372    bool _dataiorec<int>::stringtoitem(string &s, int &item);
01373    void _dataiorec<int>::itemtostring(int const &item, string &s);
01374 
01375    bool _dataiorec<int>::readitem(istream &is, int &item);
01376    void _dataiorec<int>::writeitem(ostream &os, int const &item);
01377 // unsigned
01378    // unsigned _dataiorec <unsigned>::stringtoitem(string const &s);
01379    bool _dataiorec<unsigned>::stringtoitem(string &s, unsigned &item);
01380    void _dataiorec<unsigned>::itemtostring(unsigned const &item, string &s);
01381 
01382    bool _dataiorec<unsigned>::readitem(istream &is, unsigned &item);
01383    void _dataiorec<unsigned>::writeitem(ostream &os, unsigned const &item);
01384 // long
01385    // long _dataiorec <long>::stringtoitem(string const &s);
01386    bool _dataiorec<long>::stringtoitem(string &s, long &item);
01387    void _dataiorec<long>::itemtostring(long const &item, string &s);
01388 
01389    bool _dataiorec<long>::readitem(istream &is, long &item);
01390    void _dataiorec<long>::writeitem(ostream &os, long const &item);
01391 // unsigned long
01392    // unsigned long _dataiorec <unsigned long>::stringtoitem(string const &s);
01393    bool _dataiorec<unsigned long>::stringtoitem(string &s, unsigned long &item);
01394    void _dataiorec<unsigned long>::itemtostring(unsigned long const &item, string  &s);
01395 
01396    bool _dataiorec<unsigned long>::readitem(istream &is, unsigned long &item);
01397    void _dataiorec<unsigned long>::writeitem(ostream &os, unsigned long const &item);
01398 
01399 // long long: only for compatibility: it acts as long
01400    // long _dataiorec <long>::stringtoitem(string const &s);
01401    bool _dataiorec<long long>::stringtoitem(string &s, long long &item);
01402    void _dataiorec<long long>::itemtostring(long long const &item, string &s);
01403 
01404    bool _dataiorec<long long>::readitem(istream &is, long long &item);
01405    void _dataiorec<long long>::writeitem(ostream &os, long long const &item);
01406 // unsigned long long: only for compatibility: acts as long
01407    // unsigned long _dataiorec <unsigned long>::stringtoitem(string const &s);
01408    bool _dataiorec<unsigned long long>::stringtoitem(string &s, unsigned long long &item);
01409    void _dataiorec<unsigned long long>::itemtostring(unsigned long long const &item, string  &s);
01410 
01411    bool _dataiorec<unsigned long long>::readitem(istream &is, unsigned long long &item);
01412    void _dataiorec<unsigned long long>::writeitem(ostream &os, unsigned long long const &item);
01413 
01415 // float, double, and long double
01417 // float
01418    // float _dataiorec <float>::stringtoitem(string const &s);
01419    bool _dataiorec<float>::stringtoitem(string &s, float &item);
01420    // in the input comma separated float, change the string
01421    void _dataiorec<float>::itemtostring(float const &item, string &s);
01422 
01423    bool _dataiorec<float>::readitem(istream &is, float &item);
01424    void _dataiorec<float>::writeitem(ostream &os, float const &item);
01425 // double
01426    // double _dataiorec <double>::stringtoitem(string const &s);
01427    bool _dataiorec<double>::stringtoitem(string &s, double &item);
01428    void _dataiorec<double>::itemtostring(double const &item, string &s);
01429 
01430    bool _dataiorec<double>::readitem(istream &is, double &item);
01431    void _dataiorec<double>::writeitem(ostream &os, double const &item);
01432 // long double
01433 // can not obtain long double. 
01434 // This routine get as double
01435 // it's only for compatibility
01436    // long double _dataiorec <long double>::stringtoitem(string const &s);
01437    bool  _dataiorec<long double>::stringtoitem(string &s, long double &item);
01438    void _dataiorec<long double>::itemtostring(long double const &item, string  &s);
01439 
01440    bool _dataiorec<long double>::readitem(istream &is, long double &item);
01441    void _dataiorec<long double>::writeitem(ostream &os, long double const &item);
01442 
01444 // bool
01446 
01447 // bool
01448    // bool _dataiorec <bool>::stringtoitem(string const &s);
01449    bool _dataiorec<bool>::stringtoitem(string &s, bool &item);
01450    void _dataiorec<bool>::itemtostring(bool const &item, string &s);
01451 
01452    bool _dataiorec<bool>::readitem(istream &is, bool &item);
01453    void _dataiorec<bool>::writeitem(ostream &os, bool const &item);
01454 
01455 // for doxygen usage only (skip or not the part of code)
01456 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01457 
01458 // endding group (for doxygen)
01462 #endif // #define _DATAIO_H_
01463 

Generated at Thu Sep 6 13:45:41 2001 for dataio by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001