1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
3 | <title>mixpp: parser.h Source File</title> |
---|
4 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
5 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
6 | </head><body> |
---|
7 | <!-- Generated by Doxygen 1.5.8 --> |
---|
8 | <script type="text/javascript"> |
---|
9 | <!-- |
---|
10 | function changeDisplayState (e){ |
---|
11 | var num=this.id.replace(/[^[0-9]/g,''); |
---|
12 | var button=this.firstChild; |
---|
13 | var sectionDiv=document.getElementById('dynsection'+num); |
---|
14 | if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ |
---|
15 | sectionDiv.style.display='block'; |
---|
16 | button.src='open.gif'; |
---|
17 | }else{ |
---|
18 | sectionDiv.style.display='none'; |
---|
19 | button.src='closed.gif'; |
---|
20 | } |
---|
21 | } |
---|
22 | function initDynSections(){ |
---|
23 | var divs=document.getElementsByTagName('div'); |
---|
24 | var sectionCounter=1; |
---|
25 | for(var i=0;i<divs.length-1;i++){ |
---|
26 | if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ |
---|
27 | var header=divs[i]; |
---|
28 | var section=divs[i+1]; |
---|
29 | var button=header.firstChild; |
---|
30 | if (button!='IMG'){ |
---|
31 | divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); |
---|
32 | button=document.createElement('img'); |
---|
33 | divs[i].insertBefore(button,divs[i].firstChild); |
---|
34 | } |
---|
35 | header.style.cursor='pointer'; |
---|
36 | header.onclick=changeDisplayState; |
---|
37 | header.id='dynheader'+sectionCounter; |
---|
38 | button.src='closed.gif'; |
---|
39 | section.id='dynsection'+sectionCounter; |
---|
40 | section.style.display='none'; |
---|
41 | section.style.marginLeft='14px'; |
---|
42 | sectionCounter++; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | window.onload = initDynSections; |
---|
47 | --> |
---|
48 | </script> |
---|
49 | <div class="navigation" id="top"> |
---|
50 | <div class="tabs"> |
---|
51 | <ul> |
---|
52 | <li><a href="main.html"><span>Main Page</span></a></li> |
---|
53 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
54 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
55 | <li><a href="annotated.html"><span>Classes</span></a></li> |
---|
56 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
57 | </ul> |
---|
58 | </div> |
---|
59 | <div class="tabs"> |
---|
60 | <ul> |
---|
61 | <li><a href="files.html"><span>File List</span></a></li> |
---|
62 | <li><a href="globals.html"><span>File Members</span></a></li> |
---|
63 | </ul> |
---|
64 | </div> |
---|
65 | <h1>parser.h</h1><a href="parser_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
66 | <a name="l00031"></a>00031 <span class="preprocessor">#ifndef PARSER_H</span> |
---|
67 | <a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define PARSER_H</span> |
---|
68 | <a name="l00033"></a>00033 <span class="preprocessor"></span> |
---|
69 | <a name="l00034"></a>00034 <span class="comment">// #define MAX_STR_LEN 4096</span> |
---|
70 | <a name="l00035"></a>00035 |
---|
71 | <a name="l00036"></a>00036 <span class="preprocessor">#include <<a class="code" href="vec_8h.html" title="Templated Vector Class Definitions.">itpp/base/vec.h</a>></span> |
---|
72 | <a name="l00037"></a>00037 <span class="preprocessor">#include <<a class="code" href="mat_8h.html" title="Matrix Class Definitions.">itpp/base/mat.h</a>></span> |
---|
73 | <a name="l00038"></a>00038 <span class="preprocessor">#include <<a class="code" href="array_8h.html" title="Definition of Array class (container).">itpp/base/array.h</a>></span> |
---|
74 | <a name="l00039"></a>00039 <span class="preprocessor">#include <iostream></span> |
---|
75 | <a name="l00040"></a>00040 |
---|
76 | <a name="l00041"></a>00041 |
---|
77 | <a name="l00042"></a>00042 <span class="keyword">namespace </span>itpp |
---|
78 | <a name="l00043"></a>00043 { |
---|
79 | <a name="l00044"></a>00044 |
---|
80 | <a name="l00102"></a><a class="code" href="classitpp_1_1Parser.html">00102</a> <span class="keyword">class </span><a class="code" href="classitpp_1_1Parser.html" title="Argument Parser Class.">Parser</a> |
---|
81 | <a name="l00103"></a>00103 { |
---|
82 | <a name="l00104"></a>00104 <span class="keyword">public</span>: |
---|
83 | <a name="l00105"></a>00105 |
---|
84 | <a name="l00107"></a>00107 <a class="code" href="classitpp_1_1Parser.html#7e6c4f33d314ca02afcfcbda2a02771c" title="Default Constructor.">Parser</a>(); |
---|
85 | <a name="l00108"></a>00108 |
---|
86 | <a name="l00110"></a>00110 <a class="code" href="classitpp_1_1Parser.html#7e6c4f33d314ca02afcfcbda2a02771c" title="Default Constructor.">Parser</a>(<span class="keyword">const</span> std::string &filename); |
---|
87 | <a name="l00111"></a>00111 |
---|
88 | <a name="l00113"></a>00113 <a class="code" href="classitpp_1_1Parser.html#7e6c4f33d314ca02afcfcbda2a02771c" title="Default Constructor.">Parser</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]); |
---|
89 | <a name="l00114"></a>00114 |
---|
90 | <a name="l00116"></a>00116 <a class="code" href="classitpp_1_1Parser.html#7e6c4f33d314ca02afcfcbda2a02771c" title="Default Constructor.">Parser</a>(<span class="keyword">const</span> std::string &filename, <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]); |
---|
91 | <a name="l00117"></a>00117 |
---|
92 | <a name="l00119"></a>00119 <a class="code" href="classitpp_1_1Parser.html#7e6c4f33d314ca02afcfcbda2a02771c" title="Default Constructor.">Parser</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Array.html">Array<std::string></a> &setup); |
---|
93 | <a name="l00120"></a>00120 |
---|
94 | <a name="l00122"></a>00122 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Parser.html#7479074f47cb11287b5a3c5245ca8dfb" title="Initialization function. Sets input file name.">init</a>(<span class="keyword">const</span> std::string &filename); |
---|
95 | <a name="l00123"></a>00123 |
---|
96 | <a name="l00125"></a>00125 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Parser.html#7479074f47cb11287b5a3c5245ca8dfb" title="Initialization function. Sets input file name.">init</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]); |
---|
97 | <a name="l00126"></a>00126 |
---|
98 | <a name="l00128"></a>00128 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Parser.html#7479074f47cb11287b5a3c5245ca8dfb" title="Initialization function. Sets input file name.">init</a>(<span class="keyword">const</span> std::string &filename, <span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]); |
---|
99 | <a name="l00129"></a>00129 |
---|
100 | <a name="l00131"></a>00131 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Parser.html#7479074f47cb11287b5a3c5245ca8dfb" title="Initialization function. Sets input file name.">init</a>(<span class="keyword">const</span> <a class="code" href="classitpp_1_1Array.html">Array<std::string></a> &setup); |
---|
101 | <a name="l00132"></a>00132 |
---|
102 | <a name="l00134"></a>00134 <span class="keywordtype">void</span> <a class="code" href="classitpp_1_1Parser.html#08ad1252f07cc81c1c7fe4502e281183" title="Sets silent mode if true, or verbose mode if false.">set_silentmode</a>(<span class="keywordtype">bool</span> v = <span class="keyword">true</span>); |
---|
103 | <a name="l00135"></a>00135 |
---|
104 | <a name="l00137"></a>00137 <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Parser.html#c0045afbb4d7003f282f810774eb7c4c" title="Check is name exists in the file. Returns true if the name is found and false otherwise...">exist</a>(<span class="keyword">const</span> std::string &name); |
---|
105 | <a name="l00138"></a>00138 |
---|
106 | <a name="l00140"></a>00140 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
107 | <a name="l00141"></a>00141 <span class="keywordtype">bool</span> <span class="keyword">get</span>(T &var, <span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
108 | <a name="l00142"></a>00142 |
---|
109 | <a name="l00144"></a>00144 <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Parser.html#6f8a25fbc5077decb7710f89811dc087" title="Interpret variable name as a bool.">get_bool</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
110 | <a name="l00145"></a>00145 |
---|
111 | <a name="l00147"></a>00147 <span class="keywordtype">int</span> <a class="code" href="classitpp_1_1Parser.html#2f7ca1e914536e7bde9f0595066f1f55" title="Interpret variable name as an integer.">get_int</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
112 | <a name="l00148"></a>00148 |
---|
113 | <a name="l00150"></a>00150 <span class="keywordtype">double</span> <a class="code" href="classitpp_1_1Parser.html#00f8d56022ad1961149b3462b680500d" title="Interpret variable name as a double.">get_double</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
114 | <a name="l00151"></a>00151 |
---|
115 | <a name="l00153"></a>00153 std::string <a class="code" href="classitpp_1_1Parser.html#90851d056eb05e74e4be61a08029fb0b" title="Interpret variable name as a string.">get_string</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
116 | <a name="l00154"></a>00154 |
---|
117 | <a name="l00156"></a>00156 vec <a class="code" href="classitpp_1_1Parser.html#c309bc0df16f1eb9dc26dfda27c59bfe" title="Interpret variable name as a vec.">get_vec</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
118 | <a name="l00157"></a>00157 |
---|
119 | <a name="l00159"></a>00159 ivec <a class="code" href="classitpp_1_1Parser.html#3dc404545cdc1cd456c0e8e6e0139192" title="Interpret variable name as a ivec.">get_ivec</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
120 | <a name="l00160"></a>00160 |
---|
121 | <a name="l00162"></a>00162 svec <a class="code" href="classitpp_1_1Parser.html#27d53f6423d986ed44380be9bc23d35e" title="Interpret variable name as a svec.">get_svec</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
122 | <a name="l00163"></a>00163 |
---|
123 | <a name="l00165"></a>00165 bvec <a class="code" href="classitpp_1_1Parser.html#4d242789174b3ec5343927122d8b883e" title="Interpret variable name as a bvec.">get_bvec</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
124 | <a name="l00166"></a>00166 |
---|
125 | <a name="l00168"></a>00168 mat <a class="code" href="classitpp_1_1Parser.html#2da1079bcbc37284f522873f80f091d8" title="Interpret variable name as a mat.">get_mat</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
126 | <a name="l00169"></a>00169 |
---|
127 | <a name="l00171"></a>00171 imat <a class="code" href="classitpp_1_1Parser.html#67c31088c73a21875b17326260a8be14" title="Interpret variable name as a imat.">get_imat</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
128 | <a name="l00172"></a>00172 |
---|
129 | <a name="l00174"></a>00174 smat <a class="code" href="classitpp_1_1Parser.html#862c8f572d15e907f7214ccb7fdd3a9f" title="Interpret variable name as a smat.">get_smat</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
130 | <a name="l00175"></a>00175 |
---|
131 | <a name="l00177"></a>00177 <a class="code" href="mat_8h.html#f90acd1af41bf2d1d8a4bb23662fff69" title="bin matrix">bmat</a> <a class="code" href="classitpp_1_1Parser.html#f09b3a0b1190e4595c6b5a1cb85f7c7d" title="Interpret variable name as a bmat.">get_bmat</a>(<span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num = -1); |
---|
132 | <a name="l00178"></a>00178 |
---|
133 | <a name="l00179"></a>00179 <span class="keyword">protected</span>: |
---|
134 | <a name="l00180"></a>00180 |
---|
135 | <a name="l00181"></a>00181 <span class="keyword">private</span>: |
---|
136 | <a name="l00182"></a>00182 |
---|
137 | <a name="l00184"></a>00184 std::string findname(<span class="keyword">const</span> std::string &name, |
---|
138 | <a name="l00185"></a>00185 <span class="keywordtype">bool</span> &error_flag, |
---|
139 | <a name="l00186"></a>00186 <span class="keywordtype">bool</span> &print_flag, |
---|
140 | <a name="l00187"></a>00187 <span class="keywordtype">int</span> num = 0, |
---|
141 | <a name="l00188"></a>00188 <span class="keywordtype">bool</span> keep_brackets = <span class="keyword">false</span>); |
---|
142 | <a name="l00189"></a>00189 |
---|
143 | <a name="l00190"></a>00190 <span class="keywordtype">void</span> pre_parsing(<span class="keywordtype">void</span>); |
---|
144 | <a name="l00191"></a>00191 |
---|
145 | <a name="l00192"></a>00192 <a class="code" href="classitpp_1_1Array.html">Array<std::string></a> SetupStrings; |
---|
146 | <a name="l00193"></a>00193 |
---|
147 | <a name="l00194"></a>00194 <span class="keywordtype">bool</span> VERBOSE; |
---|
148 | <a name="l00195"></a>00195 }; |
---|
149 | <a name="l00196"></a>00196 |
---|
150 | <a name="l00197"></a>00197 <span class="comment">// ----------------------- Implementation starts here -----------------------</span> |
---|
151 | <a name="l00198"></a>00198 |
---|
152 | <a name="l00199"></a>00199 <span class="keyword">template</span><<span class="keyword">class</span> T> |
---|
153 | <a name="l00200"></a><a class="code" href="classitpp_1_1Parser.html#e9d251acac7dbb48e60f614105d047cf">00200</a> <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Parser.html#e9d251acac7dbb48e60f614105d047cf" title="Get variable value if name can be found (and return true), otherwise keep old value...">Parser::get</a>(T &var, <span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num) |
---|
154 | <a name="l00201"></a>00201 { |
---|
155 | <a name="l00202"></a>00202 <span class="keywordtype">bool</span> error_flag, print_flag; |
---|
156 | <a name="l00203"></a>00203 std::string str = findname(name, error_flag, print_flag, num, <span class="keyword">true</span>); |
---|
157 | <a name="l00204"></a>00204 std::istringstream buffer(str); |
---|
158 | <a name="l00205"></a>00205 <span class="keywordflow">if</span> (error_flag) { |
---|
159 | <a name="l00206"></a>00206 <span class="keywordflow">if</span> (VERBOSE) { |
---|
160 | <a name="l00207"></a>00207 std::cout << name << <span class="stringliteral">" = "</span> << var << <span class="stringliteral">";"</span> << std::endl; |
---|
161 | <a name="l00208"></a>00208 } |
---|
162 | <a name="l00209"></a>00209 } |
---|
163 | <a name="l00210"></a>00210 <span class="keywordflow">else</span> { |
---|
164 | <a name="l00211"></a>00211 buffer >> var; |
---|
165 | <a name="l00212"></a>00212 <span class="keywordflow">if</span> (print_flag) { |
---|
166 | <a name="l00213"></a>00213 std::cout << name << <span class="stringliteral">" = "</span> << var << std::endl; |
---|
167 | <a name="l00214"></a>00214 } |
---|
168 | <a name="l00215"></a>00215 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (VERBOSE) { |
---|
169 | <a name="l00216"></a>00216 std::cout << name << <span class="stringliteral">" = "</span> << var << <span class="stringliteral">";"</span> << std::endl; |
---|
170 | <a name="l00217"></a>00217 } |
---|
171 | <a name="l00218"></a>00218 } |
---|
172 | <a name="l00219"></a>00219 <span class="keywordflow">return</span> !error_flag; |
---|
173 | <a name="l00220"></a>00220 } |
---|
174 | <a name="l00221"></a>00221 |
---|
175 | <a name="l00223"></a>00223 <span class="keyword">template</span><> |
---|
176 | <a name="l00224"></a>00224 <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Parser.html#e9d251acac7dbb48e60f614105d047cf" title="Get variable value if name can be found (and return true), otherwise keep old value...">Parser::get</a>(std::string &var, <span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num); |
---|
177 | <a name="l00226"></a>00226 <span class="keyword">template</span><> |
---|
178 | <a name="l00227"></a>00227 <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Parser.html#e9d251acac7dbb48e60f614105d047cf" title="Get variable value if name can be found (and return true), otherwise keep old value...">Parser::get</a>(<span class="keywordtype">int</span> &var, <span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num); |
---|
179 | <a name="l00229"></a>00229 <span class="keyword">template</span><> |
---|
180 | <a name="l00230"></a>00230 <span class="keywordtype">bool</span> <a class="code" href="classitpp_1_1Parser.html#e9d251acac7dbb48e60f614105d047cf" title="Get variable value if name can be found (and return true), otherwise keep old value...">Parser::get</a>(<span class="keywordtype">bool</span> &var, <span class="keyword">const</span> std::string &name, <span class="keywordtype">int</span> num); |
---|
181 | <a name="l00231"></a>00231 |
---|
182 | <a name="l00232"></a>00232 } <span class="comment">// namespace itpp</span> |
---|
183 | <a name="l00233"></a>00233 |
---|
184 | <a name="l00234"></a>00234 <span class="preprocessor">#endif // #ifndef PARSER_H</span> |
---|
185 | </pre></div></div> |
---|
186 | <hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:12 2009 for mixpp by |
---|
187 | <a href="http://www.doxygen.org/index.html"> |
---|
188 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address> |
---|
189 | </body> |
---|
190 | </html> |
---|