/******************************************************************* * * DESCRIPTION: class ModelAdmin, class SingleModelAdm * * AUTHOR: Amir Barylko & Jorge Beyoglonian * * EMAIL: mailto://amir@dc.uba.ar * mailto://jbeyoglo@dc.uba.ar * * DATE: 27/6/1998 * *******************************************************************/ /** include files **/ #include "modeladm.h" // base header #include "procadm.h" // processor header #include "strutil.h" // lowerCase #include "idcell.h" // InertialDelayCell #include "tdcell.h" // TransportDelayCell #include "flatcoup.h" // class FlatCoupledCell #include /** private data **/ ModelAdmin *SingleModelAdm::instance( NULL ) ; /** public functions **/ /******************************************************************* * Function Name: ModelAdmin ********************************************************************/ ModelAdmin::ModelAdmin() : typeCount( 0 ), modelCount( 0 ) {} ModelAdmin::~ModelAdmin() { ModelDB::iterator cursor; cursor = modelDB.begin(); for (; cursor != modelDB.end() ; cursor++) delete cursor->second; } /******************************************************************* * Function Name: registerAtomic * Description: register a new atomic type ********************************************************************/ ModelAdmin::AtomicType ModelAdmin::registerAtomic( const NewFunction &f, const string &description ) { this->kinds[ this->typeCount ] = f.duplicate() ; this->types[ lowerCase( description ) ] = this->typeCount ; this->typeCount++ ; return this->typeCount ; } /******************************************************************* * Function Name: newAtomic * Description: make a new atomic model and store it in the bd ********************************************************************/ Atomic &ModelAdmin::newAtomic( const AtomicType &type, const string &modelName ) { AtomicKinds::iterator cursor( this->kinds.find( type ) ) ; if( cursor == this->kinds.end() ) { InvalidAtomicTypeException e; e.addText( string( "The number " ) + type + " is an unregistered type" ) ; MTHROW( e ) ; } NewFunction *fn = cursor->second ; Atomic *atomic = (*fn)( modelName ) ; // SingleProcessorAdmin::Instance().generateProcessor( atomic ) ; add2DB(atomic); return *atomic ; } /******************************************************************* * Function Name: newAtomic * Description: search the AtomicType and call to the another newAtomic method ********************************************************************/ Atomic &ModelAdmin::newAtomic( const string &name, const string &modelName ) { AtomicTypes::iterator cursor( this->types.find( lowerCase( name ) ) ) ; if( cursor == this->types.end() ) { InvalidAtomicTypeException e ; e.addText( name + " is an unregistered type!" ) ; MTHROW( e ) ; } return this->newAtomic( cursor->second, modelName ) ; } /******************************************************************* * Function Name: newAtomicCell ********************************************************************/ AtomicCell &ModelAdmin::newAtomicCell( bool inertial,const string &modelName ) { AtomicCell *atomicCell ; if( inertial ) atomicCell = new InertialDelayCell( modelName ) ; else atomicCell = new TransportDelayCell( modelName ) ; // SingleProcessorAdmin::Instance().generateProcessor( atomicCell ) ; add2DB(atomicCell); return *atomicCell ; } /******************************************************************* * Function Name: newCoupled * Description: make a new coupled model and store it in the bd ********************************************************************/ Coupled &ModelAdmin::newCoupled( const string &modelName ) { Coupled *coupled = new Coupled( modelName ) ; // SingleProcessorAdmin::Instance().generateProcessor( coupled ) ; add2DB(coupled); return *coupled ; } /******************************************************************* * Function Name: newCoupledCell ********************************************************************/ CoupledCell &ModelAdmin::newCoupledCell( const string &modelName ) { CoupledCell *coupled = new CoupledCell( modelName ) ; // SingleProcessorAdmin::Instance().generateProcessor( coupled ) ; add2DB(coupled); return *coupled ; } /******************************************************************* * Function Name: newFlatCoupledCell ********************************************************************/ FlatCoupledCell &ModelAdmin::newFlatCoupledCell( const string &modelName ) { FlatCoupledCell *coupled = new FlatCoupledCell( modelName ) ; // SingleProcessorAdmin::Instance().generateProcessor( coupled ) ; add2DB(coupled); return *coupled ; } ModelAdmin &ModelAdmin::add2DB( Model *model) { model->id( newModelId() ); modelDB[model->id()] = model; modelDic[model->description()] = model; return *this; } const ModelAdmin::ModelDB& ModelAdmin::getModelDB() const { return modelDB; } Model &ModelAdmin::model(const string &modName) const { ModelDic::const_iterator cursor; cursor = modelDic.find(modName); if (cursor != modelDic.end()) return *(cursor->second); } Model &ModelAdmin::model(const ModelId &id) const { ModelDB::const_iterator cursor; cursor = modelDB.find(id); if (cursor != modelDB.end() ) return *(cursor->second); } int ModelAdmin::totalMachineCount() const { set > machineSet; ModelAdmin::ModelDB::const_iterator models; ModelPartition::const_iterator machines; for(models = this->getModelDB().begin(); models != this->getModelDB().end() ; models++) { Model * model = models->second; for(machines = model->modelPartition().begin() ; machines != model->modelPartition().end() ; machines++) { machineSet.insert(machines->first) ; } } return machineSet.size(); }