/******************************************************* * * DESCRIPTION: class BondGraph * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #ifndef BG_H #define BG_H #include #include "graph.h" #include "strutil.h" #include "excepts.h" #include "defaults_mapping.h" #include "bgcomps.h" //------------------------------- // Mensajes de error //------------------------------- #define CAUSALIZATION_ERROR_MSG "Error during causalization of component " #define ADD_COMPONENT_ERROR_MSG "Add error! Already existing component: " #define ADD_BOND_ERROR_MSG "Add bond error between components " //****************************************************** // // Class BondGraph // // Description: grafo Bond Graph // //****************************************************** class BondGraph { public: class Iterator; BondGraph(); virtual ~BondGraph(); virtual bool addComponent( BGComp * ); virtual bool delComponent( const Id & ); virtual bool addBond( const Id &, const Id &, const Id &powerDest, const Id &causalDest ); virtual bool delBond( const Id &, const Id & ); virtual bool findComponent( const Id &, BGComp * & ); virtual bool simplify(); virtual bool assignCausality(); virtual bool containsAlgebraicLoops(); virtual void print ( ostream & ); Iterator& begin(); Iterator& end(); list* adjacents( const Id & ) const; BGEdgeData &getBondData( const BGComp &, const BGComp & ); bool isFullyCausalized(); bool getMark( const Id & ); void setMark( const Id &, const bool mark = true ); void setMarkAll( const bool mark = true ); protected: friend class Iterator; friend class EC_BG_Mapper; typedef Graph BGGraph; typedef map > Comps; bool simplifyPowerThroughJunctions (); bool simplifyEqualAdjJunctions (); bool mergeAdjacents ( BGComp *, BGGraph::Iterator & ); bool assignCausalityFromComponent ( BGComp &, BGGraph::Node &, Causality, bool ); bool causalizeBond ( BGComp &, BGComp &, BGEdgeData &, Causality ); bool causalizationAllowed ( BGComp &, Causality ); bool causalizationAllowed ( BGComp &, BGComp &, Causality ); Causality getAllowedCausalityOnJunction ( BGComp &, BGComp & ); BGComp *detectAlgebraicLoopFromComp ( BGComp &, const Causality & ); BGGraph *graph; Comps *comps; public: class Iterator { public: friend class BondGraph; Iterator() :it() {}; Iterator( BondGraph &bg ) :it( bg.comps->begin() ) {} ~Iterator() {}; BGComp *operator *() const { return it.operator*().second; } Iterator& operator++() { it.operator++(); return *this; } Iterator& operator++(int i) { it.operator++(i); return *this; } Iterator& operator--() { it.operator--(); return *this; } Iterator& operator--(int i) { it.operator--(i); return *this; } bool operator==( const Iterator &iter ) const { return iter.it == this->it; } bool operator!=( const Iterator &iter ) const { return iter.it != this->it; } private: Iterator( const Comps::iterator &iter ) :it( iter ) {}; Comps::iterator it; }; }; //------------------------------- // inline functions //------------------------------- inline BondGraph::Iterator& BondGraph::begin() { Iterator *it = new Iterator( comps->begin() ); return *it; } inline BondGraph::Iterator& BondGraph::end() { Iterator *it = new Iterator( comps->end() ); return *it; } #endif