/******************************************************* * * DESCRIPTION: CD++ compiler for BG models * * AUTHOR: Mariana C. D'Abreu * * EMAIL: mdabreu@dc.uba.ar * ********************************************************/ #ifndef CDPPCOMPILER_H #define CDPPCOMPILER_H #include "ini.h" #include "strutil.h" #include "bg.h" #include "real.h" //------------------------------- // Constantes //------------------------------- #define DEFAULT_CDPP_COMPILER_MA "_bg_cdpp.ma" #define DEFAULT_OUT_FILE_EXT ".out" #define QDEVS_IMPLEMENTATION 1 #define QDEVS_COMPONENT_PREFIX "Q" //------------------------------- // Estructuras y tipos //------------------------------- typedef struct { RealValue quantum; RealValue hystWindow; } QuantizerParams; //****************************************************** // // Class BG_CDPP_Compiler // // Description: compilador de modelos Bond Graph a modelos // DEVS (N-CD++) // //****************************************************** class BG_CDPP_Compiler { public: BG_CDPP_Compiler(); virtual ~BG_CDPP_Compiler(); bool generateMA ( BondGraph &, ostream & ); bool generateMAToFile( BondGraph &, const char * = DEFAULT_CDPP_COMPILER_MA ); int getDEVSImplementation () const; string getOutputDirectory () const; QuantizerParams *getQuantizerParamsFor ( const Id & ) const; QuantizerParams *getQuantizerParamsForAll() const; string getOutputFileNameFor ( const Id & ) const; BG_CDPP_Compiler &setDEVSImplementation ( const int impl ); BG_CDPP_Compiler &setOutputDirectory ( const string &outDir ); BG_CDPP_Compiler &setQuantizerParamsForAll( const QuantizerParams & ); BG_CDPP_Compiler &setQuantizerParamsFile ( const string & ); BG_CDPP_Compiler &clearQuantizerParams (); static const QuantizerParams DefaultQuantizerParams; private: bool generateComponentsDeclaration ( BondGraph &, ostream & ); bool generatePortsDeclaration ( BondGraph &, ostream & ); bool generateLinksDeclaration ( BondGraph &, ostream & ); bool generateComponentsVars ( BondGraph &, ostream & ); bool generateLinksDeclarationFromComponent( BondGraph &, ostream &, BGComp * ); BG_CDPP_Compiler &setQuantizerParamsFor ( const Id &, const QuantizerParams & ); string getParameter( const Ini &, const string &, const string & ) const; string getOutPortName ( const BGComp &, const BGEdgeData &, const int ) const; string getInPortName ( const BGComp &, const BGEdgeData &, const int ) const; string getOutFlowName ( const BGComp &, const BGEdgeData & ) const; string getInFlowName ( const BGComp &, const BGEdgeData & ) const; string getPowerDir ( const BGComp &, const BGEdgeData & ) const; const char separator; const char labelSeparator; const char modelLSeparator; const char modelRSeparator; const char *topModelLabel; const char *componentLabel; const char *inPortsLabel; const char *outPortsLabel; const char *linkLabel; typedef map > CompsQuantizerParams; int devsImpl; string outputDirectory; const char dirSeparator; CompsQuantizerParams *compsQuantizerParams; QuantizerParams *quantizerParamsForAll; }; //------------------------------- // inline functions //------------------------------- inline int BG_CDPP_Compiler::getDEVSImplementation() const { return devsImpl; } inline string BG_CDPP_Compiler::getOutputDirectory() const { return outputDirectory; } inline QuantizerParams *BG_CDPP_Compiler::getQuantizerParamsForAll() const { return quantizerParamsForAll; } inline BG_CDPP_Compiler &BG_CDPP_Compiler::setDEVSImplementation( const int impl ) { devsImpl = impl; return *this; } inline BG_CDPP_Compiler &BG_CDPP_Compiler::setOutputDirectory( const string &outDir ) { outputDirectory = outDir; return *this; } inline BG_CDPP_Compiler &BG_CDPP_Compiler::setQuantizerParamsForAll( const QuantizerParams ¶ms ) { quantizerParamsForAll = new QuantizerParams; quantizerParamsForAll->quantum = params.quantum; quantizerParamsForAll->hystWindow = params.hystWindow; return *this; } inline string BG_CDPP_Compiler::getOutPortName( const BGComp &comp, const BGEdgeData &eData, const int bid ) const { return ( getOutFlowName( comp, eData ) + int2Str( bid ) + getPowerDir( comp, eData ) ); } inline string BG_CDPP_Compiler::getInPortName( const BGComp &comp, const BGEdgeData &eData, const int bid ) const { return ( getInFlowName( comp, eData ) + int2Str( bid ) + getPowerDir( comp, eData ) ); } inline string BG_CDPP_Compiler::getOutFlowName( const BGComp &comp, const BGEdgeData &eData ) const { return ( ( eData.isCausalityDest( comp.getId() ) ? FLOW_ID : EFFORT_ID ) ); } inline string BG_CDPP_Compiler::getInFlowName( const BGComp &comp, const BGEdgeData &eData ) const { return ( ( eData.isCausalityDest( comp.getId() ) ? EFFORT_ID : FLOW_ID ) ); } inline string BG_CDPP_Compiler::getPowerDir( const BGComp &comp, const BGEdgeData &eData ) const { return ( ( eData.isPowerDest( comp.getId() ) ? POSITIVE_ID : NEGATIVE_ID ) ); } #endif