Salome HOME
Base implementation of Notebook
[modules/kernel.git] / src / Notebook / SALOME_EvalExpr.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOME_EvalExpr.cxx
23 //  Author : Peter KURNEV
24 //  Module : SALOME
25
26
27
28 #include <SALOME_EvalExpr.hxx>
29
30 //=======================================================================
31 //function : 
32 //purpose  : 
33 //=======================================================================
34 SALOME_EvalExpr::SALOME_EvalExpr( const SALOME_String& expr )
35 {
36   myParser=NULL;
37   initialize( true, expr );
38 }
39 //=======================================================================
40 //function : 
41 //purpose  : 
42 //=======================================================================
43 SALOME_EvalExpr::SALOME_EvalExpr( const bool stdSets, const SALOME_String& expr )
44 {
45   myParser=NULL;
46   initialize( stdSets, expr );
47 }
48 //=======================================================================
49 //function : ~
50 //purpose  : 
51 //=======================================================================
52 SALOME_EvalExpr::~SALOME_EvalExpr()
53 {
54   if (myParser) {
55     delete myParser;
56   }
57 }
58 //=======================================================================
59 //function : error
60 //purpose  : 
61 //=======================================================================
62 SALOME_EvalExprError SALOME_EvalExpr::error() const
63 {
64   return myParser->error();
65 }
66 //=======================================================================
67 //function : initialize
68 //purpose  : 
69 //=======================================================================
70 void SALOME_EvalExpr::initialize( const bool stdSets, const SALOME_String& expr )
71 {
72   if (myParser) {
73     delete myParser;
74   }
75
76   myParser = new SALOME_EvalParser();
77   if ( stdSets )  {
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() );
85   }
86   setExpression( expr );
87 }
88 //=======================================================================
89 //function : calculate
90 //purpose  : 
91 //=======================================================================
92 SALOME_EvalVariant SALOME_EvalExpr::calculate(const SALOME_String& expr)
93 {
94   if ( !expr.empty() ) {
95     setExpression( expr );
96   }
97   return myParser->calculate();
98 }
99 //=======================================================================
100 //function : expression
101 //purpose  : 
102 //=======================================================================
103 SALOME_String SALOME_EvalExpr::expression() const
104 {
105   return myExpr;
106 }
107 //=======================================================================
108 //function : setExpression
109 //purpose  : 
110 //=======================================================================
111 void SALOME_EvalExpr::setExpression(const SALOME_String& expr)
112 {
113   if ( expr == expression() ){
114     return;
115   }
116   myExpr = expr;
117   myParser->setExpression( myExpr );
118 }
119 //=======================================================================
120 //function : parser
121 //purpose  : 
122 //=======================================================================
123 SALOME_EvalParser* SALOME_EvalExpr::parser() const
124 {
125   return myParser;
126 }
127
128 //=======================================================================
129 //function : operationSets
130 //purpose  : 
131 //=======================================================================
132 SALOME_ListOfEvalSet SALOME_EvalExpr::operationSets() const
133 {
134   return myParser->operationSets();
135 }
136 //=======================================================================
137 //function : insertOperationSet
138 //purpose  : 
139 //=======================================================================
140 void SALOME_EvalExpr::insertOperationSet(SALOME_EvalSet* theSet, const int idx)
141 {
142   myParser->insertOperationSet(theSet, idx);
143 }
144 //=======================================================================
145 //function : removeOperationSet
146 //purpose  : 
147 //=======================================================================
148 void SALOME_EvalExpr::removeOperationSet(SALOME_EvalSet* theSet)
149 {
150   myParser->removeOperationSet(theSet);
151 }
152 //=======================================================================
153 //function : operationSet
154 //purpose  : 
155 //=======================================================================
156 SALOME_EvalSet* SALOME_EvalExpr::operationSet(const SALOME_String& name) const
157 {
158   return myParser->operationSet( name );
159 }
160 //=======================================================================
161 //function : autoDeleteOperationSets
162 //purpose  : 
163 //=======================================================================
164 bool SALOME_EvalExpr::autoDeleteOperationSets() const
165 {
166   return myParser->autoDeleteOperationSets();
167 }
168 //=======================================================================
169 //function : setAutoDeleteOperationSets
170 //purpose  : 
171 //=======================================================================
172 void SALOME_EvalExpr::setAutoDeleteOperationSets(const bool on)
173 {
174   myParser->setAutoDeleteOperationSets( on );
175 }