]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxParser.h
Salome HOME
737fc96ceb401cabec0381e3d28a59fad8244cfd
[modules/gui.git] / src / Qtx / QtxParser.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
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.
7 // 
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/
18 //
19 // File:      QtxParser.h
20 // Author:    Alexander SOLOVYOV
21
22 #ifndef __QTX_PARSER_HEADER__
23 #define __QTX_PARSER_HEADER__
24
25 #include "Qtx.h"
26 #include <qvaluestack.h>
27 #include <qvariant.h>
28
29 #ifdef WIN32
30 #pragma warning( disable:4251 )
31 #endif
32
33
34 class QtxOperations;
35
36 typedef QVariant QtxValue;
37
38
39 //================================================================
40 // Class    : 
41 // Purpose  : 
42 //================================================================
43 class QTX_EXPORT QtxParser
44 {
45 public:
46     typedef enum
47     {
48         OK, OperandsNotMatch, InvalidResult, InvalidOperation,
49         OperationsNull, InvalidToken, CloseExpected, ExcessClose,
50         BracketsNotMatch, StackUnderflow, ExcessData
51
52     } Error;
53
54 public:
55     QtxParser( QtxOperations*, const QString& = QString::null );
56     virtual ~QtxParser();
57
58     QtxValue   calculate();
59     QtxValue   calculate( const QString& );
60     bool       setExpr( const QString& );
61
62     virtual void     clear();
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;
67
68     bool       firstInvalid( QString& ) const;
69     void       removeInvalids();
70     QString    dump() const;
71     Error      lastError() const;
72     void       paramsList( QStringList& );
73
74     static QString toString( const QValueList< QtxValue >& );
75
76 protected:
77     typedef enum { Value, Param, Open, Close, Pre, Post, Binary } PostfixItemType;
78
79     typedef struct
80     {
81         QtxValue          myValue;
82         PostfixItemType   myType;
83
84     } PostfixItem;
85
86     typedef QValueList< PostfixItem > Postfix;
87     typedef Postfix::const_iterator PostfixIterator;
88
89 protected:
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&, 
95                            int f=-1, int l=-1 );
96
97     virtual bool     parse( const QString& );
98     virtual void     setLastError( const Error );
99
100             bool     calculate( const QString&, QtxValue&, QtxValue& );
101
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 );
106
107 private:
108     typedef QValueStack < QtxValue >  QtxValueStack;
109
110 private:
111     QtxOperations*              myOperations;
112     QMap< QString, QtxValue >   myParameters;
113     Error                       myLastError;
114     Postfix                     myPost;
115 };
116
117 #endif