2 #include "QtxListOfOperations.h"
5 //================================================================
8 //================================================================
9 QtxListOfOperations::QtxListOfOperations()
13 //================================================================
16 //================================================================
17 QtxListOfOperations::~QtxListOfOperations()
21 //================================================================
24 //================================================================
25 void QtxListOfOperations::bracketsList( QStringList& list, bool open ) const
27 OperationSetsIterator anIt = mySets.begin(),
30 for( ; anIt!=aLast; anIt++ )
33 (*anIt).myOperations->bracketsList( custom, open );
34 QStringList::const_iterator aSIt = custom.begin(),
35 aSLast = custom.end();
36 for( ; aSIt!=aSLast; aSIt++ )
37 if( list.contains( *aSIt )==0 )
42 //================================================================
45 //================================================================
46 void QtxListOfOperations::opersList( QStringList& list ) const
48 OperationSetsIterator anIt = mySets.begin(),
51 for( ; anIt!=aLast; anIt++ )
54 (*anIt).myOperations->opersList( custom );
55 QStringList::const_iterator aSIt = custom.begin(),
56 aSLast = custom.end();
57 for( ; aSIt!=aSLast; aSIt++ )
58 if( list.contains( *aSIt )==0 )
63 //================================================================
66 //================================================================
67 bool QtxListOfOperations::createValue( const QString& str, QtxValue& val ) const
70 OperationSetsIterator anIt = mySets.begin(),
72 for( ; anIt!=aLast; anIt++ )
74 ok = (*anIt).myOperations->createValue( str, val );
81 //================================================================
84 //================================================================
85 int QtxListOfOperations::prior( const QString& op, bool isBin ) const
87 OperationSetsIterator anIt = mySets.begin(),
90 for( ; anIt!=aLast; anIt++ )
92 prior = (*anIt).myOperations->prior( op, isBin );
95 prior+=(*anIt).myAddPrior;
99 return prior>0 ? prior : 0;
102 //================================================================
105 //================================================================
106 QtxParser::Error QtxListOfOperations::isValid( const QString& op,
107 const QVariant::Type t1,
108 const QVariant::Type t2 ) const
110 OperationSetsIterator anIt = mySets.begin(),
111 aLast = mySets.end();
112 QtxParser::Error err = QtxParser::OK;
113 for( ; anIt!=aLast; anIt++ )
115 err = (*anIt).myOperations->isValid( op, t1, t2 );
116 if( err==QtxParser::OK )
122 //================================================================
125 //================================================================
126 QtxParser::Error QtxListOfOperations::calculate( const QString& op,
130 const char* deb = op.latin1();
132 OperationSetsIterator anIt = mySets.begin(),
133 aLast = mySets.end();
135 for( ; anIt!=aLast; anIt++ )
139 if( (*anIt).myOperations->isValid( op, v1.type(), v2.type() ) == QtxParser::OK )
141 QtxParser::Error err = (*anIt).myOperations->calculate( op, nv1, nv2 );
142 if( err==QtxParser::OK || err==QtxParser::InvalidResult )
144 QString oop = (*anIt).myName;
145 const char* ooo = oop.latin1();
151 return QtxParser::InvalidOperation;
154 //================================================================
157 //================================================================
158 void QtxListOfOperations::clear()
163 //================================================================
166 //================================================================
167 bool QtxListOfOperations::has( const QString& name ) const
169 OperationSetsIterator anIt = mySets.begin(),
170 aLast = mySets.end();
171 for( ; anIt!=aLast; anIt++ )
172 if( (*anIt).myName == name )
177 //================================================================
180 //================================================================
181 void QtxListOfOperations::append( const QString& name, QtxOperations* oper,
184 insert( name, oper, prior );
187 //================================================================
190 //================================================================
191 void QtxListOfOperations::prepend( const QString& name, QtxOperations* oper,
194 insert( name, oper, prior, 0 );
197 //================================================================
200 //================================================================
201 void QtxListOfOperations::insert( const QString& name, QtxOperations* oper,
204 if( has( name ) || oper==NULL || prior<0 )
209 op.myOperations = oper;
210 op.myAddPrior = prior;
214 mySets.insert( mySets.at( pos ), op );
217 //================================================================
220 //================================================================
221 void QtxListOfOperations::remove( const QString& name )
223 OperationSets::iterator anIt = mySets.begin(),
224 aLast = mySets.end();
225 for( ; anIt!=aLast; anIt++ )
226 if( (*anIt).myName == name )
228 mySets.erase( anIt );
233 //================================================================
236 //================================================================
237 int QtxListOfOperations::count() const
239 return mySets.count();
242 //================================================================
245 //================================================================
246 QtxOperations* QtxListOfOperations::operations( const QString& name ) const
248 OperationSetsIterator anIt = mySets.begin(),
249 aLast = mySets.end();
250 for( ; anIt!=aLast; anIt++ )
251 if( (*anIt).myName == name )
252 return (*anIt).myOperations;