paradiseo/trunk/paradiseo-eo/doc/html/eo_parser_8h-source.html
legrand c3aec878e5 Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
2006-12-12 14:49:08 +00:00

210 lines
16 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>EO: eoParser.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"> <form class="search" action="search.php" method="get">
<a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<div class="nav">
<a class="el" href="dir_000000.html">src</a>&nbsp;/&nbsp;<a class="el" href="dir_000011.html">utils</a></div>
<h1>eoParser.h</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/* (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000</span>
00002 <span class="comment"></span>
00003 <span class="comment">This library is free software; you can redistribute it and/or modify it under</span>
00004 <span class="comment">the terms of the GNU Lesser General Public License as published by the Free</span>
00005 <span class="comment">Software Foundation; either version 2 of the License, or (at your option) any</span>
00006 <span class="comment">later version.</span>
00007 <span class="comment"></span>
00008 <span class="comment">This library is distributed in the hope that it will be useful, but WITHOUT ANY</span>
00009 <span class="comment">WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A</span>
00010 <span class="comment">PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</span>
00011 <span class="comment"></span>
00012 <span class="comment">You should have received a copy of the GNU Lesser General Public License along</span>
00013 <span class="comment">with this library; if not, write to the Free Software Foundation, Inc., 59</span>
00014 <span class="comment">Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00015 <span class="comment"></span>
00016 <span class="comment">Contact: http://eodev.sourceforge.net</span>
00017 <span class="comment"> todos@geneura.ugr.es, http://geneura.ugr.es</span>
00018 <span class="comment"> Marc.Schoenauer@polytechnique.fr</span>
00019 <span class="comment"> mkeijzer@dhi.dk</span>
00020 <span class="comment">*/</span>
00021
00022
00023 <span class="preprocessor">#ifndef EO_PARSER_H</span>
00024 <span class="preprocessor"></span><span class="preprocessor">#define EO_PARSER_H</span>
00025 <span class="preprocessor"></span>
00026 <span class="preprocessor">#include &lt;map&gt;</span>
00027 <span class="preprocessor">#include &lt;sstream&gt;</span>
00028 <span class="preprocessor">#include &lt;string&gt;</span>
00029
00030 <span class="preprocessor">#include "eoParam.h"</span>
00031 <span class="preprocessor">#include "eoObject.h"</span>
00032 <span class="preprocessor">#include "eoPersistent.h"</span>
00033
<a name="l00040"></a><a class="code" href="classeo_parameter_loader.html">00040</a> <span class="keyword">class </span><a class="code" href="classeo_parameter_loader.html">eoParameterLoader</a>
00041 {
00042 <span class="keyword">public</span> :
00043
00045 <span class="keyword">virtual</span> ~<a class="code" href="classeo_parameter_loader.html">eoParameterLoader</a>();
00046
00052 <span class="keyword">virtual</span> <span class="keywordtype">void</span> processParam(<a class="code" href="classeo_param.html">eoParam</a>&amp; param, std::string section = <span class="stringliteral">""</span>) = 0;
00053
00057 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> isItThere(<a class="code" href="classeo_param.html">eoParam</a>&amp; _param) <span class="keyword">const </span>= 0;
00058
00069 <span class="keyword">template</span> &lt;<span class="keyword">class</span> ValueType&gt;
<a name="l00070"></a><a class="code" href="classeo_parameter_loader.html#a3">00070</a> <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>&amp; createParam(ValueType _defaultValue,
00071 std::string _longName,
00072 std::string _description,
00073 <span class="keywordtype">char</span> _shortHand = 0,
00074 std::string _section = <span class="stringliteral">""</span>,
00075 <span class="keywordtype">bool</span> _required = <span class="keyword">false</span>)
00076 {
00077 <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>* p = <span class="keyword">new</span> <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>(_defaultValue,
00078 _longName,
00079 _description,
00080 _shortHand,
00081 _required);
00082 ownedParams.push_back(p);
00083 processParam(*p, _section);
00084 <span class="keywordflow">return</span> *p;
00085 }
00086
00087
00088 <span class="keyword">private</span> :
00089
00090 std::vector&lt;eoParam*&gt; ownedParams;
00091 };
00092
00093
00094
<a name="l00100"></a><a class="code" href="classeo_parser.html">00100</a> <span class="keyword">class </span><a class="code" href="classeo_parser.html">eoParser</a> : <span class="keyword">public</span> <a class="code" href="classeo_parameter_loader.html">eoParameterLoader</a>, <span class="keyword">public</span> <a class="code" href="classeo_object.html">eoObject</a>, <span class="keyword">public</span> <a class="code" href="classeo_persistent.html">eoPersistent</a>
00101 {
00102
00103 <span class="keyword">public</span>:
00104
00119 <a class="code" href="classeo_parser.html#a0">eoParser</a> ( <span class="keywordtype">unsigned</span> _argc, <span class="keywordtype">char</span> **_argv , std::string _programDescription = <span class="stringliteral">""</span>,
00120 std::string _lFileParamName = <span class="stringliteral">"param-file"</span>, <span class="keywordtype">char</span> _shortHand = <span class="charliteral">'p'</span>);
00121
00125 <span class="keywordtype">void</span> <a class="code" href="classeo_parser.html#a1">processParam</a>(<a class="code" href="classeo_param.html">eoParam</a>&amp; param, std::string section = <span class="stringliteral">""</span>);
00126
00127 <span class="keywordtype">void</span> <a class="code" href="classeo_parser.html#a2">readFrom</a>(std::istream&amp; is);
00128
00129 <span class="keywordtype">void</span> <a class="code" href="classeo_parser.html#a3">printOn</a>(std::ostream&amp; os) <span class="keyword">const</span>;
00130
<a name="l00132"></a><a class="code" href="classeo_parser.html#a4">00132</a> std::string <a class="code" href="classeo_parser.html#a4">className</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="stringliteral">"Parser"</span>; }
00133
00135 <span class="keywordtype">bool</span> <a class="code" href="classeo_parser.html#a5">userNeedsHelp</a>(<span class="keywordtype">void</span>);
00140 <span class="keywordtype">void</span> <a class="code" href="classeo_parser.html#a6">printHelp</a>(std::ostream&amp; os);
00141
00142 std::string ProgramName() { <span class="keywordflow">return</span> programName; }
00143
<a name="l00148"></a><a class="code" href="classeo_parser.html#a8">00148</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classeo_parser.html#a8">isItThere</a>(<a class="code" href="classeo_param.html">eoParam</a>&amp; _param)<span class="keyword"> const</span>
00149 <span class="keyword"> </span>{ <span class="keywordflow">return</span> getValue(_param).first; }
00150
00159 <a class="code" href="classeo_param.html">eoParam</a> * <a class="code" href="classeo_parser.html#a9">getParamWithLongName</a>(<span class="keyword">const</span> std::string&amp; _name) <span class="keyword">const</span>;
00160
00161
00162
00172 <span class="keyword">template</span> &lt;<span class="keyword">class</span> ValueType&gt;
<a name="l00173"></a><a class="code" href="classeo_parser.html#a10">00173</a> <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>&amp; <a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(ValueType _defaultValue,
00174 std::string _longName,
00175 std::string _description,
00176 <span class="keywordtype">char</span> _shortHand = 0,
00177 std::string _section = <span class="stringliteral">""</span>,
00178 <span class="keywordtype">bool</span> _required = <span class="keyword">false</span>)
00179 {
00180 <a class="code" href="classeo_param.html">eoParam</a>* ptParam = <a class="code" href="classeo_parser.html#a9">getParamWithLongName</a>(_longName);
00181 <span class="keywordflow">if</span> (ptParam) {
00182 <span class="comment">// found</span>
00183 <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>* ptTypedParam =
00184 dynamic_cast&lt;eoValueParam&lt;ValueType&gt;*&gt;(ptParam);
00185 <span class="keywordflow">return</span> *ptTypedParam;
00186 }
00187 <span class="comment">// not found -&gt; create it</span>
00188 <span class="keywordflow">return</span> <a class="code" href="classeo_parameter_loader.html#a3">createParam</a> (_defaultValue, _longName, _description,
00189 _shortHand, _section, _required);
00190 }
00191
00192
00193
00210 <span class="keyword">template</span> &lt;<span class="keyword">class</span> ValueType&gt;
<a name="l00211"></a><a class="code" href="classeo_parser.html#a11">00211</a> <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>&amp; <a class="code" href="classeo_parser.html#a11">setORcreateParam</a>(ValueType _defaultValue,
00212 std::string _longName,
00213 std::string _description,
00214 <span class="keywordtype">char</span> _shortHand = 0,
00215 std::string _section = <span class="stringliteral">""</span>,
00216 <span class="keywordtype">bool</span> _required = <span class="keyword">false</span>)
00217 {
00218 <a class="code" href="classeo_value_param.html">eoValueParam&lt;ValueType&gt;</a>&amp; param = <a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_defaultValue, _longName, _description,
00219 _shortHand, _section, _required);
00220 std::ostringstream os;
00221 os &lt;&lt; _defaultValue;
00222 <span class="keywordflow">if</span>(<a class="code" href="classeo_parser.html#a8">isItThere</a>(param)) {
00223 param.<a class="code" href="classeo_value_param.html#a5">setValue</a>(os.str());
00224 } <span class="keywordflow">else</span> {
00225 longNameMap[_longName] = os.str();
00226 shortNameMap[_shortHand] = os.str();
00227 }
00228 <span class="keywordflow">return</span> param;
00229 }
00230
00231
00232
<a name="l00234"></a><a class="code" href="classeo_parser.html#a12">00234</a> <span class="keywordtype">void</span> <a class="code" href="classeo_parser.html#a12">setStopOnUnknownParam</a>(<span class="keywordtype">bool</span> _b) {stopOnUnknownParam.<a class="code" href="classeo_value_param.html#a2">value</a>()=_b;}
00235 <span class="keywordtype">bool</span> getStopOnUnknownParam() {<span class="keywordflow">return</span> stopOnUnknownParam.<a class="code" href="classeo_value_param.html#a2">value</a>();}
00236
<a name="l00238"></a><a class="code" href="classeo_parser.html#a14">00238</a> <span class="keywordtype">void</span> <a class="code" href="classeo_parser.html#a14">setPrefix</a>(<span class="keyword">const</span> std:: string &amp; _prefix) {prefix = _prefix;}
00239
00240 <span class="keywordtype">void</span> resetPrefix() {prefix = <span class="stringliteral">""</span>;}
00241
00242 std::string getPrefix() {<span class="keywordflow">return</span> prefix;}
00243
00244 <span class="keyword">private</span>:
00245
00246 <span class="keywordtype">void</span> doRegisterParam(<a class="code" href="classeo_param.html">eoParam</a>&amp; param) <span class="keyword">const</span>;
00247
00248 std::pair&lt;bool, std::string&gt; getValue(<a class="code" href="classeo_param.html">eoParam</a>&amp; _param) <span class="keyword">const</span>;
00249
00250 <span class="keywordtype">void</span> updateParameters() <span class="keyword">const</span>;
00251
00252 <span class="keyword">typedef</span> std::multimap&lt;std::string, eoParam*&gt; MultiMapType;
00253
00254 <span class="comment">// used to store all parameters that are processed</span>
00255 MultiMapType params;
00256
00257 std::string programName;
00258 std::string programDescription;
00259
00260 <span class="keyword">typedef</span> std::map&lt;char, std::string&gt; ShortNameMapType;
00261 ShortNameMapType shortNameMap;
00262
00263 <span class="keyword">typedef</span> std::map&lt;std::string, std::string&gt; LongNameMapType;
00264 LongNameMapType longNameMap;
00265
00266 <a class="code" href="classeo_value_param.html">eoValueParam&lt;bool&gt;</a> needHelp;
00267 <a class="code" href="classeo_value_param.html">eoValueParam&lt;bool&gt;</a> stopOnUnknownParam;
00268
00269 <span class="keyword">mutable</span> std::vector&lt;std::string&gt; messages;
00270
00271 std::string prefix; <span class="comment">// used for all created params - in processParam</span>
00272
00273 };
00274
00275
00276
00277 <span class="preprocessor">#endif // EO_PARSER_H</span>
00278 <span class="preprocessor"></span>
00279
00280
00281 <span class="comment">// Local Variables:</span>
00282 <span class="comment">// coding: iso-8859-1</span>
00283 <span class="comment">// mode:C++</span>
00284 <span class="comment">// c-file-style: "Stroustrup"</span>
00285 <span class="comment">// comment-column: 35</span>
00286 <span class="comment">// fill-column: 80</span>
00287 <span class="comment">// End:</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:36 2006 for EO by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
</body>
</html>