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 SALOME_String& );
48 bool setExpression( const SALOME_String& );
50 SALOME_ListOfEvalSet operationSets() const;
51 SALOME_EvalSet* operationSet( const SALOME_String& ) const;
52 void removeOperationSet( SALOME_EvalSet* );
53 void insertOperationSet( SALOME_EvalSet*, const int = -1 );
55 bool autoDeleteOperationSets() const;
56 void setAutoDeleteOperationSets( const bool );
58 virtual void clearParameters();
59 virtual bool removeParameter( const SALOME_String& name );
60 virtual SALOME_EvalVariant parameter( const SALOME_String& name ) const;
61 virtual bool hasParameter( const SALOME_String& name ) const;
62 virtual void setParameter( const SALOME_String& name, const SALOME_EvalVariant& value );
63 SALOME_StringList parameters() const;
65 SALOME_EvalExprError error() const;
67 bool firstInvalid( SALOME_String& ) const;
68 void removeInvalids();
69 SALOME_String dump() const;
71 static SALOME_String toString( const SALOME_ListOfEvalVariant& );
74 //! Types of postfix representation elements
77 Value, //!< Value (number, string, etc.)
79 Open, //!< Open bracket
80 Close, //!< Close bracket
81 Pre, //!< Unary prefix operation
82 Post, //!< Unary postfix operation
83 Binary //!< Binary operation
86 //! Postfix representation element
89 SALOME_EvalVariant myValue;
90 PostfixItemType myType;
93 typedef list<PostfixItem> Postfix; //!< postfix representation
94 typedef SALOME_ListOfEvalSet SetList; //!< list of operations
95 typedef map <SALOME_String, SALOME_EvalVariant> ParamMap; //!< parameter-to-value map
96 typedef map <SALOME_String, SALOME_EvalVariant>::value_type PairParamMap;
99 SALOME_String dump( const Postfix& ) const;
101 virtual bool prepare( const SALOME_String&, Postfix& );
102 virtual bool setOperationTypes( Postfix& );
103 virtual bool sort( const Postfix&, Postfix&, const SALOME_StringList&, const SALOME_StringList&, int f = -1, int l = -1 );
104 virtual bool parse( const SALOME_String& );
105 virtual void setError( const SALOME_EvalExprError );
107 bool calculate( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& );
109 static int search( const SALOME_StringList&, const SALOME_String&, int offset, int& matchLen, int& listind );
110 static SALOME_String note( const SALOME_String& str, int pos, int len );
111 static int globalBrackets( const Postfix&, int, int );
114 void operationList( SALOME_StringList& ) const;
115 void bracketsList( SALOME_StringList&, bool ) const;
116 bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const;
117 int priority( const SALOME_String&, bool isBin ) const;
119 SALOME_EvalExprError isValid( const SALOME_String&, const SALOME_EvalVariantType, const SALOME_EvalVariantType ) const;
120 SALOME_EvalExprError calculation( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const;
122 bool checkOperations() const;
123 void insert( Postfix& aL, const int aIndex, PostfixItem& aItem );
124 const PostfixItem& at( const Postfix& aL, const int aIndex );
125 void append( Postfix& aL, const Postfix& aL1 );
128 SALOME_ListOfEvalSet mySets;
129 SALOME_EvalExprError myError;