tstruct.cpp

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #include <iostream>
00023 #include <iomanip>
00024 #include <map>
00025 
00026 #include "util/exception.h"
00027 #include "util/fileparser.h"
00028 #include "util/string.h"
00029 #include "util/array.h"
00030 
00031 using std::cout;
00032 using std::endl;
00033 using std::setw;
00034 
00035 int main(int argc, char **argv) try
00036 {
00037     // Open file
00038     FileParser FP(String("sample.main"));
00039 
00040     /*
00041     MAIN1 A  1 2 3   # comment a
00042     MAIN1 B  4 5     # comment b
00043     MAIN1 C  c       # comment c
00044     MAIN2 D  d d     # comment d
00045     MAIN2 E  e e e   # comment e
00046     MAIN3 F  f f f f # comment f
00047     */
00048     int num_tags = 6;
00049     FileParser::Tags tags[]=
00050         {{"MAIN1", "A", "A - put comments here", true , ""            },
00051          {"MAIN1", "B", "B - put comments here", true , ""            },
00052          {"MAIN1", "C", "C - put comments here", false, "C - default" },
00053          {"MAIN2", "D", "D - put comments here", true , ""            },
00054          {"MAIN2", "E", "E - put comments here", false, "E - default" },
00055          {"MAIN3", "F", "F - put comments here", true , ""            }};
00056 
00057     FileParser::StructVals values;
00058 
00059     FP.StructFile(tags, num_tags, values);
00060     
00061     FileParser::StructVals::const_iterator it=values.begin();
00062     while (it!=values.end())
00063     {
00064         cout << setw(10) << it->first << " : " << it->second << " : " << endl;
00065         it++;
00066     }
00067     
00068     return 0;
00069 }
00070 catch (Exception * e)
00071 {
00072     e->Cout();
00073     if (e->IsFatal()) exit(1);
00074     delete e;
00075 }

Generated on Wed Jan 24 15:56:27 2007 for MechSys by  doxygen 1.4.7