1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCalculatorDBRangeSelection.hxx"
27 using namespace ParaMEDMEM;
29 const char MEDCalculatorDBRangeSelection::ALL_ELTS[]=":";
31 MEDCalculatorDBRangeSelection::MEDCalculatorDBRangeSelection(const char *v) throw(INTERP_KERNEL::Exception)
36 catch(INTERP_KERNEL::Exception& e)
41 MEDCalculatorDBRangeSelection::MEDCalculatorDBRangeSelection(int v)
46 MEDCalculatorDBRangeSelection::MEDCalculatorDBRangeSelection()
51 void MEDCalculatorDBRangeSelection::setPyStart(int val)
53 _start=TraducePyVal(val);
56 void MEDCalculatorDBRangeSelection::setPyEnd(int val)
58 _end=TraducePyVal(val);
61 std::vector<int> MEDCalculatorDBRangeSelection::getIds(int lgth) const throw(INTERP_KERNEL::Exception)
63 if(_start>=lgth || _start<0)
65 std::ostringstream oss;
66 oss << "RangeSelection::getIds : Specified range is outside possible value : " << lgth << " ! ";
67 throw INTERP_KERNEL::Exception(oss.str().c_str());
72 if(_end==std::numeric_limits<int>::max())
75 throw INTERP_KERNEL::Exception("RangeSelection::getIds : end specficied is higher than length !");
77 throw INTERP_KERNEL::Exception("RangeSelection::getIds : begin of range after end !");
78 std::vector<int> ret(trueEnd-_start);
80 for(int i=_start;i<trueEnd;i++,j++)
85 int MEDCalculatorDBRangeSelection::getSize(int lgth) const throw(INTERP_KERNEL::Exception)
87 return getIds(lgth).size();
90 bool MEDCalculatorDBRangeSelection::isAll() const
92 return _start==0 && _end==std::numeric_limits<int>::max();
95 void MEDCalculatorDBRangeSelection::setAll()
98 _end=std::numeric_limits<int>::max();
101 MEDCalculatorDBRangeSelection& MEDCalculatorDBRangeSelection::operator=(const char *v) throw(INTERP_KERNEL::Exception)
107 MEDCalculatorDBRangeSelection& MEDCalculatorDBRangeSelection::operator=(int v) throw(INTERP_KERNEL::Exception)
113 void MEDCalculatorDBRangeSelection::setValue(const char *v) throw(INTERP_KERNEL::Exception)
118 std::size_t pos=s.find_first_of(SEPARATOR);
119 if(pos!=std::string::npos)
121 std::string s1=s.substr(0,pos);
122 std::string s2=s.substr(pos+1);
123 std::size_t pos2=s2.find_first_of(SEPARATOR);
124 if(pos2!=std::string::npos)
125 throw INTERP_KERNEL::Exception("RangeSelection constructor : Only one ':' supported !");
130 std::istringstream iss(s1);
131 iss.exceptions(std::istream::failbit | std::istream::badbit);
134 throw INTERP_KERNEL::Exception("Invalid 1st part of ':' !");
138 _end=std::numeric_limits<int>::max();
141 std::istringstream iss(s2);
142 iss.exceptions(std::istream::failbit | std::istream::badbit);
145 throw INTERP_KERNEL::Exception("Invalid 2nd part of ':' !");
149 throw INTERP_KERNEL::Exception("RangeSelection constructor : begin of range after end !");
152 catch(INTERP_KERNEL::Exception& e)
156 catch(std::istream::failure& e)
158 throw INTERP_KERNEL::Exception("RangeSelection constructor : impossible to analyze one side of expr ':' !");
162 void MEDCalculatorDBRangeSelection::setValue(int v) throw(INTERP_KERNEL::Exception)
168 int MEDCalculatorDBRangeSelection::TraducePyVal(int val)