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