1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOME_EvalSet.cxx
23 // Author : Peter KURNEV
27 #include <SALOME_EvalSet.hxx>
30 #include <SALOME_Eval.hxx>
32 int toInt(const SALOME_String& str, bool *ok);
33 double toDouble(const SALOME_String& str, bool *ok);
34 SALOME_String toLower(const SALOME_String& str);
35 SALOME_String toUpper(const SALOME_String& str);
37 //=======================================================================
38 //function : SALOME_EvalSet
40 //=======================================================================
41 SALOME_EvalSet::SALOME_EvalSet()
44 //=======================================================================
45 //function : SALOME_EvalSet::~SALOME_EvalSet
47 //=======================================================================
48 SALOME_EvalSet::~SALOME_EvalSet()
51 //=======================================================================
52 //function : SALOME_EvalSet::createValue
54 //=======================================================================
55 bool SALOME_EvalSet::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const
60 //=======================================================================
61 //function : SALOME_EvalSet::contains
63 //=======================================================================
64 bool SALOME_EvalSet::contains( const SALOME_ListOfEvalSet& aL, const SALOME_EvalSet* pS)
69 SALOME_ListOfEvalSet::const_iterator aIt=aL.begin();
70 for(; aIt!=aL.end(); ++aIt) {
71 const SALOME_EvalSet* pSx=*aIt;
79 //=======================================================================
80 //function : SALOME_EvalSet::insert
82 //=======================================================================
83 void SALOME_EvalSet::insert(SALOME_ListOfEvalSet& aL, const int aIndex, SALOME_EvalSet* pS)
90 else if (aIndex==aL.size()) {
94 SALOME_ListOfEvalSet::iterator aIt=aL.begin();
95 for(i=0; aIt!=aL.end(); ++aIt, ++i) {
96 //const SALOME_EvalSet* pSx=*aIt;
104 ///////////////////////////////////
105 //=======================================================================
106 //function : SALOME_EvalSetBase
108 //=======================================================================
109 SALOME_EvalSetBase::SALOME_EvalSetBase()
112 //=======================================================================
113 //function : ~SALOME_EvalSetBase
115 //=======================================================================
116 SALOME_EvalSetBase::~SALOME_EvalSetBase()
119 //=======================================================================
120 //function : SALOME_EvalSetBase::operationList
122 //=======================================================================
123 void SALOME_EvalSetBase::operationList( SALOME_StringList& aList ) const
125 SALOME_StringList::const_iterator aIt;
128 for (; aIt!=myOpers.end(); ++aIt) {
129 aList.push_back(*aIt);
132 //=======================================================================
133 //function : SALOME_EvalSetBase::bracketsList
135 //=======================================================================
136 void SALOME_EvalSetBase::bracketsList(SALOME_StringList& aList,
139 aList.push_back( bOpen ? "(" : ")" );
141 //=======================================================================
142 //function : SALOME_EvalSetBase::addOperations
144 //=======================================================================
145 void SALOME_EvalSetBase::addOperations(const SALOME_StringList& aList)
147 SALOME_StringList::const_iterator aIt;
148 SALOME_StringSet aSet;
149 SALOME_SetPair aSetPair;
152 for (; aIt != aList.end(); ++aIt)
154 aSetPair=aSet.insert(*aIt);
155 if(aSetPair.second) {
156 myOpers.push_back( *aIt );
160 //=======================================================================
161 //function : SALOME_EvalSetBase::addTypes
163 //=======================================================================
164 void SALOME_EvalSetBase::addTypes(const SALOME_ListOfEvalVariantType& aList)
166 SALOME_ListOfEvalVariantType::const_iterator aIt;
167 SALOME_SetOfEvalVariantType aSet;
168 SALOME_SetPairOfEvalVariantType aSetPair;
171 for (; aIt != aList.end(); ++aIt ) {
172 aSetPair=aSet.insert(*aIt);
173 if(aSetPair.second) {
174 myTypes.push_back(*aIt);
178 //=======================================================================
179 //function : SALOME_EvalSetBase::isValid
181 //=======================================================================
182 SALOME_EvalExprError SALOME_EvalSetBase::isValid( const SALOME_String& op,
183 const SALOME_EvalVariantType t1,
184 const SALOME_EvalVariantType t2 ) const
186 bool bContainsT1, bContainsT2;
187 SALOME_SetOfEvalVariantType aSet;
188 SALOME_SetPairOfEvalVariantType aSetPair;
189 SALOME_ListOfEvalVariantType::const_iterator aIt;
190 SALOME_EvalVariantType aType;
193 for (; aIt != myTypes.end(); ++aIt ) {
198 aSetPair=aSet.insert(t1);
199 bContainsT1=!aSetPair.second;
201 aSetPair=aSet.insert(t2);
202 bContainsT2=!aSetPair.second;
204 if ( ( t1 == SALOME_EvalVariant_Invalid || bContainsT1 ) &&
205 ( t2 == SALOME_EvalVariant_Invalid || bContainsT2 ) &&
206 ( t1 != SALOME_EvalVariant_Invalid || t2 != SALOME_EvalVariant_Invalid ) ) {
207 if ( priority( op, t1 != SALOME_EvalVariant_Invalid && t2 != SALOME_EvalVariant_Invalid ) > 0 ) {
211 return EvalExpr_InvalidOperation;
214 return EvalExpr_OperandsNotMatch;
216 ////////////////////////////////////////////////////////////////////////
217 //=======================================================================
218 //function : SALOME_EvalSetArithmetic::SALOME_EvalSetArithmetic
220 //=======================================================================
221 SALOME_EvalSetArithmetic::SALOME_EvalSetArithmetic()
222 : SALOME_EvalSetBase()
225 SALOME_StringList aStringList;
226 SALOME_ListOfEvalVariantType aTypes;
228 aOp="+"; aStringList.push_back(aOp);
229 aOp="-"; aStringList.push_back(aOp);
230 aOp="*"; aStringList.push_back(aOp);
231 aOp="/"; aStringList.push_back(aOp);
232 aOp="="; aStringList.push_back(aOp);
233 aOp="<"; aStringList.push_back(aOp);
234 aOp=">"; aStringList.push_back(aOp);
235 aOp="<="; aStringList.push_back(aOp);
236 aOp=">="; aStringList.push_back(aOp);
237 aOp="<>"; aStringList.push_back(aOp);
238 aOp="!="; aStringList.push_back(aOp);
239 addOperations( aStringList );
241 aTypes.push_back( SALOME_EvalVariant_Int );
242 aTypes.push_back( SALOME_EvalVariant_UInt );
243 aTypes.push_back( SALOME_EvalVariant_Double );
246 //=======================================================================
247 //function : SALOME_EvalSetArithmetic::~SALOME_EvalSetArithmetic
249 //=======================================================================
250 SALOME_EvalSetArithmetic::~SALOME_EvalSetArithmetic()
253 //=======================================================================
254 //function : SALOME_EvalSetArithmetic::Name
256 //=======================================================================
257 SALOME_String SALOME_EvalSetArithmetic::Name()
261 //=======================================================================
262 //function : SALOME_EvalSetArithmetic::name
264 //=======================================================================
265 SALOME_String SALOME_EvalSetArithmetic::name()const
269 //=======================================================================
270 //function : SALOME_EvalSetArithmetic::createValue
272 //=======================================================================
273 bool SALOME_EvalSetArithmetic::createValue(const SALOME_String& str,
274 SALOME_EvalVariant& val ) const
284 SALOME_EvalVariant aRV(iX);
289 dX=toDouble(str, &ok );
291 SALOME_EvalVariant aRV(dX);
296 ok = SALOME_EvalSetBase::createValue( str, val );
299 //=======================================================================
300 //function : SALOME_EvalSetArithmetic::priority
302 //=======================================================================
303 int SALOME_EvalSetArithmetic::priority(const SALOME_String& op, bool isBin) const
307 if ( op == "<" || op == ">" || op == "=" ||
308 op == "<=" || op == ">=" || op == "<>" || op == "!=" )
310 else if ( op == "+" || op == "-" )
312 else if( op == "*" || op == "/" )
317 else if ( op == "+" || op == "-" )
322 //=======================================================================
323 //function : SALOME_EvalSetArithmetic::calculate
325 //=======================================================================
326 SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const SALOME_String& op,
327 SALOME_EvalVariant& v1,
328 SALOME_EvalVariant& v2 ) const
330 bool bValid1, bValid2, bOk;
331 SALOME_EvalExprError err;
332 SALOME_EvalVariantType aType1, aType2;
336 bValid1=v1.isValid();
337 bValid2=v2.isValid();
341 if ( bValid1 && bValid2 ) {// binary operations
342 if ( ( aType1 == SALOME_EvalVariant_Int || aType1 == SALOME_EvalVariant_UInt ) &&
343 ( aType2 == SALOME_EvalVariant_Int || aType2 == SALOME_EvalVariant_UInt ) ) {
346 _v1 = v1.toInt(&bOk);
347 _v2 = v2.toInt(&bOk);
352 else if ( op == "-" ){
355 else if ( op == "*" ){
358 else if ( op == "/" ) {
360 if ( _v1 % _v2 == 0 ) {
364 v1 = double( _v1 ) / double( _v2 );
368 err = EvalExpr_InvalidResult;
371 else if ( op == "<" ) {
374 else if ( op == ">" ){
377 else if ( op == "=" ){
380 else if ( op == "<=" ){
383 else if ( op == ">=" ){
386 else if ( op == "<>" || op == "!=" ){
390 else if ( ( aType1 == SALOME_EvalVariant_Int || aType1 == SALOME_EvalVariant_Double ) &&
391 ( aType2 == SALOME_EvalVariant_Int || aType2 == SALOME_EvalVariant_Double ) ) {
392 double _v1 = v1.toDouble(&bOk);
393 double _v2 = v2.toDouble(&bOk);
398 else if ( op == "-" ){
401 else if ( op == "*" ){
404 else if ( op == "/" ) {
409 err = EvalExpr_InvalidResult;
412 else if ( op == "<" ){
415 else if ( op == ">" ){
418 else if ( op == "=" ){
421 else if ( op == "<=" ){
424 else if ( op == ">=" ){
427 else if ( op == "<>" || op == "!=" ){
433 else {// prefix operations
435 if ( aType2 == SALOME_EvalVariant_Int ){
436 v2 = -v2.toInt(&bOk);
438 else if ( aType2 == SALOME_EvalVariant_Double ){
439 v2 = -v2.toDouble(&bOk);
445 /////////////////////////////////////////////////////////////////////////
446 //=======================================================================
447 //function : SALOME_EvalSetLogic::SALOME_EvalSetLogic
449 //=======================================================================
450 SALOME_EvalSetLogic::SALOME_EvalSetLogic()
451 : SALOME_EvalSetBase()
454 SALOME_StringList aStringList;
455 SALOME_ListOfEvalVariantType aTypes;
457 aOp="and"; aStringList.push_back(aOp);
458 aOp="&&"; aStringList.push_back(aOp);
459 aOp="or"; aStringList.push_back(aOp);
460 aOp="||"; aStringList.push_back(aOp);
461 aOp="xor"; aStringList.push_back(aOp);
462 aOp="not"; aStringList.push_back(aOp);
463 aOp="!"; aStringList.push_back(aOp);
464 aOp="imp"; aStringList.push_back(aOp);
465 aOp="="; aStringList.push_back(aOp);
466 addOperations( aStringList );
468 aTypes.push_back( SALOME_EvalVariant_Boolean );
469 aTypes.push_back( SALOME_EvalVariant_Int );
470 aTypes.push_back( SALOME_EvalVariant_UInt );
473 //=======================================================================
474 //function : SALOME_EvalSetLogic::~SALOME_EvalSetLogic
476 //=======================================================================
477 SALOME_EvalSetLogic::~SALOME_EvalSetLogic()
480 //=======================================================================
481 //function : SALOME_EvalSetLogic::Name
483 //=======================================================================
484 SALOME_String SALOME_EvalSetLogic::Name()
488 //=======================================================================
489 //function : SALOME_EvalSetLogic::name
491 //=======================================================================
492 SALOME_String SALOME_EvalSetLogic::name() const
496 //=======================================================================
497 //function : SALOME_EvalSetLogic::createValue
499 //=======================================================================
500 bool SALOME_EvalSetLogic::createValue(const SALOME_String& str, SALOME_EvalVariant& val)const
503 SALOME_String valStr = toLower(str);
505 if ( valStr == "true" || valStr == "yes" )
506 val = SALOME_EvalVariant( true );
507 else if ( valStr == "false" || valStr == "no" )
508 val = SALOME_EvalVariant( false );
510 ok = SALOME_EvalSetBase::createValue( str, val );
514 //=======================================================================
515 //function : SALOME_EvalSetLogic::priority
517 //=======================================================================
518 int SALOME_EvalSetLogic::priority(const SALOME_String& op, bool isBin) const
529 else if ( op == "=" )
534 else if ( op == "not" || op == "!" )
539 //=======================================================================
540 //function : SALOME_EvalSetLogic::priority
542 //=======================================================================
543 SALOME_EvalExprError SALOME_EvalSetLogic::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) const
545 SALOME_EvalExprError err = EvalExpr_OK;
547 int val1 = intValue( v1 );
548 int val2 = intValue( v2 );
549 if ( v1.isValid() && v2.isValid() ) {
550 if ( op == "and" || op == "&&" ) {
553 else if ( op == "or" || op == "||" ){
556 else if ( op == "xor" ){
557 v1 = ( !val1 && val2 ) || ( val1 && !val2 );
559 else if ( op == "imp" ){
562 else if ( op == "=" ){
566 else if ( op == "not" || op == "!" ){
572 //=======================================================================
573 //function : SALOME_EvalSetLogic::intValue
575 //=======================================================================
576 int SALOME_EvalSetLogic::intValue(const SALOME_EvalVariant& v) const
582 case SALOME_EvalVariant_Boolean:
583 res = v.toBool() ? 1 : 0;
585 case SALOME_EvalVariant_Int:
586 case SALOME_EvalVariant_UInt:
594 /////////////////////////////////////////////////////////////////////////
595 //=======================================================================
596 //function : SALOME_EvalSetMath::SALOME_EvalSetMath
598 //=======================================================================
599 SALOME_EvalSetMath::SALOME_EvalSetMath()
600 : SALOME_EvalSetBase()
603 SALOME_StringList aStringList;
604 SALOME_ListOfEvalVariantType aTypes;
606 aOp="sqrt"; aStringList.push_back(aOp);
607 aOp="abs"; aStringList.push_back(aOp);
608 aOp="sin"; aStringList.push_back(aOp);
609 aOp="cos"; aStringList.push_back(aOp);
610 aOp="rad2grad"; aStringList.push_back(aOp);
611 aOp="grad2rad"; aStringList.push_back(aOp);
612 addOperations( aStringList );
614 aTypes.push_back( SALOME_EvalVariant_Int );
615 aTypes.push_back( SALOME_EvalVariant_Double );
618 //=======================================================================
619 //function : SALOME_EvalSetMath::~SALOME_EvalSetMath
621 //=======================================================================
622 SALOME_EvalSetMath::~SALOME_EvalSetMath()
625 //=======================================================================
626 //function : SALOME_EvalSetMath::Name
628 //=======================================================================
629 SALOME_String SALOME_EvalSetMath::Name()
633 //=======================================================================
634 //function : SALOME_EvalSetMath::name
636 //=======================================================================
637 SALOME_String SALOME_EvalSetMath::name() const
641 //=======================================================================
642 //function : SALOME_EvalSetMath::createValue
644 //=======================================================================
645 bool SALOME_EvalSetMath::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const
651 val=toDouble(str, &ok);
653 ok = SALOME_EvalSetBase::createValue(str, val);
658 //=======================================================================
659 //function : SALOME_EvalSetMath::priority
661 //=======================================================================
662 int SALOME_EvalSetMath::priority(const SALOME_String& op, bool isBin) const
667 else if ( op == "sqrt" ||
672 || op == "grad2rad" ){
677 //=======================================================================
678 //function : SALOME_EvalSetMath::calculate
680 //=======================================================================
681 SALOME_EvalExprError SALOME_EvalSetMath::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) const
684 SALOME_EvalExprError err = EvalExpr_OK;
686 double val = v2.toDouble(&bOk);
687 if ( op == "sqrt" ) {
692 err = EvalExpr_InvalidResult;
695 else if ( op == "abs" ) {
696 if ( v2.type() == SALOME_EvalVariant_Int ) {
697 v2 = abs( v2.toInt(&bOk) );
700 v2 = fabs( v2.toDouble(&bOk) );
704 else if ( op == "sin" ) {
707 else if ( op == "cos" ) {
710 else if ( op == "grad2rad" ){
711 v2 = val * 3.14159256 / 180.0;
713 else if ( op == "rad2grad" ) {
714 v2 = val * 180.0 / 3.14159256;
719 /////////////////////////////////////////////////////////////////////////
720 //=======================================================================
721 //function : SALOME_EvalSetString::SALOME_EvalSetString
723 //=======================================================================
724 SALOME_EvalSetString::SALOME_EvalSetString()
725 : SALOME_EvalSetBase()
728 SALOME_StringList aStringList;
729 SALOME_ListOfEvalVariantType aTypes;
731 aOp="+"; aStringList.push_back(aOp);
732 aOp="="; aStringList.push_back(aOp);
733 aOp="<"; aStringList.push_back(aOp);
734 aOp=">"; aStringList.push_back(aOp);
735 aOp="<="; aStringList.push_back(aOp);
736 aOp=">="; aStringList.push_back(aOp);
737 aOp="<>"; aStringList.push_back(aOp);
738 aOp="!="; aStringList.push_back(aOp);
739 aOp="length"; aStringList.push_back(aOp);
740 aOp="lower"; aStringList.push_back(aOp);
741 aOp="upper"; aStringList.push_back(aOp);
742 addOperations( aStringList );
744 aTypes.push_back( SALOME_EvalVariant_Int );
745 aTypes.push_back( SALOME_EvalVariant_Double );
746 aTypes.push_back( SALOME_EvalVariant_String );
749 //=======================================================================
750 //function : SALOME_EvalSetString::~SALOME_EvalSetString
752 //=======================================================================
753 SALOME_EvalSetString::~SALOME_EvalSetString()
756 //=======================================================================
757 //function : SALOME_EvalSetString::Name
759 //=======================================================================
760 SALOME_String SALOME_EvalSetString::Name()
764 //=======================================================================
765 //function : SALOME_EvalSetString::name
767 //=======================================================================
768 SALOME_String SALOME_EvalSetString::name()const
772 //=======================================================================
773 //function : SALOME_EvalSetString::createValue
775 //=======================================================================
776 bool SALOME_EvalSetString::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const
779 const char* myString=str.c_str();
780 int myLength=(int)strlen(myString);
783 myString[0] == '\'' &&
784 myString[str.length() - 1] == '\'' ) {
789 pMid=new char[aNb+1];
791 for(i=0; i<aNb; ++i) {
792 pMid[i]=myString[i+1];
798 //val = str.mid( 1, str.length() - 2 );
802 ok = SALOME_EvalSetBase::createValue( str, val );
806 //=======================================================================
807 //function : SALOME_EvalSetString::priority
809 //=======================================================================
810 int SALOME_EvalSetString::priority(const SALOME_String& op, bool isBin) const
816 else if ( op == "=" || op == "<" || op == ">" ||
817 op == "<=" || op == ">=" || op == "<>" || op == "!=" ){
824 else if ( op == "length" || op == "lower" || op=="upper" ){
829 //=======================================================================
830 //function : SALOME_EvalSetString::calculate
832 //=======================================================================
833 SALOME_EvalExprError SALOME_EvalSetString::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2) const
835 SALOME_EvalExprError err = EvalExpr_OK;
836 if ( v1.isValid() && v2.isValid() )
838 SALOME_String _v1 = v1.toString();
839 SALOME_String _v2 = v2.toString();
842 else if ( op == "=" )
844 else if ( op == "<" )
846 else if ( op == ">" )
848 else if ( op == "<>" || op == "!=" )
850 else if ( op == "<=" )
851 v1 = _v1 < _v2 || _v1 == _v2;
852 else if ( op == ">=" )
853 v1 = _v1 > _v2 || _v1 == _v2;
855 else if ( !v1.isValid() && v2.isValid() )
857 SALOME_String val = v2.toString();
858 if ( op == "length" )
859 v2 = (int)val.length();
860 else if ( op == "lower" ) {
863 else if ( op == "upper" ) {
869 /////////////////////////////////////////////////////////////////////////
870 //=======================================================================
871 //function : SALOME_EvalSetSets::SALOME_EvalSetSets
873 //=======================================================================
874 SALOME_EvalSetSets::SALOME_EvalSetSets()
875 : SALOME_EvalSetBase()
878 SALOME_StringList aStringList;
879 SALOME_ListOfEvalVariantType aTypes;
881 aOp="{"; aStringList.push_back(aOp);
882 aOp="}"; aStringList.push_back(aOp);
883 aOp="<>"; aStringList.push_back(aOp);
884 aOp="!="; aStringList.push_back(aOp);
885 aOp="+"; aStringList.push_back(aOp);
886 aOp="-"; aStringList.push_back(aOp);
887 aOp="*"; aStringList.push_back(aOp);
888 aOp="in"; aStringList.push_back(aOp);
889 aOp="count"; aStringList.push_back(aOp);
890 addOperations( aStringList );
892 aTypes.push_back( SALOME_EvalVariant_List );
895 //=======================================================================
896 //function : SALOME_EvalSetSets::~SALOME_EvalSetSets
898 //=======================================================================
899 SALOME_EvalSetSets::~SALOME_EvalSetSets()
902 //=======================================================================
903 //function : SALOME_EvalSetSets::Name
905 //=======================================================================
906 SALOME_String SALOME_EvalSetSets::Name()
910 //=======================================================================
911 //function : SALOME_EvalSetSets::name
913 //=======================================================================
914 SALOME_String SALOME_EvalSetSets::name()const
918 //=======================================================================
919 //function : SALOME_EvalSetSets::bracketsList
921 //=======================================================================
922 void SALOME_EvalSetSets::bracketsList(SALOME_StringList& aList, bool bOpen ) const
924 aList.push_back( bOpen ? "{" : "}" );
925 SALOME_EvalSetBase::bracketsList(aList, bOpen);
927 //=======================================================================
928 //function : SALOME_EvalSetSets::bracketsList
930 //=======================================================================
931 int SALOME_EvalSetSets::priority(const SALOME_String& op, bool isBin) const
934 if ( op == "=" || op == "<>" || op == "!=" )
936 else if ( op == "+" || op == "-" || op == "*" )
938 else if ( op == "in" )
943 else if ( op == "{" || op == "}" )
945 else if ( op == "count" )
950 //=======================================================================
951 //function : SALOME_EvalSetSets::isValid
953 //=======================================================================
954 SALOME_EvalExprError SALOME_EvalSetSets::isValid(const SALOME_String& op,
955 const SALOME_EvalVariantType t1,
956 const SALOME_EvalVariantType t2 ) const
962 return SALOME_EvalSetBase::isValid( op, t1, t2 );
964 if ( t1 != SALOME_EvalVariant_Invalid && t2 == SALOME_EvalVariant_List ) {
968 return EvalExpr_OperandsNotMatch;
970 //=======================================================================
971 //function : SALOME_EvalSetSets::add
973 //=======================================================================
974 void SALOME_EvalSetSets::add(ValueSet& aSet, const SALOME_EvalVariant& v)
977 if ( v.isValid() && !SALOME_EvalVariant::contains( aSet, v ) ) {
981 //=======================================================================
982 //function : SALOME_EvalSetSets::add
984 //=======================================================================
985 void SALOME_EvalSetSets::add(ValueSet& s1, const ValueSet& s2)
987 ValueSet::const_iterator anIt = s2.begin();
988 for ( ; anIt != s2.end(); ++anIt )
991 //=======================================================================
992 //function : SALOME_EvalSetSets::remove
994 //=======================================================================
995 void SALOME_EvalSetSets::remove(ValueSet& aSet, const SALOME_EvalVariant& v)
999 //=======================================================================
1000 //function : SALOME_EvalSetSets::remove
1002 //=======================================================================
1003 void SALOME_EvalSetSets::remove(ValueSet& s1, const ValueSet& s2)
1005 ValueSet::const_iterator aIt = s2.begin();
1006 for (; aIt != s2.end(); ++aIt ) {
1010 //=======================================================================
1011 //function : SALOME_EvalSetSets::calculate
1013 //=======================================================================
1014 SALOME_EvalExprError SALOME_EvalSetSets::calculate(const SALOME_String& op,
1015 SALOME_EvalVariant& v1,
1016 SALOME_EvalVariant& v2 ) const
1018 SALOME_EvalExprError err = EvalExpr_OK;
1023 add( aNewList, v1.toList() );
1026 else if (op == "=" || op == "<>" || op == "!=" ||
1027 op == "+" || op == "-" || op == "*" ) {
1029 add( aNewList, v1.toList() );
1030 if ( op == "=" || op == "<>" || op == "!=" || op == "-" ) {
1031 remove( aNewList, v2.toList() );
1033 v1 = aNewList.empty() && v1.toList().size() == v2.toList().size();
1035 else if ( op == "<>" || op == "!=" ) {
1036 v1 = !aNewList.empty() || v1.toList().size() != v2.toList().size();
1042 else if ( op == "+" ) {
1043 add( aNewList, v2.toList() );
1046 else if ( op == "*" ) {
1048 add( toDelete, aNewList );
1049 remove( toDelete, v2.toList() );
1050 remove( aNewList, toDelete );
1054 else if ( op== "count" ) {
1055 v2 = (int)v2.toList().size();
1057 else if ( op == "in" ) {
1058 if ( v1.type() == SALOME_EvalVariant_List ) {
1060 ValueSet lst1 = v1.toList();
1061 ValueSet lst2 = v2.toList();
1062 ValueSet::const_iterator anIt = lst1.begin();
1063 for (; anIt != lst1.end() && res; ++anIt ){
1064 res = SALOME_EvalVariant::contains(lst2, *anIt );
1069 SALOME_ListOfEvalVariant aL=v2.toList();
1070 bool bContains=SALOME_EvalVariant::contains(aL, v1);
1071 v1=SALOME_EvalVariant(bContains);
1078 /////////////////////////////////////////////////////////////////////////
1079 //=======================================================================
1080 //function : SALOME_EvalSetConst::SALOME_EvalSetConst
1082 //=======================================================================
1083 SALOME_EvalSetConst::SALOME_EvalSetConst()
1087 //=======================================================================
1088 //function : SALOME_EvalSetConst::~SALOME_EvalSetConst
1090 //=======================================================================
1091 SALOME_EvalSetConst::~SALOME_EvalSetConst()
1094 //=======================================================================
1095 //function : SALOME_EvalSetConst::Name
1097 //=======================================================================
1098 SALOME_String SALOME_EvalSetConst::Name()
1102 //=======================================================================
1103 //function : SALOME_EvalSetConst::name
1105 //=======================================================================
1106 SALOME_String SALOME_EvalSetConst::name() const
1110 //=======================================================================
1111 //function : SALOME_EvalSetConst::createValue
1113 //=======================================================================
1114 bool SALOME_EvalSetConst::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const
1117 if ( str == "pi" ) // PI number
1118 val = SALOME_EvalVariant( 3.141593 );
1119 else if ( str == "exp" ) // Exponent value (e)
1120 val = SALOME_EvalVariant( 2.718282 );
1121 else if ( str == "g" ) // Free fall acceleration (g)
1122 val = SALOME_EvalVariant( 9.80665 );
1128 //=======================================================================
1129 //function : SALOME_EvalSetConst::operationList
1131 //=======================================================================
1132 void SALOME_EvalSetConst::operationList(SALOME_StringList&) const
1135 //=======================================================================
1136 //function : SALOME_EvalSetConst::bracketsList
1138 //=======================================================================
1139 void SALOME_EvalSetConst::bracketsList(SALOME_StringList& , bool) const
1142 //=======================================================================
1143 //function : SALOME_EvalSetConst::priority
1145 //=======================================================================
1146 int SALOME_EvalSetConst::priority(const SALOME_String& /*op*/, bool /*isBin*/ ) const
1150 //=======================================================================
1151 //function : SALOME_EvalSetConst::isValid
1153 //=======================================================================
1154 SALOME_EvalExprError SALOME_EvalSetConst::isValid(const SALOME_String& /*op*/,
1155 const SALOME_EvalVariantType /*t1*/,
1156 const SALOME_EvalVariantType /*t2*/ ) const
1158 return EvalExpr_InvalidOperation;
1160 //=======================================================================
1161 //function : SALOME_EvalSetConst::calculate
1163 //=======================================================================
1164 SALOME_EvalExprError SALOME_EvalSetConst::calculate(const SALOME_String&,
1165 SALOME_EvalVariant&,
1166 SALOME_EvalVariant& ) const
1168 return EvalExpr_InvalidOperation;
1171 /////////////////////////////////////////////////////////////////////////
1172 //=======================================================================
1173 //function : toUpper
1175 //=======================================================================
1176 SALOME_String toUpper(const SALOME_String& str)
1179 const char* mystring=str.c_str();
1185 mylength=strlen(mystring);
1186 for (i=0; i < mylength; i++) {
1187 aC=(char)toupper(mystring[i]);
1193 //=======================================================================
1194 //function : tolower
1196 //=======================================================================
1197 SALOME_String toLower(const SALOME_String& str)
1200 const char* mystring=str.c_str();
1206 mylength=strlen(mystring);
1207 for (i=0; i < mylength; i++) {
1208 aC=(char)tolower(mystring[i]);
1214 //=======================================================================
1215 //function : toDouble
1217 //=======================================================================
1218 double toDouble(const SALOME_String& str, bool *ok)
1221 const char* mystring=str.c_str();
1227 value=strtod(mystring,&ptr);
1228 if (ptr != mystring) {
1238 //=======================================================================
1241 //=======================================================================
1242 int toInt(const SALOME_String& str, bool *ok)
1245 const char* mystring=str.c_str();
1252 mylength=strlen(mystring);
1253 value = (int)strtol(mystring, &ptr,10);
1255 if (ptr != mystring) {
1256 for (i=0; i < mylength; i++) {
1257 if (mystring[i] == '.') {