1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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.
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/
20 // Author: Alexander SOLOVYOV
22 #ifndef __QTX_PARSER_HEADER__
23 #define __QTX_PARSER_HEADER__
26 #include <qvaluestack.h>
30 #pragma warning( disable:4251 )
36 typedef QVariant QtxValue;
39 //================================================================
42 //================================================================
43 class QTX_EXPORT QtxParser
48 OK, OperandsNotMatch, InvalidResult, InvalidOperation,
49 OperationsNull, InvalidToken, CloseExpected, ExcessClose,
50 BracketsNotMatch, StackUnderflow, ExcessData
55 QtxParser( QtxOperations*, const QString& = QString::null );
59 QtxValue calculate( const QString& );
60 bool setExpr( const QString& );
63 virtual bool has ( const QString& name ) const;
64 virtual void set ( const QString& name, const QtxValue& value );
65 virtual bool remove( const QString& name );
66 virtual QtxValue value ( const QString& name ) const;
68 bool firstInvalid( QString& ) const;
69 void removeInvalids();
71 Error lastError() const;
72 void paramsList( QStringList& );
74 static QString toString( const QValueList< QtxValue >& );
77 typedef enum { Value, Param, Open, Close, Pre, Post, Binary } PostfixItemType;
82 PostfixItemType myType;
86 typedef QValueList< PostfixItem > Postfix;
87 typedef Postfix::const_iterator PostfixIterator;
90 QString dump( const Postfix& ) const;
91 virtual bool prepare( const QString&, Postfix& );
92 virtual bool setOperationTypes( Postfix& );
93 virtual bool sort( const Postfix&, Postfix&,
94 const QStringList&, const QStringList&,
97 virtual bool parse( const QString& );
98 virtual void setLastError( const Error );
100 bool calculate( const QString&, QtxValue&, QtxValue& );
102 static int search ( const QStringList&, const QString&, int offset,
103 int& matchLen, int& listind );
104 static QString note ( const QString& str, int pos, int len );
105 static int globalBrackets( const Postfix&, int, int );
108 typedef QValueStack < QtxValue > QtxValueStack;
111 QtxOperations* myOperations;
112 QMap< QString, QtxValue > myParameters;