1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOME_EvalExpr.cxx
23 // Author : Peter KURNEV
28 #include <SALOME_EvalExpr.hxx>
30 //=======================================================================
33 //=======================================================================
34 SALOME_EvalExpr::SALOME_EvalExpr(const RString& expr)
37 intialize( true, expr );
39 //=======================================================================
42 //=======================================================================
43 SALOME_EvalExpr::SALOME_EvalExpr(const bool stdSets, const RString& expr)
46 intialize( stdSets, expr );
48 //=======================================================================
51 //=======================================================================
52 SALOME_EvalExpr::~SALOME_EvalExpr()
58 //=======================================================================
61 //=======================================================================
62 SALOME_EvalExprError SALOME_EvalExpr::error() const
64 return myParser->error();
66 //=======================================================================
67 //function : intialize
69 //=======================================================================
70 void SALOME_EvalExpr::intialize(const bool stdSets, const RString& expr)
76 myParser = new SALOME_EvalParser();
78 myParser->setAutoDeleteOperationSets( true );
79 myParser->insertOperationSet( new SALOME_EvalSetLogic() );
80 myParser->insertOperationSet( new SALOME_EvalSetArithmetic() );
81 myParser->insertOperationSet( new SALOME_EvalSetString() );
82 myParser->insertOperationSet( new SALOME_EvalSetMath() );
83 myParser->insertOperationSet( new SALOME_EvalSetSets() );
84 myParser->insertOperationSet( new SALOME_EvalSetConst() );
86 setExpression( expr );
88 //=======================================================================
89 //function : calculate
91 //=======================================================================
92 SALOME_EvalVariant SALOME_EvalExpr::calculate(const RString& expr)
94 if ( !expr.empty() ) {
95 setExpression( expr );
97 return myParser->calculate();
99 //=======================================================================
100 //function : expression
102 //=======================================================================
103 RString SALOME_EvalExpr::expression() const
107 //=======================================================================
108 //function : setExpression
110 //=======================================================================
111 void SALOME_EvalExpr::setExpression(const RString& expr)
113 if ( expr == expression() ){
117 myParser->setExpression( myExpr );
119 //=======================================================================
122 //=======================================================================
123 SALOME_EvalParser* SALOME_EvalExpr::parser() const
128 //=======================================================================
129 //function : operationSets
131 //=======================================================================
132 SALOME_ListOfPEvalSet SALOME_EvalExpr::operationSets() const
134 return myParser->operationSets();
136 //=======================================================================
137 //function : insertOperationSet
139 //=======================================================================
140 void SALOME_EvalExpr::insertOperationSet(SALOME_EvalSet* theSet, const int idx)
142 myParser->insertOperationSet(theSet, idx);
144 //=======================================================================
145 //function : removeOperationSet
147 //=======================================================================
148 void SALOME_EvalExpr::removeOperationSet(SALOME_EvalSet* theSet)
150 myParser->removeOperationSet(theSet);
152 //=======================================================================
153 //function : operationSet
155 //=======================================================================
156 SALOME_EvalSet* SALOME_EvalExpr::operationSet(const RString& name) const
158 return myParser->operationSet( name );
160 //=======================================================================
161 //function : autoDeleteOperationSets
163 //=======================================================================
164 bool SALOME_EvalExpr::autoDeleteOperationSets() const
166 return myParser->autoDeleteOperationSets();
168 //=======================================================================
169 //function : setAutoDeleteOperationSets
171 //=======================================================================
172 void SALOME_EvalExpr::setAutoDeleteOperationSets(const bool on)
174 myParser->setAutoDeleteOperationSets( on );