// dataio 0.5 (beta) - Copyright (C) 2001, by Sadao Massago // // file: sampsec.cpp (section usage example) // // requires: dataio.h, dataio.cpp, stringutil.h, stringutil.cpp // // ----------------------------------------------------------------------// // The dataio library and related files is licenced under the term of // // GNU Lesser General Public License version 2.1 or latter // // (see lesser.txt for detail). // // For information over GNU or GNU compatible license, visit the site // // http://www.gnu.org. // //#include <string> #include <iostream> #include <strstream> #include <vector> // #define _DATAIODEBUG_ // #define _DEBUG_ #include "dataio.h" // it want to copile for single linkable file (without using makefile) // comment above include and active follow two includes: // #include "stringutil.cpp" // #include "dataio.cpp" // for main() #include <fstream> class fileinfo { public: string fname; vector <string> path; string type; }; // void main(int argc, char **argv) // { int main() { string prog; fileinfo fi; unsigned runs; bool print_log; unsigned long imax; bool ask; bool nocomment; dataio cfg, fileinfoio, process; ifstream f("sampsec.txt"); if(!f) { cout << "main:error: can't open input files"<< endl; return 1; } // file open succeeds // setting io cfg.add("prog-name", &prog); cfg.add("files", &fileinfoio); fileinfoio.add("file-name", &fi.fname); fileinfoio.add("default-path", &fi.path); fileinfoio.add("default file type", &fi.type); cfg.add("process", &process); process.add(&runs); process.add("print-log-on", &print_log); process.add("max-iter", &imax); process.addcomment("max-iter", "iteration limit"); process.add("ask-to-user", &ask); process.additemcomment(&ask, "if exception occur, ask to user"); cfg.add("print-comment-off", &nocomment); cfg.addcomment("this is win ini like config example"); cfg.addcomment("contain non win ini standard features"); cfg.addcomment("print-comment-off", "no process comment printing mode"); cfg.ignorecase(true); cfg.attribseparator='='; cfg.sectionnameopen = '['; cfg.sectionnameclose = ']'; cfg.columnseparator=' '; cfg.extendedmode = false; // near as standard cout << "readding config file\n"; f >> cfg; cout << "main: config loaded...\n"; cout << "loaded data\n"; cout << cfg << endl; cout << "now, cfg in CSV (with columnseparator=\'\\t\')\n"; cfg.ignorecase(true); cfg.attribseparator='\0'; // disable cfg.sectionnameopen = '\0'; // disable (need to disable both) cfg.sectionnameclose = '\0'; // disable (need to disable both) cfg.columnseparator='\t'; cout << cfg; }