[Avida-SVN] r2907 - in development: Avida.xcodeproj source/actions source/analyze source/drivers source/main source/platform source/script source/targets/avida-viewer source/targets/viewer-text source/tools

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Oct 31 11:47:54 PDT 2008


Author: brysonda
Date: 2008-10-31 14:47:53 -0400 (Fri, 31 Oct 2008)
New Revision: 2907

Added:
   development/source/drivers/cDMObject.h
   development/source/drivers/tDMSingleton.h
   development/source/tools/tDataCommandManager.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/actions/cActionLibrary.cc
   development/source/actions/cActionLibrary.h
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyzeCommandAction.h
   development/source/analyze/cAnalyzeGenotype.cc
   development/source/analyze/cAnalyzeGenotype.h
   development/source/drivers/cAvidaDriver.h
   development/source/drivers/cDefaultAnalyzeDriver.cc
   development/source/drivers/cDefaultAnalyzeDriver.h
   development/source/drivers/cDefaultRunDriver.cc
   development/source/drivers/cDefaultRunDriver.h
   development/source/drivers/cDriverManager.cc
   development/source/drivers/cDriverManager.h
   development/source/drivers/cDriverStatusConduit.h
   development/source/drivers/cFallbackWorldDriver.h
   development/source/drivers/cWorldDriver.h
   development/source/main/avida.cc
   development/source/main/avida.h
   development/source/main/cEventList.cc
   development/source/main/cWorld.cc
   development/source/main/cWorld.h
   development/source/platform/PlatformExpert.cc
   development/source/script/ASAnalyzeLib.cc
   development/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc
   development/source/targets/avida-viewer/cTextViewerDriver.cc
   development/source/targets/viewer-text/cDriver_TextViewer.cc
Log:
Restructure global object registration, including the driver objects, the cActionLibrary instance, and the cAnalyzeGenotype data entry dictionary.

Add new tDMSingleton class that can be used to wrap and initialize singleton objects that self register with the driver manager for destruction on termination.

Add new tDataCommandManager, to wrap the functionality of data entry dictionaries (cAnalyzeGenotype is the only one at the moment), so that such structures can be managed by the new tDMSingleton class.


Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/Avida.xcodeproj/project.pbxproj	2008-10-31 18:47:53 UTC (rev 2907)
@@ -745,6 +745,9 @@
 		70B1A7590B7E431F00067486 /* experimental.org */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = experimental.org; sourceTree = "<group>"; };
 		70B3984E0947B29D0018F09D /* tManagedPointerArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tManagedPointerArray.h; sourceTree = "<group>"; };
 		70B6514C0BEA6FAD002472ED /* unit-tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "unit-tests"; sourceTree = BUILT_PRODUCTS_DIR; };
+		70B984220EBB5B7F00A828B1 /* tDMSingleton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tDMSingleton.h; sourceTree = "<group>"; };
+		70B9842B0EBB5D4C00A828B1 /* cDMObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cDMObject.h; sourceTree = "<group>"; };
+		70B984B40EBB71B500A828B1 /* tDataCommandManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tDataCommandManager.h; sourceTree = "<group>"; };
 		70BB2A290E9FA12F008269D2 /* ASAvidaLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASAvidaLib.h; sourceTree = "<group>"; };
 		70BB2A2A0E9FA12F008269D2 /* ASAvidaLib.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ASAvidaLib.cc; sourceTree = "<group>"; };
 		70BB2ABF0EA4F896008269D2 /* tThreadSpecific.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tThreadSpecific.h; sourceTree = "<group>"; };
@@ -984,6 +987,8 @@
 				701D93E6094CBF71008B845F /* cDefaultAnalyzeDriver.h */,
 				701D93E7094CBF71008B845F /* cDefaultAnalyzeDriver.cc */,
 				70BB2AC20EA4FF25008269D2 /* cDriverStatusConduit.h */,
+				70B984220EBB5B7F00A828B1 /* tDMSingleton.h */,
+				70B9842B0EBB5D4C00A828B1 /* cDMObject.h */,
 			);
 			path = drivers;
 			sourceTree = "<group>";
@@ -1638,6 +1643,7 @@
 				70F9FD990C4E89C40083B788 /* tAutoRelease.h */,
 				70EFD65E0D975B5E00FAD32A /* cConstBurstSchedule.h */,
 				70EFD65F0D975B5E00FAD32A /* cConstBurstSchedule.cc */,
+				70B984B40EBB71B500A828B1 /* tDataCommandManager.h */,
 			);
 			path = tools;
 			sourceTree = "<group>";

Modified: development/source/actions/cActionLibrary.cc
===================================================================
--- development/source/actions/cActionLibrary.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/actions/cActionLibrary.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -31,8 +31,10 @@
 #include "PrintActions.h"
 #include "SaveLoadActions.h"
 
+#include "tDMSingleton.h"
 
-cActionLibrary* cActionLibrary::ConstructDefaultActionLibrary()
+
+cActionLibrary* cActionLibrary::buildDefaultActionLibrary()
 {
   cActionLibrary* actlib = new cActionLibrary();
 
@@ -46,6 +48,18 @@
   return actlib;
 }
 
+
+void cActionLibrary::Initialize()
+{
+  tDMSingleton<cActionLibrary>::Initialize(&cActionLibrary::buildDefaultActionLibrary);
+}
+
+cActionLibrary& cActionLibrary::GetInstance()
+{
+  return tDMSingleton<cActionLibrary>::GetInstance();
+}
+
+
 const cString cActionLibrary::DescribeAll() const
 {
   tList<cString> names;

Modified: development/source/actions/cActionLibrary.h
===================================================================
--- development/source/actions/cActionLibrary.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/actions/cActionLibrary.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -52,10 +52,18 @@
   
   tObjectFactoryNoCase<cAction* (cWorld*, const cString&)> m_factory;
   tDictionary<ClassDescFunction> m_desc_funcs;
+  
+  static cActionLibrary* buildDefaultActionLibrary();
 
-public:
   cActionLibrary() { ; }
+
   
+public:
+  ~cActionLibrary() { ; }
+  
+  static void Initialize();
+  static cActionLibrary& GetInstance();
+  
   template<typename ClassType> bool Register(const cString& key)
   {
     ClassDescFunction func;
@@ -79,8 +87,6 @@
     return "(Not Available)";
   }  
   const cString DescribeAll() const;
-  
-  static cActionLibrary* ConstructDefaultActionLibrary();
 };
 
 

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/analyze/cAnalyze.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -42,8 +42,8 @@
 #include "cAnalyzeGenotype.h"
 #include "cAnalyzeTreeStats_CumulativeStemminess.h"
 #include "cAnalyzeTreeStats_Gamma.h"
-#include "tAnalyzeJob.h"
 #include "cAvidaContext.h"
+#include "cCPUTestInfo.h"
 #include "cDataFile.h"
 #include "cEnvironment.h"
 #include "cFitnessMatrix.h"
@@ -61,19 +61,20 @@
 #include "cProbSchedule.h"
 #include "cReaction.h"
 #include "cReactionProcess.h"
+#include "cResource.h"
 #include "cResourceHistory.h"
 #include "cSchedule.h"
 #include "cSpecies.h"
 #include "cStringIterator.h"
+#include "cTestCPU.h"
+#include "cWorld.h"
+#include "cWorldDriver.h"
+#include "tAnalyzeJob.h"
+#include "tDataCommandManager.h"
 #include "tDataEntry.h"
 #include "tDataEntryCommand.h"
+#include "tHashTable.h"
 #include "tMatrix.h"
-#include "cTestCPU.h"
-#include "cCPUTestInfo.h"
-#include "cResource.h"
-#include "tHashTable.h"
-#include "cWorld.h"
-#include "cWorldDriver.h"
 
 #include "defs.h"
 
@@ -912,7 +913,7 @@
   // Construct a linked list of data types that can be loaded...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, input_file.GetFormat(), output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(input_file.GetFormat(), output_list);
   bool id_inc = input_file.GetFormat().HasString("id");
   
   // Setup the genome...
@@ -963,7 +964,7 @@
   cString test_value = cur_string.PopWord();
   
   // Get the dynamic command to look up the stat we need.
-  tDataEntryCommand<cAnalyzeGenotype> * stat_command = cAnalyzeGenotype::GetDataCommand(m_world, stat_name);
+  tDataEntryCommand<cAnalyzeGenotype>* stat_command = cAnalyzeGenotype::GetDataCommandManager().GetDataCommand(stat_name);
   
   
   // Check for various possible errors before moving on...
@@ -1915,7 +1916,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(cur_string, output_list);
   
   // Determine the file type...
   int file_type = FILE_TYPE_TEXT;
@@ -1961,7 +1962,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(cur_string, output_list);
   
   // Determine the file type...
   int file_type = FILE_TYPE_TEXT;
@@ -2150,7 +2151,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(cur_string, output_list);
   
   // check if file is already in use.
   bool file_active = m_world->GetDataFileManager().IsOpen(filename);
@@ -2179,7 +2180,7 @@
   else cout << "Detailing Batches..." << endl;
   
   // Find its associated command...
-  tDataEntryCommand<cAnalyzeGenotype>* cur_command = cAnalyzeGenotype::GetDataCommand(m_world, keyword);
+  tDataEntryCommand<cAnalyzeGenotype>* cur_command = cAnalyzeGenotype::GetDataCommandManager().GetDataCommand(keyword);
   if (!cur_command) {
     cout << "error: no data entry, unable to detail batches" << endl;
     return;
@@ -2282,7 +2283,7 @@
   // Construct a linked list of details needed...
   tList<tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator<tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, cStringList(cur_string), output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(cStringList(cur_string), output_list);
   
   
   // Setup the file...
@@ -2381,7 +2382,7 @@
   // Construct a linked list of details needed...
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(cur_string, output_list);
   
   // Determine the file type...
   int file_type = FILE_TYPE_TEXT;
@@ -4645,7 +4646,7 @@
   msg.Set("There are %d column args.", arg_list.GetSize());
   m_world->GetDriver().NotifyComment(msg);
   
-  cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(arg_list, output_list);
   
   m_world->GetDriver().NotifyComment("Args are loaded.");
   
@@ -4905,7 +4906,7 @@
   
   cout << "There are " << arg_list.GetSize() << " column args." << endl;
   
-  cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(arg_list, output_list);
   
   cout << "Args are loaded." << endl;
   
@@ -5249,7 +5250,7 @@
   tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
   tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
   cStringList arg_list(cur_string);
-  cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
+  cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(arg_list, output_list);
   const int num_traits = output_list.GetSize();
   
   // Setup the map_inst_set with the NULL instruction
@@ -9230,7 +9231,7 @@
   }
   cAnalyzeCommandDefBase* command_def = lib_it.Get();
   
-  if (command_def == NULL && m_world->GetActionLibrary().Supports(name)) {
+  if (command_def == NULL && cActionLibrary::GetInstance().Supports(name)) {
     command_def = new cAnalyzeCommandAction(name, m_world);
     command_lib.PushRear(command_def);
   }

Modified: development/source/analyze/cAnalyzeCommandAction.h
===================================================================
--- development/source/analyze/cAnalyzeCommandAction.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/analyze/cAnalyzeCommandAction.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -53,7 +53,7 @@
   
   void Run(cAnalyze* analyze, const cString& args, cAnalyzeCommand& command) const
   {
-    cAction* action = m_world->GetActionLibrary().Create(name, m_world, args);
+    cAction* action = cActionLibrary::GetInstance().Create(name, m_world, args);
     cAvidaContext& ctx = m_world->GetDefaultContext();
     action->Process(ctx);
   }

Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/analyze/cAnalyzeGenotype.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -44,8 +44,8 @@
 
 #include "tArray.h"
 #include "tAutoRelease.h"
-#include "tDataEntry.h"
-#include "tDataEntryCommand.h"
+#include "tDataCommandManager.h"
+#include "tDMSingleton.h"w
 
 
 #include <cmath>
@@ -189,9 +189,16 @@
 }
 
 
-tDictionary<tDataEntry<cAnalyzeGenotype>*>* cAnalyzeGenotype::BuildDEDict(cWorld* world)
+void cAnalyzeGenotype::Initialize()
 {
-  tDictionary<tDataEntry<cAnalyzeGenotype>*>* dedict = new tDictionary<tDataEntry<cAnalyzeGenotype>*>;
+  tDMSingleton<tDataCommandManager<cAnalyzeGenotype> >::Initialize(&cAnalyzeGenotype::buildDataCommandManager);
+}
+
+
+tDataCommandManager<cAnalyzeGenotype>* cAnalyzeGenotype::buildDataCommandManager()
+{
+  tDataCommandManager<cAnalyzeGenotype>* dcm = new tDataCommandManager<cAnalyzeGenotype>;
+  
   // A basic macro to link a keyword to a description and Get and Set methods in cAnalyzeGenotype.
 #define ADD_GDATA(TYPE, KEYWORD, DESC, GET, SET, COMP, NSTR, HSTR)                                \
   {                                                                                               \
@@ -201,7 +208,7 @@
     cString html_str = "align=center";                                                            \
     if (hstr_str != "0") html_str = HSTR;                                                         \
                                                                                                   \
-    dedict->Add(KEYWORD, new tDataEntryOfType<cAnalyzeGenotype, TYPE>                              \
+    dcm->Add(KEYWORD, new tDataEntryOfType<cAnalyzeGenotype, TYPE>                              \
       (KEYWORD, DESC, &cAnalyzeGenotype::GET, &cAnalyzeGenotype::SET, COMP, null_str, html_str)); \
   }
 
@@ -286,10 +293,10 @@
   ADD_GDATA(int (), 		"total_task_performance_count", "Total Tasks Performed",	GetTotalTaskPerformanceCount, SetNULL, 1, 0, 0);
   
   
-  dedict->Add("task", new tDataEntryOfType<cAnalyzeGenotype, int (int, const cStringList&)>
-              ("task", &cAnalyzeGenotype::DescTask, &cAnalyzeGenotype::GetTaskCount, 5));
-  dedict->Add("env_input", new tDataEntryOfType<cAnalyzeGenotype, int (int)>
-              ("env_input", &cAnalyzeGenotype::DescEnvInput, &cAnalyzeGenotype::GetEnvInput));
+  dcm->Add("task", new tDataEntryOfType<cAnalyzeGenotype, int (int, const cStringList&)>
+           ("task", &cAnalyzeGenotype::DescTask, &cAnalyzeGenotype::GetTaskCount, 5));
+  dcm->Add("env_input", new tDataEntryOfType<cAnalyzeGenotype, int (int)>
+           ("env_input", &cAnalyzeGenotype::DescEnvInput, &cAnalyzeGenotype::GetEnvInput));
     
   // The remaining values should actually go in a seperate list called
   // "population_data_list", but for the moment we're going to put them
@@ -301,61 +308,17 @@
   ADD_GDATA(int (),     "dom_id",       "Dominant Genotype ID",            GetID,         SetID,         0, 0, 0);
   ADD_GDATA(cString (), "dom_sequence", "Dominant Genotype Sequence",      GetSequence,   SetSequence,   0, "(N/A)", "");
   
-  return dedict;
   
+  return dcm;
 #undef ADD_GDATA
 }
 
-void cAnalyzeGenotype::DestroyDEDict(tDictionary<tDataEntry<cAnalyzeGenotype>*>* dedict)
+const tDataCommandManager<cAnalyzeGenotype>& cAnalyzeGenotype::GetDataCommandManager()
 {
-  tArray<tDataEntry<cAnalyzeGenotype>*> entries;
-  dedict->GetValues(entries);
-  for (int i = 0; i < entries.GetSize(); i++) delete entries[i];
-  delete dedict;
+  return tDMSingleton<tDataCommandManager<cAnalyzeGenotype> >::GetInstance();
 }
 
 
-
-// Find a data entry bassed on a keyword
-tDataEntryCommand<cAnalyzeGenotype>* cAnalyzeGenotype::GetDataCommand(cWorld* world, const cString& cmd) 
-{
-  cString arg_list = cmd;
-  cString idx = arg_list.Pop(':');
-  cString entry_name = idx.Pop('.');
-  
-  tDataEntry<cAnalyzeGenotype>* data_entry;
-  if (world->GetGenotypeDEDict().Find(entry_name, data_entry)) {
-    return new tDataEntryCommand<cAnalyzeGenotype>(data_entry, idx, arg_list);
-  }
-  
-  cDriverManager::Status().NotifyWarning(cStringUtil::Stringf("data entry '%s' not found, best match is '%s'", *entry_name,
-                                                              *(world->GetGenotypeDEDict().NearMatch(entry_name))));
-  
-  return NULL;
-}
-
-
-// Pass in the arguments for a command and fill out the entries in list format....
-void cAnalyzeGenotype::LoadDataCommandList(cWorld* world, cStringList arg_list,
-                                    tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list)
-{
-  if (arg_list.GetSize() == 0) {
-    // If no args were given, load all of the stats.
-    // @TODO - handle indexed items...  under this scheme only the first task and env_input value will be output    
-
-    tArray<tDataEntry<cAnalyzeGenotype>*> data_entries;
-    world->GetGenotypeDEDict().GetValues(data_entries);
-    for (int i = 0; i < data_entries.GetSize(); i++)
-      output_list.PushRear(new tDataEntryCommand<cAnalyzeGenotype>(data_entries[i]));
-  } else {
-    while (arg_list.GetSize() != 0) {
-      tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetDataCommand(world, arg_list.Pop());
-      if (cur_command) output_list.PushRear(cur_command);
-    }
-  }
-}
-
-
 cString cAnalyzeGenotype::DescTask(int task_id) const
 {
   if (task_id > task_counts.GetSize()) return "";

Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/analyze/cAnalyzeGenotype.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -65,9 +65,7 @@
 class cInstSet;
 class cTestCPU;
 class cWorld;
-template<class T> class tDataEntry;
-template<class T> class tDataEntryCommand;
-template<class T> class tDictionary;
+template<class T> class tDataCommandManager;
 
 
 class cAnalyzeGenotype;
@@ -225,6 +223,8 @@
   void CheckLand() const;
   void CheckPhenPlast() const;
   void SummarizePhenotypicPlasticity(const cPhenPlastGenotype& pp) const;
+  
+  static tDataCommandManager<cAnalyzeGenotype>* buildDataCommandManager();
 
 
 
@@ -234,11 +234,8 @@
   cAnalyzeGenotype(const cAnalyzeGenotype & _gen);
   ~cAnalyzeGenotype();
   
-  static tDictionary<tDataEntry<cAnalyzeGenotype>*>* BuildDEDict(cWorld* world);
-  static void DestroyDEDict(tDictionary<tDataEntry<cAnalyzeGenotype>*>* dedict);
-  
-  static tDataEntryCommand<cAnalyzeGenotype>* GetDataCommand(cWorld* world, const cString& cmd);
-  static void LoadDataCommandList(cWorld* world, cStringList arg_list, tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list);
+  static void Initialize();
+  static const tDataCommandManager<cAnalyzeGenotype>& GetDataCommandManager();
 
   void Recalculate(cAvidaContext& ctx, cCPUTestInfo* test_info = NULL, cAnalyzeGenotype* parent_genotype = NULL, int num_trials = 1);
   void PrintTasks(std::ofstream& fp, int min_task = 0, int max_task = -1);

Modified: development/source/drivers/cAvidaDriver.h
===================================================================
--- development/source/drivers/cAvidaDriver.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cAvidaDriver.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,11 +25,14 @@
 #ifndef cAvidaDriver_h
 #define cAvidaDriver_h
 
+#include "cDMObject.h"
+
+
 // This class is an abstract base class from which all driver classes
 // in Avida descend.  cAvidaDriver objects are friends with cWorld,
 // allowing them to register cWorldDriver's with an instance of cWorld.
 
-class cAvidaDriver
+class cAvidaDriver : public virtual cDMObject
 {
 private:
   cAvidaDriver(const cAvidaDriver&); // @not_implemented

Added: development/source/drivers/cDMObject.h
===================================================================
--- development/source/drivers/cDMObject.h	                        (rev 0)
+++ development/source/drivers/cDMObject.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -0,0 +1,35 @@
+/*
+ *  cDMObject.h
+ *  Avida
+ *
+ *  Created by David on 10/31/08.
+ *  Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef cDMObject_h
+#define cDMObject_h
+
+class cDMObject
+{
+public:
+  virtual ~cDMObject() { ; }
+};
+
+
+#endif

Modified: development/source/drivers/cDefaultAnalyzeDriver.cc
===================================================================
--- development/source/drivers/cDefaultAnalyzeDriver.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDefaultAnalyzeDriver.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -37,13 +37,13 @@
 cDefaultAnalyzeDriver::cDefaultAnalyzeDriver(cWorld* world, bool inter)
   : m_world(world), m_interactive(inter)
 {
-  cDriverManager::Register(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Register(this);
   world->SetDriver(this);
 }
 
 cDefaultAnalyzeDriver::~cDefaultAnalyzeDriver()
 {
-  cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Unregister(this);
   delete m_world;
 }
 

Modified: development/source/drivers/cDefaultAnalyzeDriver.h
===================================================================
--- development/source/drivers/cDefaultAnalyzeDriver.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDefaultAnalyzeDriver.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,12 +25,8 @@
 #ifndef cDefaultAnalyzeDriver_h
 #define cDefaultAnalyzeDriver_h
 
-#ifndef cAvidaDriver_h
 #include "cAvidaDriver.h"
-#endif
-#ifndef cWorldDriver_h
 #include "cWorldDriver.h"
-#endif
 
 #if USE_tMemTrack
 # ifndef tMemTrack_h

Modified: development/source/drivers/cDefaultRunDriver.cc
===================================================================
--- development/source/drivers/cDefaultRunDriver.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDefaultRunDriver.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -48,7 +48,7 @@
 cDefaultRunDriver::cDefaultRunDriver(cWorld* world) : m_world(world), m_done(false), 
       m_fastforward(false),m_last_generation(0),  m_generation_same_update_count(0) 
 {
-  cDriverManager::Register(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Register(this);
   world->SetDriver(this);
   
   // Save this config variable
@@ -58,7 +58,7 @@
 
 cDefaultRunDriver::~cDefaultRunDriver()
 {
-  cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Unregister(this);
   delete m_world;
 }
 

Modified: development/source/drivers/cDefaultRunDriver.h
===================================================================
--- development/source/drivers/cDefaultRunDriver.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDefaultRunDriver.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,16 +25,13 @@
 #ifndef cDefaultRunDriver_h
 #define cDefaultRunDriver_h
 
-#ifndef cAvidaDriver_h
 #include "cAvidaDriver.h"
-#endif
-#ifndef cWorldDriver_h
 #include "cWorldDriver.h"
-#endif
 
 class cString;
 class cWorld;
 
+
 class cDefaultRunDriver : public cAvidaDriver, public cWorldDriver
 {
 private:

Modified: development/source/drivers/cDriverManager.cc
===================================================================
--- development/source/drivers/cDriverManager.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDriverManager.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -24,41 +24,25 @@
 
 #include "cDriverManager.h"
 
-#include "cActionLibrary.h"
-#include "cAvidaDriver.h"
 #include "cDriverStatusConduit.h"
-#include "cWorldDriver.h"
+#include "cDMObject.h"
 
 #include <cassert>
 #include <cstdlib>
 
 
-cDriverManager* cDriverManager::m_dm = NULL;
+cDriverManager* cDriverManager::s_dm = NULL;
 
-cDriverManager::cDriverManager()
-{
-  m_actlib = cActionLibrary::ConstructDefaultActionLibrary();
-}
-
 cDriverManager::~cDriverManager()
 {
-  cAvidaDriver* adrv;
-  while ((adrv = m_adrvs.Pop())) {
-    delete adrv;
-  }
-  
-  cWorldDriver* wdrv;
-  while ((wdrv = m_wdrvs.Pop())) {
-    delete wdrv;
-  }
-  
-  delete m_actlib;
+  cDMObject* obj;
+  while ((obj = m_objs.Pop())) delete obj;
 }
 
 void cDriverManager::Initialize()
 {
-  if (m_dm == NULL) {
-    m_dm = new cDriverManager();
+  if (s_dm == NULL) {
+    s_dm = new cDriverManager();
     if (atexit(cDriverManager::Destroy)) {
       // Failed to register with atexit, this is bad, very bad.
       exit(-1);
@@ -68,59 +52,37 @@
 
 void cDriverManager::Destroy()
 {
-  delete m_dm;
+  delete s_dm;
 }
 
-void cDriverManager::Register(cAvidaDriver* drv)
+void cDriverManager::Register(cDMObject* obj)
 {
-  assert(m_dm);
-  m_dm->m_mutex.Lock();
-  m_dm->m_adrvs.Push(drv);
-  m_dm->m_mutex.Unlock();
+  assert(s_dm);
+  s_dm->m_mutex.Lock();
+  s_dm->m_objs.Push(obj);
+  s_dm->m_mutex.Unlock();
 }
 
-void cDriverManager::Register(cWorldDriver* drv)
+void cDriverManager::Unregister(cDMObject* obj)
 {
-  assert(m_dm);
-  m_dm->m_mutex.Lock();
-  m_dm->m_wdrvs.Push(drv);
-  m_dm->m_mutex.Unlock();
+  assert(s_dm);
+  s_dm->m_mutex.Lock();
+  s_dm->m_objs.Remove(obj);
+  s_dm->m_mutex.Unlock();
 }
 
-void cDriverManager::Unregister(cAvidaDriver* drv)
-{
-  assert(m_dm);
-  m_dm->m_mutex.Lock();
-  m_dm->m_adrvs.Remove(drv);
-  m_dm->m_mutex.Unlock();
-}
-
-void cDriverManager::Unregister(cWorldDriver* drv)
-{
-  assert(m_dm);
-  m_dm->m_mutex.Lock();
-  m_dm->m_wdrvs.Remove(drv);
-  m_dm->m_mutex.Unlock();
-}
-
 cDriverStatusConduit& cDriverManager::Status()
 {
-  cDriverStatusConduit* conduit = m_dm->m_conduit.Get();
+  cDriverStatusConduit* conduit = s_dm->m_conduit.Get();
   if (!conduit) {
     conduit = new cDriverStatusConduit;
-    m_dm->m_conduit.Set(conduit);
+    s_dm->m_conduit.Set(conduit);
   }
   return *conduit;
 }
 
 void cDriverManager::SetConduit(cDriverStatusConduit* conduit)
 {
-  m_dm->m_conduit.Set(conduit);
+  assert(s_dm);
+  s_dm->m_conduit.Set(conduit);
 }
-
-
-cActionLibrary* cDriverManager::GetActionLibrary()
-{
-  assert(m_dm);
-  return m_dm->m_actlib;
-}

Modified: development/source/drivers/cDriverManager.h
===================================================================
--- development/source/drivers/cDriverManager.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDriverManager.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,36 +25,25 @@
 #ifndef cDriverManager_h
 #define cDriverManager_h
 
-#ifndef tList_h
 #include "tList.h"
-#endif
-#ifndef cMutex_h
 #include "cMutex.h"
-#endif
-#ifndef tThreadSpecific_h
+#include "cDriverStatusConduit.h"
 #include "tThreadSpecific.h"
-#endif
 
-class cActionLibrary;
-class cAvidaDriver;
-class cDriverStatusConduit;
-class cWorldDriver;
+class cDMObject;
 
 
 class cDriverManager
 {
 private:
-  static cDriverManager* m_dm;
+  static cDriverManager* s_dm;
   
-  tList<cAvidaDriver> m_adrvs;
-  tList<cWorldDriver> m_wdrvs;
+  tList<cDMObject> m_objs;
   
   cMutex m_mutex;
-  cActionLibrary* m_actlib;
-  
   tThreadSpecific<cDriverStatusConduit> m_conduit;
   
-  cDriverManager();
+  cDriverManager() { ; }
   ~cDriverManager();
 
   cDriverManager(const cDriverManager&); // @not_implemented
@@ -65,16 +54,11 @@
 public:
   static void Initialize(); // initialize static driver manager.  This method is NOT thread-safe.
 
-  static void Register(cAvidaDriver* drv);
-  static void Register(cWorldDriver* drv);
-
-  static void Unregister(cAvidaDriver* drv);
-  static void Unregister(cWorldDriver* drv);
+  static void Register(cDMObject* obj);
+  static void Unregister(cDMObject* obj);
   
   static cDriverStatusConduit& Status();
   static void SetConduit(cDriverStatusConduit* conduit);
-    
-  static cActionLibrary* GetActionLibrary();
 };
 
 

Modified: development/source/drivers/cDriverStatusConduit.h
===================================================================
--- development/source/drivers/cDriverStatusConduit.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cDriverStatusConduit.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,9 +25,9 @@
 #ifndef cDriverStatusConduit_h
 #define cDriverStatusConduit_h
 
-
 class cString;
 
+
 class cDriverStatusConduit
 {
 private:

Modified: development/source/drivers/cFallbackWorldDriver.h
===================================================================
--- development/source/drivers/cFallbackWorldDriver.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cFallbackWorldDriver.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,13 +25,10 @@
 #ifndef cFallbackWorldDriver_h
 #define cFallbackWorldDriver_h
 
-#ifndef cDriverManager_h
 #include "cDriverManager.h"
-#endif
-#ifndef cWorldDriver_h
 #include "cWorldDriver.h"
-#endif
 
+
 class cFallbackWorldDriver : public cWorldDriver
 {
 private:

Modified: development/source/drivers/cWorldDriver.h
===================================================================
--- development/source/drivers/cWorldDriver.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/drivers/cWorldDriver.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -25,24 +25,19 @@
 #ifndef cWorldDriver_h
 #define cWorldDriver_h
 
-// This class is an abstract base class that is used by actions within
-// a cWorld to notify its driver of various states and conditions.
+#include "cDMObject.h"
 
-#if USE_tMemTrack
-# ifndef tMemTrack_h
-#  include "tMemTrack.h"
-# endif
-#endif
-
 #include <iostream>
 
 class cString;
 
-class cWorldDriver
+
+// This class is an abstract base class that is used by actions within
+// a cWorld to notify its driver of various states and conditions.
+
+
+class cWorldDriver : public virtual cDMObject
 {
-#if USE_tMemTrack
-  tMemTrack<cWorldDriver> mt;
-#endif
 private:
   cWorldDriver(const cWorldDriver&); // @not_implemented
   cWorldDriver& operator=(const cWorldDriver&); // @not_implemented

Added: development/source/drivers/tDMSingleton.h
===================================================================
--- development/source/drivers/tDMSingleton.h	                        (rev 0)
+++ development/source/drivers/tDMSingleton.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -0,0 +1,107 @@
+/*
+ *  tDMSingleton.h
+ *  Avida
+ *
+ *  Created by David on 10/31/08.
+ *  Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef tDMSingleton_h
+#define tDMSingleton_h
+
+#include "cDMObject.h"
+#include "cDriverManager.h"
+#include "cMutex.h"
+
+
+template<typename T> class tDMSingleton : public cDMObject
+{
+private:
+  static tDMSingleton* s_dms;
+  
+  T* m_object;
+  
+  
+  tDMSingleton(T* object) : m_object(object) { ; }
+  
+  tDMSingleton(); // @not_implemented
+  tDMSingleton(const tDMSingleton&); // @not_implemented
+  tDMSingleton& operator=(const tDMSingleton&); // @not_implemented
+  
+  
+public:
+  ~tDMSingleton() { delete m_object; }
+
+  static void Initialize(T* (construct)())
+  {
+    if (!s_dms) {
+      s_dms = new tDMSingleton((*construct)());
+      cDriverManager::Register(s_dms);
+    }
+  }
+
+  static T& GetInstance() { return *s_dms->m_object; }
+};
+
+template<typename T> tDMSingleton<T>* tDMSingleton<T>::s_dms = NULL;
+
+
+template<typename T> class tLazyDMSingleton : public cDMObject
+{
+private:
+  static tLazyDMSingleton* s_dms;
+  
+  cMutex m_mutex;
+  T* (*m_construct)();
+  T* m_object;
+  
+  
+  tLazyDMSingleton(T* (*construct)()) : m_object(NULL), m_construct(construct) { ; }
+  
+  tLazyDMSingleton(); // @not_implemented
+  tLazyDMSingleton(const tLazyDMSingleton&); // @not_implemented
+  tLazyDMSingleton& operator=(const tLazyDMSingleton&); // @not_implemented
+  
+  
+public:
+  ~tLazyDMSingleton() { delete m_object; }
+  
+  static void Initialize(T* (*construct)())
+  {
+    if (!s_dms) {
+      s_dms = new tLazyDMSingleton(construct);
+      cDriverManager::Register(s_dms);
+    }
+  }
+
+  static T& GetInstance()
+  {
+    cMutexAutoLock lock(s_dms->m_mutex);
+    
+    if (!s_dms->m_object) {
+      s_dms->m_object = (*s_dms->m_construct)();
+    }
+    
+    return *s_dms->m_object;
+  }
+};
+
+template<typename T> tLazyDMSingleton<T>* tLazyDMSingleton<T>::s_dms = NULL;
+
+#endif

Modified: development/source/main/avida.cc
===================================================================
--- development/source/main/avida.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/main/avida.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -26,6 +26,7 @@
 
 #include "defs.h"
 #include "cActionLibrary.h"
+#include "cAnalyzeGenotype.h"
 #include "cAvidaConfig.h"
 #include "cDriverManager.h"
 #include "cString.h"
@@ -41,9 +42,19 @@
 #include <csignal>
 #include <cstdio>
 
+
 using namespace std;
 
+
 namespace Avida {
+  
+void Initialize()
+{
+  cActionLibrary::Initialize();
+  cAnalyzeGenotype::Initialize();
+}
+  
+  
 
 cString GetVersion()
 {
@@ -152,7 +163,7 @@
     // Print out a list of all possibel actions (was events).
     if (cur_arg == "-e" || cur_arg == "-events" || cur_arg == "-actions") {
       cout << endl << "Supported Actions:" << endl;
-      cout << cDriverManager::GetActionLibrary()->DescribeAll() << endl;
+      cout << cActionLibrary::GetInstance().DescribeAll() << endl;
       exit(0);
     }
     

Modified: development/source/main/avida.h
===================================================================
--- development/source/main/avida.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/main/avida.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -32,6 +32,8 @@
 
 namespace Avida
 {
+  void Initialize();
+  
   cString GetVersion();
   void PrintVersionBanner();
   

Modified: development/source/main/cEventList.cc
===================================================================
--- development/source/main/cEventList.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/main/cEventList.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -58,7 +58,7 @@
 bool cEventList::AddEvent(eTriggerType trigger, double start, double interval,
                           double stop, const cString& name, const cString& args)
 {
-  cAction* action = m_world->GetActionLibrary().Create(name, m_world, args);
+  cAction* action = cActionLibrary::GetInstance().Create(name, m_world, args);
   
   if (action != NULL) {
     cEventListEntry* entry = new cEventListEntry(action, name, trigger, start, interval, stop);

Modified: development/source/main/cWorld.cc
===================================================================
--- development/source/main/cWorld.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/main/cWorld.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -59,8 +59,6 @@
   if (m_data_mgr) { m_data_mgr->FlushAll(); }
   delete m_data_mgr; m_data_mgr = NULL;
   
-  cAnalyzeGenotype::DestroyDEDict(m_dedict_genotype);
-
   // Delete Last
   delete m_conf; m_conf = NULL;
 
@@ -81,8 +79,6 @@
   if (rand_seed != m_rng.GetSeed()) cout << " -> " << m_rng.GetSeed();
   cout << endl;
   
-  m_actlib = cDriverManager::GetActionLibrary();
-  
   m_data_mgr = new cDataFileManager(m_conf->DATA_DIR.Get(), (m_conf->VERBOSITY.Get() > VERBOSE_ON));
   if (m_conf->VERBOSITY.Get() > VERBOSE_NORMAL)
     cout << "Data Directory: " << m_data_mgr->GetTargetDir() << endl;
@@ -132,9 +128,6 @@
   const bool sterilize_neut = m_conf->STERILIZE_NEUTRAL.Get() > 0.0;
   const bool sterilize_pos = m_conf->STERILIZE_BENEFICIAL.Get() > 0.0;
   m_test_sterilize = (sterilize_fatal || sterilize_neg || sterilize_neut || sterilize_pos);
-
-  
-  m_dedict_genotype = cAnalyzeGenotype::BuildDEDict(this);
 }
 
 cAnalyze& cWorld::GetAnalyze()

Modified: development/source/main/cWorld.h
===================================================================
--- development/source/main/cWorld.h	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/main/cWorld.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -47,7 +47,6 @@
 
 #include <cassert>
 
-class cActionLibrary;
 class cAnalyze;
 class cAnalyzeGenotype;
 class cAvidaDriver;
@@ -68,7 +67,6 @@
   tMemTrack<cWorld> mt;
 #endif
 protected:
-  cActionLibrary* m_actlib;
   cAnalyze* m_analyze;
   cAvidaConfig* m_conf;
   cAvidaContext m_ctx;
@@ -80,7 +78,6 @@
   cPopulation* m_pop;
   cStats* m_stats;
   cWorldDriver* m_driver;
-  tDictionary<tDataEntry<cAnalyzeGenotype>*>* m_dedict_genotype;
 
   cRandom m_rng;
   
@@ -103,7 +100,6 @@
   void SetDriver(cWorldDriver* driver, bool take_ownership = false);
   
   // General Object Accessors
-  cActionLibrary& GetActionLibrary() { return *m_actlib; }
   cAnalyze& GetAnalyze();
   cAvidaConfig& GetConfig() { return *m_conf; }
   cAvidaContext& GetDefaultContext() { return m_ctx; }
@@ -116,8 +112,6 @@
   cStats& GetStats() { return *m_stats; }
   cWorldDriver& GetDriver() { return *m_driver; }
   
-  const tDictionary<tDataEntry<cAnalyzeGenotype>*>& GetGenotypeDEDict() const { return *m_dedict_genotype; }
-  
   // Access to Data File Manager
   std::ofstream& GetDataFileOFStream(const cString& fname) { return m_data_mgr->GetOFStream(fname); }
   cDataFile& GetDataFile(const cString& fname) { return m_data_mgr->Get(fname); }  
@@ -139,7 +133,6 @@
   // Save to archive 
   template<class Archive>
   void save(Archive & a, const unsigned int version) const {
-    a.ArkvObj("m_actlib", m_actlib);
     a.ArkvObj("m_analyze", m_analyze);
     a.ArkvObj("m_conf", m_conf);
     a.ArkvObj("m_ctx", m_ctx);
@@ -163,7 +156,6 @@
   // Load from archive 
   template<class Archive>
   void load(Archive & a, const unsigned int version){
-    a.ArkvObj("m_actlib", m_actlib);
     a.ArkvObj("m_analyze", m_analyze);
     a.ArkvObj("m_conf", m_conf);
     a.ArkvObj("m_ctx", m_ctx);

Modified: development/source/platform/PlatformExpert.cc
===================================================================
--- development/source/platform/PlatformExpert.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/platform/PlatformExpert.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -50,6 +50,7 @@
     signal(SIGINT, Avida::Exit);
 
     cDriverManager::Initialize();
+    Avida::Initialize();
   }
 
   

Modified: development/source/script/ASAnalyzeLib.cc
===================================================================
--- development/source/script/ASAnalyzeLib.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/script/ASAnalyzeLib.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -41,7 +41,7 @@
 #include "cInitFile.h"
 #include "cWorld.h"
 
-#include "tDataEntryCommand.h"
+#include "tDataCommandManager.h"
 
 
 class cWorld;
@@ -116,7 +116,7 @@
     // Construct a linked list of data types that can be loaded...
     tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
     tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
-    cAnalyzeGenotype::LoadDataCommandList(world, input_file.GetFormat(), output_list);
+    cAnalyzeGenotype::GetDataCommandManager().LoadCommandList(input_file.GetFormat(), output_list);
     bool id_inc = input_file.GetFormat().HasString("id");
     
     // Setup the genome...
@@ -168,8 +168,8 @@
   BIND_FUNCTION(cWorld, "LoadOrganismWithInstSet", LoadOrganismWithInstSet, cAnalyzeGenotype* (const cString&, cInstSet*));
   BIND_FUNCTION(cWorld, "LoadSequence", LoadSequence, cAnalyzeGenotype* (const cString&));
   BIND_FUNCTION(cWorld, "LoadSequenceWithInstSet", LoadSequenceWithInstSet, cAnalyzeGenotype* (const cString&, cInstSet*));
-  BIND_FUNCTION(cWorld, "LoadBatch", LoadBatch, cAnalyzeGenotype* (const cString&));
-  BIND_FUNCTION(cWorld, "LoadBatchWithInstSet", LoadBatchWithInstSet, cAnalyzeGenotype* (const cString&, cInstSet*));
+  BIND_FUNCTION(cWorld, "LoadBatch", LoadBatch, cGenotypeBatch* (const cString&));
+  BIND_FUNCTION(cWorld, "LoadBatchWithInstSet", LoadBatchWithInstSet, cGenotypeBatch* (const cString&, cInstSet*));
 
 
 #undef BIND_FUNCTION

Modified: development/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc
===================================================================
--- development/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/targets/avida-viewer/cTextViewerAnalyzeDriver.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -48,13 +48,13 @@
 {
   m_view = new cAnalyzeView(world);
 
-  cDriverManager::Register(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Register(this);
   world->SetDriver(this);
 }
 
 cTextViewerAnalyzeDriver::~cTextViewerAnalyzeDriver()
 {
-  cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Unregister(this);
 
   if (m_view != NULL) EndProg(0);
 }

Modified: development/source/targets/avida-viewer/cTextViewerDriver.cc
===================================================================
--- development/source/targets/avida-viewer/cTextViewerDriver.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/targets/avida-viewer/cTextViewerDriver.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -48,13 +48,13 @@
   m_view = new cView(world);
   m_view->SetViewMode(world->GetConfig().VIEW_MODE.Get());
 
-  cDriverManager::Register(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Register(this);
   world->SetDriver(this);
 }
 
 cTextViewerDriver::~cTextViewerDriver()
 {
-  cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Unregister(this);
   
   if (m_view != NULL) EndProg(0);
 }

Modified: development/source/targets/viewer-text/cDriver_TextViewer.cc
===================================================================
--- development/source/targets/viewer-text/cDriver_TextViewer.cc	2008-10-31 05:23:21 UTC (rev 2906)
+++ development/source/targets/viewer-text/cDriver_TextViewer.cc	2008-10-31 18:47:53 UTC (rev 2907)
@@ -57,7 +57,7 @@
   // Setup the initial view mode (loaded from avida.cfg)
   m_info.SetViewMode(world->GetConfig().VIEW_MODE.Get());
     
-  cDriverManager::Register(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Register(this);
   world->SetDriver(this);
 
   // Setup NCURSES...
@@ -98,7 +98,7 @@
 
 cDriver_TextViewer::~cDriver_TextViewer()
 {
-  cDriverManager::Unregister(static_cast<cAvidaDriver*>(this));
+  cDriverManager::Unregister(this);
   delete m_world;
     
   ExitTextViewer(0);

Added: development/source/tools/tDataCommandManager.h
===================================================================
--- development/source/tools/tDataCommandManager.h	                        (rev 0)
+++ development/source/tools/tDataCommandManager.h	2008-10-31 18:47:53 UTC (rev 2907)
@@ -0,0 +1,94 @@
+/*
+ *  tDataCommandManager.h
+ *  Avida
+ *
+ *  Created by David on 10/31/08.
+ *  Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+#ifndef tDataCommandManager_h
+#define tDataCommandManager_h
+
+#include "cStringUtil.h"
+#include "tDataEntry.h"
+#include "tDataEntryCommand.h"
+#include "tDictionary.h"
+#include "tList.h"
+
+
+template <class TargetType> class tDataCommandManager
+{
+private:
+  tDictionary<tDataEntry<TargetType>*> m_entry_dict;  
+  
+public:
+  tDataCommandManager() { ; }
+  ~tDataCommandManager()
+  {
+    tArray<tDataEntry<cAnalyzeGenotype>*> entries;
+    m_entry_dict.GetValues(entries);
+    for (int i = 0; i < entries.GetSize(); i++) delete entries[i];
+  }
+  
+  void Add(const cString& name, tDataEntry<TargetType>* entry) { m_entry_dict.Add(name, entry); }
+  
+
+  tDataEntryCommand<cAnalyzeGenotype>* GetDataCommand(const cString& cmd, cString** error_str = NULL) const
+  {
+    cString arg_list = cmd;
+    cString idx = arg_list.Pop(':');
+    cString entry_name = idx.Pop('.');
+    
+    tDataEntry<cAnalyzeGenotype>* data_entry;
+    if (m_entry_dict.Find(entry_name, data_entry)) {
+      return new tDataEntryCommand<cAnalyzeGenotype>(data_entry, idx, arg_list);
+    }
+    
+    if (error_str) {
+      (*error_str) = new cString(cStringUtil::Stringf("data entry '%s' not found, best match is '%s'", *entry_name,
+                                                      *(m_entry_dict.NearMatch(entry_name))));
+    }
+    
+    return NULL;
+  }
+  
+  void LoadCommandList(cStringList arg_list, tList<tDataEntryCommand<TargetType> >& output_list,
+                       tList<cString>* errors = NULL) const
+  {
+    if (arg_list.GetSize() == 0) {
+      // If no args were given, load all of the stats.
+      // @TODO - handle indexed items...  under this scheme only the first task and env_input value will be output    
+      
+      tArray<tDataEntry<TargetType>*> data_entries;
+      m_entry_dict.GetValues(data_entries);
+      for (int i = 0; i < data_entries.GetSize(); i++)
+        output_list.PushRear(new tDataEntryCommand<TargetType>(data_entries[i]));
+    } else {
+      while (arg_list.GetSize() != 0) {
+        cString* error_str = NULL;
+        tDataEntryCommand<TargetType>* cur_command = GetDataCommand(arg_list.Pop());
+        if (cur_command) output_list.PushRear(cur_command);
+        if (errors && error_str) errors->PushRear(error_str);
+      }
+    }
+  }
+};
+
+
+#endif




More information about the Avida-cvs mailing list