1 | // $Id: FileParser.cc 1862 2005-05-19 15:23:57Z thea $ |
---|
2 | // Author: Alessandro Thea 2005/05/17 |
---|
3 | |
---|
4 | /***************************************************************************** |
---|
5 | * ESAF: Euso Simulation and Analysis Framework * |
---|
6 | * * |
---|
7 | * Id: FileParser * |
---|
8 | * Package: <packagename> * |
---|
9 | * Coordinator: <coordinator> * |
---|
10 | * * |
---|
11 | *****************************************************************************/ |
---|
12 | |
---|
13 | //_____________________________________________________________________________ |
---|
14 | // |
---|
15 | // FileParser |
---|
16 | // |
---|
17 | // <extensive class description> |
---|
18 | // |
---|
19 | // Config file parameters |
---|
20 | // ====================== |
---|
21 | // |
---|
22 | // <parameter name>: <parameter description> |
---|
23 | // -Valid options: <available options> |
---|
24 | // |
---|
25 | |
---|
26 | #include "FileParser.hh" |
---|
27 | #include "utils.hh" |
---|
28 | #include <iostream> |
---|
29 | |
---|
30 | ClassImp(FileParser) |
---|
31 | |
---|
32 | //_____________________________________________________________________________ |
---|
33 | FileParser::FileParser( const string& path ) : fPath(path) { |
---|
34 | // |
---|
35 | // Constructor |
---|
36 | // |
---|
37 | |
---|
38 | fComments.push_back("#"); |
---|
39 | |
---|
40 | fDelimiters = "\t "; |
---|
41 | |
---|
42 | } |
---|
43 | |
---|
44 | //_____________________________________________________________________________ |
---|
45 | FileParser::~FileParser() { |
---|
46 | // |
---|
47 | // Destructor |
---|
48 | // |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | //______________________________________________________________________________ |
---|
53 | Bool_t FileParser::ParseLine( string line ) { |
---|
54 | |
---|
55 | size_t pos; |
---|
56 | |
---|
57 | // erase comments |
---|
58 | |
---|
59 | list<string>::iterator it = fComments.begin(); |
---|
60 | while( it != fComments.end() ) { |
---|
61 | Msg(EsafMsg::Info) << '\'' << *it << '\'' << MsgDispatch; |
---|
62 | pos = line.find(*it); |
---|
63 | if ( pos!=string::npos ) line.erase(pos); |
---|
64 | it++; |
---|
65 | } |
---|
66 | |
---|
67 | string value; |
---|
68 | list<string> ls; |
---|
69 | line = SwallowSpaces(line); |
---|
70 | |
---|
71 | while(!line.empty()){ |
---|
72 | pos = line.find_first_of(fDelimiters); |
---|
73 | value = line.substr(0, pos); |
---|
74 | if ( pos == string::npos ) |
---|
75 | line.erase(); |
---|
76 | else |
---|
77 | line.erase(0,pos+1); |
---|
78 | line = SwallowSpaces(line); |
---|
79 | value = RSwallowSpaces(value); |
---|
80 | ls.push_back(value); |
---|
81 | } |
---|
82 | fWords.push_back(ls); |
---|
83 | |
---|
84 | return kTRUE; |
---|
85 | } |
---|
86 | |
---|
87 | //______________________________________________________________________________ |
---|
88 | void FileParser::Dump() const { |
---|
89 | |
---|
90 | list< list<string> >::const_iterator iRow; |
---|
91 | list<string>::const_iterator iCol; |
---|
92 | |
---|
93 | for( iRow = fWords.begin(); iRow != fWords.end(); iRow++) { |
---|
94 | for ( iCol = iRow->begin(); iCol != iRow->end(); iCol++ ) |
---|
95 | Msg(EsafMsg::Info) << "'" << *iCol << "' " << MsgFlush; |
---|
96 | Msg(EsafMsg::Info) << MsgDispatch; |
---|
97 | } |
---|
98 | } |
---|