// Author : Peter KURNEV
// Module : SALOME
-
-
#include <SALOME_EvalExpr.hxx>
+#include <SALOME_EvalParser.hxx>
//=======================================================================
-//function :
-//purpose :
-//=======================================================================
-SALOME_EvalExpr::SALOME_EvalExpr( const SALOME_String& expr )
-{
- myParser=NULL;
- initialize( true, expr );
-}
-//=======================================================================
-//function :
+//function : Constructor
//purpose :
//=======================================================================
-SALOME_EvalExpr::SALOME_EvalExpr( const bool stdSets, const SALOME_String& expr )
+SALOME_EvalExpr::SALOME_EvalExpr( const SALOME_String& theExpr, const bool isStdSets )
{
- myParser=NULL;
- initialize( stdSets, expr );
+ myParser = 0;
+ initialize( theExpr, isStdSets );
}
+
//=======================================================================
-//function : ~
+//function : Destructor
//purpose :
//=======================================================================
SALOME_EvalExpr::~SALOME_EvalExpr()
{
- if (myParser) {
- delete myParser;
- }
+ delete myParser;
}
+
//=======================================================================
//function : error
//purpose :
//=======================================================================
SALOME_EvalExprError SALOME_EvalExpr::error() const
{
- return myParser->error();
+ return myParser ? myParser->error() : EvalExpr_OK;
}
+
//=======================================================================
//function : initialize
//purpose :
//=======================================================================
-void SALOME_EvalExpr::initialize( const bool stdSets, const SALOME_String& expr )
+void SALOME_EvalExpr::initialize( const SALOME_String& theExpr, const bool isStdSets )
{
- if (myParser) {
- delete myParser;
- }
+ delete myParser;
myParser = new SALOME_EvalParser();
- if ( stdSets ) {
+ if( isStdSets )
+ {
myParser->setAutoDeleteOperationSets( true );
myParser->insertOperationSet( new SALOME_EvalSetLogic() );
myParser->insertOperationSet( new SALOME_EvalSetArithmetic() );
myParser->insertOperationSet( new SALOME_EvalSetSets() );
myParser->insertOperationSet( new SALOME_EvalSetConst() );
}
- setExpression( expr );
+ setExpression( theExpr );
}
+
//=======================================================================
//function : calculate
//purpose :
//=======================================================================
-SALOME_EvalVariant SALOME_EvalExpr::calculate(const SALOME_String& expr)
+SALOME_EvalVariant SALOME_EvalExpr::calculate( const SALOME_String& theExpr )
{
- if ( !expr.empty() ) {
- setExpression( expr );
- }
+ setExpression( theExpr );
return myParser->calculate();
}
+
//=======================================================================
//function : expression
//purpose :
{
return myExpr;
}
+
//=======================================================================
//function : setExpression
//purpose :
//=======================================================================
-void SALOME_EvalExpr::setExpression(const SALOME_String& expr)
+void SALOME_EvalExpr::setExpression( const SALOME_String& theExpr )
{
- if ( expr == expression() ){
+ if( theExpr == expression() )
return;
- }
- myExpr = expr;
+
+ myExpr = theExpr;
myParser->setExpression( myExpr );
}
+
//=======================================================================
//function : parser
//purpose :
//=======================================================================
SALOME_ListOfEvalSet SALOME_EvalExpr::operationSets() const
{
- return myParser->operationSets();
+ return myParser ? myParser->operationSets() : SALOME_ListOfEvalSet();
}
+
//=======================================================================
//function : insertOperationSet
//purpose :
//=======================================================================
-void SALOME_EvalExpr::insertOperationSet(SALOME_EvalSet* theSet, const int idx)
+void SALOME_EvalExpr::insertOperationSet( SALOME_EvalSet* theSet, const int theIndex )
{
- myParser->insertOperationSet(theSet, idx);
+ myParser->insertOperationSet( theSet, theIndex );
}
+
//=======================================================================
//function : removeOperationSet
//purpose :
//=======================================================================
-void SALOME_EvalExpr::removeOperationSet(SALOME_EvalSet* theSet)
+void SALOME_EvalExpr::removeOperationSet( SALOME_EvalSet* theSet )
{
- myParser->removeOperationSet(theSet);
+ myParser->removeOperationSet( theSet );
}
+
//=======================================================================
//function : operationSet
//purpose :
//=======================================================================
-SALOME_EvalSet* SALOME_EvalExpr::operationSet(const SALOME_String& name) const
+SALOME_EvalSet* SALOME_EvalExpr::operationSet( const SALOME_String& theName ) const
{
- return myParser->operationSet( name );
+ return myParser->operationSet( theName );
}
+
//=======================================================================
//function : autoDeleteOperationSets
//purpose :
//function : setAutoDeleteOperationSets
//purpose :
//=======================================================================
-void SALOME_EvalExpr::setAutoDeleteOperationSets(const bool on)
+void SALOME_EvalExpr::setAutoDeleteOperationSets( const bool isAutoDel )
{
- myParser->setAutoDeleteOperationSets( on );
+ myParser->setAutoDeleteOperationSets( isAutoDel );
}
//=======================================================================
void SALOME_EvalExpr::substitute( const SALOME_String& theParamName, const SALOME_EvalExpr& theExpr )
{
myParser->substitute( theParamName, theExpr.parser() );
- myExpr = myParser->rebuildExpression();
+ myExpr = myParser->reverseBuild();
}
#include <stack>
#include <list>
-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 : contains
+//purpose :
+//=======================================================================
+bool contains( const SALOME_StringList& theList, const SALOME_String& theItem )
+{
+ return find( theList.begin(), theList.end(), theItem ) != theList.end();
+}
+
+//=======================================================================
+//function : trimmed
+//purpose :
+//=======================================================================
+SALOME_String trimmed( const SALOME_String& theStr, const char theTrimmed )
+{
+ char aX[2];
+ size_t mylength, i;
+ SALOME_String aRet;
+
+ const char* mystring=theStr.c_str();
+ if(!mystring) {
+ return aRet;
+ }
+
+ mylength=strlen(mystring);
+ if (!mylength) {
+ return aRet;
+ }
+
+ aX[1]=0;
+ for (i=0; i<mylength; ++i) {
+ char aC=mystring[i];
+ if (aC != theTrimmed) {
+ aX[0]=aC;
+ aRet.append(aX);
+ }
+ }
+ return aRet;
+}
+
+//=======================================================================
+//function : trimmed
+//purpose :
+//=======================================================================
+SALOME_String trimmed( const SALOME_String& theStr )
+{
+ char aWhat[] = { '\t', '\n', '\v', '\f', '\r', ' ' };
+ int i, aNb;
+ SALOME_String aRet;
+ aRet = theStr;
+ aNb=sizeof(aWhat)/sizeof(aWhat[0]);
+ for (i=0; i<aNb; ++i) {
+ aRet = trimmed(aRet, aWhat[i]);
+ }
+ return aRet;
+}
+
+//=======================================================================
+//function : isSpace
+//purpose :
+//=======================================================================
+bool isSpace( const char theChar )
+{
+ bool bRet;
+ char aWhat[]={
+ '\t', '\n', '\v', '\f', '\r', ' '
+ };
+ int i, aNb;
+ //
+ bRet=false;
+ aNb=sizeof(aWhat)/sizeof(aWhat[0]);
+ for (i=0; i<aNb; ++i) {
+ bRet=(theChar==aWhat[i]);
+ if (bRet) {
+ break;
+ }
+ }
+ return bRet;
+}
+
+//=======================================================================
+//function : indexOf
+//purpose :
+//=======================================================================
+int indexOf( const SALOME_StringList& theList, const SALOME_String& theItem )
+{
+ int i, iRet;
+ SALOME_StringList::const_iterator aIt;
+ //
+ iRet=-1;
+ //
+ aIt=theList.begin();
+ for (i=0; aIt!=theList.end(); ++aIt, ++i)
+ {
+ const SALOME_String aSx=*aIt;
+ if (aSx==theItem) {
+ iRet=i;
+ break;
+ }
+ }
+ return iRet;
+}
//=======================================================================
-//function :
+//function : Constructor
//purpose :
//=======================================================================
SALOME_EvalParser::SALOME_EvalParser()
{
setError( EvalExpr_OK );
}
+
//=======================================================================
-//function : ~
+//function : Destructor
//purpose :
//=======================================================================
SALOME_EvalParser::~SALOME_EvalParser()
{
- if (autoDeleteOperationSets()) {
- //qDeleteAll( mySets );// !!!
- SALOME_ListOfEvalSet::const_iterator aIt = mySets.begin();
- for (; aIt != mySets.end() ; ++aIt ) {
- SALOME_EvalSet* pEvalSet=*aIt;
- if (pEvalSet) {
- delete pEvalSet;
- pEvalSet=NULL;
- }
- }
+ if( autoDeleteOperationSets() )
+ {
+ SALOME_ListOfEvalSet::const_iterator it = mySets.begin(), last = mySets.end();
+ for( ; it!=last; it++ )
+ delete *it;
}
}
+
//=======================================================================
//function : operationSets
//purpose :
{
return mySets;
}
+
//=======================================================================
//function : operationSet
//purpose :
//=======================================================================
-SALOME_EvalSet* SALOME_EvalParser::operationSet(const SALOME_String& theName) const
+SALOME_EvalSet* SALOME_EvalParser::operationSet( const SALOME_String& theName ) const
{
- SALOME_EvalSet* pSet;
- //
- pSet = NULL;
- SALOME_ListOfEvalSet::const_iterator it = mySets.begin();
- for (; it != mySets.end() && !pSet; ++it ) {
- if ( (*it)->name()==theName ) {
+ SALOME_EvalSet* pSet = 0;
+ SALOME_ListOfEvalSet::const_iterator it = mySets.begin(), last = mySets.end();
+ for( ; it!=last && !pSet; it++ )
+ if( (*it)->name()==theName )
pSet = *it;
- }
- }
return pSet;
}
+
//=======================================================================
//function : insertOperationSet
//purpose :
//=======================================================================
-void SALOME_EvalParser::insertOperationSet(SALOME_EvalSet* theSet,
- const int idx)
+void SALOME_EvalParser::insertOperationSet( SALOME_EvalSet* theSet, const int theIndex )
{
- if (SALOME_EvalSet::contains(mySets, theSet)) {
+ if( SALOME_EvalSet::contains( mySets, theSet ) )
return;
- }
- //
- int iSize=(int)mySets.size();
- int index = idx < 0 ? iSize : idx;
- if (index>iSize) {
- index=iSize;
- }
- SALOME_EvalSet::insert(mySets, index, theSet);
+
+ int aSize = (int)mySets.size();
+ int anIndex = theIndex < 0 ? aSize : theIndex;
+ if( anIndex > aSize )
+ anIndex = aSize;
+ SALOME_EvalSet::insert( mySets, anIndex, theSet );
}
+
//=======================================================================
//function : removeOperationSet
//purpose :
//=======================================================================
-void SALOME_EvalParser::removeOperationSet(SALOME_EvalSet* theSet)
+void SALOME_EvalParser::removeOperationSet( SALOME_EvalSet* theSet )
{
- //mySets.removeAll( theSet );
- mySets.remove(theSet);
+ mySets.remove( theSet );
}
+
//=======================================================================
//function : autoDeleteOperationSets
//purpose :
{
return myAutoDel;
}
+
//=======================================================================
//function : setAutoDeleteOperationSets
//purpose :
//=======================================================================
-void SALOME_EvalParser::setAutoDeleteOperationSets( const bool theOn )
+void SALOME_EvalParser::setAutoDeleteOperationSets( const bool isAutoDel )
{
- myAutoDel = theOn;
+ myAutoDel = isAutoDel;
}
+
//=======================================================================
//function : search
//purpose :
//=======================================================================
-int SALOME_EvalParser::search(const SALOME_StringList& aList, const SALOME_String& 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;
//function : prepare
//purpose :
//=======================================================================
-bool SALOME_EvalParser::prepare(const SALOME_String& expr, Postfix& post)
+bool SALOME_EvalParser::prepare( const SALOME_String& theExpr, Postfix& thePostfix )
{
- int pos = 0;
- int len =(int)expr.length();
+ int aPos = 0;
+ int aLen = (int)theExpr.length();
stack<int> aBracketStack;
SALOME_StringList anOpers, anOpenBr, aCloseBr;
+
if ( !checkOperations() )
return false;
- bracketsList( anOpenBr, true );
- bracketsList( aCloseBr, false );
+ bracketsList( anOpenBr, aCloseBr );
operationList( anOpers );
- while ( pos < len && error() == EvalExpr_OK ) {
- PostfixItem item;
- char aC=expr[pos];
- //
- while ( pos < len && isSpace(aC) ) {
- pos++;
- }
- //
- if ( pos >= len ) {
+ while( aPos < aLen && error() == EvalExpr_OK )
+ {
+ PostfixItem anItem;
+ char aChar = theExpr[aPos];
+
+ while( aPos < aLen && isSpace( aChar ) )
+ aPos++;
+
+ if ( aPos >= aLen )
break;
- }
- //
- int mBrLen = 0, mLen = 0, br_ind = -1, op_ind = -1;
- int oPos = search( anOpenBr, expr, pos, mBrLen, br_ind );
- int cPos = oPos == pos ? -1 : search( aCloseBr, expr, pos, mBrLen, br_ind );
- int opPos = search( anOpers, expr, pos, mLen, op_ind );
- //
- if ( aC=='\'') {
- int vpos = pos + 1;
- while ( vpos < (int)expr.length() && expr[vpos] != '\'' ) {
+
+ int aBrLen = 0, mLen = 0, aBrInd = -1, anOpInd = -1;
+ int oPos = search( anOpenBr, theExpr, aPos, aBrLen, aBrInd );
+ int cPos = oPos == aPos ? -1 : search( aCloseBr, theExpr, aPos, aBrLen, aBrInd );
+ int opPos = search( anOpers, theExpr, aPos, mLen, anOpInd );
+
+ if( aChar=='\'')
+ {
+ int vpos = aPos + 1;
+ while ( vpos < aLen && theExpr[vpos] != '\'' )
vpos++;
- }
- //
- mLen = vpos - pos + 1;
- //
- int res = createValue( note( expr, pos, mLen ), item.myValue );
- item.myType = res ? Value : Param;
- post.push_back( item );
- pos = vpos + 1;
+
+ mLen = vpos - aPos + 1;
+ bool ok = createValue( note( theExpr, aPos, mLen ), anItem.myValue );
+ anItem.myType = ok ? Value : Param;
+ thePostfix.push_back( anItem );
+ aPos = vpos + 1;
continue;
}
- //
- if ( oPos == pos ) {
- aBracketStack.push( br_ind );
- item.myValue = note( expr, pos, mBrLen );
- item.myType = Open;
- post.push_back( item );
+
+ if ( oPos == aPos )
+ {
+ aBracketStack.push( aBrInd );
+ anItem.myValue = note( theExpr, aPos, aBrLen );
+ anItem.myType = Open;
+ thePostfix.push_back( anItem );
}
- else if ( cPos == pos ) {
- if ( aBracketStack.size() == 0 ) {
+ else if ( cPos == aPos )
+ {
+ if ( aBracketStack.size() == 0 )
+ {
setError( EvalExpr_ExcessClose );
break;
}
- if ( br_ind != aBracketStack.top() ) {
+ if ( aBrInd != aBracketStack.top() )
+ {
setError( EvalExpr_BracketsNotMatch );
break;
}
- else {
+ else
+ {
aBracketStack.pop();
- item.myValue = note( expr, pos, mBrLen );
- item.myType = Close;
- post.push_back( item );
+ anItem.myValue = note( theExpr, aPos, aBrLen );
+ anItem.myType = Close;
+ thePostfix.push_back( anItem );
}
}
- else {
- mBrLen = 0;
- }
- //
- if ( opPos == pos ) {
- mBrLen = 0;
- item.myValue = note( expr, pos, mLen );
- item.myType = Binary;
+ else
+ aBrLen = 0;
- if ( oPos == pos ) {
- insert(post, (int)(post.size()-1), item);
- }
+ if ( opPos == aPos )
+ {
+ aBrLen = 0;
+ anItem.myValue = note( theExpr, aPos, mLen );
+ anItem.myType = Binary;
+
+ if( oPos == aPos )
+ insert(thePostfix, (int)(thePostfix.size()-1), anItem);
else
- post.push_back( item );
+ thePostfix.push_back( anItem );
}
- else {
+ else
+ {
mLen = 0;
- if ( oPos != pos && cPos != pos ) {
- int i;
- for ( i = pos + 1; i < (int)expr.length(); i++ ) {
- if ( isSpace(expr[i]) ) {
+ if( oPos != aPos && cPos != aPos )
+ {
+ int i;
+ for( i = aPos + 1; i < aLen; i++ )
+ if( isSpace( theExpr[i] ) )
break;
- }
- }
- //
+
int vpos = i;
- if ( oPos >= 0 && oPos < vpos ) {
+ if ( oPos >= 0 && oPos < vpos )
vpos = oPos;
- }
- if ( cPos >= 0 && cPos < vpos ){
+ if ( cPos >= 0 && cPos < vpos )
vpos = cPos;
- }
- if ( opPos >= 0 && opPos < vpos ){
+ if ( opPos >= 0 && opPos < vpos )
vpos = opPos;
- }
- while( vpos < (int)expr.length() &&
- ( isalpha(expr[vpos]) ||
- isdigit(expr[vpos]) ||
- expr[vpos]=='_' )
- ) {
+ while( vpos < aLen && ( isalpha( theExpr[vpos] ) || isdigit( theExpr[vpos] ) || theExpr[vpos]=='_' ) )
vpos++;
- }
- //
- mLen = vpos - pos;
- bool res = createValue( note( expr, pos, mLen ), item.myValue );
- item.myType = res ? Value : Param;
- post.push_back( item );
+
+ mLen = vpos - aPos;
+ bool ok = createValue( note( theExpr, aPos, mLen ), anItem.myValue );
+ anItem.myType = ok ? Value : Param;
+ thePostfix.push_back( anItem );
}
}
- pos += mBrLen + mLen;
+ aPos += aBrLen + mLen;
}
//Bracket checking
- int brValue = 0;
- for ( Postfix::iterator anIt = post.begin(); anIt != post.end(); ++anIt ) {
- if ( (*anIt).myType == Open ){
- brValue++;
- }
- else if ( (*anIt).myType == Close ) {
- if ( brValue > 0 ){
- brValue--;
- }
- else {
+ int aBrValue = 0;
+ for( Postfix::iterator it = thePostfix.begin(), last = thePostfix.end(); it != last; it++ )
+ if( it->myType == Open )
+ aBrValue++;
+ else if( it->myType == Close )
+ if( aBrValue > 0 )
+ aBrValue--;
+ else
+ {
setError( EvalExpr_ExcessClose );
break;
}
- }
- }
- //
- if ( brValue > 0 )
- {
+
+ if( aBrValue > 0 )
setError( EvalExpr_CloseExpected );
- }
- //
+
return error() == EvalExpr_OK;
}
+
//=======================================================================
//function : setOperationTypes
//purpose :
return false;
SALOME_StringList anOpen, aClose;
- //
- bracketsList( anOpen, true );
- bracketsList( aClose, false );
+ bracketsList( anOpen, aClose );
Postfix::iterator aPrev, aNext;
Postfix::iterator anIt = post.begin();
SALOME_StringList opens, closes;
setError( EvalExpr_OK );
- bracketsList( opens, true );
- bracketsList( closes, false );
+ bracketsList( opens, closes );
return prepare( expr, p ) && setOperationTypes( p ) && sort( p, myPostfix, opens, closes );
}
return SALOME_EvalVariant();
setError( EvalExpr_OK );
- //
- SALOME_StringList anOpen, aClose;
+
PostfixItemType aType;
- //
- bracketsList( anOpen, true );
- bracketsList( aClose, false );
+ SALOME_StringList anOpen, aClose;
+ bracketsList( anOpen, aClose );
stack<SALOME_EvalVariant> aStack;
Postfix::iterator anIt = myPostfix.begin(), aLast = myPostfix.end();
//function : rebuildExpression
//purpose :
//=======================================================================
-SALOME_String SALOME_EvalParser::rebuildExpression() const
+SALOME_String SALOME_EvalParser::reverseBuild() const
{
std::stack<RebultExprItem> aStack;
//function : operationList
//purpose :
//=======================================================================
-void SALOME_EvalParser::bracketsList( SALOME_StringList& theList, bool open ) const
+void SALOME_EvalParser::bracketsList( SALOME_StringList& theOpens, SALOME_StringList& theCloses ) const
{
- SALOME_ListOfEvalSet::const_iterator it = mySets.begin();
- for (; it != mySets.end(); ++it ) {
- SALOME_StringList custom;
- SALOME_EvalSet* aSet = *it;
- aSet->bracketsList( custom, open );
- SALOME_StringList::const_iterator sIt = custom.begin();
- for (; sIt != custom.end(); ++sIt ) {
- if ( !contains(theList, *sIt ) )
- theList.push_back( *sIt );
- }
+ SALOME_ListOfEvalSet::const_iterator it = mySets.begin(), last = mySets.end();
+ for( ; it!=last; it++ )
+ {
+ SALOME_StringList aCustom;
+
+ (*it)->bracketsList( aCustom, true );
+ SALOME_StringList::const_iterator sIt = aCustom.begin(), sLast = aCustom.end();
+ for( ; sIt != sLast; sIt++ )
+ if( !contains( theOpens, *sIt ) )
+ theOpens.push_back( *sIt );
+
+ aCustom.clear();
+ (*it)->bracketsList( aCustom, false );
+ sIt = aCustom.begin(); sLast = aCustom.end();
+ for( ; sIt != sLast; sIt++ )
+ if( !contains( theCloses, *sIt ) )
+ theCloses.push_back( *sIt );
}
}
//=======================================================================
//function : insert
//purpose :
//=======================================================================
-void SALOME_EvalParser::insert(Postfix& aL,
- const int aIndex,
- PostfixItem& pS)
+void SALOME_EvalParser::insert( Postfix& aL, const int aIndex, const PostfixItem& pS )
{
int i;
//
}
}
}
-//=======================================================================
-//function : indexOf
-//purpose :
-//=======================================================================
-int indexOf( const SALOME_StringList& aLS, const SALOME_String& aS )
-{
- int i, iRet;
- SALOME_StringList::const_iterator aIt;
- //
- iRet=-1;
- //
- aIt=aLS.begin();
- for (i=0; aIt!=aLS.end(); ++aIt, ++i)
- {
- const SALOME_String aSx=*aIt;
- if (aSx==aS) {
- iRet=i;
- break;
- }
- }
- return iRet;
-}
-//=======================================================================
-//function : contains
-//purpose :
-//=======================================================================
-bool contains( const SALOME_StringList& aLS, const SALOME_String& aS )
-{
- bool bRet;
- //
- bRet=false;
- SALOME_StringList::const_iterator aIt;
- //
- aIt=aLS.begin();
- for (; aIt!=aLS.end(); ++aIt) {
- const SALOME_String aSx=*aIt;
- if (aSx==aS) {
- bRet=!bRet;
- break;
- }
- }
- return bRet;
-}
-
-
-//=======================================================================
-//function : isSpace
-//purpose :
-//=======================================================================
-bool isSpace(const char aC)
-{
- bool bRet;
- char aWhat[]={
- '\t', '\n', '\v', '\f', '\r', ' '
- };
- int i, aNb;
- //
- bRet=false;
- aNb=sizeof(aWhat)/sizeof(aWhat[0]);
- for (i=0; i<aNb; ++i) {
- bRet=(aC==aWhat[i]);
- if (bRet) {
- break;
- }
- }
- return bRet;
-}
-//=======================================================================
-//function : trimmed
-//purpose :
-//=======================================================================
-SALOME_String trimmed(const SALOME_String& str)
-{
- char aWhat[]={
- '\t', '\n', '\v', '\f', '\r', ' '
- };
- int i, aNb;
- SALOME_String aRet;
- //
- aRet=str;
- aNb=sizeof(aWhat)/sizeof(aWhat[0]);
- for (i=0; i<aNb; ++i) {
- aRet=trimmed(aRet, aWhat[i]);
- }
- return aRet;
-}
-//=======================================================================
-//function : trimmed
-//purpose :
-//=======================================================================
-SALOME_String trimmed(const SALOME_String& str, const char aWhat)
-{
- char aX[2];
- size_t mylength, i;
- SALOME_String aRet;
- //
- const char* mystring=str.c_str();
- if(!mystring) {
- return aRet;
- }
- //
- mylength=strlen(mystring);
- if (!mylength) {
- return aRet;
- }
- //
- aX[1]=0;
- for (i=0; i<mylength; ++i) {
- char aC=mystring[i];
- if (aC != aWhat) {
- aX[0]=aC;
- aRet.append(aX);
- }
- }
- return aRet;
-}
-
-
#ifndef SALOME_EvalParser_Header_File
#define SALOME_EvalParser_Header_File
-//
+
#ifdef WNT
#pragma warning(disable : 4786)
#endif
-//
+
#include <list>
#include <map>
-//
#include <SALOME_EvalVariant.hxx>
#include <SALOME_EvalSet.hxx>
#include <SALOME_Eval.hxx>
SALOME_EvalParser();
virtual ~SALOME_EvalParser();
- SALOME_EvalVariant calculate();
- SALOME_EvalVariant calculate( const SALOME_String& );
- bool setExpression( const SALOME_String& );
-
- 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 );
-
- 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;
-
- bool firstInvalid( SALOME_String& ) const;
+ bool setExpression ( const SALOME_String& theExpr );
+ SALOME_EvalExprError error () const;
+ SALOME_EvalVariant calculate ();
+ SALOME_EvalVariant calculate ( const SALOME_String& theExpr );
+ void substitute ( const SALOME_String& theParamName, SALOME_EvalParser* theNewExpr );
+ SALOME_String reverseBuild () const;
+ bool firstInvalid ( SALOME_String& theItem ) const;
void removeInvalids();
- SALOME_String dump() const;
- static SALOME_String toString( const SALOME_ListOfEvalVariant& );
+ SALOME_ListOfEvalSet operationSets () const;
+ SALOME_EvalSet* operationSet ( const SALOME_String& theName ) const;
+ void removeOperationSet ( SALOME_EvalSet* theSet );
+ void insertOperationSet ( SALOME_EvalSet* theSet, const int theIndex = -1 );
+ bool autoDeleteOperationSets () const;
+ void setAutoDeleteOperationSets( const bool isAutoDel );
- bool isMonoParam() const;
+ SALOME_String dump() const;
- void substitute( const SALOME_String& theParamName,
- SALOME_EvalParser* theNewExpr );
+ virtual void clearParameters();
+ virtual bool removeParameter( const SALOME_String& theName );
+ virtual SALOME_EvalVariant parameter ( const SALOME_String& theName ) const;
+ virtual bool hasParameter ( const SALOME_String& theName ) const;
+ virtual void setParameter ( const SALOME_String& theName, const SALOME_EvalVariant& theValue );
+ SALOME_StringList parameters () const;
+ bool isMonoParam () const;
- SALOME_String rebuildExpression() const;
+ static SALOME_String toString( const SALOME_ListOfEvalVariant& theList );
protected:
//! Types of postfix representation elements
protected:
SALOME_String dump( const Postfix& ) const;
- 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 );
-
- bool calculate( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& );
+ virtual bool prepare ( const SALOME_String& theExpr, Postfix& thePostfix );
+ virtual bool setOperationTypes( Postfix& thePostfix );
+ virtual bool sort ( const Postfix& theInitPostfix, Postfix& theResPostfix, const SALOME_StringList& theOpen,
+ const SALOME_StringList& theClose, int theFirst = -1, int theLast = -1 );
+ virtual bool parse ( const SALOME_String& theExpr );
+ virtual void setError ( const SALOME_EvalExprError theErr );
- 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 );
+ bool calculate ( const SALOME_String& theExpr, SALOME_EvalVariant& theArg1, SALOME_EvalVariant& theArg2 );
+ static int search ( const SALOME_StringList& theList, const SALOME_String& theItem, int theOffset,
+ int& theMatchLen, int& theIndex );
+ static SALOME_String note ( const SALOME_String& theStr, int thePos, int theLen );
+ static int globalBrackets( const Postfix& thePostfix, int theFirst, int theLast );
private:
- 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;
-
- SALOME_EvalExprError isValid( const SALOME_String&, const SALOME_EvalVariantType, const SALOME_EvalVariantType ) const;
- SALOME_EvalExprError calculation( const SALOME_String&, SALOME_EvalVariant&, SALOME_EvalVariant& ) const;
-
- bool checkOperations() const;
- static void insert( Postfix& aL, const int aIndex, PostfixItem& aItem );
- static const PostfixItem& at( const Postfix& aL, const int aIndex );
- static void append( Postfix& aL, const Postfix& aL1 );
+ void operationList ( SALOME_StringList& theRes ) const;
+ void bracketsList ( SALOME_StringList& theOpens, SALOME_StringList& theCloses ) const;
+ bool createValue ( const SALOME_String& theStr, SALOME_EvalVariant& theRes ) const;
+ int priority ( const SALOME_String& theOp, bool isBin ) const;
+ SALOME_EvalExprError isValid ( const SALOME_String& theOp, SALOME_EvalVariantType theArg1, SALOME_EvalVariantType theArg2 ) const;
+ SALOME_EvalExprError calculation ( const SALOME_String& theOp, SALOME_EvalVariant& theArg1, SALOME_EvalVariant& theArg2 ) const;
+ bool checkOperations() const;
+
+ static void insert( Postfix& thePostfix, const int theIndex, const PostfixItem& theItem );
+ static const PostfixItem& at ( const Postfix& thePostfix, const int theIndex );
+ static void append( Postfix& thePostfix, const Postfix& theAppendedPostfix );
private:
friend class RebultExprItem;