paradiseo/trunk/paradiseo-eo/doc/html/eo_int_bounds_8cpp-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

110 lines
8.1 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: eoIntBounds.cpp 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>eoIntBounds.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifdef _MSC_VER</span>
00002 <span class="preprocessor"></span><span class="comment">// to avoid long name warnings</span>
00003 <span class="preprocessor">#pragma warning(disable:4786)</span>
00004 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00005 <span class="preprocessor"></span>
00006 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
00007 <span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
00008 <span class="preprocessor">#endif</span>
00009 <span class="preprocessor"></span>
00010 <span class="preprocessor">#include &lt;ctime&gt;</span>
00011 <span class="preprocessor">#include &lt;sstream&gt;</span>
00012
00013 <span class="preprocessor">#include "eoIntBounds.h"</span>
00014
00015
00016 <span class="comment">// the global dummy bounds</span>
00017 <span class="comment">// (used for unbounded variables when bounds are required)</span>
00018 <a class="code" href="classeo_int_no_bounds.html">eoIntNoBounds</a> eoDummyIntNoBounds;
00019
00021 <span class="keyword">extern</span> <span class="keywordtype">bool</span> remove_leading(std::string &amp; _s, <span class="keyword">const</span> std::string _delim);
00022 <span class="keyword">extern</span> <span class="keywordtype">double</span> read_double(std::string _s);
00023 <span class="keyword">extern</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> read_int(std::string _s);
00024
00025
<a name="l00028"></a><a class="code" href="classeo_general_int_bounds.html#d0">00028</a> <a class="code" href="classeo_int_bounds.html">eoIntBounds</a>* <a class="code" href="classeo_general_int_bounds.html#d0">eoGeneralIntBounds::getBoundsFromString</a>(std::string _value)
00029 {
00030 <span class="comment">// now read</span>
00031 std::string delim(<span class="stringliteral">",; "</span>);
00032 std::string beginOrClose(<span class="stringliteral">"[(])"</span>);
00033 <span class="keywordflow">if</span> (!remove_leading(_value, delim)) <span class="comment">// only delimiters were left</span>
00034 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralIntBounds Ctor"</span>);
00035
00036 <span class="comment">// look for opening char</span>
00037 size_t posDeb = _value.find_first_of(beginOrClose); <span class="comment">// allow ]a,b]</span>
00038 <span class="keywordflow">if</span> (posDeb &gt;= _value.size()) <span class="comment">// nothing left to read</span>
00039 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralIntBounds Ctor"</span>);
00040
00041 <span class="comment">// ending char: next {}() after posDeb</span>
00042 size_t posFin = _value.find_first_of(beginOrClose,posDeb+1);
00043 <span class="keywordflow">if</span> (posFin &gt;= _value.size()) <span class="comment">// not found</span>
00044 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralIntBounds Ctor"</span>);
00045
00046 <span class="comment">// the bounds</span>
00047 std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1);
00048 <span class="comment">// and remove from original string</span>
00049 _value = _value.substr(posFin+1);
00050
00051 remove_leading(sBounds, delim);
00052 size_t posDelim = sBounds.find_first_of(delim);
00053 <span class="keywordflow">if</span> (posDelim &gt;= sBounds.size())
00054 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralIntBounds Ctor"</span>);
00055
00056 <span class="keywordtype">bool</span> minBounded=<span class="keyword">false</span>, maxBounded=<span class="keyword">false</span>;
00057 <span class="keywordtype">long</span> <span class="keywordtype">int</span> minBound=0, maxBound=0;
00058
00059 <span class="comment">// min bound</span>
00060 std::string sMinBounds = sBounds.substr(0,posDelim);
00061
00062 <span class="keywordflow">if</span> ( (sMinBounds != std::string(<span class="stringliteral">"-inf"</span>)) &amp;&amp;
00063 (sMinBounds != std::string(<span class="stringliteral">"-infinity"</span>))
00064 )
00065 {
00066 minBounded = <span class="keyword">true</span>;
00067 minBound = read_int(sMinBounds);
00068 }
00069
00070 <span class="comment">// max bound</span>
00071 size_t posEndDelim = sBounds.find_first_not_of(delim,posDelim);
00072
00073 std::string sMaxBounds = sBounds.substr(posEndDelim);
00074
00075 <span class="keywordflow">if</span> ( (sMaxBounds != std::string(<span class="stringliteral">"+inf"</span>)) &amp;&amp;
00076 (sMaxBounds != std::string(<span class="stringliteral">"+infinity"</span>))
00077 )
00078 {
00079 maxBounded = <span class="keyword">true</span>;
00080 maxBound = read_int(sMaxBounds);
00081 }
00082
00083 <span class="comment">// now create the embedded eoIntBounds object</span>
00084 <a class="code" href="classeo_int_bounds.html">eoIntBounds</a> * locBound;
00085 <span class="keywordflow">if</span> (minBounded &amp;&amp; maxBounded)
00086 {
00087 <span class="keywordflow">if</span> (maxBound &lt;= minBound)
00088 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralIntBounds Ctor"</span>);
00089 locBound = <span class="keyword">new</span> <a class="code" href="classeo_int_interval.html">eoIntInterval</a>(minBound, maxBound);
00090 }
00091 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!minBounded &amp;&amp; !maxBounded) <span class="comment">// no bound at all</span>
00092 locBound = <span class="keyword">new</span> <a class="code" href="classeo_int_no_bounds.html">eoIntNoBounds</a>;
00093 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!minBounded &amp;&amp; maxBounded)
00094 locBound = <span class="keyword">new</span> <a class="code" href="classeo_int_above_bound.html">eoIntAboveBound</a>(maxBound);
00095 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (minBounded &amp;&amp; !maxBounded)
00096 locBound = <span class="keyword">new</span> <a class="code" href="classeo_int_below_bound.html">eoIntBelowBound</a>(minBound);
00097 <span class="keywordflow">return</span> locBound;
00098 }
</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>