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"
23 //================================================================
26 //================================================================
27 QtxListOfOperations::QtxListOfOperations()
31 //================================================================
34 //================================================================
35 QtxListOfOperations::~QtxListOfOperations()
39 //================================================================
42 //================================================================
43 void QtxListOfOperations::bracketsList( QStringList& list, bool open ) const
45 OperationSetsIterator anIt = mySets.begin(),
48 for( ; anIt!=aLast; anIt++ )
51 (*anIt).myOperations->bracketsList( custom, open );
52 QStringList::const_iterator aSIt = custom.begin(),
53 aSLast = custom.end();
54 for( ; aSIt!=aSLast; aSIt++ )
55 if( list.contains( *aSIt )==0 )
60 //================================================================
63 //================================================================
64 void QtxListOfOperations::opersList( QStringList& list ) const
66 OperationSetsIterator anIt = mySets.begin(),
69 for( ; anIt!=aLast; anIt++ )
72 (*anIt).myOperations->opersList( custom );
73 QStringList::const_iterator aSIt = custom.begin(),
74 aSLast = custom.end();
75 for( ; aSIt!=aSLast; aSIt++ )
76 if( list.contains( *aSIt )==0 )
81 //================================================================
84 //================================================================
85 bool QtxListOfOperations::createValue( const QString& str, QtxValue& val ) const
88 OperationSetsIterator anIt = mySets.begin(),
90 for( ; anIt!=aLast; anIt++ )
92 ok = (*anIt).myOperations->createValue( str, val );
99 //================================================================
102 //================================================================
103 int QtxListOfOperations::prior( const QString& op, bool isBin ) const
105 OperationSetsIterator anIt = mySets.begin(),
106 aLast = mySets.end();
108 for( ; anIt!=aLast; anIt++ )
110 prior = (*anIt).myOperations->prior( op, isBin );
113 prior+=(*anIt).myAddPrior;
117 return prior>0 ? prior : 0;
120 //================================================================
123 //================================================================
124 QtxParser::Error QtxListOfOperations::isValid( const QString& op,
125 const QVariant::Type t1,
126 const QVariant::Type t2 ) const
128 OperationSetsIterator anIt = mySets.begin(),
129 aLast = mySets.end();
130 QtxParser::Error err = QtxParser::OK;
131 for( ; anIt!=aLast; anIt++ )
133 err = (*anIt).myOperations->isValid( op, t1, t2 );
134 if( err==QtxParser::OK )
140 //================================================================
143 //================================================================
144 QtxParser::Error QtxListOfOperations::calculate( const QString& op,
148 const char* deb = op.latin1();
150 OperationSetsIterator anIt = mySets.begin(),
151 aLast = mySets.end();
153 for( ; anIt!=aLast; anIt++ )
157 if( (*anIt).myOperations->isValid( op, v1.type(), v2.type() ) == QtxParser::OK )
159 QtxParser::Error err = (*anIt).myOperations->calculate( op, nv1, nv2 );
160 if( err==QtxParser::OK || err==QtxParser::InvalidResult )
162 QString oop = (*anIt).myName;
163 const char* ooo = oop.latin1();
169 return QtxParser::InvalidOperation;
172 //================================================================
175 //================================================================
176 void QtxListOfOperations::clear()
181 //================================================================
184 //================================================================
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 )
195 //================================================================
198 //================================================================
199 void QtxListOfOperations::append( const QString& name, QtxOperations* oper,
202 insert( name, oper, prior );
205 //================================================================
208 //================================================================
209 void QtxListOfOperations::prepend( const QString& name, QtxOperations* oper,
212 insert( name, oper, prior, 0 );
215 //================================================================
218 //================================================================
219 void QtxListOfOperations::insert( const QString& name, QtxOperations* oper,
222 if( has( name ) || oper==NULL || prior<0 )
227 op.myOperations = oper;
228 op.myAddPrior = prior;
232 mySets.insert( mySets.at( pos ), op );
235 //================================================================
238 //================================================================
239 void QtxListOfOperations::remove( const QString& name )
241 OperationSets::iterator anIt = mySets.begin(),
242 aLast = mySets.end();
243 for( ; anIt!=aLast; anIt++ )
244 if( (*anIt).myName == name )
246 mySets.erase( anIt );
251 //================================================================
254 //================================================================
255 int QtxListOfOperations::count() const
257 return mySets.count();
260 //================================================================
263 //================================================================
264 QtxOperations* QtxListOfOperations::operations( const QString& name ) const
266 OperationSetsIterator anIt = mySets.begin(),
267 aLast = mySets.end();
268 for( ; anIt!=aLast; anIt++ )
269 if( (*anIt).myName == name )
270 return (*anIt).myOperations;