00001 #ifdef _MSC_VER
00002
00003 #pragma warning(disable:4786)
00004 #endif
00005
00006 #ifdef HAVE_CONFIG_H
00007 #include <config.h>
00008 #endif
00009
00010 #include <ctime>
00011 #include <sstream>
00012
00013 #include "eoIntBounds.h"
00014
00015
00016
00017
00018 eoIntNoBounds eoDummyIntNoBounds;
00019
00021 extern bool remove_leading(std::string & _s, const std::string _delim);
00022 extern double read_double(std::string _s);
00023 extern long int read_int(std::string _s);
00024
00025
00028 eoIntBounds* eoGeneralIntBounds::getBoundsFromString(std::string _value)
00029 {
00030
00031 std::string delim(",; ");
00032 std::string beginOrClose("[(])");
00033 if (!remove_leading(_value, delim))
00034 throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
00035
00036
00037 size_t posDeb = _value.find_first_of(beginOrClose);
00038 if (posDeb >= _value.size())
00039 throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
00040
00041
00042 size_t posFin = _value.find_first_of(beginOrClose,posDeb+1);
00043 if (posFin >= _value.size())
00044 throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
00045
00046
00047 std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1);
00048
00049 _value = _value.substr(posFin+1);
00050
00051 remove_leading(sBounds, delim);
00052 size_t posDelim = sBounds.find_first_of(delim);
00053 if (posDelim >= sBounds.size())
00054 throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
00055
00056 bool minBounded=false, maxBounded=false;
00057 long int minBound=0, maxBound=0;
00058
00059
00060 std::string sMinBounds = sBounds.substr(0,posDelim);
00061
00062 if ( (sMinBounds != std::string("-inf")) &&
00063 (sMinBounds != std::string("-infinity"))
00064 )
00065 {
00066 minBounded = true;
00067 minBound = read_int(sMinBounds);
00068 }
00069
00070
00071 size_t posEndDelim = sBounds.find_first_not_of(delim,posDelim);
00072
00073 std::string sMaxBounds = sBounds.substr(posEndDelim);
00074
00075 if ( (sMaxBounds != std::string("+inf")) &&
00076 (sMaxBounds != std::string("+infinity"))
00077 )
00078 {
00079 maxBounded = true;
00080 maxBound = read_int(sMaxBounds);
00081 }
00082
00083
00084 eoIntBounds * locBound;
00085 if (minBounded && maxBounded)
00086 {
00087 if (maxBound <= minBound)
00088 throw std::runtime_error("Syntax error in eoGeneralIntBounds Ctor");
00089 locBound = new eoIntInterval(minBound, maxBound);
00090 }
00091 else if (!minBounded && !maxBounded)
00092 locBound = new eoIntNoBounds;
00093 else if (!minBounded && maxBounded)
00094 locBound = new eoIntAboveBound(maxBound);
00095 else if (minBounded && !maxBounded)
00096 locBound = new eoIntBelowBound(minBound);
00097 return locBound;
00098 }