From: asl Date: Thu, 19 Nov 2009 05:42:21 +0000 (+0000) Subject: Base implementation X-Git-Tag: PHASE_17_Part1_V1~49 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5b146243ff451fdf45c032b4dc29a9229d9a1eac;p=modules%2Fkernel.git Base implementation --- diff --git a/src/Notebook/SALOME_Eval.hxx b/src/Notebook/SALOME_Eval.hxx index 77b3800da..739fa752c 100755 --- a/src/Notebook/SALOME_Eval.hxx +++ b/src/Notebook/SALOME_Eval.hxx @@ -34,29 +34,27 @@ #include #include #include -// -using namespace std; - -typedef string RString; -typedef list RStringList; -typedef RStringList::iterator ListIteratorOfRStringList; -typedef set SetOfRString; -typedef SetOfRString::iterator SetIteratorOfSetOfRString; -typedef pair< SetIteratorOfSetOfRString, bool > SetPair; +typedef std::string SALOME_String; +typedef std::list SALOME_StringList; +typedef SALOME_StringList::iterator SALOME_ListIteratorOfStringList; +typedef std::set SALOME_StringSet; +typedef SALOME_StringSet::iterator SALOME_SetIteratorOfStringSet; +typedef std::pair< SALOME_SetIteratorOfStringSet, bool > SALOME_SetPair; + typedef enum - { - SALOME_EvalExpr_OK, //!< No errors found - SALOME_EvalExpr_OperandsNotMatch, //!< Types of arguments are invalid for this operation - SALOME_EvalExpr_InvalidResult, //!< Operation cannot find result (for example, division by zero) - SALOME_EvalExpr_InvalidOperation, //!< Unknown operation - SALOME_EvalExpr_OperationsNull, //!< Internal operations pointer of parser is null - SALOME_EvalExpr_InvalidToken, //!< Invalid token (neither operation, nor parameter of value) - SALOME_EvalExpr_CloseExpected, //!< Closing bracket is expected - SALOME_EvalExpr_ExcessClose, //!< Extra closing bracket is found - SALOME_EvalExpr_BracketsNotMatch, //!< Opening and closing brackets are of different type, e.g. [) - SALOME_EvalExpr_StackUnderflow, //!< There are no arguments in the stack for the operation - SALOME_EvalExpr_ExcessData //!< The parsing is finished, but there are more then one value in the stack - } SALOME_EvalExprError; +{ + EvalExpr_OK, //!< No errors found + EvalExpr_OperandsNotMatch, //!< Types of arguments are invalid for this operation + EvalExpr_InvalidResult, //!< Operation cannot find result (for example, division by zero) + EvalExpr_InvalidOperation, //!< Unknown operation + EvalExpr_OperationsNull, //!< Internal operations pointer of parser is null + EvalExpr_InvalidToken, //!< Invalid token (neither operation, nor parameter of value) + EvalExpr_CloseExpected, //!< Closing bracket is expected + EvalExpr_ExcessClose, //!< Extra closing bracket is found + EvalExpr_BracketsNotMatch, //!< Opening and closing brackets are of different type, e.g. [) + EvalExpr_StackUnderflow, //!< There are no arguments in the stack for the operation + EvalExpr_ExcessData //!< The parsing is finished, but there are more then one value in the stack +} SALOME_EvalExprError; #endif diff --git a/src/Notebook/SALOME_EvalExpr.cxx b/src/Notebook/SALOME_EvalExpr.cxx index 177d4190b..148144552 100755 --- a/src/Notebook/SALOME_EvalExpr.cxx +++ b/src/Notebook/SALOME_EvalExpr.cxx @@ -31,19 +31,19 @@ //function : //purpose : //======================================================================= -SALOME_EvalExpr::SALOME_EvalExpr(const RString& expr) +SALOME_EvalExpr::SALOME_EvalExpr( const SALOME_String& expr ) { myParser=NULL; - intialize( true, expr ); + initialize( true, expr ); } //======================================================================= //function : //purpose : //======================================================================= -SALOME_EvalExpr::SALOME_EvalExpr(const bool stdSets, const RString& expr) +SALOME_EvalExpr::SALOME_EvalExpr( const bool stdSets, const SALOME_String& expr ) { myParser=NULL; - intialize( stdSets, expr ); + initialize( stdSets, expr ); } //======================================================================= //function : ~ @@ -64,10 +64,10 @@ SALOME_EvalExprError SALOME_EvalExpr::error() const return myParser->error(); } //======================================================================= -//function : intialize +//function : initialize //purpose : //======================================================================= -void SALOME_EvalExpr::intialize(const bool stdSets, const RString& expr) +void SALOME_EvalExpr::initialize( const bool stdSets, const SALOME_String& expr ) { if (myParser) { delete myParser; @@ -89,7 +89,7 @@ void SALOME_EvalExpr::intialize(const bool stdSets, const RString& expr) //function : calculate //purpose : //======================================================================= -SALOME_EvalVariant SALOME_EvalExpr::calculate(const RString& expr) +SALOME_EvalVariant SALOME_EvalExpr::calculate(const SALOME_String& expr) { if ( !expr.empty() ) { setExpression( expr ); @@ -100,7 +100,7 @@ SALOME_EvalVariant SALOME_EvalExpr::calculate(const RString& expr) //function : expression //purpose : //======================================================================= -RString SALOME_EvalExpr::expression() const +SALOME_String SALOME_EvalExpr::expression() const { return myExpr; } @@ -108,7 +108,7 @@ RString SALOME_EvalExpr::expression() const //function : setExpression //purpose : //======================================================================= -void SALOME_EvalExpr::setExpression(const RString& expr) +void SALOME_EvalExpr::setExpression(const SALOME_String& expr) { if ( expr == expression() ){ return; @@ -129,7 +129,7 @@ SALOME_EvalParser* SALOME_EvalExpr::parser() const //function : operationSets //purpose : //======================================================================= -SALOME_ListOfPEvalSet SALOME_EvalExpr::operationSets() const +SALOME_ListOfEvalSet SALOME_EvalExpr::operationSets() const { return myParser->operationSets(); } @@ -153,7 +153,7 @@ void SALOME_EvalExpr::removeOperationSet(SALOME_EvalSet* theSet) //function : operationSet //purpose : //======================================================================= -SALOME_EvalSet* SALOME_EvalExpr::operationSet(const RString& name) const +SALOME_EvalSet* SALOME_EvalExpr::operationSet(const SALOME_String& name) const { return myParser->operationSet( name ); } diff --git a/src/Notebook/SALOME_EvalExpr.hxx b/src/Notebook/SALOME_EvalExpr.hxx index 756e4b350..09254c66f 100755 --- a/src/Notebook/SALOME_EvalExpr.hxx +++ b/src/Notebook/SALOME_EvalExpr.hxx @@ -34,34 +34,32 @@ class SALOME_EvalExpr { public: - SALOME_EvalExpr(const RString& = RString()); - SALOME_EvalExpr( const bool, const RString& = RString() ); + SALOME_EvalExpr(const SALOME_String& = SALOME_String()); + SALOME_EvalExpr( const bool, const SALOME_String& = SALOME_String() ); ~SALOME_EvalExpr(); - SALOME_EvalVariant calculate( const RString& = RString() ); + SALOME_EvalVariant calculate( const SALOME_String& = SALOME_String() ); - RString expression() const; - void setExpression( const RString& ); + SALOME_String expression() const; + void setExpression( const SALOME_String& ); - SALOME_EvalExprError error() const; - SALOME_EvalParser* parser() const; + SALOME_EvalExprError error() const; + SALOME_EvalParser* parser() const; - bool autoDeleteOperationSets() const; - void setAutoDeleteOperationSets( const bool ); + bool autoDeleteOperationSets() const; + void setAutoDeleteOperationSets( const bool ); - SALOME_ListOfPEvalSet operationSets() const; - SALOME_EvalSet* operationSet( const RString& ) const; - void removeOperationSet(SALOME_EvalSet* ); - void insertOperationSet(SALOME_EvalSet*, - const int = -1 ); + SALOME_ListOfEvalSet operationSets() const; + SALOME_EvalSet* operationSet( const SALOME_String& ) const; + void removeOperationSet( SALOME_EvalSet* ); + void insertOperationSet( SALOME_EvalSet*, const int = -1 ); private: - void intialize(const bool, - const RString& ); + void initialize( const bool, const SALOME_String& ); private: - RString myExpr; - SALOME_EvalParser* myParser; + SALOME_String myExpr; + SALOME_EvalParser* myParser; }; #endif diff --git a/src/Notebook/SALOME_EvalParser.cxx b/src/Notebook/SALOME_EvalParser.cxx index 8d9dfb180..905b7adf8 100755 --- a/src/Notebook/SALOME_EvalParser.cxx +++ b/src/Notebook/SALOME_EvalParser.cxx @@ -28,40 +28,30 @@ #include #include -static - bool contains(const RStringList& aLS, - const RString& aS); -static - RString trimmed(const RString& str); - -static - RString trimmed(const RString& str, const char aWhat); - -static - bool isSpace(const char aC); - -static - int indexOf(const RStringList& aLS, - const RString& aS); +bool contains(const SALOME_StringList& aLS, const SALOME_String& aS); +SALOME_String trimmed(const SALOME_String& str); +SALOME_String trimmed(const SALOME_String& str, const char aWhat); +bool isSpace(const char aC); +int indexOf(const SALOME_StringList& aLS, const SALOME_String& aS); //======================================================================= -//function : -//purpose : +//function : +//purpose : //======================================================================= SALOME_EvalParser::SALOME_EvalParser() : myAutoDel( false ) { - setError( SALOME_EvalExpr_OK ); + setError( EvalExpr_OK ); } //======================================================================= //function : ~ -//purpose : +//purpose : //======================================================================= SALOME_EvalParser::~SALOME_EvalParser() { if (autoDeleteOperationSets()) { //qDeleteAll( mySets );// !!! - SALOME_ListOfPEvalSet::const_iterator aIt = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator aIt = mySets.begin(); for (; aIt != mySets.end() ; ++aIt ) { SALOME_EvalSet* pEvalSet=*aIt; if (pEvalSet) { @@ -73,22 +63,22 @@ SALOME_EvalParser::~SALOME_EvalParser() } //======================================================================= //function : operationSets -//purpose : +//purpose : //======================================================================= -SALOME_ListOfPEvalSet SALOME_EvalParser::operationSets() const +SALOME_ListOfEvalSet SALOME_EvalParser::operationSets() const { return mySets; } //======================================================================= //function : operationSet -//purpose : +//purpose : //======================================================================= -SALOME_EvalSet* SALOME_EvalParser::operationSet(const RString& theName) const +SALOME_EvalSet* SALOME_EvalParser::operationSet(const SALOME_String& theName) const { SALOME_EvalSet* pSet; // pSet = NULL; - SALOME_ListOfPEvalSet::const_iterator it = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator it = mySets.begin(); for (; it != mySets.end() && !pSet; ++it ) { if ( (*it)->name()==theName ) { pSet = *it; @@ -98,15 +88,15 @@ SALOME_EvalSet* SALOME_EvalParser::operationSet(const RString& theName) const } //======================================================================= //function : insertOperationSet -//purpose : +//purpose : //======================================================================= -void SALOME_EvalParser::insertOperationSet(SALOME_EvalSet* theSet, +void SALOME_EvalParser::insertOperationSet(SALOME_EvalSet* theSet, const int idx) { if (SALOME_EvalSet::contains(mySets, theSet)) { return; } - // + // int iSize=(int)mySets.size(); int index = idx < 0 ? iSize : idx; if (index>iSize) { @@ -116,7 +106,7 @@ void SALOME_EvalParser::insertOperationSet(SALOME_EvalSet* theSet, } //======================================================================= //function : removeOperationSet -//purpose : +//purpose : //======================================================================= void SALOME_EvalParser::removeOperationSet(SALOME_EvalSet* theSet) { @@ -125,7 +115,7 @@ void SALOME_EvalParser::removeOperationSet(SALOME_EvalSet* theSet) } //======================================================================= //function : autoDeleteOperationSets -//purpose : +//purpose : //======================================================================= bool SALOME_EvalParser::autoDeleteOperationSets() const { @@ -133,7 +123,7 @@ bool SALOME_EvalParser::autoDeleteOperationSets() const } //======================================================================= //function : setAutoDeleteOperationSets -//purpose : +//purpose : //======================================================================= void SALOME_EvalParser::setAutoDeleteOperationSets( const bool theOn ) { @@ -141,26 +131,23 @@ void SALOME_EvalParser::setAutoDeleteOperationSets( const bool theOn ) } //======================================================================= //function : search -//purpose : +//purpose : //======================================================================= -int SALOME_EvalParser::search(const RStringList& aList, - const RString& aStr, - int offset, - int& matchLen, - int& listind ) +int SALOME_EvalParser::search(const SALOME_StringList& aList, const SALOME_String& aStr, int offset, int& matchLen, int& listind ) { int min = -1; int ind = 0; int pos; //static const basic_string ::size_type npos = -1; // - RStringList::const_iterator aIt = aList.begin(), aLast = aList.end(); - for (ind = 0; aIt != aLast; aIt++, ind++ ) { - const RString& aStrX=*aIt; - + SALOME_StringList::const_iterator aIt = aList.begin(), aLast = aList.end(); + for (ind = 0; aIt != aLast; aIt++, ind++ ) + { + const SALOME_String& aStrX=*aIt; + pos=(int)aStr.find(aStrX, offset); - if ( pos >= 0 && - ( min < 0 || min > pos || + if ( pos >= 0 && + ( min < 0 || min > pos || ( min == pos && matchLen < (int)aStrX.length()) ) ) { @@ -168,7 +155,7 @@ int SALOME_EvalParser::search(const RStringList& aList, listind = ind; matchLen = (int)aStrX.length(); } - + } if ( min < 0 ){ matchLen = 0; @@ -177,11 +164,11 @@ int SALOME_EvalParser::search(const RStringList& aList, } //======================================================================= //function : note -//purpose : +//purpose : //======================================================================= -RString SALOME_EvalParser::note(const RString& aStr, int pos, int len ) +SALOME_String SALOME_EvalParser::note(const SALOME_String& aStr, int pos, int len ) { - RString aStr1; + SALOME_String aStr1; // aStr1=aStr.substr(pos, len); aStr1=trimmed(aStr1); @@ -191,22 +178,22 @@ RString SALOME_EvalParser::note(const RString& aStr, int pos, int len ) //======================================================================= //function : prepare -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::prepare(const RString& expr, Postfix& post) +bool SALOME_EvalParser::prepare(const SALOME_String& expr, Postfix& post) { int pos = 0; int len =(int)expr.length(); stack aBracketStack; - RStringList anOpers, anOpenBr, aCloseBr; + SALOME_StringList anOpers, anOpenBr, aCloseBr; if ( !checkOperations() ) return false; bracketsList( anOpenBr, true ); bracketsList( aCloseBr, false ); operationList( anOpers ); - - while ( pos < len && error() == SALOME_EvalExpr_OK ) { + + while ( pos < len && error() == EvalExpr_OK ) { PostfixItem item; char aC=expr[pos]; // @@ -246,11 +233,11 @@ bool SALOME_EvalParser::prepare(const RString& expr, Postfix& post) } else if ( cPos == pos ) { if ( aBracketStack.size() == 0 ) { - setError( SALOME_EvalExpr_ExcessClose ); + setError( EvalExpr_ExcessClose ); break; } if ( br_ind != aBracketStack.top() ) { - setError( SALOME_EvalExpr_BracketsNotMatch ); + setError( EvalExpr_BracketsNotMatch ); break; } else { @@ -278,7 +265,7 @@ bool SALOME_EvalParser::prepare(const RString& expr, Postfix& post) else { mLen = 0; if ( oPos != pos && cPos != pos ) { - int i; + int i; for ( i = pos + 1; i < (int)expr.length(); i++ ) { if ( isSpace(expr[i]) ) { break; @@ -296,10 +283,10 @@ bool SALOME_EvalParser::prepare(const RString& expr, Postfix& post) vpos = opPos; } - while( vpos < (int)expr.length() && - ( isalpha(expr[vpos]) || - isdigit(expr[vpos]) || - expr[vpos]=='_' ) + while( vpos < (int)expr.length() && + ( isalpha(expr[vpos]) || + isdigit(expr[vpos]) || + expr[vpos]=='_' ) ) { vpos++; } @@ -324,28 +311,29 @@ bool SALOME_EvalParser::prepare(const RString& expr, Postfix& post) brValue--; } else { - setError( SALOME_EvalExpr_ExcessClose ); + setError( EvalExpr_ExcessClose ); break; } } } // - if ( brValue > 0 ) { - setError( SALOME_EvalExpr_CloseExpected ); + if ( brValue > 0 ) + { + setError( EvalExpr_CloseExpected ); } // - return error() == SALOME_EvalExpr_OK; + return error() == EvalExpr_OK; } //======================================================================= //function : setOperationTypes -//purpose : +//purpose : //======================================================================= bool SALOME_EvalParser::setOperationTypes( Postfix& post ) { if ( !checkOperations() ) return false; - RStringList anOpen, aClose; + SALOME_StringList anOpen, aClose; // bracketsList( anOpen, true ); bracketsList( aClose, false ); @@ -374,7 +362,7 @@ bool SALOME_EvalParser::setOperationTypes( Postfix& post ) (*anIt).myType = Post; // SALOME_EvalVariant& aRV=(*anIt).myValue; - RString aRVS=aRV.toString(); + SALOME_String aRVS=aRV.toString(); // if ( contains(anOpen, aRVS) ) { (*anIt).myType = Pre; @@ -384,14 +372,14 @@ bool SALOME_EvalParser::setOperationTypes( Postfix& post ) } } - return error() == SALOME_EvalExpr_OK; + return error() == EvalExpr_OK; } //======================================================================= //function : globalBrackets -//purpose : +//purpose : //======================================================================= -int SALOME_EvalParser::globalBrackets(const Postfix& post, - int f, +int SALOME_EvalParser::globalBrackets(const Postfix& post, + int f, int l ) { int i; @@ -431,21 +419,17 @@ int SALOME_EvalParser::globalBrackets(const Postfix& post, if( br_num 0 ) { - setError( SALOME_EvalExpr_CloseExpected ); + setError( EvalExpr_CloseExpected ); break; } } } // - if ( error() == SALOME_EvalExpr_OK ) { + if ( error() == EvalExpr_OK ) { if ( min >= 0 ) { Postfix one; list parts; @@ -587,13 +571,13 @@ bool SALOME_EvalParser::sort(const Postfix& post, } } } - return error() == SALOME_EvalExpr_OK; + return error() == EvalExpr_OK; } //======================================================================= //function : parse -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::parse( const RString& expr ) +bool SALOME_EvalParser::parse( const SALOME_String& expr ) { myPostfix.clear(); @@ -601,9 +585,9 @@ bool SALOME_EvalParser::parse( const RString& expr ) return false; Postfix p; - RStringList opens, closes; + SALOME_StringList opens, closes; - setError( SALOME_EvalExpr_OK ); + setError( EvalExpr_OK ); bracketsList( opens, true ); bracketsList( closes, false ); @@ -611,11 +595,9 @@ bool SALOME_EvalParser::parse( const RString& expr ) } //======================================================================= //function : calculate -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::calculate(const RString& op, - SALOME_EvalVariant& v1, - SALOME_EvalVariant& v2 ) +bool SALOME_EvalParser::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) { SALOME_EvalExprError aErr; SALOME_EvalVariantType aType1, aType2; @@ -624,27 +606,27 @@ bool SALOME_EvalParser::calculate(const RString& op, aType2=v2.type(); // aErr = isValid( op, aType1, aType2 ); - if ( aErr == SALOME_EvalExpr_OK ){ + if ( aErr == EvalExpr_OK ){ aErr=calculation( op, v1, v2 ); setError( aErr ); } else{ setError( aErr ); } - return error() == SALOME_EvalExpr_OK; + return error() == EvalExpr_OK; } //======================================================================= //function : calculate -//purpose : +//purpose : //======================================================================= SALOME_EvalVariant SALOME_EvalParser::calculate() { if ( !checkOperations() ) return SALOME_EvalVariant(); - setError( SALOME_EvalExpr_OK ); + setError( EvalExpr_OK ); // - RStringList anOpen, aClose; + SALOME_StringList anOpen, aClose; PostfixItemType aType; // bracketsList( anOpen, true ); @@ -652,10 +634,10 @@ SALOME_EvalVariant SALOME_EvalParser::calculate() stack aStack; Postfix::iterator anIt = myPostfix.begin(), aLast = myPostfix.end(); - for ( ; anIt != aLast && error() == SALOME_EvalExpr_OK; anIt++ ) { - const PostfixItem& aPostfixItem=*anIt; + for ( ; anIt != aLast && error() == EvalExpr_OK; anIt++ ) { + const PostfixItem& aPostfixItem=*anIt; aType=aPostfixItem.myType; - RString nn = aPostfixItem.myValue.toString(); + SALOME_String nn = aPostfixItem.myValue.toString(); // if ( aType == Param ) { if ( hasParameter( nn ) ) { @@ -664,11 +646,11 @@ SALOME_EvalVariant SALOME_EvalParser::calculate() aStack.push( v ); } else { - setError( SALOME_EvalExpr_InvalidToken ); + setError( EvalExpr_InvalidToken ); } } else { - setError( SALOME_EvalExpr_InvalidToken ); + setError( EvalExpr_InvalidToken ); } } // @@ -687,7 +669,7 @@ SALOME_EvalVariant SALOME_EvalParser::calculate() SALOME_ListOfEvalVariant aSet; while ( true ) { if ( aStack.empty() ) { - setError( SALOME_EvalExpr_StackUnderflow ); + setError( EvalExpr_StackUnderflow ); break; } if ( aStack.top().isValid() ) { @@ -708,7 +690,7 @@ SALOME_EvalVariant SALOME_EvalParser::calculate() else if ( aStack.size() >= 1 ) { SALOME_EvalVariant inv; SALOME_EvalVariant *v1, *v2; - v1=&aStack.top(); + v1=&aStack.top(); v2 = &inv; //"post-" case if ( aType == Pre ) { v2 = &aStack.top(); @@ -717,7 +699,7 @@ SALOME_EvalVariant SALOME_EvalParser::calculate() calculate( nn, *v1, *v2 ); } else { - setError( SALOME_EvalExpr_StackUnderflow ); + setError( EvalExpr_StackUnderflow ); } }//else if ( aType== Pre || aType == Post ) { else if ( aType == Binary ) { @@ -727,53 +709,53 @@ SALOME_EvalVariant SALOME_EvalParser::calculate() calculate( nn, aStack.top(), v2 ); } else { - setError( SALOME_EvalExpr_StackUnderflow ); + setError( EvalExpr_StackUnderflow ); } } } // SALOME_EvalVariant res; - if ( error() == SALOME_EvalExpr_OK ) { + if ( error() == EvalExpr_OK ) { int count; - + count = (int)aStack.size(); if ( count == 0 ) { - setError( SALOME_EvalExpr_StackUnderflow ); + setError( EvalExpr_StackUnderflow ); } else if( count == 1 ) { res = aStack.top(); } else{ - setError( SALOME_EvalExpr_ExcessData ); + setError( EvalExpr_ExcessData ); } } return res; } //======================================================================= //function : calculate -//purpose : +//purpose : //======================================================================= -SALOME_EvalVariant SALOME_EvalParser::calculate( const RString& expr ) +SALOME_EvalVariant SALOME_EvalParser::calculate( const SALOME_String& expr ) { setExpression( expr ); return calculate(); } //======================================================================= //function : setExpression -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::setExpression( const RString& expr ) +bool SALOME_EvalParser::setExpression( const SALOME_String& expr ) { return parse( expr ); } //======================================================================= //function : hasParameter -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::hasParameter( const RString& name ) const +bool SALOME_EvalParser::hasParameter( const SALOME_String& name ) const { bool bRet; - RString aStr; + SALOME_String aStr; ParamMap::const_iterator aIt; aStr=trimmed(name); aIt=myParams.find(aStr); @@ -782,39 +764,38 @@ bool SALOME_EvalParser::hasParameter( const RString& name ) const } //======================================================================= //function : setParameter -//purpose : +//purpose : //======================================================================= -void SALOME_EvalParser::setParameter( const RString& name, const SALOME_EvalVariant& value ) +void SALOME_EvalParser::setParameter( const SALOME_String& name, const SALOME_EvalVariant& value ) { - RString aStr; + SALOME_String aStr; // aStr=trimmed(name); - PairParamMap aPair(aStr, value); - myParams.insert(aPair); + myParams[aStr] = value; } //======================================================================= //function : removeParameter -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::removeParameter( const RString& name ) +bool SALOME_EvalParser::removeParameter( const SALOME_String& name ) { int iRet; - RString aStr; + SALOME_String aStr; // aStr=trimmed(name); iRet=(int)myParams.erase(aStr); return iRet? true : false; - + } //======================================================================= //function : parameter -//purpose : +//purpose : //======================================================================= -SALOME_EvalVariant SALOME_EvalParser::parameter( const RString& theName ) const +SALOME_EvalVariant SALOME_EvalParser::parameter( const SALOME_String& theName ) const { SALOME_EvalVariant res; ParamMap::const_iterator aIt; - RString aStr; + SALOME_String aStr; aStr=trimmed(theName); aIt=myParams.find(theName); if (aIt!=myParams.end()) { @@ -826,9 +807,9 @@ SALOME_EvalVariant SALOME_EvalParser::parameter( const RString& theName ) const } //======================================================================= //function : firstInvalid -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::firstInvalid( RString& name ) const +bool SALOME_EvalParser::firstInvalid( SALOME_String& name ) const { ParamMap::const_iterator aIt = myParams.begin(); for (; aIt != myParams.end(); aIt++ ) { @@ -843,7 +824,7 @@ bool SALOME_EvalParser::firstInvalid( RString& name ) const } //======================================================================= //function : removeInvalids -//purpose : +//purpose : //======================================================================= void SALOME_EvalParser::removeInvalids() { @@ -862,7 +843,7 @@ void SALOME_EvalParser::removeInvalids() } //======================================================================= //function : error -//purpose : +//purpose : //======================================================================= SALOME_EvalExprError SALOME_EvalParser::error() const { @@ -870,7 +851,7 @@ SALOME_EvalExprError SALOME_EvalParser::error() const } //======================================================================= //function : setError -//purpose : +//purpose : //======================================================================= void SALOME_EvalParser::setError(SALOME_EvalExprError err) @@ -879,19 +860,19 @@ void SALOME_EvalParser::setError(SALOME_EvalExprError err) } //======================================================================= //function : dump -//purpose : +//purpose : //======================================================================= -RString SALOME_EvalParser::dump() const +SALOME_String SALOME_EvalParser::dump() const { return dump( myPostfix ); } //======================================================================= //function : dump -//purpose : +//purpose : //======================================================================= -RString SALOME_EvalParser::dump( const Postfix& post ) const +SALOME_String SALOME_EvalParser::dump( const Postfix& post ) const { - RString res; + SALOME_String res; // if ( !checkOperations() ) { return res; @@ -899,7 +880,7 @@ RString SALOME_EvalParser::dump( const Postfix& post ) const // Postfix::const_iterator anIt = post.begin(); for (; anIt != post.end(); anIt++ ) { - if ((*anIt).myType == Value && + if ((*anIt).myType == Value && (*anIt).myValue.type() == SALOME_EvalVariant_String ) { res += "'" + (*anIt).myValue.toString() + "'"; } @@ -923,15 +904,15 @@ RString SALOME_EvalParser::dump( const Postfix& post ) const } //======================================================================= //function : parameters -//purpose : +//purpose : //======================================================================= -RStringList SALOME_EvalParser::parameters() const +SALOME_StringList SALOME_EvalParser::parameters() const { - RStringList lst; + SALOME_StringList lst; Postfix::const_iterator anIt = myPostfix.begin(); for (; anIt != myPostfix.end(); anIt++ ) { if ( (*anIt).myType == Param ) { - RString name = (*anIt).myValue.toString(); + SALOME_String name = (*anIt).myValue.toString(); if ( !contains(lst, name ) ) { lst.push_back( name ); } @@ -941,7 +922,7 @@ RStringList SALOME_EvalParser::parameters() const } //======================================================================= //function : clearParameters -//purpose : +//purpose : //======================================================================= void SALOME_EvalParser::clearParameters() { @@ -949,11 +930,11 @@ void SALOME_EvalParser::clearParameters() } //======================================================================= //function : toString -//purpose : +//purpose : //======================================================================= -RString SALOME_EvalParser::toString( const SALOME_ListOfEvalVariant& theList ) +SALOME_String SALOME_EvalParser::toString( const SALOME_ListOfEvalVariant& theList ) { - RString res = "set : [ "; + SALOME_String res = "set : [ "; SALOME_ListOfEvalVariant::const_iterator aIt = theList.begin(); for ( ; aIt != theList.end(); aIt++ ) res += (*aIt).toString() + " "; @@ -962,16 +943,16 @@ RString SALOME_EvalParser::toString( const SALOME_ListOfEvalVariant& theList ) } //======================================================================= //function : operationList -//purpose : +//purpose : //======================================================================= -void SALOME_EvalParser::operationList( RStringList& theList ) const +void SALOME_EvalParser::operationList( SALOME_StringList& theList ) const { - SALOME_ListOfPEvalSet::const_iterator aIt = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator aIt = mySets.begin(); for (; aIt != mySets.end(); ++aIt ) { - RStringList custom; + SALOME_StringList custom; SALOME_EvalSet* aSet = *aIt; aSet->operationList( custom ); - RStringList::const_iterator sIt = custom.begin(); + SALOME_StringList::const_iterator sIt = custom.begin(); for ( ; sIt != custom.end(); ++sIt ) { if ( !contains(theList, *sIt ) ) { theList.push_back( *sIt ); @@ -981,17 +962,16 @@ void SALOME_EvalParser::operationList( RStringList& theList ) const } //======================================================================= //function : operationList -//purpose : +//purpose : //======================================================================= -void SALOME_EvalParser::bracketsList(RStringList& theList, - bool open ) const -{ - SALOME_ListOfPEvalSet::const_iterator it = mySets.begin(); +void SALOME_EvalParser::bracketsList( SALOME_StringList& theList, bool open ) const +{ + SALOME_ListOfEvalSet::const_iterator it = mySets.begin(); for (; it != mySets.end(); ++it ) { - RStringList custom; + SALOME_StringList custom; SALOME_EvalSet* aSet = *it; aSet->bracketsList( custom, open ); - RStringList::const_iterator sIt = custom.begin(); + SALOME_StringList::const_iterator sIt = custom.begin(); for (; sIt != custom.end(); ++sIt ) { if ( !contains(theList, *sIt ) ) theList.push_back( *sIt ); @@ -1000,14 +980,13 @@ void SALOME_EvalParser::bracketsList(RStringList& theList, } //======================================================================= //function : createValue -//purpose : +//purpose : //======================================================================= -bool SALOME_EvalParser::createValue(const RString& str, - SALOME_EvalVariant& val) const +bool SALOME_EvalParser::createValue( const SALOME_String& str, SALOME_EvalVariant& val ) const { bool ok = false; // - SALOME_ListOfPEvalSet::const_iterator it = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator it = mySets.begin(); for (; it != mySets.end() && !ok; ++it ) { ok = (*it)->createValue( str, val ); } @@ -1015,14 +994,13 @@ bool SALOME_EvalParser::createValue(const RString& str, } //======================================================================= //function : priority -//purpose : +//purpose : //======================================================================= -int SALOME_EvalParser::priority(const RString& op, - bool isBin ) const +int SALOME_EvalParser::priority( const SALOME_String& op, bool isBin ) const { int i = 0; int priority = 0; - SALOME_ListOfPEvalSet::const_iterator it = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator it = mySets.begin(); for (; it != mySets.end() && priority <= 0; ++it, i++ ){ priority = (*it)->priority( op, isBin ); } @@ -1030,19 +1008,18 @@ int SALOME_EvalParser::priority(const RString& op, } //======================================================================= //function : isValid -//purpose : +//purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalParser::isValid(const RString& op, - const SALOME_EvalVariantType t1, - const SALOME_EvalVariantType t2 ) const +SALOME_EvalExprError SALOME_EvalParser::isValid( const SALOME_String& op, const SALOME_EvalVariantType t1, + const SALOME_EvalVariantType t2 ) const { - SALOME_EvalExprError err = SALOME_EvalExpr_OK; + SALOME_EvalExprError err = EvalExpr_OK; // - SALOME_ListOfPEvalSet::const_iterator it = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator it = mySets.begin(); for (; it != mySets.end(); ++it ) { SALOME_EvalSet *pSet=*it; err = pSet->isValid( op, t1, t2 ); - if ( err == SALOME_EvalExpr_OK ){ + if ( err == EvalExpr_OK ){ break; } } @@ -1050,11 +1027,9 @@ SALOME_EvalExprError SALOME_EvalParser::isValid(const RString& op, } //======================================================================= //function : calculation -//purpose : +//purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalParser::calculation(const RString& op, - SALOME_EvalVariant& v1, - SALOME_EvalVariant& v2 ) const +SALOME_EvalExprError SALOME_EvalParser::calculation( const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) const { SALOME_EvalVariant nv1, nv2; SALOME_EvalSet *pSet; @@ -1064,15 +1039,15 @@ SALOME_EvalExprError SALOME_EvalParser::calculation(const RString& op, aType1=v1.type(); aType2=v2.type(); // - SALOME_ListOfPEvalSet::const_iterator aIt = mySets.begin(); + SALOME_ListOfEvalSet::const_iterator aIt = mySets.begin(); for (; aIt != mySets.end(); ++aIt ) { pSet=*aIt; nv1 = v1; nv2 = v2; aErr=pSet->isValid( op, aType1, aType2); - if ( aErr == SALOME_EvalExpr_OK ) { + if ( aErr == EvalExpr_OK ) { aErr = pSet->calculate( op, nv1, nv2 ); - if ( aErr == SALOME_EvalExpr_OK || aErr == SALOME_EvalExpr_InvalidResult ) { + if ( aErr == EvalExpr_OK || aErr == EvalExpr_InvalidResult ) { v1 = nv1; v2 = nv2; return aErr; @@ -1080,11 +1055,11 @@ SALOME_EvalExprError SALOME_EvalParser::calculation(const RString& op, } } // - return SALOME_EvalExpr_InvalidOperation; + return EvalExpr_InvalidOperation; } //======================================================================= //function : checkOperations -//purpose : +//purpose : //======================================================================= bool SALOME_EvalParser::checkOperations() const { @@ -1092,12 +1067,12 @@ bool SALOME_EvalParser::checkOperations() const return true; SALOME_EvalParser* that = (SALOME_EvalParser*)this; - that->setError( SALOME_EvalExpr_OperationsNull ); + that->setError( EvalExpr_OperationsNull ); return false; } //======================================================================= //function : append -//purpose : +//purpose : //======================================================================= void SALOME_EvalParser::append(Postfix& aL, const Postfix& aL1) @@ -1109,9 +1084,9 @@ void SALOME_EvalParser::append(Postfix& aL, } //======================================================================= //function : at -//purpose : +//purpose : //======================================================================= -const SALOME_EvalParser::PostfixItem& SALOME_EvalParser::at(const Postfix& aL, +const SALOME_EvalParser::PostfixItem& SALOME_EvalParser::at(const Postfix& aL, const int aIndex) { int i; @@ -1125,9 +1100,9 @@ const SALOME_EvalParser::PostfixItem& SALOME_EvalParser::at(const Postfix& aL, } //======================================================================= //function : insert -//purpose : +//purpose : //======================================================================= -void SALOME_EvalParser::insert(Postfix& aL, +void SALOME_EvalParser::insert(Postfix& aL, const int aIndex, PostfixItem& pS) { @@ -1151,19 +1126,19 @@ void SALOME_EvalParser::insert(Postfix& aL, } //======================================================================= //function : indexOf -//purpose : +//purpose : //======================================================================= -int indexOf(const RStringList& aLS, - const RString& aS) +int indexOf( const SALOME_StringList& aLS, const SALOME_String& aS ) { int i, iRet; - RStringList::const_iterator aIt; + SALOME_StringList::const_iterator aIt; // iRet=-1; // aIt=aLS.begin(); - for (i=0; aIt!=aLS.end(); ++aIt, ++i) { - const RString aSx=*aIt; + for (i=0; aIt!=aLS.end(); ++aIt, ++i) + { + const SALOME_String aSx=*aIt; if (aSx==aS) { iRet=i; break; @@ -1173,19 +1148,18 @@ int indexOf(const RStringList& aLS, } //======================================================================= //function : contains -//purpose : +//purpose : //======================================================================= -bool contains(const RStringList& aLS, - const RString& aS) +bool contains( const SALOME_StringList& aLS, const SALOME_String& aS ) { bool bRet; // bRet=false; - RStringList::const_iterator aIt; + SALOME_StringList::const_iterator aIt; // aIt=aLS.begin(); for (; aIt!=aLS.end(); ++aIt) { - const RString aSx=*aIt; + const SALOME_String aSx=*aIt; if (aSx==aS) { bRet=!bRet; break; @@ -1197,7 +1171,7 @@ bool contains(const RStringList& aLS, //======================================================================= //function : isSpace -//purpose : +//purpose : //======================================================================= bool isSpace(const char aC) { @@ -1219,15 +1193,15 @@ bool isSpace(const char aC) } //======================================================================= //function : trimmed -//purpose : +//purpose : //======================================================================= -RString trimmed(const RString& str) +SALOME_String trimmed(const SALOME_String& str) { char aWhat[]={ '\t', '\n', '\v', '\f', '\r', ' ' }; int i, aNb; - RString aRet; + SALOME_String aRet; // aRet=str; aNb=sizeof(aWhat)/sizeof(aWhat[0]); @@ -1238,19 +1212,19 @@ RString trimmed(const RString& str) } //======================================================================= //function : trimmed -//purpose : +//purpose : //======================================================================= -RString trimmed(const RString& str, const char aWhat) +SALOME_String trimmed(const SALOME_String& str, const char aWhat) { char aX[2]; size_t mylength, i; - RString aRet; - // + SALOME_String aRet; + // const char* mystring=str.c_str(); if(!mystring) { return aRet; } - // + // mylength=strlen(mystring); if (!mylength) { return aRet; diff --git a/src/Notebook/SALOME_EvalParser.hxx b/src/Notebook/SALOME_EvalParser.hxx index e53049b99..a575af088 100755 --- a/src/Notebook/SALOME_EvalParser.hxx +++ b/src/Notebook/SALOME_EvalParser.hxx @@ -43,38 +43,37 @@ public: SALOME_EvalParser(); virtual ~SALOME_EvalParser(); - SALOME_EvalVariant calculate(); - SALOME_EvalVariant calculate( const RString& ); - bool setExpression( const RString& ); + SALOME_EvalVariant calculate(); + SALOME_EvalVariant calculate( const SALOME_String& ); + bool setExpression( const SALOME_String& ); - SALOME_ListOfPEvalSet operationSets() const; - SALOME_PEvalSet operationSet( const RString& ) const; - void removeOperationSet(SALOME_PEvalSet ); - void insertOperationSet(SALOME_PEvalSet, - const int = -1 ); + SALOME_ListOfEvalSet operationSets() const; + SALOME_EvalSet* operationSet( const SALOME_String& ) const; + void removeOperationSet( SALOME_EvalSet* ); + void insertOperationSet( SALOME_EvalSet*, const int = -1 ); - bool autoDeleteOperationSets() const; - void setAutoDeleteOperationSets( const bool ); + bool autoDeleteOperationSets() const; + void setAutoDeleteOperationSets( const bool ); - virtual void clearParameters(); - virtual bool removeParameter( const RString& name ); - virtual SALOME_EvalVariant parameter( const RString& name ) const; - virtual bool hasParameter( const RString& name ) const; - virtual void setParameter( const RString& name, - const SALOME_EvalVariant& value ); - RStringList parameters() const; + virtual void clearParameters(); + virtual bool removeParameter( const SALOME_String& name ); + virtual SALOME_EvalVariant parameter( const SALOME_String& name ) const; + virtual bool hasParameter( const SALOME_String& name ) const; + virtual void setParameter( const SALOME_String& name, const SALOME_EvalVariant& value ); + SALOME_StringList parameters() const; - SALOME_EvalExprError error() const; + SALOME_EvalExprError error() const; - bool firstInvalid( RString& ) const; - void removeInvalids(); - RString dump() const; + bool firstInvalid( SALOME_String& ) const; + void removeInvalids(); + SALOME_String dump() const; - static RString toString( const SALOME_ListOfEvalVariant& ); + static SALOME_String toString( const SALOME_ListOfEvalVariant& ); protected: //! Types of postfix representation elements - typedef enum { + typedef enum + { Value, //!< Value (number, string, etc.) Param, //!< Parameter Open, //!< Open bracket @@ -85,88 +84,52 @@ protected: } PostfixItemType; //! Postfix representation element - typedef struct { - SALOME_EvalVariant myValue; - PostfixItemType myType; + typedef struct + { + SALOME_EvalVariant myValue; + PostfixItemType myType; } PostfixItem; - typedef list Postfix; //!< postfix representation - typedef SALOME_ListOfPEvalSet SetList; //!< list of operations - typedef map ParamMap; //!< parameter-to-value map - typedef map ::value_type PairParamMap; + typedef list Postfix; //!< postfix representation + typedef SALOME_ListOfEvalSet SetList; //!< list of operations + typedef map ParamMap; //!< parameter-to-value map + typedef map ::value_type PairParamMap; protected: - RString dump( const Postfix& ) const; + SALOME_String dump( const Postfix& ) const; - virtual bool prepare( const RString&, Postfix& ); + virtual bool prepare( const SALOME_String&, Postfix& ); + virtual bool setOperationTypes( Postfix& ); + virtual bool sort( const Postfix&, Postfix&, const SALOME_StringList&, const SALOME_StringList&, int f = -1, int l = -1 ); + virtual bool parse( const SALOME_String& ); + virtual void setError( const SALOME_EvalExprError ); - virtual bool setOperationTypes( Postfix& ); + bool calculate( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ); - virtual bool sort(const Postfix&, - Postfix&, - const RStringList&, - const RStringList&, - int f = -1, - int l = -1 ); - - virtual bool parse( const RString& ); - virtual void setError( const SALOME_EvalExprError ); - - bool calculate(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ); - - static int search(const RStringList&, - const RString&, - int offset, - int& matchLen, - int& listind ); - - static RString note(const RString& str, - int pos, - int len ); - - static int globalBrackets(const Postfix&, - int, - int ); + static int search( const SALOME_StringList&, const SALOME_String&, int offset, int& matchLen, int& listind ); + static SALOME_String note( const SALOME_String& str, int pos, int len ); + static int globalBrackets( const Postfix&, int, int ); private: - void operationList(RStringList& ) const; - - void bracketsList(RStringList&, - bool ) const; - - bool createValue(const RString&, - SALOME_EvalVariant& ) const; - - int priority(const RString&, - bool isBin ) const; - - SALOME_EvalExprError isValid(const RString&, - const SALOME_EvalVariantType, - const SALOME_EvalVariantType ) const; - - SALOME_EvalExprError calculation(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; + void operationList( SALOME_StringList& ) const; + void bracketsList( SALOME_StringList&, bool ) const; + bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + int priority( const SALOME_String&, bool isBin ) const; - bool checkOperations() const; - //////////////////////////////////// - void insert(Postfix& aL, - const int aIndex, - PostfixItem& aItem); + SALOME_EvalExprError isValid( const SALOME_String&, const SALOME_EvalVariantType, const SALOME_EvalVariantType ) const; + SALOME_EvalExprError calculation( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; - const PostfixItem& at(const Postfix& aL, - const int aIndex); + bool checkOperations() const; + void insert( Postfix& aL, const int aIndex, PostfixItem& aItem ); + const PostfixItem& at( const Postfix& aL, const int aIndex ); + void append( Postfix& aL, const Postfix& aL1 ); - void SALOME_EvalParser::append(Postfix& aL, - const Postfix& aL1); private: - SALOME_ListOfPEvalSet mySets; - SALOME_EvalExprError myError; - ParamMap myParams; - Postfix myPostfix; - bool myAutoDel; + SALOME_ListOfEvalSet mySets; + SALOME_EvalExprError myError; + ParamMap myParams; + Postfix myPostfix; + bool myAutoDel; }; #endif diff --git a/src/Notebook/SALOME_EvalSet.cxx b/src/Notebook/SALOME_EvalSet.cxx index 882aa1c52..92c032049 100755 --- a/src/Notebook/SALOME_EvalSet.cxx +++ b/src/Notebook/SALOME_EvalSet.cxx @@ -28,14 +28,11 @@ // #include #include -static - int toInt(const RString& str, bool *ok); -static - double toDouble(const RString& str, bool *ok); -static - RString tolower(const RString& str); -static - RString toupper(const RString& str); + +int toInt(const SALOME_String& str, bool *ok); +double toDouble(const SALOME_String& str, bool *ok); +SALOME_String toLower(const SALOME_String& str); +SALOME_String toUpper(const SALOME_String& str); //======================================================================= //function : SALOME_EvalSet @@ -55,8 +52,7 @@ SALOME_EvalSet::~SALOME_EvalSet() //function : SALOME_EvalSet::createValue //purpose : //======================================================================= -bool SALOME_EvalSet::createValue(const RString& str, - SALOME_EvalVariant& val) const +bool SALOME_EvalSet::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const { val=str; return false; @@ -65,13 +61,12 @@ bool SALOME_EvalSet::createValue(const RString& str, //function : SALOME_EvalSet::contains //purpose : //======================================================================= -bool SALOME_EvalSet::contains(const SALOME_ListOfPEvalSet& aL, - const SALOME_EvalSet* pS) +bool SALOME_EvalSet::contains( const SALOME_ListOfEvalSet& aL, const SALOME_EvalSet* pS) { bool bRet; // bRet=false; - SALOME_ListOfPEvalSet::const_iterator aIt=aL.begin(); + SALOME_ListOfEvalSet::const_iterator aIt=aL.begin(); for(; aIt!=aL.end(); ++aIt) { const SALOME_EvalSet* pSx=*aIt; bRet=pSx==pS; @@ -85,9 +80,7 @@ bool SALOME_EvalSet::contains(const SALOME_ListOfPEvalSet& aL, //function : SALOME_EvalSet::insert //purpose : //======================================================================= -void SALOME_EvalSet::insert(SALOME_ListOfPEvalSet& aL, - const int aIndex, - SALOME_EvalSet* pS) +void SALOME_EvalSet::insert(SALOME_ListOfEvalSet& aL, const int aIndex, SALOME_EvalSet* pS) { int i; // @@ -98,7 +91,7 @@ void SALOME_EvalSet::insert(SALOME_ListOfPEvalSet& aL, aL.push_back(pS); } else { - SALOME_ListOfPEvalSet::iterator aIt=aL.begin(); + SALOME_ListOfEvalSet::iterator aIt=aL.begin(); for(i=0; aIt!=aL.end(); ++aIt, ++i) { //const SALOME_EvalSet* pSx=*aIt; if (i==aIndex) { @@ -127,10 +120,9 @@ SALOME_EvalSetBase::~SALOME_EvalSetBase() //function : SALOME_EvalSetBase::operationList //purpose : //======================================================================= -void SALOME_EvalSetBase::operationList(RStringList& aList) const +void SALOME_EvalSetBase::operationList( SALOME_StringList& aList ) const { - using namespace std; - RStringList::const_iterator aIt; + SALOME_StringList::const_iterator aIt; // aIt=myOpers.begin(); for (; aIt!=myOpers.end(); ++aIt) { @@ -141,7 +133,7 @@ void SALOME_EvalSetBase::operationList(RStringList& aList) const //function : SALOME_EvalSetBase::bracketsList //purpose : //======================================================================= -void SALOME_EvalSetBase::bracketsList(RStringList& aList, +void SALOME_EvalSetBase::bracketsList(SALOME_StringList& aList, bool bOpen) const { aList.push_back( bOpen ? "(" : ")" ); @@ -150,14 +142,15 @@ void SALOME_EvalSetBase::bracketsList(RStringList& aList, //function : SALOME_EvalSetBase::addOperations //purpose : //======================================================================= -void SALOME_EvalSetBase::addOperations(const RStringList& aList) +void SALOME_EvalSetBase::addOperations(const SALOME_StringList& aList) { - RStringList::const_iterator aIt; - SetOfRString aSet; - SetPair aSetPair; + SALOME_StringList::const_iterator aIt; + SALOME_StringSet aSet; + SALOME_SetPair aSetPair; // aIt=aList.begin(); - for (; aIt != aList.end(); ++aIt) { + for (; aIt != aList.end(); ++aIt) + { aSetPair=aSet.insert(*aIt); if(aSetPair.second) { myOpers.push_back( *aIt ); @@ -186,9 +179,9 @@ void SALOME_EvalSetBase::addTypes(const SALOME_ListOfEvalVariantType& aList) //function : SALOME_EvalSetBase::isValid //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetBase::isValid(const RString& op, - const SALOME_EvalVariantType t1, - const SALOME_EvalVariantType t2 ) const +SALOME_EvalExprError SALOME_EvalSetBase::isValid( const SALOME_String& op, + const SALOME_EvalVariantType t1, + const SALOME_EvalVariantType t2 ) const { bool bContainsT1, bContainsT2; SALOME_SetOfEvalVariantType aSet; @@ -212,13 +205,13 @@ SALOME_EvalExprError SALOME_EvalSetBase::isValid(const RString& op, ( t2 == SALOME_EvalVariant_Invalid || bContainsT2 ) && ( t1 != SALOME_EvalVariant_Invalid || t2 != SALOME_EvalVariant_Invalid ) ) { if ( priority( op, t1 != SALOME_EvalVariant_Invalid && t2 != SALOME_EvalVariant_Invalid ) > 0 ) { - return SALOME_EvalExpr_OK; + return EvalExpr_OK; } else { - return SALOME_EvalExpr_InvalidOperation; + return EvalExpr_InvalidOperation; } } - return SALOME_EvalExpr_OperandsNotMatch; + return EvalExpr_OperandsNotMatch; } //////////////////////////////////////////////////////////////////////// //======================================================================= @@ -228,8 +221,8 @@ SALOME_EvalExprError SALOME_EvalSetBase::isValid(const RString& op, SALOME_EvalSetArithmetic::SALOME_EvalSetArithmetic() : SALOME_EvalSetBase() { - RString aOp; - RStringList aStringList; + SALOME_String aOp; + SALOME_StringList aStringList; SALOME_ListOfEvalVariantType aTypes; // aOp="+"; aStringList.push_back(aOp); @@ -261,7 +254,7 @@ SALOME_EvalSetArithmetic::~SALOME_EvalSetArithmetic() //function : SALOME_EvalSetArithmetic::Name //purpose : //======================================================================= -RString SALOME_EvalSetArithmetic::Name() +SALOME_String SALOME_EvalSetArithmetic::Name() { return "Arithmetic"; } @@ -269,7 +262,7 @@ RString SALOME_EvalSetArithmetic::Name() //function : SALOME_EvalSetArithmetic::name //purpose : //======================================================================= -RString SALOME_EvalSetArithmetic::name()const +SALOME_String SALOME_EvalSetArithmetic::name()const { return Name(); } @@ -277,7 +270,7 @@ RString SALOME_EvalSetArithmetic::name()const //function : SALOME_EvalSetArithmetic::createValue //purpose : //======================================================================= -bool SALOME_EvalSetArithmetic::createValue(const RString& str, +bool SALOME_EvalSetArithmetic::createValue(const SALOME_String& str, SALOME_EvalVariant& val ) const { bool ok; @@ -307,7 +300,7 @@ bool SALOME_EvalSetArithmetic::createValue(const RString& str, //function : SALOME_EvalSetArithmetic::priority //purpose : //======================================================================= -int SALOME_EvalSetArithmetic::priority(const RString& op, bool isBin) const +int SALOME_EvalSetArithmetic::priority(const SALOME_String& op, bool isBin) const { if ( isBin ) { @@ -330,7 +323,7 @@ int SALOME_EvalSetArithmetic::priority(const RString& op, bool isBin) const //function : SALOME_EvalSetArithmetic::calculate //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const RString& op, +SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) const { @@ -338,7 +331,7 @@ SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const RString& op, SALOME_EvalExprError err; SALOME_EvalVariantType aType1, aType2; // - err = SALOME_EvalExpr_OK; + err = EvalExpr_OK; // bValid1=v1.isValid(); bValid2=v2.isValid(); @@ -372,7 +365,7 @@ SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const RString& op, } } else { - err = SALOME_EvalExpr_InvalidResult; + err = EvalExpr_InvalidResult; } } else if ( op == "<" ) { @@ -413,7 +406,7 @@ SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const RString& op, v1 = _v1 / _v2; } else{ - err = SALOME_EvalExpr_InvalidResult; + err = EvalExpr_InvalidResult; } } else if ( op == "<" ){ @@ -457,19 +450,19 @@ SALOME_EvalExprError SALOME_EvalSetArithmetic::calculate(const RString& op, SALOME_EvalSetLogic::SALOME_EvalSetLogic() : SALOME_EvalSetBase() { - RString aOp; - RStringList aStringList; + SALOME_String aOp; + SALOME_StringList aStringList; SALOME_ListOfEvalVariantType aTypes; // - aOp="and"; aStringList.push_back(aOp); + aOp="and"; aStringList.push_back(aOp); aOp="&&"; aStringList.push_back(aOp); aOp="or"; aStringList.push_back(aOp); aOp="||"; aStringList.push_back(aOp); - aOp="xor"; aStringList.push_back(aOp); - aOp="not"; aStringList.push_back(aOp); - aOp="!"; aStringList.push_back(aOp); - aOp="imp"; aStringList.push_back(aOp); - aOp="="; aStringList.push_back(aOp); + aOp="xor"; aStringList.push_back(aOp); + aOp="not"; aStringList.push_back(aOp); + aOp="!"; aStringList.push_back(aOp); + aOp="imp"; aStringList.push_back(aOp); + aOp="="; aStringList.push_back(aOp); addOperations( aStringList ); // aTypes.push_back( SALOME_EvalVariant_Boolean ); @@ -488,7 +481,7 @@ SALOME_EvalSetLogic::~SALOME_EvalSetLogic() //function : SALOME_EvalSetLogic::Name //purpose : //======================================================================= -RString SALOME_EvalSetLogic::Name() +SALOME_String SALOME_EvalSetLogic::Name() { return "Logic"; } @@ -496,7 +489,7 @@ RString SALOME_EvalSetLogic::Name() //function : SALOME_EvalSetLogic::name //purpose : //======================================================================= -RString SALOME_EvalSetLogic::name() const +SALOME_String SALOME_EvalSetLogic::name() const { return Name(); } @@ -504,10 +497,10 @@ RString SALOME_EvalSetLogic::name() const //function : SALOME_EvalSetLogic::createValue //purpose : //======================================================================= -bool SALOME_EvalSetLogic::createValue(const RString& str, SALOME_EvalVariant& val)const +bool SALOME_EvalSetLogic::createValue(const SALOME_String& str, SALOME_EvalVariant& val)const { bool ok = true; - RString valStr = tolower(str); + SALOME_String valStr = toLower(str); // if ( valStr == "true" || valStr == "yes" ) val = SALOME_EvalVariant( true ); @@ -522,7 +515,7 @@ bool SALOME_EvalSetLogic::createValue(const RString& str, SALOME_EvalVariant& va //function : SALOME_EvalSetLogic::priority //purpose : //======================================================================= -int SALOME_EvalSetLogic::priority(const RString& op, bool isBin) const +int SALOME_EvalSetLogic::priority(const SALOME_String& op, bool isBin) const { if ( isBin ) { @@ -547,11 +540,9 @@ int SALOME_EvalSetLogic::priority(const RString& op, bool isBin) const //function : SALOME_EvalSetLogic::priority //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetLogic::calculate(const RString& op, - SALOME_EvalVariant& v1, - SALOME_EvalVariant& v2 ) const +SALOME_EvalExprError SALOME_EvalSetLogic::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) const { - SALOME_EvalExprError err = SALOME_EvalExpr_OK; + SALOME_EvalExprError err = EvalExpr_OK; // int val1 = intValue( v1 ); int val2 = intValue( v2 ); @@ -608,8 +599,8 @@ int SALOME_EvalSetLogic::intValue(const SALOME_EvalVariant& v) const SALOME_EvalSetMath::SALOME_EvalSetMath() : SALOME_EvalSetBase() { - RString aOp; - RStringList aStringList; + SALOME_String aOp; + SALOME_StringList aStringList; SALOME_ListOfEvalVariantType aTypes; // aOp="sqrt"; aStringList.push_back(aOp); @@ -635,7 +626,7 @@ SALOME_EvalSetMath::~SALOME_EvalSetMath() //function : SALOME_EvalSetMath::Name //purpose : //======================================================================= -RString SALOME_EvalSetMath::Name() +SALOME_String SALOME_EvalSetMath::Name() { return "Math"; } @@ -643,7 +634,7 @@ RString SALOME_EvalSetMath::Name() //function : SALOME_EvalSetMath::name //purpose : //======================================================================= -RString SALOME_EvalSetMath::name() const +SALOME_String SALOME_EvalSetMath::name() const { return Name(); } @@ -651,7 +642,7 @@ RString SALOME_EvalSetMath::name() const //function : SALOME_EvalSetMath::createValue //purpose : //======================================================================= -bool SALOME_EvalSetMath::createValue(const RString& str, SALOME_EvalVariant& val) const +bool SALOME_EvalSetMath::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const { bool ok = false; // @@ -668,7 +659,7 @@ bool SALOME_EvalSetMath::createValue(const RString& str, SALOME_EvalVariant& val //function : SALOME_EvalSetMath::priority //purpose : //======================================================================= -int SALOME_EvalSetMath::priority(const RString& op, bool isBin) const +int SALOME_EvalSetMath::priority(const SALOME_String& op, bool isBin) const { if ( isBin ){ return 0; @@ -687,12 +678,10 @@ int SALOME_EvalSetMath::priority(const RString& op, bool isBin) const //function : SALOME_EvalSetMath::calculate //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetMath::calculate(const RString& op, - SALOME_EvalVariant& v1, - SALOME_EvalVariant& v2 ) const +SALOME_EvalExprError SALOME_EvalSetMath::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2 ) const { bool bOk; - SALOME_EvalExprError err = SALOME_EvalExpr_OK; + SALOME_EvalExprError err = EvalExpr_OK; double val = v2.toDouble(&bOk); if ( op == "sqrt" ) { @@ -700,7 +689,7 @@ SALOME_EvalExprError SALOME_EvalSetMath::calculate(const RString& op, v2 = sqrt( val ); } else { - err = SALOME_EvalExpr_InvalidResult; + err = EvalExpr_InvalidResult; } } else if ( op == "abs" ) { @@ -735,8 +724,8 @@ SALOME_EvalExprError SALOME_EvalSetMath::calculate(const RString& op, SALOME_EvalSetString::SALOME_EvalSetString() : SALOME_EvalSetBase() { - RString aOp; - RStringList aStringList; + SALOME_String aOp; + SALOME_StringList aStringList; SALOME_ListOfEvalVariantType aTypes; // aOp="+"; aStringList.push_back(aOp); @@ -768,7 +757,7 @@ SALOME_EvalSetString::~SALOME_EvalSetString() //function : SALOME_EvalSetString::Name //purpose : //======================================================================= -RString SALOME_EvalSetString::Name() +SALOME_String SALOME_EvalSetString::Name() { return "String"; } @@ -776,7 +765,7 @@ RString SALOME_EvalSetString::Name() //function : SALOME_EvalSetString::name //purpose : //======================================================================= -RString SALOME_EvalSetString::name()const +SALOME_String SALOME_EvalSetString::name()const { return Name(); } @@ -784,8 +773,7 @@ RString SALOME_EvalSetString::name()const //function : SALOME_EvalSetString::createValue //purpose : //======================================================================= -bool SALOME_EvalSetString::createValue(const RString& str, - SALOME_EvalVariant& val) const +bool SALOME_EvalSetString::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const { bool ok = false; const char* myString=str.c_str(); @@ -819,8 +807,7 @@ bool SALOME_EvalSetString::createValue(const RString& str, //function : SALOME_EvalSetString::priority //purpose : //======================================================================= -int SALOME_EvalSetString::priority(const RString& op, - bool isBin) const +int SALOME_EvalSetString::priority(const SALOME_String& op, bool isBin) const { if ( isBin ) { if ( op == "+" ) { @@ -843,14 +830,13 @@ int SALOME_EvalSetString::priority(const RString& op, //function : SALOME_EvalSetString::calculate //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetString::calculate(const RString& op, - SALOME_EvalVariant& v1, - SALOME_EvalVariant& v2) const +SALOME_EvalExprError SALOME_EvalSetString::calculate(const SALOME_String& op, SALOME_EvalVariant& v1, SALOME_EvalVariant& v2) const { - SALOME_EvalExprError err = SALOME_EvalExpr_OK; - if ( v1.isValid() && v2.isValid() ) { - RString _v1 = v1.toString(); - RString _v2 = v2.toString(); + SALOME_EvalExprError err = EvalExpr_OK; + if ( v1.isValid() && v2.isValid() ) + { + SALOME_String _v1 = v1.toString(); + SALOME_String _v2 = v2.toString(); if ( op == "+" ) v1 = _v1 + _v2; else if ( op == "=" ) @@ -866,15 +852,16 @@ SALOME_EvalExprError SALOME_EvalSetString::calculate(const RString& op, else if ( op == ">=" ) v1 = _v1 > _v2 || _v1 == _v2; } - else if ( !v1.isValid() && v2.isValid() ) { - RString val = v2.toString(); + else if ( !v1.isValid() && v2.isValid() ) + { + SALOME_String val = v2.toString(); if ( op == "length" ) v2 = (int)val.length(); else if ( op == "lower" ) { - v2=tolower(val); + v2=toLower(val); } else if ( op == "upper" ) { - v2=toupper(val); + v2=toUpper(val); } } return err; @@ -887,8 +874,8 @@ SALOME_EvalExprError SALOME_EvalSetString::calculate(const RString& op, SALOME_EvalSetSets::SALOME_EvalSetSets() : SALOME_EvalSetBase() { - RString aOp; - RStringList aStringList; + SALOME_String aOp; + SALOME_StringList aStringList; SALOME_ListOfEvalVariantType aTypes; // aOp="{"; aStringList.push_back(aOp); @@ -916,7 +903,7 @@ SALOME_EvalSetSets::~SALOME_EvalSetSets() //function : SALOME_EvalSetSets::Name //purpose : //======================================================================= -RString SALOME_EvalSetSets::Name() +SALOME_String SALOME_EvalSetSets::Name() { return "Sets"; } @@ -924,7 +911,7 @@ RString SALOME_EvalSetSets::Name() //function : SALOME_EvalSetSets::name //purpose : //======================================================================= -RString SALOME_EvalSetSets::name()const +SALOME_String SALOME_EvalSetSets::name()const { return Name(); } @@ -932,8 +919,7 @@ RString SALOME_EvalSetSets::name()const //function : SALOME_EvalSetSets::bracketsList //purpose : //======================================================================= -void SALOME_EvalSetSets::bracketsList(RStringList& aList, - bool bOpen ) const +void SALOME_EvalSetSets::bracketsList(SALOME_StringList& aList, bool bOpen ) const { aList.push_back( bOpen ? "{" : "}" ); SALOME_EvalSetBase::bracketsList(aList, bOpen); @@ -942,7 +928,7 @@ void SALOME_EvalSetSets::bracketsList(RStringList& aList, //function : SALOME_EvalSetSets::bracketsList //purpose : //======================================================================= -int SALOME_EvalSetSets::priority(const RString& op, bool isBin) const +int SALOME_EvalSetSets::priority(const SALOME_String& op, bool isBin) const { if ( isBin ) { if ( op == "=" || op == "<>" || op == "!=" ) @@ -965,21 +951,21 @@ int SALOME_EvalSetSets::priority(const RString& op, bool isBin) const //function : SALOME_EvalSetSets::isValid //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetSets::isValid(const RString& op, - const SALOME_EvalVariantType t1, - const SALOME_EvalVariantType t2 ) const +SALOME_EvalExprError SALOME_EvalSetSets::isValid(const SALOME_String& op, + const SALOME_EvalVariantType t1, + const SALOME_EvalVariantType t2 ) const { if ( op == "{" ) { - return SALOME_EvalExpr_OK; + return EvalExpr_OK; } if ( op != "in" ) { return SALOME_EvalSetBase::isValid( op, t1, t2 ); } if ( t1 != SALOME_EvalVariant_Invalid && t2 == SALOME_EvalVariant_List ) { - return SALOME_EvalExpr_OK; + return EvalExpr_OK; } //else - return SALOME_EvalExpr_OperandsNotMatch; + return EvalExpr_OperandsNotMatch; } //======================================================================= //function : SALOME_EvalSetSets::add @@ -1025,11 +1011,11 @@ void SALOME_EvalSetSets::remove(ValueSet& s1, const ValueSet& s2) //function : SALOME_EvalSetSets::calculate //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetSets::calculate(const RString& op, - SALOME_EvalVariant& v1, - SALOME_EvalVariant& v2 ) const +SALOME_EvalExprError SALOME_EvalSetSets::calculate(const SALOME_String& op, + SALOME_EvalVariant& v1, + SALOME_EvalVariant& v2 ) const { - SALOME_EvalExprError err = SALOME_EvalExpr_OK; + SALOME_EvalExprError err = EvalExpr_OK; // !!! if ( op != "{" ) { if ( op == "}" ) { @@ -1109,7 +1095,7 @@ SALOME_EvalSetConst::~SALOME_EvalSetConst() //function : SALOME_EvalSetConst::Name //purpose : //======================================================================= -RString SALOME_EvalSetConst::Name() +SALOME_String SALOME_EvalSetConst::Name() { return "Const"; } @@ -1117,7 +1103,7 @@ RString SALOME_EvalSetConst::Name() //function : SALOME_EvalSetConst::name //purpose : //======================================================================= -RString SALOME_EvalSetConst::name() const +SALOME_String SALOME_EvalSetConst::name() const { return Name(); } @@ -1125,7 +1111,7 @@ RString SALOME_EvalSetConst::name() const //function : SALOME_EvalSetConst::createValue //purpose : //======================================================================= -bool SALOME_EvalSetConst::createValue(const RString& str, SALOME_EvalVariant& val) const +bool SALOME_EvalSetConst::createValue(const SALOME_String& str, SALOME_EvalVariant& val) const { bool ok = true; if ( str == "pi" ) // PI number @@ -1143,21 +1129,21 @@ bool SALOME_EvalSetConst::createValue(const RString& str, SALOME_EvalVariant& va //function : SALOME_EvalSetConst::operationList //purpose : //======================================================================= -void SALOME_EvalSetConst::operationList(RStringList&) const +void SALOME_EvalSetConst::operationList(SALOME_StringList&) const { } //======================================================================= //function : SALOME_EvalSetConst::bracketsList //purpose : //======================================================================= -void SALOME_EvalSetConst::bracketsList(RStringList& , bool) const +void SALOME_EvalSetConst::bracketsList(SALOME_StringList& , bool) const { } //======================================================================= //function : SALOME_EvalSetConst::priority //purpose : //======================================================================= -int SALOME_EvalSetConst::priority(const RString& /*op*/, bool /*isBin*/ ) const +int SALOME_EvalSetConst::priority(const SALOME_String& /*op*/, bool /*isBin*/ ) const { return 0; } @@ -1165,34 +1151,34 @@ int SALOME_EvalSetConst::priority(const RString& /*op*/, bool /*isBin*/ ) const //function : SALOME_EvalSetConst::isValid //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetConst::isValid(const RString& /*op*/, - const SALOME_EvalVariantType /*t1*/, - const SALOME_EvalVariantType /*t2*/ ) const +SALOME_EvalExprError SALOME_EvalSetConst::isValid(const SALOME_String& /*op*/, + const SALOME_EvalVariantType /*t1*/, + const SALOME_EvalVariantType /*t2*/ ) const { - return SALOME_EvalExpr_InvalidOperation; + return EvalExpr_InvalidOperation; } //======================================================================= //function : SALOME_EvalSetConst::calculate //purpose : //======================================================================= -SALOME_EvalExprError SALOME_EvalSetConst::calculate(const RString&, +SALOME_EvalExprError SALOME_EvalSetConst::calculate(const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const { - return SALOME_EvalExpr_InvalidOperation; + return EvalExpr_InvalidOperation; } ///////////////////////////////////////////////////////////////////////// //======================================================================= -//function : toupper +//function : toUpper //purpose : //======================================================================= -RString toupper(const RString& str) +SALOME_String toUpper(const SALOME_String& str) { char aC; const char* mystring=str.c_str(); size_t mylength, i; - RString aRet; + SALOME_String aRet; // aRet=str; if(mystring) { @@ -1208,12 +1194,12 @@ RString toupper(const RString& str) //function : tolower //purpose : //======================================================================= -RString tolower(const RString& str) +SALOME_String toLower(const SALOME_String& str) { char aC; const char* mystring=str.c_str(); size_t mylength, i; - RString aRet; + SALOME_String aRet; // aRet=str; if(mystring) { @@ -1229,7 +1215,7 @@ RString tolower(const RString& str) //function : toDouble //purpose : //======================================================================= -double toDouble(const RString& str, bool *ok) +double toDouble(const SALOME_String& str, bool *ok) { char *ptr; const char* mystring=str.c_str(); @@ -1253,7 +1239,7 @@ double toDouble(const RString& str, bool *ok) //function : toInt //purpose : //======================================================================= -int toInt(const RString& str, bool *ok) +int toInt(const SALOME_String& str, bool *ok) { char *ptr; const char* mystring=str.c_str(); diff --git a/src/Notebook/SALOME_EvalSet.hxx b/src/Notebook/SALOME_EvalSet.hxx index ff6b0164e..ce59ce54f 100755 --- a/src/Notebook/SALOME_EvalSet.hxx +++ b/src/Notebook/SALOME_EvalSet.hxx @@ -26,20 +26,17 @@ #ifndef SALOME_EvalSet_Header_File #define SALOME_EvalSet_Header_File -// + +#include +#include +#include + #ifdef WNT #pragma warning(disable : 4786) #endif -// -#include -#include -#include -// -using namespace std; -// + class SALOME_EvalSet; -typedef SALOME_EvalSet* SALOME_PEvalSet; -typedef list SALOME_ListOfPEvalSet; +typedef std::list SALOME_ListOfEvalSet; //======================================================================= //class : SALOME_EvalSet @@ -49,40 +46,20 @@ class SALOME_EvalSet { public: SALOME_EvalSet(); - // virtual ~SALOME_EvalSet(); - // - virtual RString name() const = 0; - // - virtual void operationList( RStringList& ) const = 0; - // - virtual void bracketsList(RStringList&, - bool open ) const = 0; - // - virtual bool createValue(const RString&, - SALOME_EvalVariant& ) const; - // - virtual int priority( const RString&, bool isBin ) const = 0; - // - virtual SALOME_EvalExprError isValid(const RString&, - const SALOME_EvalVariantType, - const SALOME_EvalVariantType) const = 0; - - virtual SALOME_EvalExprError calculate(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant&) const = 0; - // - static bool contains(const SALOME_ListOfPEvalSet&, - const SALOME_EvalSet*); - // - static void insert (SALOME_ListOfPEvalSet& aL, - const int aIndex, - SALOME_EvalSet* pS); - // + + virtual SALOME_String name() const = 0; + virtual void operationList( SALOME_StringList& ) const = 0; + virtual void bracketsList( SALOME_StringList&, bool open ) const = 0; + virtual bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + virtual int priority( const SALOME_String&, bool isBin ) const = 0; + virtual SALOME_EvalExprError isValid(const SALOME_String&, const SALOME_EvalVariantType, const SALOME_EvalVariantType) const = 0; + virtual SALOME_EvalExprError calculate(const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant&) const = 0; + + static bool contains( const SALOME_ListOfEvalSet&, const SALOME_EvalSet* ); + static void insert( SALOME_ListOfEvalSet& aL, const int aIndex, SALOME_EvalSet* pS ); }; -// -// //======================================================================= //class : SALOME_EvalSetBase //purpose : @@ -91,27 +68,22 @@ class SALOME_EvalSetBase : public SALOME_EvalSet { public: SALOME_EvalSetBase(); - // virtual ~SALOME_EvalSetBase(); - // - virtual void operationList( RStringList& ) const; - virtual void bracketsList ( RStringList&, bool open ) const; - virtual - SALOME_EvalExprError isValid(const RString&, - const SALOME_EvalVariantType a, - const SALOME_EvalVariantType b) const; + virtual void operationList( SALOME_StringList& ) const; + virtual void bracketsList ( SALOME_StringList&, bool open ) const; - + virtual SALOME_EvalExprError isValid( const SALOME_String&, const SALOME_EvalVariantType a, const SALOME_EvalVariantType b) const; protected: - void addTypes(const SALOME_ListOfEvalVariantType&); - void addOperations(const RStringList& ); + void addTypes( const SALOME_ListOfEvalVariantType& ); + void addOperations( const SALOME_StringList& ); private: - RStringList myOpers; - SALOME_ListOfEvalVariantType myTypes; + SALOME_StringList myOpers; + SALOME_ListOfEvalVariantType myTypes; }; + //======================================================================= //class : SALOME_EvalSetArithmetic //purpose : @@ -122,19 +94,14 @@ public: SALOME_EvalSetArithmetic(); virtual ~SALOME_EvalSetArithmetic(); - virtual bool createValue(const RString&, - SALOME_EvalVariant& ) const; - - virtual int priority(const RString&, - bool isBin ) const; - - virtual SALOME_EvalExprError calculate(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; + virtual bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + virtual int priority( const SALOME_String&, bool isBin ) const; + virtual SALOME_EvalExprError calculate(const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; - static RString Name(); - virtual RString name() const; + static SALOME_String Name(); + virtual SALOME_String name() const; }; + //======================================================================= //class : SALOME_EvalSetLogic //purpose : @@ -146,23 +113,17 @@ public: virtual ~SALOME_EvalSetLogic(); - virtual bool createValue(const RString&, - SALOME_EvalVariant& ) const; - - virtual int priority(const RString&, - bool isBin ) const; - - virtual SALOME_EvalExprError calculate(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; + virtual bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + virtual int priority( const SALOME_String&, bool isBin ) const; + virtual SALOME_EvalExprError calculate( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; - static RString Name(); - - virtual RString name() const; + static SALOME_String Name(); + virtual SALOME_String name() const; private: - int intValue(const SALOME_EvalVariant& ) const; + int intValue(const SALOME_EvalVariant& ) const; }; + //======================================================================= //class : SALOME_EvalSetMath //purpose : @@ -173,19 +134,14 @@ public: SALOME_EvalSetMath(); virtual ~SALOME_EvalSetMath(); - virtual bool createValue(const RString&, - SALOME_EvalVariant&) const; + virtual bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + virtual int priority( const SALOME_String&, bool isBin ) const; + virtual SALOME_EvalExprError calculate(const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; - virtual int priority (const RString&, - bool isBin) const; - - virtual SALOME_EvalExprError calculate (const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; - - static RString Name(); - virtual RString name() const; + static SALOME_String Name(); + virtual SALOME_String name() const; }; + //======================================================================= //class : SALOME_EvalSetString //purpose : @@ -196,19 +152,14 @@ public: SALOME_EvalSetString(); virtual ~SALOME_EvalSetString(); - virtual bool createValue(const RString&, - SALOME_EvalVariant& ) const; - - virtual int priority( const RString&, - bool isBin ) const; + virtual bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + virtual int priority( const SALOME_String&, bool isBin ) const; + virtual SALOME_EvalExprError calculate(const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; - virtual SALOME_EvalExprError calculate( const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; - - static RString Name(); - virtual RString name() const; + static SALOME_String Name(); + virtual SALOME_String name() const; }; + //======================================================================= //class : SALOME_EvalSetSets //purpose : @@ -221,28 +172,21 @@ public: public: SALOME_EvalSetSets(); virtual ~SALOME_EvalSetSets(); - // - static RString Name(); - virtual RString name() const; - // - virtual void bracketsList(RStringList&, bool open ) const; - // - virtual int priority(const RString&, bool isBin ) const; - - virtual SALOME_EvalExprError isValid(const RString&, - const SALOME_EvalVariantType, - const SALOME_EvalVariantType) const; - - virtual SALOME_EvalExprError calculate(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; - - static void add (ValueSet&, const SALOME_EvalVariant& ); - static void add (ValueSet&, const ValueSet& ); - static void remove(ValueSet&, const SALOME_EvalVariant& ); - static void remove(ValueSet&, const ValueSet& ); + virtual int priority( const SALOME_String&, bool isBin ) const; + virtual SALOME_EvalExprError calculate(const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; + virtual SALOME_EvalExprError isValid( const SALOME_String&, const SALOME_EvalVariantType, const SALOME_EvalVariantType ) const; + virtual void bracketsList( SALOME_StringList&, bool open ) const; + + static SALOME_String Name(); + virtual SALOME_String name() const; + + static void add ( ValueSet&, const SALOME_EvalVariant& ); + static void add ( ValueSet&, const ValueSet& ); + static void remove( ValueSet&, const SALOME_EvalVariant& ); + static void remove( ValueSet&, const ValueSet& ); }; + //======================================================================= //class : SALOME_EvalSetConst //purpose : @@ -253,24 +197,15 @@ public: SALOME_EvalSetConst(); virtual ~SALOME_EvalSetConst(); - static RString Name(); - virtual RString name() const; - - virtual bool createValue( const RString&, SALOME_EvalVariant& ) const; - - virtual void operationList( RStringList& ) const; - - virtual void bracketsList( RStringList&, bool open ) const; - - virtual int priority( const RString&, bool isBin ) const; - - virtual SALOME_EvalExprError isValid(const RString&, - const SALOME_EvalVariantType, - const SALOME_EvalVariantType ) const; + static SALOME_String Name(); + virtual SALOME_String name() const; - virtual SALOME_EvalExprError calculate(const RString&, - SALOME_EvalVariant&, - SALOME_EvalVariant& ) const; + virtual bool createValue( const SALOME_String&, SALOME_EvalVariant& ) const; + virtual void operationList( SALOME_StringList& ) const; + virtual void bracketsList( SALOME_StringList&, bool open ) const; + virtual int priority( const SALOME_String&, bool isBin ) const; + virtual SALOME_EvalExprError isValid( const SALOME_String&, const SALOME_EvalVariantType, const SALOME_EvalVariantType ) const; + virtual SALOME_EvalExprError calculate( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const; }; #endif diff --git a/src/Notebook/SALOME_EvalVariant.cxx b/src/Notebook/SALOME_EvalVariant.cxx index 33a38748f..403458c0c 100755 --- a/src/Notebook/SALOME_EvalVariant.cxx +++ b/src/Notebook/SALOME_EvalVariant.cxx @@ -39,8 +39,8 @@ SALOME_EvalVariantData::SALOME_EvalVariantData(const SALOME_EvalVariantData& oth // switch (myType) { case SALOME_EvalVariant_String: { - RString& aStr=*(RString *)(other.myValue.myPtr); - RString *pStr=new RString(aStr); + SALOME_String& aStr=*(SALOME_String *)(other.myValue.myPtr); + SALOME_String *pStr=new SALOME_String(aStr); myValue.myPtr=(void*)pStr; } break; @@ -67,8 +67,8 @@ SALOME_EvalVariantData& SALOME_EvalVariantData::operator=(const SALOME_EvalVaria myType=other.myType; switch (myType) { case SALOME_EvalVariant_String: { - RString& aStr=*(string *)(other.myValue.myPtr); - RString *pStr=new RString(aStr); + SALOME_String& aStr=*(string *)(other.myValue.myPtr); + SALOME_String *pStr=new SALOME_String(aStr); myValue.myPtr=(void*)pStr; } break; @@ -136,8 +136,8 @@ bool SALOME_EvalVariantData::operator==(const SALOME_EvalVariantData& theOther) bRet=false; } else { - RString& myStr=*(RString *)(myValue.myPtr); - RString& aOther=*(RString *)(theOther.myValue.myPtr); + SALOME_String& myStr=*(SALOME_String *)(myValue.myPtr); + SALOME_String& aOther=*(SALOME_String *)(theOther.myValue.myPtr); bRet=myStr==aOther; } } @@ -237,10 +237,10 @@ SALOME_EvalVariant::SALOME_EvalVariant(double theValue) //function : SALOME_EvalVariant //purpose : //======================================================================= -SALOME_EvalVariant::SALOME_EvalVariant(const RString& theValue) +SALOME_EvalVariant::SALOME_EvalVariant(const SALOME_String& theValue) { ChangeDataType()=SALOME_EvalVariant_String; - RString *p=new RString(theValue); + SALOME_String *p=new SALOME_String(theValue); ChangeDataValue().myPtr=(void*)p; } //======================================================================= @@ -257,12 +257,12 @@ SALOME_EvalVariant::SALOME_EvalVariant(const SALOME_ListOfEvalVariant& theValue) //function : operator= //purpose : //======================================================================= -void SALOME_EvalVariant::operator=(const RString& theValue) +void SALOME_EvalVariant::operator=(const SALOME_String& theValue) { clear(); // ChangeDataType()=SALOME_EvalVariant_String; - RString *p=new RString(theValue); + SALOME_String *p=new SALOME_String(theValue); ChangeDataValue().myPtr=(void*)p; } //======================================================================= @@ -318,7 +318,7 @@ void SALOME_EvalVariant::operator=(const char* theValue) clear(); // ChangeDataType()=SALOME_EvalVariant_String; - RString *p=new RString(theValue); + SALOME_String *p=new SALOME_String(theValue); ChangeDataValue().myPtr=(void*)p; } //======================================================================= @@ -342,8 +342,8 @@ bool SALOME_EvalVariant::toBool() const return DataValueDouble() != 0.; } else if ( aType == SALOME_EvalVariant_String ) { - RString aZero("0"), aFalse("false"); - const RString& aStr=DataValueString(); + SALOME_String aZero("0"), aFalse("false"); + const SALOME_String& aStr=DataValueString(); return !(aStr==aZero || aStr==aFalse || aStr.empty()); } return false; @@ -373,7 +373,7 @@ int SALOME_EvalVariant::toInt(bool *ok) const else if (aType == SALOME_EvalVariant_String) { int iRet; // - const RString& aStr=DataValueString(); + const SALOME_String& aStr=DataValueString(); const char *pStr=aStr.c_str(); iRet=atoi(pStr); return iRet; @@ -417,7 +417,7 @@ double SALOME_EvalVariant::toDouble(bool *ok) const else if (aType == SALOME_EvalVariant_String) { double dRet; // - const RString& aStr=DataValueString(); + const SALOME_String& aStr=DataValueString(); const char *pStr=aStr.c_str(); dRet=atof(pStr); return dRet; @@ -429,11 +429,11 @@ double SALOME_EvalVariant::toDouble(bool *ok) const //function : toString //purpose : //======================================================================= -RString SALOME_EvalVariant::toString() const +SALOME_String SALOME_EvalVariant::toString() const { bool bOk; char buffer[32]; - RString aS; + SALOME_String aS; // SALOME_EvalVariantType aType=type(); // @@ -460,7 +460,7 @@ RString SALOME_EvalVariant::toString() const aS=buffer; } else if (aType == SALOME_EvalVariant_String) { - const RString& aStr=DataValueString(); + const SALOME_String& aStr=DataValueString(); aS=aStr; } return aS; diff --git a/src/Notebook/SALOME_EvalVariant.hxx b/src/Notebook/SALOME_EvalVariant.hxx index 621c7d532..136ec16f4 100755 --- a/src/Notebook/SALOME_EvalVariant.hxx +++ b/src/Notebook/SALOME_EvalVariant.hxx @@ -98,7 +98,7 @@ class SALOME_EvalVariantData { void clear(){ if (myType==SALOME_EvalVariant_String) { if (myValue.myPtr) { - RString *pStr=(RString *)myValue.myPtr; + SALOME_String *pStr=(SALOME_String *)myValue.myPtr; delete pStr; myValue.myPtr=NULL; } @@ -129,17 +129,21 @@ class SALOME_EvalVariantData { //======================================================================= class SALOME_EvalVariant { - public: - SALOME_EvalVariant(){ - }; - // - ~SALOME_EvalVariant(){ - myData.clear(); - }; - // - SALOME_EvalVariant(const SALOME_EvalVariant& other) : - myData(other.myData) { - }; +public: + SALOME_EvalVariant() + { + }; + + // + ~SALOME_EvalVariant() + { + myData.clear(); + }; + + // + SALOME_EvalVariant(const SALOME_EvalVariant& other) : myData(other.myData) + { + }; // SALOME_EvalVariant& operator=(const SALOME_EvalVariant& other) { myData=other.myData; @@ -151,7 +155,7 @@ class SALOME_EvalVariant }; // //// - void operator=(const RString& aString); + void operator=(const SALOME_String& aString); void operator=(const bool theValue); void operator=(const int theValue); void operator=(const uint theValue); @@ -162,7 +166,7 @@ class SALOME_EvalVariant SALOME_EvalVariant(int i); SALOME_EvalVariant(uint ui); SALOME_EvalVariant(double d); - SALOME_EvalVariant(const RString& s); + SALOME_EvalVariant(const SALOME_String& s); SALOME_EvalVariant(const SALOME_ListOfEvalVariant& s); // SALOME_EvalVariantType type() const { @@ -185,7 +189,7 @@ class SALOME_EvalVariant int toInt(bool *ok) const; uint toUInt(bool *ok) const; double toDouble(bool *ok) const; - RString toString() const; + SALOME_String toString() const; SALOME_ListOfEvalVariant toList() const; // const SALOME_EvalVariantData& Data() const{ @@ -248,7 +252,7 @@ class SALOME_EvalVariant return DataValue().myDouble; }; // - const RString& DataValueString() const { + const SALOME_String& DataValueString() const { return *((string *)(DataValue().myPtr)); }; // diff --git a/src/Notebook/SALOME_Notebook.cxx b/src/Notebook/SALOME_Notebook.cxx index 2cbd52cc8..f050b5119 100644 --- a/src/Notebook/SALOME_Notebook.cxx +++ b/src/Notebook/SALOME_Notebook.cxx @@ -25,32 +25,271 @@ // #include +#include -SALOME_Notebook::SALOME_Notebook() +SALOME_Notebook::SALOME_Notebook( SALOMEDS::Study_ptr theStudy ) { + myStudy = SALOMEDS::Study::_duplicate( theStudy ); } -void SALOME_Notebook::AddDependency( SALOME::ParameterizedObject_ptr obj, SALOME::ParameterizedObject_ptr ref ) +CORBA::Boolean SALOME_Notebook::AddDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ) { - std::string anObjEntry = obj->GetEntry(), aRefEntry = ref->GetEntry(); - std::list& aList = myDependencies[anObjEntry]; - if( find( aList.begin(), aList.end(), aRefEntry ) == aList.end() ) - aList.push_back( aRefEntry ); + return AddDependency( GetKey( theObj ), GetKey( theRef ) ); } -void SALOME_Notebook::RemoveDependency( SALOME::ParameterizedObject_ptr obj, SALOME::ParameterizedObject_ptr ref ) +void SALOME_Notebook::RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ) { - std::string anObjEntry = obj->GetEntry(), aRefEntry = ref->GetEntry(); - std::map< std::string, std::list >::iterator it = myDependencies.find( anObjEntry ); - if( it!=myDependencies.end() ) - it->second.remove( aRefEntry ); + std::string anObjKey = GetKey( theObj ), aRefKey = GetKey( theRef ); + myDeps[anObjKey].remove( aRefKey ); } -void SALOME_Notebook::ClearDependencies( SALOME::ParameterizedObject_ptr obj ) +void SALOME_Notebook::ClearDependencies( SALOME::ParameterizedObject_ptr theObj ) { - myDependencies.erase( obj->GetEntry() ); + ClearDependencies( GetKey( theObj ) ); } -void SALOME_Notebook::Update( SALOME::ParameterizedObject_ptr obj ) +void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj ) { + printf( "SetToUpdate: %s\n", GetKey( theObj ).c_str() ); + + SALOME::Parameter_ptr aParam = SALOME::Parameter::_narrow( theObj ); + if( !CORBA::is_nil( aParam ) ) + { + std::string anEntry = aParam->GetEntry(); + SALOME_Parameter* aParamPtr = myParams[anEntry]; + std::string aKey = GetKey( anEntry ); + ClearDependencies( aKey ); + AddDependencies( aParamPtr ); + } + + /* + printf( "Dependencies:\n" ); + std::map< std::string, std::list >::const_iterator mit = myDeps.begin(), mlast = myDeps.end(); + for( ; mit!=mlast; mit++ ) + { + printf( "%s -> [ ", mit->first.c_str() ); + std::list::const_iterator lit = mit->second.begin(), llast = mit->second.end(); + for( ; lit!=llast; lit++ ) + printf( "%s ", (*lit).c_str() ); + printf( "]\n" ); + } + */ + + std::string anObjKey = GetKey( theObj ); + std::list aDeps = GetAllDependingOn( anObjKey ); + std::list::const_iterator it = aDeps.begin(), last = aDeps.end(); + for( ; it!=last; it++ ) + if( find( myToUpdate.begin(), myToUpdate.end(), *it ) == myToUpdate.end() ) + myToUpdate.push_back( KeyHelper( *it, this ) ); + + //myToUpdate.sort(); + std::list::iterator uit = myToUpdate.begin(), uit1, ulast = myToUpdate.end(); + for( ; uit!=ulast; uit++ ) + for( uit1=uit, uit1++; uit1!=ulast; uit1++ ) + if( *uit1 < *uit ) + { + KeyHelper tmp = *uit1; + *uit1 = *uit; + *uit = tmp; + } + + uit = myToUpdate.begin(); ulast = myToUpdate.end(); + for( ; uit!=ulast; uit++ ) + printf( "To update: %s\n", (*uit).key().c_str() ); +} + +void SALOME_Notebook::Update() +{ + //printf( "Update\n" ); + std::list< KeyHelper > aPostponedUpdate; + std::list::const_iterator it = myToUpdate.begin(), last = myToUpdate.end(); + for( ; it!=last; it++ ) + { + std::string aKey = (*it).key(); + SALOME::ParameterizedObject_ptr anObj = FindObject( aKey ); + if( CORBA::is_nil( anObj ) ) + aPostponedUpdate.push_back( *it ); + else + anObj->Update(); + } + myToUpdate = aPostponedUpdate; +} + +CORBA::Boolean SALOME_Notebook::AddExpr( const char* theExpr ) +{ + return AddParam( new SALOME_Parameter( this, theExpr ) ); +} + +CORBA::Boolean SALOME_Notebook::AddNameExpr( const char* theName, const char* theExpr ) +{ + return AddParam( new SALOME_Parameter( this, theName, theExpr ) ); +} + +CORBA::Boolean SALOME_Notebook::AddValue( const char* theName, CORBA::Double theValue ) +{ + return AddParam( new SALOME_Parameter( this, theName, theValue ) ); +} + +void SALOME_Notebook::Remove( const char* theParamName ) +{ + std::string aKey = GetKey( theParamName ); + ClearDependencies( aKey ); + myDeps.erase( aKey ); + myParams.erase( theParamName ); +} + +SALOME::Parameter_ptr SALOME_Notebook::Param( const char* theParamName ) +{ + //printf( "Param, name = %s\n", theParamName ); + return ParamPtr( theParamName )->_this(); +} + +SALOME_Parameter* SALOME_Notebook::ParamPtr( const char* theParamName ) const +{ + std::map< std::string, SALOME_Parameter* >::const_iterator it = myParams.find( theParamName ); + return it==myParams.end() ? 0 : it->second; +} + +bool SALOME_Notebook::AddParam( SALOME_Parameter* theParam ) +{ + std::string anEntry = theParam->GetEntry(); + //printf( "Add param: %s\n", anEntry.c_str() ); + + std::map< std::string, SALOME_Parameter* >::const_iterator it = myParams.find( anEntry ); + if( it!=myParams.end() ) + { + delete it->second; + ClearDependencies( GetKey( anEntry ) ); + } + + bool ok = AddDependencies( theParam ); + //printf( "Add param: %s, Result = %i\n\n", anEntry.c_str(), ok ); + + if( !ok ) + { + //printf( "Removed\n" ); + Remove( anEntry.c_str() ); + } + + return ok; +} + +bool SALOME_Notebook::AddDependencies( SALOME_Parameter* theParam ) +{ + //printf( "Dependencies search\n" ); + std::string anEntry = theParam->GetEntry(); + std::string aParamKey = GetKey( anEntry ); + myParams[anEntry] = theParam; + SALOME_StringList aDeps = theParam->Dependencies(); + SALOME_StringList::const_iterator dit = aDeps.begin(), dlast = aDeps.end(); + bool ok = true; + for( ; dit!=dlast && ok; dit++ ) + { + std::string aKey = GetKey( *dit ); + ok = AddDependency( aParamKey, aKey ); + //printf( "add dep to %s, res = %i\n", aKey.c_str(), ok ); + } + return ok; +} + +bool SALOME_Notebook::AddDependency( const std::string& theObjKey, const std::string& theRefKey ) +{ + std::list aDeps = GetAllDependingOn( theObjKey ); + if( find( aDeps.begin(), aDeps.end(), theRefKey ) != aDeps.end () ) + return false; //after creation a cyclic dependency could appear + + std::list& aList = myDeps[theObjKey]; + bool ok = find( aList.begin(), aList.end(), theRefKey ) == aList.end(); + if( ok ) + aList.push_back( theRefKey ); + + return ok; +} + +void SALOME_Notebook::ClearDependencies( const std::string& theObjKey ) +{ + //printf( "Clear dependencies: %s\n", theObjKey.c_str() ); + myDeps.erase( theObjKey ); +} + +std::string SALOME_Notebook::GetKey( SALOME::ParameterizedObject_ptr theObj ) +{ + return std::string( theObj->GetComponent() ) + "#" + theObj->GetEntry(); +} + +std::string SALOME_Notebook::GetKey( const std::string& theParamName ) +{ + return PARAM_COMPONENT + "#" + theParamName; +} + +std::list SALOME_Notebook::GetAllDependingOn( const std::string& theKey ) +{ + std::list aDeps, aCurrents, aNewCurrents; + aCurrents.push_back( theKey ); + aDeps.push_back( theKey ); + while( aCurrents.size() > 0 ) + { + aNewCurrents.clear(); + std::list::const_iterator cit = aCurrents.begin(), clast = aCurrents.end(); + for( ; cit!=clast; cit++ ) + { + //printf( "Check of %s:\n", (*cit).c_str() ); + std::map< std::string, std::list >::const_iterator dit = myDeps.begin(), dlast = myDeps.end(); + for( ; dit!=dlast; dit++ ) + { + std::string k = dit->first; + //printf( "\t%s\n", k.c_str() ); + if( find( dit->second.begin(), dit->second.end(), *cit ) != dit->second.end() && + find( aDeps.begin(), aDeps.end(), k ) == aDeps.end() ) + { + //printf( "\t\tadd\n" ); + aNewCurrents.push_back( k ); + aDeps.push_back( k ); + } + } + } + + aCurrents = aNewCurrents; + } + return aDeps; +} + +SALOME::ParameterizedObject_ptr SALOME_Notebook::FindObject( const std::string& theKey ) +{ + int aPos = theKey.find( "#" ); + std::string aComponent = theKey.substr( 0, aPos ), anEntry = theKey.substr( aPos+1, theKey.length()-aPos-1 ); + if( aComponent == PARAM_COMPONENT ) + return Param( anEntry.c_str() ); + else + return SALOME::ParameterizedObject::_narrow( myStudy->FindObjectByInternalEntry( aComponent.c_str(), anEntry.c_str() ) ); +} + +SALOME_Notebook::KeyHelper::KeyHelper( const std::string& theKey, SALOME_Notebook* theNotebook ) +: myKey( theKey ), myNotebook( theNotebook ) +{ +} + +std::string SALOME_Notebook::KeyHelper::key() const +{ + return myKey; +} + +bool SALOME_Notebook::KeyHelper::operator < ( const KeyHelper& theKH ) const +{ + bool ok; + const std::list &aList1 = myNotebook->myDeps[myKey], &aList2 = myNotebook->myDeps[theKH.myKey]; + if( find( aList1.begin(), aList1.end(), theKH.myKey ) != aList1.end() ) + ok = false; + else if( find( aList2.begin(), aList2.end(), myKey ) != aList2.end() ) + ok = true; + else + ok = myKey < theKH.myKey; + + //printf( "%s < %s ? %i\n", myKey.c_str(), theKH.myKey.c_str(), ok ); + return ok; +} + +bool SALOME_Notebook::KeyHelper::operator == ( const std::string& theKey ) const +{ + return myKey == theKey; } diff --git a/src/Notebook/SALOME_Notebook.hxx b/src/Notebook/SALOME_Notebook.hxx index 8350092a0..aa8c399b4 100644 --- a/src/Notebook/SALOME_Notebook.hxx +++ b/src/Notebook/SALOME_Notebook.hxx @@ -28,23 +28,67 @@ #include #include CORBA_SERVER_HEADER(SALOME_Notebook) +#include CORBA_SERVER_HEADER(SALOMEDS) #include #include #include #include -class SALOME_Notebook: public POA_SALOME::Notebook, public SALOME::GenericObj_i +class SALOME_Parameter; + +class SALOME_Notebook : public virtual POA_SALOME::Notebook, public virtual SALOME::GenericObj_i { public: - SALOME_Notebook(); + SALOME_Notebook( SALOMEDS::Study_ptr theStudy ); + + virtual CORBA::Boolean AddDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ); + virtual void RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ); + virtual void ClearDependencies( SALOME::ParameterizedObject_ptr theObj ); + virtual void SetToUpdate( SALOME::ParameterizedObject_ptr theObj ); + virtual void Update(); + + virtual CORBA::Boolean AddExpr( const char* theExpr ); + virtual CORBA::Boolean AddNameExpr( const char* theName, const char* theExpr ); + virtual CORBA::Boolean AddValue( const char* theName, CORBA::Double theValue ); + virtual void Remove( const char* theParamName ); + virtual SALOME::Parameter_ptr Param( const char* theParamName ); + + SALOME_Parameter* ParamPtr( const char* theParamName ) const; + +protected: + bool AddParam( SALOME_Parameter* theParam ); + bool AddDependencies( SALOME_Parameter* theParam ); + bool AddDependency( const std::string& theObjKey, const std::string& theRefKey ); + void ClearDependencies( const std::string& theObjKey ); - virtual void AddDependency( SALOME::ParameterizedObject_ptr obj, SALOME::ParameterizedObject_ptr ref ); - virtual void RemoveDependency( SALOME::ParameterizedObject_ptr obj, SALOME::ParameterizedObject_ptr ref ); - virtual void ClearDependencies( SALOME::ParameterizedObject_ptr obj ); - virtual void Update( SALOME::ParameterizedObject_ptr obj ); +private: + std::string GetKey( SALOME::ParameterizedObject_ptr theObj ); + std::string GetKey( const std::string& theParamName ); + + //! return list of objects that depend on object with given key + std::list GetAllDependingOn( const std::string& theKey ); + SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey ); private: - std::map< std::string, std::list > myDependencies; + std::map< std::string, std::list > myDeps; + std::map< std::string, SALOME_Parameter* > myParams; + + friend class KeyHelper; + class KeyHelper + { + public: + KeyHelper( const std::string& theKey, SALOME_Notebook* theNotebook ); + std::string key() const; + bool operator < ( const KeyHelper& theKH ) const; + bool operator == ( const std::string& theKey ) const; + + private: + std::string myKey; + SALOME_Notebook* myNotebook; + }; + std::list< KeyHelper > myToUpdate; + + SALOMEDS::Study_var myStudy; }; #endif diff --git a/src/Notebook/SALOME_Parameter.cxx b/src/Notebook/SALOME_Parameter.cxx index 878843824..607101a52 100644 --- a/src/Notebook/SALOME_Parameter.cxx +++ b/src/Notebook/SALOME_Parameter.cxx @@ -25,230 +25,150 @@ // #include +#include #include #include #include -SALOME_Parameter::SALOME_Parameter( bool val ) +SALOME_Parameter::SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theName, double theValue ) +: myNotebook( theNotebook ), myName( theName ), myResult( theValue ), myIsAnonimous( false ), myIsCalculable( false ) { - myStr = 0; - myBool = val; - myType = SALOME::TBoolean; } -SALOME_Parameter::SALOME_Parameter( int val ) +SALOME_Parameter::SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theName, const std::string& theExpr ) +: myNotebook( theNotebook ), myName( theName ), myExpr( theExpr ), myIsAnonimous( false ), myIsCalculable( true ) { - myStr = 0; - myInt = val; - myType = SALOME::TInteger; + Update(); } -SALOME_Parameter::SALOME_Parameter( double val ) +SALOME_Parameter::SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theExpr ) +: myNotebook( theNotebook ), myName( theExpr ), myExpr( theExpr ), myIsAnonimous( true ), myIsCalculable( true ) { - myStr = 0; - myDouble = val; - myType = SALOME::TReal; + Update(); } -SALOME_Parameter::SALOME_Parameter( const char* val ) +SALOME_Parameter::~SALOME_Parameter() { - SetValue( val ); } -SALOME_Parameter::~SALOME_Parameter() +char* SALOME_Parameter::GetEntry() { - free( myStr ); + return CORBA::string_dup( myName.c_str() ); } -bool SALOME_Parameter::GetBoolean( const char* expr, bool& val ) +char* SALOME_Parameter::GetComponent() { - bool res = true; - if( strcmp( expr, "true" )==0 || strcmp( expr, "TRUE" )==0 ) - val = true; - - else if( strcmp( expr, "false" )==0 || strcmp( expr, "FALSE" )==0 ) - val = false; - - else - res = false; - - return res; + return CORBA::string_dup( PARAM_COMPONENT.c_str() ); } -void SALOME_Parameter::SetValue( const char* expr ) +CORBA::Boolean SALOME_Parameter::IsValid() { - if( sscanf( expr, "%lf", &myDouble ) == 1 ) - myType = SALOME::TReal; - - else if( sscanf( expr, "%i", &myInt ) == 1 ) - myType = SALOME::TInteger; - - else if( GetBoolean( expr, myBool ) ) - myType = SALOME::TBoolean; - - else if( true /* Expression check */ ) - { - myType = SALOME::TExpression; - myStr = strdup( expr ); - } - - else - { - myType = SALOME::TString; - myStr = strdup( expr ); - } - - SetIsValid( true ); + return myResult.isValid(); } -SALOME::ParamType SALOME_Parameter::GetType() +void SALOME_Parameter::Update() { - return myType; + //printf( "Update of %s\n", GetEntry() ); + if( myIsCalculable ) + { + //1. Set parameters values + SALOME_StringList deps = myExpr.parser()->parameters(); + SALOME_StringList::const_iterator it = deps.begin(), last = deps.end(); + for( ; it!=last; it++ ) + { + std::string aName = *it; + SALOME_Parameter* aParam = myNotebook->ParamPtr( const_cast( aName.c_str() ) ); + if( aParam ) + { + //printf( "\tset %s = %lf\n", aName.c_str(), aParam->AsReal() ); + myExpr.parser()->setParameter( aName, aParam->myResult ); + } + else + { + myResult = SALOME_EvalVariant(); + return; + } + } + + //2. Calculate + myResult = myExpr.calculate(); + //printf( "\tresult = %lf\n", AsReal() ); + } } -char* SALOME_Parameter::AsString() +void SALOME_Parameter::SetExpr( const char* theExpr ) { - if( !IsValid() ) - throw SALOME_Exception( LOCALIZED( "Parameter is invalid" ) ); + if( myIsAnonimous ) + myNotebook->AddExpr( theExpr ); - char buf[256]; const char* res; - switch( myType ) + else { - case SALOME::TBoolean: - res = myBool ? "true" : "false"; - break; - - case SALOME::TInteger: - sprintf( buf, "%i", myInt ); - res = buf; - break; - - case SALOME::TReal: - sprintf( buf, "%lf", myInt ); - res = buf; - break; - - case SALOME::TExpression: - case SALOME::TString: - res = myStr; - break; + myExpr.setExpression( theExpr ); + myIsCalculable = true; + Update(); + myNotebook->SetToUpdate( _this() ); } - - return strdup( res ); } -CORBA::Long SALOME_Parameter::AsInteger() +void SALOME_Parameter::SetReal( CORBA::Double theValue ) { - if( !IsValid() ) - throw SALOME_Exception( LOCALIZED( "Parameter is invalid" ) ); - - CORBA::Long res = 0; - switch( myType ) + if( myIsAnonimous ) { - case SALOME::TBoolean: - res = (int)myBool; - break; - - case SALOME::TInteger: - res = myInt; - break; - - case SALOME::TReal: - res = (int)myDouble; - break; - - case SALOME::TExpression: - res = Calculate()->AsInteger(); - break; - - case SALOME::TString: - { - int val; - if( sscanf( myStr, "%i", &val ) == 0 ) - throw SALOME_Exception( LOCALIZED( "Parameter can not be converted into Integer" ) ); - res = val; - break; - } } - - return res; + else + { + myResult = theValue; + myIsCalculable = false; + Update(); + myNotebook->SetToUpdate( _this() ); + } } -CORBA::Double SALOME_Parameter::AsDouble() +SALOME::ParamType SALOME_Parameter::GetType() { - if( !IsValid() ) - throw SALOME_Exception( LOCALIZED( "Parameter is invalid" ) ); - - CORBA::Double res = 0; - switch( myType ) + switch( myResult.type() ) { - case SALOME::TBoolean: - res = (double)myBool; - break; + case SALOME_EvalVariant_Boolean: + return SALOME::TBoolean; - case SALOME::TInteger: - res = (double)myInt; - break; + case SALOME_EvalVariant_Int: + case SALOME_EvalVariant_UInt: + return SALOME::TInteger; - case SALOME::TReal: - res = myDouble; - break; + case SALOME_EvalVariant_Double: + return SALOME::TReal; - case SALOME::TExpression: - res = Calculate()->AsDouble(); - break; + case SALOME_EvalVariant_String: + return SALOME::TString; - case SALOME::TString: - { - double val; - if( sscanf( myStr, "%lf", &val ) == 0 ) - throw SALOME_Exception( LOCALIZED( "Parameter can not be converted into Real" ) ); - res = val; - break; - } + default: + return SALOME::TUnknown; } - - return res; } -CORBA::Boolean SALOME_Parameter::AsBoolean() +char* SALOME_Parameter::AsString() { - bool res; - switch( myType ) - { - case SALOME::TBoolean: - res = myBool; - break; - - case SALOME::TInteger: - res = (bool)myInt; - break; - - case SALOME::TReal: - res = (bool)myDouble; - break; - - case SALOME::TExpression: - res = Calculate()->AsBoolean(); - break; + return CORBA::string_dup( myResult.toString().c_str() ); +} - case SALOME::TString: - { - if( !GetBoolean( myStr, res ) ) - throw SALOME_Exception( LOCALIZED( "Parameter can not be converted into Boolean" ) ); +CORBA::Long SALOME_Parameter::AsInteger() +{ + bool ok; + return myResult.toInt( &ok ); +} - break; - } - } - return res; +CORBA::Double SALOME_Parameter::AsReal() +{ + bool ok; + return myResult.toDouble( &ok ); } -SALOME_Parameter* SALOME_Parameter::Calculate() +CORBA::Boolean SALOME_Parameter::AsBoolean() { - return myType == SALOME::TExpression ? this : this; + return myResult.toBool(); } -char* SALOME_Parameter::GetEntry() +SALOME_StringList SALOME_Parameter::Dependencies() const { - return ""; + return myIsCalculable ? myExpr.parser()->parameters() : SALOME_StringList(); } diff --git a/src/Notebook/SALOME_Parameter.hxx b/src/Notebook/SALOME_Parameter.hxx index f27c6fd84..06ba90e36 100644 --- a/src/Notebook/SALOME_Parameter.hxx +++ b/src/Notebook/SALOME_Parameter.hxx @@ -27,40 +27,52 @@ #define __SALOME_PARAMETER_H__ #include +#include -class SALOME_Parameter: public POA_SALOME::Parameter, public SALOME_ParameterizedObject +#include + +class SALOME_Notebook; + +const std::string PARAM_COMPONENT = ""; + +class SALOME_Parameter : public virtual POA_SALOME::Parameter, public virtual SALOME_ParameterizedObject { public: //! standard constructor - SALOME_Parameter( bool val ); - SALOME_Parameter( int val ); - SALOME_Parameter( double val ); - SALOME_Parameter( const char* val ); + SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theName, double theValue ); + SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theName, const std::string& theExpr ); + SALOME_Parameter( SALOME_Notebook* theNotebook, const std::string& theExpr ); //! standard destructor virtual ~SALOME_Parameter(); virtual char* GetEntry(); - virtual void SetValue( const char* expr ); + virtual char* GetComponent(); + + virtual CORBA::Boolean IsValid(); + + virtual void Update(); + + virtual void SetExpr( const char* theExpr ); + + virtual void SetReal( CORBA::Double theValue ); virtual SALOME::ParamType GetType(); virtual char* AsString(); virtual CORBA::Long AsInteger(); - virtual CORBA::Double AsDouble(); + virtual CORBA::Double AsReal(); virtual CORBA::Boolean AsBoolean(); -protected: - virtual SALOME_Parameter* Calculate(); - virtual bool GetBoolean( const char* expr, bool& val ); + SALOME_StringList Dependencies() const; private: - int myInt; - double myDouble; - char* myStr; - bool myBool; - SALOME::ParamType myType; + SALOME_Notebook* myNotebook; + std::string myName; + SALOME_EvalExpr myExpr; + SALOME_EvalVariant myResult; + bool myIsAnonimous, myIsCalculable; }; #endif diff --git a/src/Notebook/SALOME_ParameterizedObject.hxx b/src/Notebook/SALOME_ParameterizedObject.hxx index ca27ced9f..163fd8c7a 100644 --- a/src/Notebook/SALOME_ParameterizedObject.hxx +++ b/src/Notebook/SALOME_ParameterizedObject.hxx @@ -31,16 +31,16 @@ #include #include -class SALOME_ParameterizedObject: public POA_SALOME::ParameterizedObject, public SALOME::GenericObj_i +class SALOME_ParameterizedObject: public virtual POA_SALOME::ParameterizedObject, public virtual SALOME::GenericObj_i { public: //! standard constructor SALOME_ParameterizedObject(); - + //! standard destructor - virtual ~SALOME_ParameterizedObject(); + virtual ~SALOME_ParameterizedObject(); + - //return object's entry virtual char* GetEntry() = 0; diff --git a/src/Notebook/Test/NotebookTest.cxx b/src/Notebook/Test/NotebookTest.cxx index b9b2cc834..d0f36defe 100644 --- a/src/Notebook/Test/NotebookTest.cxx +++ b/src/Notebook/Test/NotebookTest.cxx @@ -57,8 +57,8 @@ void NotebookTest::testParameterInt() bool bOk; int j; int aResult[aNb], aX; - RString aExp[aNb]; - RString aA, aB, aC; + SALOME_String aExp[aNb]; + SALOME_String aA, aB, aC; SALOME_EvalVariant aRVR, aRVA, aRVC, aRVB; SALOME_EvalVariantType aType; SALOME_EvalExprError aErr; @@ -99,7 +99,7 @@ void NotebookTest::testParameterInt() aRVR=aEvalExpr.calculate(); // aErr=aEvalExpr.error(); - CPPUNIT_ASSERT(aErr==SALOME_EvalExpr_OK); + CPPUNIT_ASSERT(aErr==EvalExpr_OK); // aType=aRVR.type(); CPPUNIT_ASSERT(aType==SALOME_EvalVariant_Int); @@ -119,8 +119,8 @@ void NotebookTest::testParameterDouble() bool bOk; int j; double aResult[aNb], aX; - RString aExp[aNb]; - RString aA, aB, aC; + SALOME_String aExp[aNb]; + SALOME_String aA, aB, aC; SALOME_EvalVariant aRVR, aRVA, aRVC, aRVB; SALOME_EvalVariantType aType; SALOME_EvalExprError aErr; @@ -162,7 +162,7 @@ void NotebookTest::testParameterDouble() aErr=aEvalExpr.error(); // // 1. Check the result on validity - CPPUNIT_ASSERT(aErr==SALOME_EvalExpr_OK); + CPPUNIT_ASSERT(aErr==EvalExpr_OK); // // 2. Check the type of the result aType=aRVR.type(); @@ -183,9 +183,9 @@ void NotebookTest::testParameterString() const int aNb=8; //bool bOk; int j; - RString aResult[aNb], aX; - RString aExp[aNb]; - RString aA, aB, aC, aD; + SALOME_String aResult[aNb], aX; + SALOME_String aExp[aNb]; + SALOME_String aA, aB, aC, aD; SALOME_EvalVariant aRVR, aRVA, aRVC, aRVB, aRVD; SALOME_EvalVariantType aType, aTypeR[aNb]; SALOME_EvalExprError aErr; @@ -243,7 +243,7 @@ void NotebookTest::testParameterString() aErr=aEvalExpr.error(); // // 1. Check the result on validity - CPPUNIT_ASSERT(aErr==SALOME_EvalExpr_OK); + CPPUNIT_ASSERT(aErr==EvalExpr_OK); // // 2. Check the type of the result aType=aRVR.type(); @@ -264,8 +264,8 @@ void NotebookTest::testParameterBoolean() const int aNb=4; int j; bool aResult[aNb], aX; - RString aExp[aNb]; - RString aA, aB, aC, aD; + SALOME_String aExp[aNb]; + SALOME_String aA, aB, aC, aD; SALOME_EvalVariant aRVR, aRVA, aRVC, aRVB, aRVD; SALOME_EvalVariantType aType, aTypeR[aNb]; SALOME_EvalExprError aErr; @@ -311,7 +311,7 @@ void NotebookTest::testParameterBoolean() aErr=aEvalExpr.error(); // // 1. Check the result on validity - CPPUNIT_ASSERT(aErr==SALOME_EvalExpr_OK); + CPPUNIT_ASSERT(aErr==EvalExpr_OK); // // 2. Check the type of the result aType=aRVR.type();