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_EvalParser.hxx
23 // Author : Peter KURNEV
26 #ifndef SALOME_EvalParser_Header_File
27 #define SALOME_EvalParser_Header_File
30 #pragma warning(disable : 4786)
36 #include <SALOME_EvalVariant.hxx>
37 #include <SALOME_EvalSet.hxx>
38 #include <SALOME_Eval.hxx>
40 class SALOME_EvalParser
44 virtual ~SALOME_EvalParser();
46 SALOME_EvalVariant calculate();
47 SALOME_EvalVariant calculate( const RString& );
48 bool setExpression( const RString& );
50 SALOME_ListOfPEvalSet operationSets() const;
51 SALOME_PEvalSet operationSet( const RString& ) const;
52 void removeOperationSet(SALOME_PEvalSet );
53 void insertOperationSet(SALOME_PEvalSet,
56 bool autoDeleteOperationSets() const;
57 void setAutoDeleteOperationSets( const bool );
59 virtual void clearParameters();
60 virtual bool removeParameter( const RString& name );
61 virtual SALOME_EvalVariant parameter( const RString& name ) const;
62 virtual bool hasParameter( const RString& name ) const;
63 virtual void setParameter( const RString& name,
64 const SALOME_EvalVariant& value );
65 RStringList parameters() const;
67 SALOME_EvalExprError error() const;
69 bool firstInvalid( RString& ) const;
70 void removeInvalids();
73 static RString toString( const SALOME_ListOfEvalVariant& );
76 //! Types of postfix representation elements
78 Value, //!< Value (number, string, etc.)
80 Open, //!< Open bracket
81 Close, //!< Close bracket
82 Pre, //!< Unary prefix operation
83 Post, //!< Unary postfix operation
84 Binary //!< Binary operation
87 //! Postfix representation element
89 SALOME_EvalVariant myValue;
90 PostfixItemType myType;
93 typedef list<PostfixItem> Postfix; //!< postfix representation
94 typedef SALOME_ListOfPEvalSet SetList; //!< list of operations
95 typedef map <RString, SALOME_EvalVariant> ParamMap; //!< parameter-to-value map
96 typedef map <RString, SALOME_EvalVariant>::value_type PairParamMap;
99 RString dump( const Postfix& ) const;
101 virtual bool prepare( const RString&, Postfix& );
103 virtual bool setOperationTypes( Postfix& );
105 virtual bool sort(const Postfix&,
112 virtual bool parse( const RString& );
113 virtual void setError( const SALOME_EvalExprError );
115 bool calculate(const RString&,
117 SALOME_EvalVariant& );
119 static int search(const RStringList&,
125 static RString note(const RString& str,
129 static int globalBrackets(const Postfix&,
134 void operationList(RStringList& ) const;
136 void bracketsList(RStringList&,
139 bool createValue(const RString&,
140 SALOME_EvalVariant& ) const;
142 int priority(const RString&,
145 SALOME_EvalExprError isValid(const RString&,
146 const SALOME_EvalVariantType,
147 const SALOME_EvalVariantType ) const;
149 SALOME_EvalExprError calculation(const RString&,
151 SALOME_EvalVariant& ) const;
153 bool checkOperations() const;
154 ////////////////////////////////////
155 void insert(Postfix& aL,
159 const PostfixItem& at(const Postfix& aL,
162 void SALOME_EvalParser::append(Postfix& aL,
165 SALOME_ListOfPEvalSet mySets;
166 SALOME_EvalExprError myError;