[Avida-cvs] [Avida2-svn] r335 - in trunk/source: event tools
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Oct 6 17:16:06 PDT 2005
Author: brysonda
Date: 2005-10-06 20:16:06 -0400 (Thu, 06 Oct 2005)
New Revision: 335
Modified:
trunk/source/event/cEventFactoryManager.cc
trunk/source/event/cEventFactoryManager.h
trunk/source/event/cPopulationEventFactory.h
trunk/source/tools/tObjectFactory.h
Log:
Alter tObjectFactory, Event Factories so that they will work on Windows?
Modified: trunk/source/event/cEventFactoryManager.cc
===================================================================
--- trunk/source/event/cEventFactoryManager.cc 2005-10-06 23:54:52 UTC (rev 334)
+++ trunk/source/event/cEventFactoryManager.cc 2005-10-07 00:16:06 UTC (rev 335)
@@ -23,7 +23,7 @@
}
cEventFactoryManager::~cEventFactoryManager(){
- tListIterator<tObjectFactory<cEvent ()> > it(m_factory_list);
+ tListIterator<tObjectFactory<cEvent* ()> > it(m_factory_list);
while (it.Next() != NULL) delete it.Get();
}
@@ -36,7 +36,7 @@
// factory_id < 0 => send to all factories
if( factory_id < 0 ) {
- tListIterator<tObjectFactory<cEvent ()> > it(m_factory_list);
+ tListIterator<tObjectFactory<cEvent* ()> > it(m_factory_list);
while (it.Next() != NULL) {
event = (it.Get())->Create(name);
@@ -56,7 +56,7 @@
}
-int cEventFactoryManager::AddFactory(tObjectFactory<cEvent ()>* factory)
+int cEventFactoryManager::AddFactory(tObjectFactory<cEvent* ()>* factory)
{
assert( factory != NULL );
m_factory_list.Push(factory);
@@ -69,15 +69,14 @@
void cEventFactoryManager::PrintAllEventDescriptions()
{
- tListIterator<tObjectFactory<cEvent ()> > it(m_factory_list);
+ tListIterator<tObjectFactory<cEvent* ()> > it(m_factory_list);
while (it.Next() != NULL) {
- tList<cEvent> events;
+ tArray<cEvent*> events;
it.Get()->CreateAll(events);
- tListIterator<cEvent> events_it(events);
- while (events_it.Next() != NULL) {
- cout << events_it.Get()->GetDescription() << endl;
- delete events_it.Get();
+ for (int i = 0; i < events.GetSize(); i++) {
+ cout << events[i]->GetDescription() << endl;
+ delete events[i];
}
}
}
\ No newline at end of file
Modified: trunk/source/event/cEventFactoryManager.h
===================================================================
--- trunk/source/event/cEventFactoryManager.h 2005-10-06 23:54:52 UTC (rev 334)
+++ trunk/source/event/cEventFactoryManager.h 2005-10-07 00:16:06 UTC (rev 335)
@@ -33,7 +33,7 @@
class cEventFactoryManager {
private:
- tList< tObjectFactory<cEvent ()> > m_factory_list;
+ tList< tObjectFactory<cEvent* ()> > m_factory_list;
// not implemented, prevents inadvertent wrong instantiation
cEventFactoryManager( const cEventFactoryManager & );
@@ -42,7 +42,7 @@
cEventFactoryManager();
~cEventFactoryManager();
- int AddFactory(tObjectFactory<cEvent ()>* factory);
+ int AddFactory(tObjectFactory<cEvent* ()>* factory);
/**
* This function is used to construct an event. It sends the event's name
Modified: trunk/source/event/cPopulationEventFactory.h
===================================================================
--- trunk/source/event/cPopulationEventFactory.h 2005-10-06 23:54:52 UTC (rev 334)
+++ trunk/source/event/cPopulationEventFactory.h 2005-10-07 00:16:06 UTC (rev 335)
@@ -19,7 +19,7 @@
class cPopulation;
class cString;
-class cPopulationEventFactory : public tObjectFactory<cEvent ()> {
+class cPopulationEventFactory : public tObjectFactory<cEvent* ()> {
private:
cPopulation *m_population;
public:
@@ -28,7 +28,7 @@
cEvent* Create(const cString& key)
{
- cPopulationEvent* event = static_cast<cPopulationEvent*>(this->tObjectFactory<cEvent ()>::Create(key));
+ cPopulationEvent* event = static_cast<cPopulationEvent*>(this->tObjectFactory<cEvent* ()>::Create(key));
if( event != NULL ){
event->SetFactoryId( GetFactoryId() );
event->SetPopulation( m_population );
Modified: trunk/source/tools/tObjectFactory.h
===================================================================
--- trunk/source/tools/tObjectFactory.h 2005-10-06 23:54:52 UTC (rev 334)
+++ trunk/source/tools/tObjectFactory.h 2005-10-07 00:16:06 UTC (rev 335)
@@ -13,7 +13,9 @@
#ifndef TDICTIONARY_HH
#include "tDictionary.hh"
#endif
-
+#ifndef TARRAY_HH
+#include "tArray.hh"
+#endif
#ifndef TLIST_HH
#include "tList.hh"
#endif
@@ -25,25 +27,25 @@
namespace nObjectFactory
{
template<typename BaseType, typename ClassType>
- BaseType* createObject()
+ BaseType createObject()
{
return new ClassType();
}
template<typename BaseType, typename ClassType, typename Arg1Type>
- BaseType* createObject(Arg1Type arg1)
+ BaseType createObject(Arg1Type arg1)
{
return new ClassType(arg1);
}
template<typename BaseType, typename ClassType, typename Arg1Type, typename Arg2Type>
- BaseType* createObject(Arg1Type arg1, Arg2Type arg2)
+ BaseType createObject(Arg1Type arg1, Arg2Type arg2)
{
return new ClassType(arg1, arg2);
}
template<typename BaseType, typename ClassType, typename Arg1Type, typename Arg2Type, typename Arg3Type>
- BaseType* createObject(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
+ BaseType createObject(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
{
return new ClassType(arg1, arg2, arg3);
}
@@ -53,7 +55,7 @@
class tObjectFactory<BaseType ()>
{
protected:
- typedef BaseType* (*CreateObjectFunction)();
+ typedef BaseType (*CreateObjectFunction)();
tDictionary<CreateObjectFunction> m_create_funcs;
int m_factory_id;
@@ -79,7 +81,7 @@
return (m_create_funcs.Remove(key) != NULL);
}
- virtual BaseType* Create(const cString& key)
+ virtual BaseType Create(const cString& key)
{
CreateObjectFunction func;
if (m_create_funcs.Find(key, func))
@@ -88,15 +90,17 @@
return NULL;
}
- virtual void CreateAll(tList<BaseType>& objects)
+ virtual void CreateAll(tArray<BaseType>& objects)
{
tList<cString> names;
tList<CreateObjectFunction> funcs;
- m_create_funcs.AsLists(names, funcs);
+ m_create_funcs.AsLists(names, funcs);
+ objects.Resize(names.GetSize());
tListIterator<cString> names_it(names);
- while (names_it.Next() != NULL) objects.Push(Create(*names_it.Get()));
+ for (int i = 0; names_it.Next() != NULL; i++)
+ objects[i] = Create(*names_it.Get());
}
};
@@ -104,7 +108,7 @@
class tObjectFactory<BaseType (Arg1Type)>
{
protected:
- typedef BaseType* (*CreateObjectFunction)(Arg1Type);
+ typedef BaseType (*CreateObjectFunction)(Arg1Type);
tDictionary<CreateObjectFunction> m_create_funcs;
int m_factory_id;
@@ -130,7 +134,7 @@
return (m_create_funcs.Remove(key) != NULL);
}
- virtual BaseType* Create(const cString& key, Arg1Type arg1)
+ virtual BaseType Create(const cString& key, Arg1Type arg1)
{
CreateObjectFunction func;
if (m_create_funcs.Find(key, func))
More information about the Avida-cvs
mailing list