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 #include "QtxListOfOperations.h"
26 QtxListOfOperations::QtxListOfOperations()
33 QtxListOfOperations::~QtxListOfOperations()
38 \return fills list with brackets symbols
39 \param list - list to be filled
40 \param open - if it is true, it is necessary to fill with open brackets otherwise with close
42 void QtxListOfOperations::bracketsList( QStringList& list, bool open ) const
44 OperationSetsIterator anIt = mySets.begin(),
47 for( ; anIt!=aLast; anIt++ )
50 (*anIt).myOperations->bracketsList( custom, open );
51 QStringList::const_iterator aSIt = custom.begin(),
52 aSLast = custom.end();
53 for( ; aSIt!=aSLast; aSIt++ )
54 if( list.contains( *aSIt )==0 )
60 Fills list with operation names
62 void QtxListOfOperations::opersList( QStringList& list ) const
64 OperationSetsIterator anIt = mySets.begin(),
67 for( ; anIt!=aLast; anIt++ )
70 (*anIt).myOperations->opersList( custom );
71 QStringList::const_iterator aSIt = custom.begin(),
72 aSLast = custom.end();
73 for( ; aSIt!=aSLast; aSIt++ )
74 if( list.contains( *aSIt )==0 )
80 Create some value by it's string representation
82 bool QtxListOfOperations::createValue( const QString& str, QtxValue& val ) const
85 OperationSetsIterator anIt = mySets.begin(),
87 for( ; anIt!=aLast; anIt++ )
89 ok = (*anIt).myOperations->createValue( str, val );
97 \return priority of operation
99 int QtxListOfOperations::prior( const QString& op, bool isBin ) const
101 OperationSetsIterator anIt = mySets.begin(),
102 aLast = mySets.end();
104 for( ; anIt!=aLast; anIt++ )
106 prior = (*anIt).myOperations->prior( op, isBin );
109 prior+=(*anIt).myAddPrior;
113 return prior>0 ? prior : 0;
117 \return whether values with passed types are valid for arguments of operation
118 \param op - name of operation
119 \param t1 - type of first argument
120 \param t2 - type of second argument
122 QtxParser::Error QtxListOfOperations::isValid( const QString& op,
123 const QVariant::Type t1,
124 const QVariant::Type t2 ) const
126 OperationSetsIterator anIt = mySets.begin(),
127 aLast = mySets.end();
128 QtxParser::Error err = QtxParser::OK;
129 for( ; anIt!=aLast; anIt++ )
131 err = (*anIt).myOperations->isValid( op, t1, t2 );
132 if( err==QtxParser::OK )
139 Calculates result of operation
140 \return one of error states
141 \param op - name of operation
142 \param v1 - first operation argument (must be used also to store result)
143 \param v2 - second operation argument
145 QtxParser::Error QtxListOfOperations::calculate( const QString& op,
149 const char* deb = op.latin1();
151 OperationSetsIterator anIt = mySets.begin(),
152 aLast = mySets.end();
154 for( ; anIt!=aLast; anIt++ )
158 if( (*anIt).myOperations->isValid( op, v1.type(), v2.type() ) == QtxParser::OK )
160 QtxParser::Error err = (*anIt).myOperations->calculate( op, nv1, nv2 );
161 if( err==QtxParser::OK || err==QtxParser::InvalidResult )
163 QString oop = (*anIt).myName;
164 const char* ooo = oop.latin1();
170 return QtxParser::InvalidOperation;
174 Clears list of operations
176 void QtxListOfOperations::clear()
182 \return true if list contains operations
183 \param name - name of operation
185 bool QtxListOfOperations::has( const QString& name ) const
187 OperationSetsIterator anIt = mySets.begin(),
188 aLast = mySets.end();
189 for( ; anIt!=aLast; anIt++ )
190 if( (*anIt).myName == name )
196 Appends operations to list
197 \param name - name of operations
198 \param oper - operations
199 \param prior - additional prior
201 void QtxListOfOperations::append( const QString& name, QtxOperations* oper,
204 insert( name, oper, prior );
208 Prepends operations to list
209 \param name - name of operations
210 \param oper - operations
211 \param prior - additional prior
213 void QtxListOfOperations::prepend( const QString& name, QtxOperations* oper,
216 insert( name, oper, prior, 0 );
220 Inserts operations to list
221 \param name - name of operations
222 \param oper - operations
223 \param prior - additional prior
224 \param pos - insert position
226 void QtxListOfOperations::insert( const QString& name, QtxOperations* oper,
229 if( has( name ) || oper==NULL || prior<0 )
234 op.myOperations = oper;
235 op.myAddPrior = prior;
239 mySets.insert( mySets.at( pos ), op );
243 Removes operations from list
244 \param name - name of operations
246 void QtxListOfOperations::remove( const QString& name )
248 OperationSets::iterator anIt = mySets.begin(),
249 aLast = mySets.end();
250 for( ; anIt!=aLast; anIt++ )
251 if( (*anIt).myName == name )
253 mySets.erase( anIt );
259 \return count of operations in list
261 int QtxListOfOperations::count() const
263 return mySets.count();
267 \return operations by name
268 \name - name of operations
270 QtxOperations* QtxListOfOperations::operations( const QString& name ) const
272 OperationSetsIterator anIt = mySets.begin(),
273 aLast = mySets.end();
274 for( ; anIt!=aLast; anIt++ )
275 if( (*anIt).myName == name )
276 return (*anIt).myOperations;