#include <string>
#include <list>
#include <set>
-//
-using namespace std;
-
-typedef string RString;
-typedef list<string> RStringList;
-typedef RStringList::iterator ListIteratorOfRStringList;
-typedef set<RString> SetOfRString;
-typedef SetOfRString::iterator SetIteratorOfSetOfRString;
-typedef pair< SetIteratorOfSetOfRString, bool > SetPair;
+typedef std::string SALOME_String;
+typedef std::list<SALOME_String> SALOME_StringList;
+typedef SALOME_StringList::iterator SALOME_ListIteratorOfStringList;
+typedef std::set<SALOME_String> 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
//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 : ~
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;
//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 );
//function : expression
//purpose :
//=======================================================================
-RString SALOME_EvalExpr::expression() const
+SALOME_String SALOME_EvalExpr::expression() const
{
return myExpr;
}
//function : setExpression
//purpose :
//=======================================================================
-void SALOME_EvalExpr::setExpression(const RString& expr)
+void SALOME_EvalExpr::setExpression(const SALOME_String& expr)
{
if ( expr == expression() ){
return;
//function : operationSets
//purpose :
//=======================================================================
-SALOME_ListOfPEvalSet SALOME_EvalExpr::operationSets() const
+SALOME_ListOfEvalSet SALOME_EvalExpr::operationSets() const
{
return myParser->operationSets();
}
//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 );
}
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
#include <stack>
#include <list>
-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) {
}
//=======================================================================
//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;
}
//=======================================================================
//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) {
}
//=======================================================================
//function : removeOperationSet
-//purpose :
+//purpose :
//=======================================================================
void SALOME_EvalParser::removeOperationSet(SALOME_EvalSet* theSet)
{
}
//=======================================================================
//function : autoDeleteOperationSets
-//purpose :
+//purpose :
//=======================================================================
bool SALOME_EvalParser::autoDeleteOperationSets() const
{
}
//=======================================================================
//function : setAutoDeleteOperationSets
-//purpose :
+//purpose :
//=======================================================================
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 <char>::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())
)
) {
listind = ind;
matchLen = (int)aStrX.length();
}
-
+
}
if ( min < 0 ){
matchLen = 0;
}
//=======================================================================
//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);
//=======================================================================
//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<int> 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];
//
}
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 {
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;
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++;
}
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 );
(*anIt).myType = Post;
//
SALOME_EvalVariant& aRV=(*anIt).myValue;
- RString aRVS=aRV.toString();
+ SALOME_String aRVS=aRV.toString();
//
if ( contains(anOpen, aRVS) ) {
(*anIt).myType = Pre;
}
}
- 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;
if( br_num<min_br_num )
min_br_num = br_num;
}
-
+
//delete pPost;
delete [] (PostfixItem *)pPost;
return br+min_br_num;
}
//=======================================================================
//function : sort
-//purpose :
-//=======================================================================
-bool SALOME_EvalParser::sort(const Postfix& post,
- Postfix& res,
- const RStringList& anOpen,
- const RStringList& aClose,
- int f,
- int l)
+//purpose :
+//=======================================================================
+bool SALOME_EvalParser::sort( const Postfix& post, Postfix& res, const SALOME_StringList& anOpen,
+ const SALOME_StringList& aClose, int f, int l )
{
if ( l < f ){
return true;
min = cur_pr;
argmin.clear();
argmin.push_back( f + i );
- min_types.clear();
+ min_types.clear();
min_types.push_back( tt );
}
}
}
else {
- setError( SALOME_EvalExpr_InvalidOperation );
+ setError( EvalExpr_InvalidOperation );
break;
}
}
else if ( tt == Open ){
- RString opBr = item.myValue.toString();
+ SALOME_String opBr = item.myValue.toString();
int ind, brValue = 0;
ind = indexOf(anOpen, opBr );
while ( j <= l ) {
if ( anItem.myType == Close ) {
brValue--;
- RString clBr = anItem.myValue.toString();
+ SALOME_String clBr = anItem.myValue.toString();
if ( indexOf(aClose, clBr ) == ind && brValue == 0 ){
break;
}
}
//
if ( brValue > 0 ) {
- setError( SALOME_EvalExpr_CloseExpected );
+ setError( EvalExpr_CloseExpected );
break;
}
}
}
//
- if ( error() == SALOME_EvalExpr_OK ) {
+ if ( error() == EvalExpr_OK ) {
if ( min >= 0 ) {
Postfix one;
list<Postfix> parts;
}
}
}
- 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();
return false;
Postfix p;
- RStringList opens, closes;
+ SALOME_StringList opens, closes;
- setError( SALOME_EvalExpr_OK );
+ setError( EvalExpr_OK );
bracketsList( opens, true );
bracketsList( closes, false );
}
//=======================================================================
//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;
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 );
stack<SALOME_EvalVariant> 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 ) ) {
aStack.push( v );
}
else {
- setError( SALOME_EvalExpr_InvalidToken );
+ setError( EvalExpr_InvalidToken );
}
}
else {
- setError( SALOME_EvalExpr_InvalidToken );
+ setError( EvalExpr_InvalidToken );
}
}
//
SALOME_ListOfEvalVariant aSet;
while ( true ) {
if ( aStack.empty() ) {
- setError( SALOME_EvalExpr_StackUnderflow );
+ setError( EvalExpr_StackUnderflow );
break;
}
if ( aStack.top().isValid() ) {
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();
calculate( nn, *v1, *v2 );
}
else {
- setError( SALOME_EvalExpr_StackUnderflow );
+ setError( EvalExpr_StackUnderflow );
}
}//else if ( aType== Pre || aType == Post ) {
else if ( aType == Binary ) {
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);
}
//=======================================================================
//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()) {
}
//=======================================================================
//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++ ) {
}
//=======================================================================
//function : removeInvalids
-//purpose :
+//purpose :
//=======================================================================
void SALOME_EvalParser::removeInvalids()
{
}
//=======================================================================
//function : error
-//purpose :
+//purpose :
//=======================================================================
SALOME_EvalExprError SALOME_EvalParser::error() const
{
}
//=======================================================================
//function : setError
-//purpose :
+//purpose :
//=======================================================================
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;
//
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() + "'";
}
}
//=======================================================================
//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 );
}
}
//=======================================================================
//function : clearParameters
-//purpose :
+//purpose :
//=======================================================================
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() + " ";
}
//=======================================================================
//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 );
}
//=======================================================================
//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 );
}
//=======================================================================
//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 );
}
}
//=======================================================================
//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 );
}
}
//=======================================================================
//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;
}
}
}
//=======================================================================
//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;
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;
}
}
//
- return SALOME_EvalExpr_InvalidOperation;
+ return EvalExpr_InvalidOperation;
}
//=======================================================================
//function : checkOperations
-//purpose :
+//purpose :
//=======================================================================
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)
}
//=======================================================================
//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;
}
//=======================================================================
//function : insert
-//purpose :
+//purpose :
//=======================================================================
-void SALOME_EvalParser::insert(Postfix& aL,
+void SALOME_EvalParser::insert(Postfix& aL,
const int aIndex,
PostfixItem& pS)
{
}
//=======================================================================
//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;
}
//=======================================================================
//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;
//=======================================================================
//function : isSpace
-//purpose :
+//purpose :
//=======================================================================
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]);
}
//=======================================================================
//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;
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
} PostfixItemType;
//! Postfix representation element
- typedef struct {
- SALOME_EvalVariant myValue;
- PostfixItemType myType;
+ typedef struct
+ {
+ SALOME_EvalVariant myValue;
+ PostfixItemType myType;
} PostfixItem;
- typedef list<PostfixItem> Postfix; //!< postfix representation
- typedef SALOME_ListOfPEvalSet SetList; //!< list of operations
- typedef map <RString, SALOME_EvalVariant> ParamMap; //!< parameter-to-value map
- typedef map <RString, SALOME_EvalVariant>::value_type PairParamMap;
+ typedef list<PostfixItem> Postfix; //!< postfix representation
+ typedef SALOME_ListOfEvalSet SetList; //!< list of operations
+ typedef map <SALOME_String, SALOME_EvalVariant> ParamMap; //!< parameter-to-value map
+ typedef map <SALOME_String, SALOME_EvalVariant>::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
//
#include <math.h>
#include <SALOME_Eval.hxx>
-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
//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;
//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;
//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;
//
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) {
//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) {
//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 ? "(" : ")" );
//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 );
//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;
( 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;
}
////////////////////////////////////////////////////////////////////////
//=======================================================================
SALOME_EvalSetArithmetic::SALOME_EvalSetArithmetic()
: SALOME_EvalSetBase()
{
- RString aOp;
- RStringList aStringList;
+ SALOME_String aOp;
+ SALOME_StringList aStringList;
SALOME_ListOfEvalVariantType aTypes;
//
aOp="+"; aStringList.push_back(aOp);
//function : SALOME_EvalSetArithmetic::Name
//purpose :
//=======================================================================
-RString SALOME_EvalSetArithmetic::Name()
+SALOME_String SALOME_EvalSetArithmetic::Name()
{
return "Arithmetic";
}
//function : SALOME_EvalSetArithmetic::name
//purpose :
//=======================================================================
-RString SALOME_EvalSetArithmetic::name()const
+SALOME_String SALOME_EvalSetArithmetic::name()const
{
return Name();
}
//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;
//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 )
{
//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
{
SALOME_EvalExprError err;
SALOME_EvalVariantType aType1, aType2;
//
- err = SALOME_EvalExpr_OK;
+ err = EvalExpr_OK;
//
bValid1=v1.isValid();
bValid2=v2.isValid();
}
}
else {
- err = SALOME_EvalExpr_InvalidResult;
+ err = EvalExpr_InvalidResult;
}
}
else if ( op == "<" ) {
v1 = _v1 / _v2;
}
else{
- err = SALOME_EvalExpr_InvalidResult;
+ err = EvalExpr_InvalidResult;
}
}
else if ( 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 );
//function : SALOME_EvalSetLogic::Name
//purpose :
//=======================================================================
-RString SALOME_EvalSetLogic::Name()
+SALOME_String SALOME_EvalSetLogic::Name()
{
return "Logic";
}
//function : SALOME_EvalSetLogic::name
//purpose :
//=======================================================================
-RString SALOME_EvalSetLogic::name() const
+SALOME_String SALOME_EvalSetLogic::name() const
{
return Name();
}
//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 );
//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 )
{
//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 );
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);
//function : SALOME_EvalSetMath::Name
//purpose :
//=======================================================================
-RString SALOME_EvalSetMath::Name()
+SALOME_String SALOME_EvalSetMath::Name()
{
return "Math";
}
//function : SALOME_EvalSetMath::name
//purpose :
//=======================================================================
-RString SALOME_EvalSetMath::name() const
+SALOME_String SALOME_EvalSetMath::name() const
{
return Name();
}
//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;
//
//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;
//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" ) {
v2 = sqrt( val );
}
else {
- err = SALOME_EvalExpr_InvalidResult;
+ err = EvalExpr_InvalidResult;
}
}
else if ( op == "abs" ) {
SALOME_EvalSetString::SALOME_EvalSetString()
: SALOME_EvalSetBase()
{
- RString aOp;
- RStringList aStringList;
+ SALOME_String aOp;
+ SALOME_StringList aStringList;
SALOME_ListOfEvalVariantType aTypes;
//
aOp="+"; aStringList.push_back(aOp);
//function : SALOME_EvalSetString::Name
//purpose :
//=======================================================================
-RString SALOME_EvalSetString::Name()
+SALOME_String SALOME_EvalSetString::Name()
{
return "String";
}
//function : SALOME_EvalSetString::name
//purpose :
//=======================================================================
-RString SALOME_EvalSetString::name()const
+SALOME_String SALOME_EvalSetString::name()const
{
return Name();
}
//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();
//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 == "+" ) {
//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 == "=" )
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;
SALOME_EvalSetSets::SALOME_EvalSetSets()
: SALOME_EvalSetBase()
{
- RString aOp;
- RStringList aStringList;
+ SALOME_String aOp;
+ SALOME_StringList aStringList;
SALOME_ListOfEvalVariantType aTypes;
//
aOp="{"; aStringList.push_back(aOp);
//function : SALOME_EvalSetSets::Name
//purpose :
//=======================================================================
-RString SALOME_EvalSetSets::Name()
+SALOME_String SALOME_EvalSetSets::Name()
{
return "Sets";
}
//function : SALOME_EvalSetSets::name
//purpose :
//=======================================================================
-RString SALOME_EvalSetSets::name()const
+SALOME_String SALOME_EvalSetSets::name()const
{
return Name();
}
//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);
//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 == "!=" )
//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
//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 == "}" ) {
//function : SALOME_EvalSetConst::Name
//purpose :
//=======================================================================
-RString SALOME_EvalSetConst::Name()
+SALOME_String SALOME_EvalSetConst::Name()
{
return "Const";
}
//function : SALOME_EvalSetConst::name
//purpose :
//=======================================================================
-RString SALOME_EvalSetConst::name() const
+SALOME_String SALOME_EvalSetConst::name() const
{
return Name();
}
//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
//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;
}
//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) {
//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) {
//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();
//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();
#ifndef SALOME_EvalSet_Header_File
#define SALOME_EvalSet_Header_File
-//
+
+#include <list>
+#include <SALOME_Eval.hxx>
+#include <SALOME_EvalVariant.hxx>
+
#ifdef WNT
#pragma warning(disable : 4786)
#endif
-//
-#include <string>
-#include <list>
-#include <SALOME_EvalVariant.hxx>
-//
-using namespace std;
-//
+
class SALOME_EvalSet;
-typedef SALOME_EvalSet* SALOME_PEvalSet;
-typedef list<SALOME_EvalSet*> SALOME_ListOfPEvalSet;
+typedef std::list<SALOME_EvalSet*> SALOME_ListOfEvalSet;
//=======================================================================
//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 :
{
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 :
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 :
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 :
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 :
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 :
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 :
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
//
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;
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;
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;
}
}
//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;
}
//=======================================================================
//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;
}
//=======================================================================
clear();
//
ChangeDataType()=SALOME_EvalVariant_String;
- RString *p=new RString(theValue);
+ SALOME_String *p=new SALOME_String(theValue);
ChangeDataValue().myPtr=(void*)p;
}
//=======================================================================
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;
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;
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;
//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();
//
aS=buffer;
}
else if (aType == SALOME_EvalVariant_String) {
- const RString& aStr=DataValueString();
+ const SALOME_String& aStr=DataValueString();
aS=aStr;
}
return aS;
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;
}
//=======================================================================
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;
};
//
////
- 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);
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 {
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{
return DataValue().myDouble;
};
//
- const RString& DataValueString() const {
+ const SALOME_String& DataValueString() const {
return *((string *)(DataValue().myPtr));
};
//
//
#include <SALOME_Notebook.hxx>
+#include <SALOME_Parameter.hxx>
-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<std::string>& 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<std::string> >::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<std::string> >::const_iterator mit = myDeps.begin(), mlast = myDeps.end();
+ for( ; mit!=mlast; mit++ )
+ {
+ printf( "%s -> [ ", mit->first.c_str() );
+ std::list<std::string>::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<std::string> aDeps = GetAllDependingOn( anObjKey );
+ std::list<std::string>::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<KeyHelper>::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<KeyHelper>::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<std::string> aDeps = GetAllDependingOn( theObjKey );
+ if( find( aDeps.begin(), aDeps.end(), theRefKey ) != aDeps.end () )
+ return false; //after creation a cyclic dependency could appear
+
+ std::list<std::string>& 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<std::string> SALOME_Notebook::GetAllDependingOn( const std::string& theKey )
+{
+ std::list<std::string> aDeps, aCurrents, aNewCurrents;
+ aCurrents.push_back( theKey );
+ aDeps.push_back( theKey );
+ while( aCurrents.size() > 0 )
+ {
+ aNewCurrents.clear();
+ std::list<std::string>::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<std::string> >::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<std::string> &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;
}
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(SALOME_Notebook)
+#include CORBA_SERVER_HEADER(SALOMEDS)
#include <SALOME_GenericObj_i.hh>
#include <string>
#include <list>
#include <map>
-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<std::string> GetAllDependingOn( const std::string& theKey );
+ SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey );
private:
- std::map< std::string, std::list<std::string> > myDependencies;
+ std::map< std::string, std::list<std::string> > 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
//
#include <SALOME_Parameter.hxx>
+#include <SALOME_Notebook.hxx>
#include <Utils_SALOME_Exception.hxx>
#include <utilities.h>
#include <stdio.h>
-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<char*>( 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();
}
#define __SALOME_PARAMETER_H__
#include <SALOME_ParameterizedObject.hxx>
+#include <SALOME_EvalExpr.hxx>
-class SALOME_Parameter: public POA_SALOME::Parameter, public SALOME_ParameterizedObject
+#include <string>
+
+class SALOME_Notebook;
+
+const std::string PARAM_COMPONENT = "<params>";
+
+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
#include <SALOME_GenericObj_i.hh>
#include <list>
-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;
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;
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);
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;
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();
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;
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();
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;
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();