// // C_Relation.cpp // galgas-developer // // Created by Pierre Molinaro on 22/05/14. //---------------------------------------------------------------------------------------------------------------------- #include "bdd/C_Relation.h" #include "utilities/C_SharedObject.h" //---------------------------------------------------------------------------------------------------------------------- // cVariablesInRelationConfiguration //---------------------------------------------------------------------------------------------------------------------- class cVariablesInRelationConfiguration : public C_SharedObject { //--- Constructor public: cVariablesInRelationConfiguration (LOCATION_ARGS) ; public: cVariablesInRelationConfiguration (cVariablesInRelationConfiguration * inPtr COMMA_LOCATION_ARGS) ; public: void addVariable (const C_String & inVariableName, const C_RelationSingleType & inType) ; //--- Accessors public: uint32_t bitCount (void) const ; public: C_String nameForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const ; public: C_RelationSingleType typeForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const ; public: uint32_t constantCountForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const ; public: void deleteVariableAtIndex (const int32_t inIndex COMMA_LOCATION_ARGS) ; public: void deleteLastVariable (LOCATION_ARGS) ; public: inline int32_t variableCount (void) const { return mBDDStartIndexArray.count () ; } public: inline uint32_t bddStartBitIndexForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { return mBDDStartIndexArray (inIndex COMMA_THERE) ; } public: inline uint32_t bddBitCountForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { return mVariableTypeArray (inIndex COMMA_THERE).BDDBitCount () ; } public: C_String constantNameForVariableAndValue (const int32_t inIndex, const uint32_t inValue COMMA_LOCATION_ARGS) const ; //--- public: void checkIdenticalTo (const cVariablesInRelationConfiguration * inVariables COMMA_LOCATION_ARGS) const ; //--- Operations on 3 set configurations public: void swap021 (LOCATION_ARGS) ; public: void swap102 (LOCATION_ARGS) ; public: void swap120 (LOCATION_ARGS) ; public: void swap201 (LOCATION_ARGS) ; public: void swap210 (LOCATION_ARGS) ; #ifndef DO_NOT_GENERATE_CHECKINGS private: void checkConfiguration (LOCATION_ARGS) const ; #endif //--- Attributes private: TC_UniqueArray mBDDStartIndexArray ; private: TC_UniqueArray mVariableNameArray ; private: TC_UniqueArray mVariableTypeArray ; } ; //---------------------------------------------------------------------------------------------------------------------- cVariablesInRelationConfiguration:: cVariablesInRelationConfiguration (LOCATION_ARGS) : C_SharedObject (THERE), mBDDStartIndexArray (), mVariableNameArray (), mVariableTypeArray () { } //---------------------------------------------------------------------------------------------------------------------- cVariablesInRelationConfiguration:: cVariablesInRelationConfiguration (cVariablesInRelationConfiguration * inPtr COMMA_LOCATION_ARGS) : C_SharedObject (THERE), mBDDStartIndexArray (), mVariableNameArray (), mVariableTypeArray () { macroValidSharedObjectThere (inPtr, cVariablesInRelationConfiguration) ; mBDDStartIndexArray.appendObjectsFromArray (inPtr->mBDDStartIndexArray) ; mVariableNameArray.appendObjectsFromArray (inPtr->mVariableNameArray) ; mVariableTypeArray.appendObjectsFromArray (inPtr->mVariableTypeArray) ; #ifndef DO_NOT_GENERATE_CHECKINGS checkConfiguration (HERE) ; #endif } //---------------------------------------------------------------------------------------------------------------------- #ifndef DO_NOT_GENERATE_CHECKINGS void cVariablesInRelationConfiguration::checkConfiguration (LOCATION_ARGS) const { MF_AssertThere (mBDDStartIndexArray.count () == mVariableNameArray.count (), "mBDDStartIndexArray.count () == %lld != mVariableNameArray.count () == %lld", mBDDStartIndexArray.count (), mVariableNameArray.count ()) ; MF_AssertThere (mBDDStartIndexArray.count () == mVariableTypeArray.count (), "mBDDStartIndexArray.count () == %lld != mVariableTypeArray.count () == %lld", mBDDStartIndexArray.count (), mVariableTypeArray.count ()) ; uint32_t bddIndex = 0 ; for (int32_t i=0 ; imVariableTypeArray.count() ; for (int32_t i=0 ; (imVariableTypeArray (i COMMA_HERE) ; } MF_AssertThere (same, "cVariablesInRelationConfiguration::checkIdenticalTo failure", 0, 0) ; if (! same) { printf ("*** cVariablesInRelationConfiguration::checkIdenticalTo failure ***\n") ; exit (1) ; } } //---------------------------------------------------------------------------------------------------------------------- void cVariablesInRelationConfiguration::deleteVariableAtIndex (const int32_t inIndex COMMA_LOCATION_ARGS) { macroUniqueSharedObject (this) ; uint32_t idx = mBDDStartIndexArray (inIndex COMMA_THERE) ; mBDDStartIndexArray.removeObjectAtIndex (inIndex COMMA_THERE) ; mVariableNameArray.removeObjectAtIndex (inIndex COMMA_THERE) ; mVariableTypeArray.removeObjectAtIndex (inIndex COMMA_THERE) ; for (int32_t i=inIndex ; iisUniquelyReferenced ()) { cVariablesInRelationConfiguration * ptr = NULL ; macroMyNew (ptr, cVariablesInRelationConfiguration (mVariablesPtr COMMA_THERE)) ; macroAssignSharedObject (mVariablesPtr, ptr) ; macroDetachSharedObject (ptr) ; } } } //---------------------------------------------------------------------------------------------------------------------- void C_RelationConfiguration::addVariable (const C_String & inVariableName, const C_RelationSingleType & inType) { insulate (HERE) ; macroValidSharedObject (mVariablesPtr, cVariablesInRelationConfiguration) ; mVariablesPtr->addVariable (inVariableName, inType) ; } //---------------------------------------------------------------------------------------------------------------------- void C_RelationConfiguration::appendConfiguration (const C_RelationConfiguration & inConfiguration) { insulate (HERE) ; for (int32_t i=0 ; iaddVariable (variableName, type) ; } } //---------------------------------------------------------------------------------------------------------------------- C_String C_RelationConfiguration::nameForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->nameForVariable (inIndex COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- C_RelationSingleType C_RelationConfiguration::typeForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->typeForVariable (inIndex COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- uint32_t C_RelationConfiguration::bitCount (void) const { uint32_t result = 0 ; if (NULL != mVariablesPtr) { macroValidSharedObject (mVariablesPtr, cVariablesInRelationConfiguration) ; result = mVariablesPtr->bitCount () ; } return result ; } //---------------------------------------------------------------------------------------------------------------------- int32_t C_RelationConfiguration::variableCount (void) const { int32_t result = 0 ; if (NULL != mVariablesPtr) { macroValidSharedObject (mVariablesPtr, cVariablesInRelationConfiguration) ; result = mVariablesPtr->variableCount () ; } return result ; } //---------------------------------------------------------------------------------------------------------------------- uint32_t C_RelationConfiguration::constantCountForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->constantCountForVariable (inIndex COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- uint32_t C_RelationConfiguration::bddStartBitIndexForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->bddStartBitIndexForVariable (inIndex COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- uint32_t C_RelationConfiguration::bddBitCountForVariable (const int32_t inIndex COMMA_LOCATION_ARGS) const { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->bddBitCountForVariable (inIndex COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- C_String C_RelationConfiguration::constantNameForVariableAndValue (const int32_t inIndex, const uint32_t inValue COMMA_LOCATION_ARGS) const { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->constantNameForVariableAndValue (inIndex, inValue COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- void C_RelationConfiguration::checkIdenticalTo (const C_RelationConfiguration & inConfiguration COMMA_LOCATION_ARGS) const { bool same = mVariablesPtr == inConfiguration.mVariablesPtr ; if ((! same) && (NULL != mVariablesPtr) && (NULL != inConfiguration.mVariablesPtr)) { macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; mVariablesPtr->checkIdenticalTo (inConfiguration.mVariablesPtr COMMA_THERE) ; }else if (! same) { printf ("*** C_RelationConfiguration::checkIdenticalTo failure ***\n") ; exit (1) ; } } //---------------------------------------------------------------------------------------------------------------------- void C_RelationConfiguration::deleteVariableAtIndex (const int32_t inIndex COMMA_LOCATION_ARGS) { insulate (THERE) ; macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->deleteVariableAtIndex (inIndex COMMA_THERE) ; } //---------------------------------------------------------------------------------------------------------------------- void C_RelationConfiguration::deleteLastVariable (LOCATION_ARGS) { insulate (THERE) ; macroValidSharedObjectThere (mVariablesPtr, cVariablesInRelationConfiguration) ; return mVariablesPtr->deleteLastVariable (THERE) ; } //---------------------------------------------------------------------------------------------------------------------- C_RelationConfiguration C_RelationConfiguration::swap021 (LOCATION_ARGS) const { C_RelationConfiguration result = *this ; result.insulate (THERE) ; macroValidSharedObjectThere (result.mVariablesPtr, cVariablesInRelationConfiguration) ; result.mVariablesPtr->swap021 (THERE) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- C_RelationConfiguration C_RelationConfiguration::swap102 (LOCATION_ARGS) const { C_RelationConfiguration result = *this ; result.insulate (THERE) ; macroValidSharedObjectThere (result.mVariablesPtr, cVariablesInRelationConfiguration) ; result.mVariablesPtr->swap102 (THERE) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- C_RelationConfiguration C_RelationConfiguration::swap120 (LOCATION_ARGS) const { C_RelationConfiguration result = *this ; result.insulate (THERE) ; macroValidSharedObjectThere (result.mVariablesPtr, cVariablesInRelationConfiguration) ; result.mVariablesPtr->swap120 (THERE) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- C_RelationConfiguration C_RelationConfiguration::swap201 (LOCATION_ARGS) const { C_RelationConfiguration result = *this ; result.insulate (THERE) ; macroValidSharedObjectThere (result.mVariablesPtr, cVariablesInRelationConfiguration) ; result.mVariablesPtr->swap201 (THERE) ; return result ; } //---------------------------------------------------------------------------------------------------------------------- C_RelationConfiguration C_RelationConfiguration::swap210 (LOCATION_ARGS) const { C_RelationConfiguration result = *this ; result.insulate (THERE) ; macroValidSharedObjectThere (result.mVariablesPtr, cVariablesInRelationConfiguration) ; result.mVariablesPtr->swap210 (THERE) ; return result ; } //----------------------------------------------------------------------------------------------------------------------