From 81c114b785d34be0e216d8a4218b38adb1d20dc0 Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 25 Nov 2009 12:39:27 +0000 Subject: [PATCH] debug of unit tests cases --- src/Notebook/SALOME_Notebook.cxx | 62 ++++++++++++++++++++------------ src/Notebook/SALOME_Notebook.hxx | 27 ++++++++------ 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/Notebook/SALOME_Notebook.cxx b/src/Notebook/SALOME_Notebook.cxx index 9351cddc8..c811839fa 100644 --- a/src/Notebook/SALOME_Notebook.cxx +++ b/src/Notebook/SALOME_Notebook.cxx @@ -54,7 +54,7 @@ std::string arg( const std::string& theStr, const std::string& theArg1, const st { aPos = aRes.find( "%2" ); if( aPos >= 0 ) - aRes.replace( aPos, 2, theArg1 ); + aRes.replace( aPos, 2, theArg2 ); else break; } @@ -65,7 +65,7 @@ std::string arg( const std::string& theStr, const std::string& theArg1, const st -SALOME_Notebook::KeyHelper::KeyHelper( const std::string& theKey, SALOME_Notebook* theNotebook ) +SALOME_Notebook::KeyHelper::KeyHelper( const std::string& theKey, const SALOME_Notebook* theNotebook ) : myKey( theKey ), myNotebook( theNotebook ) { } @@ -78,7 +78,10 @@ std::string SALOME_Notebook::KeyHelper::key() const bool SALOME_Notebook::KeyHelper::operator < ( const KeyHelper& theKH ) const { bool ok; - const std::list &aList1 = myNotebook->myDependencies[myKey], &aList2 = myNotebook->myDependencies[theKH.myKey]; + const std::list + &aList1 = myNotebook->myDependencies.find( myKey )->second, + &aList2 = myNotebook->myDependencies.find( theKH.myKey )->second; + if( find( aList1.begin(), aList1.end(), theKH.myKey ) != aList1.end() ) ok = false; else if( find( aList2.begin(), aList2.end(), myKey ) != aList2.end() ) @@ -101,7 +104,7 @@ bool SALOME_Notebook::KeyHelper::operator == ( const std::string& theKey ) const SALOME_Notebook::SALOME_Notebook( PortableServer::POA_ptr thePOA, SALOMEDS::Study_ptr theStudy ) -: SALOME::GenericObj_i( thePOA ) +: SALOME::GenericObj_i( thePOA ), myUpdateOnlyParameters( false ) { myStudy = SALOMEDS::Study::_duplicate( theStudy ); } @@ -118,7 +121,7 @@ void SALOME_Notebook::RemoveDependency( SALOME::ParameterizedObject_ptr theObj, std::string anObjKey = GetKey( theObj ), aRefKey = GetKey( theRef ); std::map< std::string, std::list >::iterator it = myDependencies.find( anObjKey ); if( it == myDependencies.end() ) - throwError( arg( "Dependency between '%1' and '%2' is not found", theObj->GetEntry(), theObj->GetEntry() ) ); + ThrowError( arg( "Dependency between '%1' and '%2' is not found", theObj->GetEntry(), theObj->GetEntry() ) ); else it->second.remove( aRefKey ); } @@ -173,8 +176,17 @@ void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj ) */ } +bool SALOME_Notebook::CanUpdate( SALOME::ParameterizedObject_ptr theObj ) const +{ + if( CORBA::is_nil( theObj ) ) + return false; + + return !myUpdateOnlyParameters || !CORBA::is_nil( SALOME::Parameter::_narrow( theObj ) ); +} + void SALOME_Notebook::Update( CORBA::Boolean theOnlyParameters ) { + myUpdateOnlyParameters = theOnlyParameters; //Utils_Locker lock( &myMutex ); //1. Simple recompute @@ -185,10 +197,10 @@ void SALOME_Notebook::Update( CORBA::Boolean theOnlyParameters ) std::string aKey = (*it).key(); //printf( "key = %s\n", aKey.c_str() ); SALOME::ParameterizedObject_ptr anObj = FindObject( aKey ); - if( CORBA::is_nil( anObj ) ) - aPostponedUpdate.push_back( *it ); - else + if( CanUpdate( anObj ) ) anObj->Update( _this() ); + else + aPostponedUpdate.push_back( *it ); } myToUpdate = aPostponedUpdate; @@ -221,7 +233,7 @@ bool SALOME_Notebook::Substitute( SubstitutionInfo& theSubstitution ) for( ; it!=last; it++ ) { SALOME::ParameterizedObject_ptr anObj = FindObject( it->key() ); - if( CORBA::is_nil( anObj ) ) + if( !CanUpdate( anObj ) ) { aPostponedUpdate.push_back( *it ); continue; @@ -335,7 +347,7 @@ void SALOME_Notebook::AddString( const char* theName, const char* theValue ) AddParameter( new SALOME_Parameter( this, theName, theValue, false ) ); } -SALOME_Notebook::SubstitutionInfo SALOME_Notebook::CreateSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename ) +SALOME_Notebook::SubstitutionInfo SALOME_Notebook::CreateSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename ) const { SubstitutionInfo anInfo; anInfo.myName = theName; @@ -369,9 +381,12 @@ void SALOME_Notebook::Rename( const char* theOldName, const char* theNewName ) CheckParamName( theNewName, aMsg ); if( aMsg.length() == 0 ) + { AddSubstitution( theOldName, theNewName, true ); + Update( true ); + } else - throwError( aMsg ); + ThrowError( aMsg ); } void SALOME_Notebook::Remove( const char* theParamName ) @@ -385,9 +400,10 @@ void SALOME_Notebook::Remove( const char* theParamName ) else anExpr = aParam->AsString(); AddSubstitution( theParamName, anExpr, false ); + Update( true ); } else - throwError( arg( "The parameter '%1' is not found", theParamName ) ); + ThrowError( arg( "The parameter '%1' is not found", theParamName ) ); } void SALOME_Notebook::UpdateAnonymous( const std::string& theOldName, const std::string& theNewName ) @@ -471,7 +487,7 @@ void SALOME_Notebook::AddParameter( SALOME_Parameter* theParam ) std::string anEntry = theParam->GetEntry(), aMsg; if( !theParam->IsAnonymous() && !CheckParamName( anEntry, aMsg ) ) - throwError( aMsg ); + ThrowError( aMsg ); //printf( "Add param: %s\n", anEntry.c_str() ); @@ -520,7 +536,7 @@ void SALOME_Notebook::AddDependency( const std::string& theObjKey, const std::st std::list aDeps = GetAllDependingOn( theObjKey ); if( find( aDeps.begin(), aDeps.end(), theRefKey ) != aDeps.end () ) - throwError( arg( "Dependency %1 -> %2 creates a cyclic dependency", anObjName, aRefName ) ); + ThrowError( arg( "Dependency %1 -> %2 creates a cyclic dependency", anObjName, aRefName ) ); //after creation a cyclic dependency could appear std::list& aList = myDependencies[theObjKey]; @@ -528,7 +544,7 @@ void SALOME_Notebook::AddDependency( const std::string& theObjKey, const std::st if( ok ) aList.push_back( theRefKey ); else - throwError( arg( "Dependency %1 -> %2 is already created", anObjName, aRefName ) ); + ThrowError( arg( "Dependency %1 -> %2 is already created", anObjName, aRefName ) ); } void SALOME_Notebook::ClearDependencies( const std::string& theObjKey, SALOME::DependenciesType theType ) @@ -559,22 +575,22 @@ void SALOME_Notebook::ClearDependencies( const std::string& theObjKey, SALOME::D it->second = aNewDeps; } -std::string SALOME_Notebook::GetKey( SALOME::ParameterizedObject_ptr theObj ) +std::string SALOME_Notebook::GetKey( SALOME::ParameterizedObject_ptr theObj ) const { return GetKey( theObj->GetComponent(), theObj->GetEntry() ); } -std::string SALOME_Notebook::GetKey( const std::string& theComponent, const std::string& theEntry ) +std::string SALOME_Notebook::GetKey( const std::string& theComponent, const std::string& theEntry ) const { return arg( "%1#%2", theComponent, theEntry ); } -std::string SALOME_Notebook::GetKey( const std::string& theParamName ) +std::string SALOME_Notebook::GetKey( const std::string& theParamName ) const { return GetKey( PARAM_COMPONENT, theParamName ); } -std::list SALOME_Notebook::GetAllDependingOn( const std::string& theKey ) +std::list SALOME_Notebook::GetAllDependingOn( const std::string& theKey ) const { //Utils_Locker lock( &myMutex ); @@ -615,11 +631,11 @@ std::string SALOME_Notebook::GetComponent( const std::string& theKey, std::strin return theKey.substr( 0, aPos ); } -SALOME::ParameterizedObject_ptr SALOME_Notebook::FindObject( const std::string& theKey ) +SALOME::ParameterizedObject_ptr SALOME_Notebook::FindObject( const std::string& theKey ) const { std::string anEntry, aComponent = GetComponent( theKey, anEntry ); if( aComponent == PARAM_COMPONENT ) - return GetParameter( anEntry.c_str() ); + return GetParameterPtr( anEntry.c_str() )->_this(); else return SALOME::ParameterizedObject::_narrow( myStudy->FindObjectByInternalEntry( aComponent.c_str(), anEntry.c_str() ) ); } @@ -761,7 +777,7 @@ void SALOME_Notebook::ParseDependencies( const std::string& theData ) { std::vector aParts = Split( theData, " ", false ); if( aParts.size() < 2 || aParts.at( 1 ) != "->" ) - throwError( arg( "Incorrect parts format: %1", theData ) ); + ThrowError( arg( "Incorrect parts format: %1", theData ) ); std::string aKey = aParts[0]; for( int i = 2, n = aParts.size(); i < n; i++ ) @@ -912,7 +928,7 @@ char* SALOME_Notebook::Dump() return CORBA::string_dup( aStr.c_str() ); } -void SALOME_Notebook::throwError( const std::string& theErrorMsg ) +void SALOME_Notebook::ThrowError( const std::string& theErrorMsg ) const { SALOME::NotebookError anError; anError.Reason = CORBA::string_dup( theErrorMsg.c_str() ); diff --git a/src/Notebook/SALOME_Notebook.hxx b/src/Notebook/SALOME_Notebook.hxx index b0b3746d8..3023da03b 100644 --- a/src/Notebook/SALOME_Notebook.hxx +++ b/src/Notebook/SALOME_Notebook.hxx @@ -37,6 +37,10 @@ #include class SALOME_Parameter; +std::string arg( const std::string& theStr, const std::string& theArg1 ); +std::string arg( const std::string& theStr, const std::string& theArg1, const std::string& theArg2 ); + + class SALOME_Notebook : public virtual POA_SALOME::Notebook, public virtual SALOME::GenericObj_i { @@ -72,7 +76,7 @@ public: static std::vector Split( const std::string& theData, const std::string& theSeparator, bool theIsKeepEmpty ); -protected: +private: void AddParameter( SALOME_Parameter* theParam ); void AddDependencies( SALOME_Parameter* theParam ); void AddDependency( const std::string& theObjKey, const std::string& theRefKey ); @@ -82,27 +86,27 @@ protected: std::string GetComponent( const std::string& theKey, std::string& theEntry ) const; void ParseDependencies( const std::string& theData ); -private: - std::string GetKey( SALOME::ParameterizedObject_ptr theObj ); - std::string GetKey( const std::string& theComponent, const std::string& theParamName ); - std::string GetKey( const std::string& theParamName ); - std::list GetAllDependingOn( const std::string& theKey ); - SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey ); - void throwError( const std::string& theErrorMsg ); + std::string GetKey( SALOME::ParameterizedObject_ptr theObj ) const; + std::string GetKey( const std::string& theComponent, const std::string& theParamName ) const; + std::string GetKey( const std::string& theParamName ) const; + std::list GetAllDependingOn( const std::string& theKey ) const; + SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey ) const; + void ThrowError( const std::string& theErrorMsg ) const; + bool CanUpdate( SALOME::ParameterizedObject_ptr theObj ) const; private: friend class KeyHelper; class KeyHelper { public: - KeyHelper( const std::string& theKey, SALOME_Notebook* theNotebook ); + KeyHelper( const std::string& theKey, const 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; + const SALOME_Notebook* myNotebook; }; typedef struct @@ -115,7 +119,7 @@ private: private: void Sort( std::list< KeyHelper >& theList ) const; bool Substitute( SubstitutionInfo& theSubstitution ); - SubstitutionInfo CreateSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename ); + SubstitutionInfo CreateSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename ) const; void AddSubstitution( const std::string& theName, const std::string& theExpr, bool theIsRename ); private: @@ -125,6 +129,7 @@ private: std::list mySubstitutions; SALOMEDS::Study_var myStudy; Utils_Mutex myMutex; + bool myUpdateOnlyParameters; }; #endif -- 2.39.2