00001 #include "PsEventCreator.h" 00002 #include "PsEvent.h" 00003 #include <map> 00004 00005 PsEventCreator::EventCreatorContainerType * PsEventCreator::getEventCreatorContainer() 00006 { 00007 static EventCreatorContainerType * realEventCreatorContainer = new EventCreatorContainerType () ; 00008 return realEventCreatorContainer ; 00009 } 00010 00011 void PsEventCreator::declareAlias( const PsName & name1, const PsName & name2 ) 00012 { 00013 static map <const PsName, const PsName> unInsertedAliases ; 00014 PsName nameToInsert ; 00015 00016 //first find the event creator 00017 EventCreatorContainerType::iterator i = getEventCreatorContainer()->find ( name1 ) ; 00018 nameToInsert = name2 ; 00019 if ( i == getEventCreatorContainer()->end() ) 00020 { 00021 i = getEventCreatorContainer()->find ( name2 ) ; 00022 nameToInsert = name1 ; 00023 } 00024 if ( i == getEventCreatorContainer()->end() ) 00025 { 00026 // remember the declaration 00027 unInsertedAliases.insert (pair<const PsName, const PsName> (name1, name2) ) ; 00028 unInsertedAliases.insert (pair<const PsName, const PsName> (name2, name1) ) ; 00029 } 00030 else 00031 { 00032 getEventCreatorContainer()->insert (PsEventCreator::EventCreatorContainerType::value_type (nameToInsert, (*i).second ) ) ; 00033 00034 //look in the uninserted aliases if one could not be inserted 00035 map <const PsName, const PsName>::iterator j = unInsertedAliases.find ( name1 ); 00036 if ( j == unInsertedAliases.end() ) 00037 { 00038 j = unInsertedAliases.find ( name2 ); 00039 } 00040 if ( j != unInsertedAliases.end() ) 00041 { 00042 getEventCreatorContainer()->insert (PsEventCreator::EventCreatorContainerType::value_type ( (*j).second, (*i).second ) ) ; 00043 // remove the 2 instances declaring name and (*j).second as aliases 00044 unInsertedAliases.erase ( unInsertedAliases.find ( (*j).second ) ) ; 00045 unInsertedAliases.erase ( j ) ; 00046 } 00047 } 00048 } 00049 00050 00051 PsEventCreator::PsEventCreator ( const PsName & className ) : 00052 _typeICanCreate ( className ) 00053 { 00054 // cerr<<"PsEventCreator::PsEventCreator inserting "<<className<<" in the map of events that can be created from their name"<<endl; 00055 getEventCreatorContainer()->insert (PsEventCreator::EventCreatorContainerType::value_type (className, this) ) ; 00056 } 00057 00058 00059 00060 PsEventCreator::~PsEventCreator () 00061 { 00062 getEventCreatorContainer()->erase ( _typeICanCreate ) ; 00063 } 00064 00065 00066 00067 PsEvent * PsEventCreator::createEvent (const PsName & classToCreate, const PsEventIdentifier & eventId, const PsDate & date, const PsName & sender, const PsName & receiver ) 00068 { 00069 EventCreatorContainerType::iterator i = getEventCreatorContainer()->find (classToCreate) ; 00070 00071 if ( i == getEventCreatorContainer()->end() ) 00072 { 00073 cerr<<"PsEventCreator::createEvent "<<getEventCreatorContainer()->size()<<" event creators in the map"<<endl; 00074 cerr<<"PsEventCreator::createEvent: cannot create valued event of class "<<classToCreate 00075 <<" but I can create: "; 00076 for ( i = getEventCreatorContainer()->begin() ; 00077 i != getEventCreatorContainer()->end() ; 00078 ++i) 00079 { 00080 assert ( (*i).first != classToCreate ) ; 00081 cerr<<(*i).first<<"("<<(*i).second<<"), "; 00082 } 00083 cerr<<endl; 00084 cerr<<"If in heterogeneous environment try calling PsEventCreator:::declareAlias ( "<<classToCreate<<", ...) ; in main"<<endl; 00085 cerr<<"Or, if using g++ with version < 3, a call to "<<classToCreate<<"::myEventCreator::touch()"<<endl; 00086 } 00087 00088 00089 return (*i).second->createRealEvent (eventId,date,sender,receiver) ; 00090 00091 } 00092 00093 00094 00095 PsEvent * PsEventCreator::createRealEvent (const PsEventIdentifier & eventId, const PsDate & date, const PsName & sender, const PsName & receiver ) 00096 { 00097 return new PsEvent (eventId, date, sender, receiver) ; 00098 } 00099 00100
| Documentation generated on Mon Nov 25 15:24:59 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |