[Avida-cvs] [avida-svn] r603 - in development: . Avida.xcodeproj source source/actions source/analyze source/classification source/cpu source/drivers source/event source/main source/targets/avida source/targets/avida-viewer source/tools

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Apr 10 10:31:08 PDT 2006


Author: brysonda
Date: 2006-04-10 13:31:08 -0400 (Mon, 10 Apr 2006)
New Revision: 603

Added:
   development/source/actions/
   development/source/actions/CMakeLists.txt
   development/source/actions/LandscapeActions.cc
   development/source/actions/LandscapeActions.h
   development/source/actions/cAction.h
   development/source/actions/cActionLibrary.h
   development/source/analyze/cAnalyzeCommandAction.h
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/CMakeLists.txt
   development/source/CMakeLists.txt
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyze.h
   development/source/analyze/cAnalyzeCommandDef.h
   development/source/analyze/cAnalyzeCommandDefBase.h
   development/source/analyze/cAnalyzeGenotype.cc
   development/source/analyze/cAnalyzeJobQueue.h
   development/source/analyze/cAnalyzeUtil.cc
   development/source/classification/cGenotype.cc
   development/source/classification/cSpecies.cc
   development/source/cpu/cTestUtil.cc
   development/source/drivers/cDefaultAnalyzeDriver.cc
   development/source/drivers/cDefaultRunDriver.cc
   development/source/drivers/cDriverManager.cc
   development/source/drivers/cDriverManager.h
   development/source/event/cEventManager.cc
   development/source/main/cAvidaContext.h
   development/source/main/cFitnessMatrix.cc
   development/source/main/cLandscape.cc
   development/source/main/cLandscape.h
   development/source/main/cPopulation.cc
   development/source/main/cWorld.cc
   development/source/main/cWorld.h
   development/source/targets/avida-viewer/CMakeLists.txt
   development/source/targets/avida/CMakeLists.txt
   development/source/tools/tDictionary.h
   development/source/tools/tHashTable.h
   development/source/tools/tObjectFactory.h
Log:
Implement actions framework, intended for use in merging events and analyze commands.

Implement SAMPLE_LANDSCAPE as a demonstration of actions framework.  Can be scheduled as an event, as well as called from Analyze mode (meaning it is now available in analyze, where it was not before).

Move cAnalyze instantiation into cWorld.  Lazily initialized on first use.   This is to support Actions using analysis state at any time.

Fix cEventManager to prevent crash when supplying a non-existent event name, error message should now be reported correctly.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2006-04-08 13:28:45 UTC (rev 602)
+++ development/Avida.xcodeproj/project.pbxproj	2006-04-10 17:31:08 UTC (rev 603)
@@ -114,6 +114,9 @@
 		7073165D097C6C8F00815164 /* cParser.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7073165B097C6C8F00815164 /* cParser.cc */; };
 		70731665097C6DF500815164 /* cASLibrary.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70731663097C6DF500815164 /* cASLibrary.cc */; };
 		7073166B097C6E0C00815164 /* cASSymbol.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70731669097C6E0C00815164 /* cASSymbol.cc */; };
+		707AF0B209EAC7FD001AEA89 /* LandscapeActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 707AF04509EAB529001AEA89 /* LandscapeActions.cc */; };
+		707AF0B309EAC801001AEA89 /* LandscapeActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 707AF04509EAB529001AEA89 /* LandscapeActions.cc */; };
+		707AF0B409EAC805001AEA89 /* LandscapeActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 707AF04509EAB529001AEA89 /* LandscapeActions.cc */; };
 		70AA941A09D486CA006A24C8 /* system-alloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF50209CFB0B400924128 /* system-alloc.cc */; };
 		70AA941B09D486CB006A24C8 /* tcmalloc-logging.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF57F09CFBD3D00924128 /* tcmalloc-logging.cc */; };
 		70AA941C09D486CD006A24C8 /* tcmalloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF56309CFBB9500924128 /* tcmalloc.cc */; };
@@ -553,7 +556,7 @@
 		700AE91B09DB65F200A073FD /* cTaskContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cTaskContext.h; sourceTree = "<group>"; };
 		700AEB7B09E3490300A073FD /* avida-smt.cfg */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = "avida-smt.cfg"; sourceTree = "<group>"; };
 		700E28CF0859FFD700CF158A /* tObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tObjectFactory.h; sourceTree = "<group>"; };
-		700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
+		700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
 		701384330900A45B0087ED2E /* organism.smtx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = organism.smtx; sourceTree = "<group>"; };
 		7013845F09028B3E0087ED2E /* cAvidaConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cAvidaConfig.h; sourceTree = "<group>"; };
 		7013846009028B3E0087ED2E /* cAvidaConfig.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cAvidaConfig.cc; sourceTree = "<group>"; };
@@ -637,6 +640,12 @@
 		70731668097C6E0C00815164 /* cASSymbol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASSymbol.h; sourceTree = "<group>"; };
 		70731669097C6E0C00815164 /* cASSymbol.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cASSymbol.cc; sourceTree = "<group>"; };
 		707A687408E3750300576968 /* cHardwareTracer_SMT.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareTracer_SMT.h; sourceTree = "<group>"; };
+		707AEEEF09E80725001AEA89 /* cAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cAction.h; sourceTree = "<group>"; };
+		707AEEFE09E83381001AEA89 /* cActionLibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cActionLibrary.h; sourceTree = "<group>"; };
+		707AEF8C09EA8B2D001AEA89 /* cAnalyzeCommandAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cAnalyzeCommandAction.h; sourceTree = "<group>"; };
+		707AF04409EAB529001AEA89 /* LandscapeActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LandscapeActions.h; sourceTree = "<group>"; };
+		707AF04509EAB529001AEA89 /* LandscapeActions.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LandscapeActions.cc; sourceTree = "<group>"; };
+		707AF0F809EACC5E001AEA89 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
 		7093DB4009D6F50300DE7FEB /* tSmartArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tSmartArray.h; sourceTree = "<group>"; };
 		70AA941909D486AE006A24C8 /* libtcmalloc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libtcmalloc.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		70B0864808F4972600FC65FE /* cLandscape.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLandscape.h; sourceTree = "<group>"; };
@@ -882,7 +891,7 @@
 		70DCAC77097AF730002F8733 /* key_chart */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = key_chart; sourceTree = "<group>"; };
 		70DCAC78097AF730002F8733 /* viewer.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = viewer.cc; sourceTree = "<group>"; };
 		70DCAC9B097AF7C0002F8733 /* primitive.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = primitive.cc; sourceTree = "<group>"; };
-		70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
+		70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
 		70DCAD1F097AF81A002F8733 /* AvidaScript.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AvidaScript.h; sourceTree = "<group>"; };
 		70DCAD20097AF81A002F8733 /* cLexer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLexer.h; sourceTree = "<group>"; };
 		70DCAD21097AF81A002F8733 /* cLexer.l */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.lex; path = cLexer.l; sourceTree = "<group>"; };
@@ -1089,10 +1098,23 @@
 				7054A17D09A8032600038658 /* tAnalyzeJob.h */,
 				7054A1B309A810CB00038658 /* cAnalyzeJobWorker.h */,
 				7054A1B409A810CB00038658 /* cAnalyzeJobWorker.cc */,
+				707AEF8C09EA8B2D001AEA89 /* cAnalyzeCommandAction.h */,
 			);
 			path = analyze;
 			sourceTree = "<group>";
 		};
+		707AEEEE09E80699001AEA89 /* actions */ = {
+			isa = PBXGroup;
+			children = (
+				707AF0F809EACC5E001AEA89 /* CMakeLists.txt */,
+				707AEEEF09E80725001AEA89 /* cAction.h */,
+				707AEEFE09E83381001AEA89 /* cActionLibrary.h */,
+				707AF04409EAB529001AEA89 /* LandscapeActions.h */,
+				707AF04509EAB529001AEA89 /* LandscapeActions.cc */,
+			);
+			path = actions;
+			sourceTree = "<group>";
+		};
 		70DCAC54097AF730002F8733 /* targets */ = {
 			isa = PBXGroup;
 			children = (
@@ -1257,6 +1279,7 @@
 		DCC30C670762539A008F7A48 /* Main Source */ = {
 			isa = PBXGroup;
 			children = (
+				707AEEEE09E80699001AEA89 /* actions */,
 				70422A1B091B141000A5E67F /* analyze */,
 				70F7D8C8092546DC009E311D /* classification */,
 				DCC30F7C0762539D008F7A48 /* cpu */,
@@ -2084,6 +2107,7 @@
 				7054A17309A8014600038658 /* cAnalyzeJobQueue.cc in Sources */,
 				7054A1B809A810CB00038658 /* cAnalyzeJobWorker.cc in Sources */,
 				7005A70609BA0FA90007E16E /* cTestCPUInterface.cc in Sources */,
+				707AF0B409EAC805001AEA89 /* LandscapeActions.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2212,6 +2236,7 @@
 				7054A17109A8014600038658 /* cAnalyzeJobQueue.cc in Sources */,
 				7054A1B609A810CB00038658 /* cAnalyzeJobWorker.cc in Sources */,
 				7005A70409BA0FA90007E16E /* cTestCPUInterface.cc in Sources */,
+				707AF0B309EAC801001AEA89 /* LandscapeActions.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2324,6 +2349,7 @@
 				7054A1BA09A810CB00038658 /* cAnalyzeJobWorker.cc in Sources */,
 				7005A70809BA0FA90007E16E /* cTestCPUInterface.cc in Sources */,
 				7005A83209BA621F0007E16E /* cOrgMessage.cc in Sources */,
+				707AF0B209EAC7FD001AEA89 /* LandscapeActions.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt	2006-04-08 13:28:45 UTC (rev 602)
+++ development/CMakeLists.txt	2006-04-10 17:31:08 UTC (rev 603)
@@ -227,6 +227,7 @@
 # Shortcuts to the source subdirectories.
 SET(THIRDPARTY_SRC_DIR ${PROJECT_SOURCE_DIR}/source/third-party)
 SET(TOOLS_SRC_DIR ${PROJECT_SOURCE_DIR}/source/tools)
+SET(ACTIONS_SRC_DIR ${PROJECT_SOURCE_DIR}/source/actions)
 SET(ANALYZE_SRC_DIR ${PROJECT_SOURCE_DIR}/source/analyze)
 SET(CLASSIFICATION_SRC_DIR ${PROJECT_SOURCE_DIR}/source/classification)
 SET(CPU_SRC_DIR ${PROJECT_SOURCE_DIR}/source/cpu)
@@ -237,6 +238,7 @@
 # Shortcuts to the build subdirectories.
 SET(THIRDPARTY_BLD_DIR ${PROJECT_BINARY_DIR}/source/third-party)
 SET(TOOLS_BLD_DIR ${PROJECT_BINARY_DIR}/source/tools)
+SET(ACTIONS_BLD_DIR ${PROJECT_BINARY_DIR}/source/actions)
 SET(ANALYZE_BLD_DIR ${PROJECT_BINARY_DIR}/source/analyze)
 SET(CLASSSIFICATION_BLD_DIR ${PROJECT_BINARY_DIR}/source/classification)
 SET(CPU_BLD_DIR ${PROJECT_BINARY_DIR}/source/cpu)
@@ -248,6 +250,7 @@
 # include-directories).
 SET(ALL_INC_DIRS
   ${TOOLS_SRC_DIR}
+  ${ACTIONS_SRC_DIR}
   ${ANALYZE_SRC_DIR}
   ${CLASSIFICATION_SRC_DIR}
   ${CPU_SRC_DIR}
@@ -262,6 +265,7 @@
 # link-subdirecties).
 SET(ALL_LIB_DIRS
   ${TOOLS_BLD_DIR}
+  ${ACTIONS_BLD_DIR}
   ${ANALYZE_BLD_DIR}
   ${CLASSIFICATION_BLD_DIR}
   ${CPU_BLD_DIR}

Modified: development/source/CMakeLists.txt
===================================================================
--- development/source/CMakeLists.txt	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/CMakeLists.txt	2006-04-10 17:31:08 UTC (rev 603)
@@ -1,5 +1,5 @@
 
-SUBDIRS(analyze classification cpu drivers event main targets third-party tools support utils/task_events)
+SUBDIRS(actions analyze classification cpu drivers event main targets third-party tools support utils/task_events)
 IF(AVD_PY_BINDINGS)
   SUBDIRS(bindings python)
 ENDIF(AVD_PY_BINDINGS)

Added: development/source/actions/CMakeLists.txt
===================================================================
--- development/source/actions/CMakeLists.txt	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/actions/CMakeLists.txt	2006-04-10 17:31:08 UTC (rev 603)
@@ -0,0 +1,8 @@
+INCLUDE_DIRECTORIES(${ALL_INC_DIRS})
+
+SET(libactions_a_SOURCES
+  LandscapeActions.cc
+)
+
+ADD_LIBRARY(actions ${libactions_a_SOURCES})
+


Property changes on: development/source/actions/CMakeLists.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: development/source/actions/LandscapeActions.cc
===================================================================
--- development/source/actions/LandscapeActions.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/actions/LandscapeActions.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -0,0 +1,81 @@
+/*
+ *  LandscapeActions.cc
+ *  Avida
+ *
+ *  Created by David on 4/10/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#include "LandscapeActions.h"
+
+#include "cAction.h"
+#include "cActionLibrary.h"
+#include "cAnalyze.h"
+#include "cAnalyzeGenotype.h"
+#include "tAnalyzeJob.h"
+#include "cClassificationManager.h"
+#include "cGenotype.h"
+#include "cGenotypeBatch.h"
+#include "cHardwareManager.h"
+#include "cLandscape.h"
+#include "cStats.h"
+#include "cWorld.h"
+
+
+class cActionSampleLandscape : public cAction
+{
+private:
+  cString m_filename;
+  int m_sample_size;
+  tList<cLandscape> m_batch;
+
+public:
+  cActionSampleLandscape(cWorld* world, const cString& args)
+    : cAction(world, args), m_filename("land-sample.dat"), m_sample_size(0)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_sample_size = largs.PopWord().AsInt();
+    if (m_sample_size == 0) m_sample_size = m_world->GetHardwareManager().GetInstSet().GetSize() - 1;
+    if (largs.GetSize()) m_filename = largs.PopWord();
+  }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    int update = -1;
+    cLandscape* land = NULL;
+    
+    if (ctx.GetAnalyzeMode()) {
+      cAnalyzeJobQueue& jobqueue = m_world->GetAnalyze().GetJobQueue();
+      cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+      
+      tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
+      cAnalyzeGenotype* genotype = NULL;
+      while (genotype = batch_it.Next()) {
+        cLandscape* land = new cLandscape(m_world, genotype->GetGenome(), inst_set);
+        m_batch.PushRear(land);
+        jobqueue.AddJob(new tAnalyzeJob<cLandscape>(land, &cLandscape::SampleProcess));
+      }
+      jobqueue.Execute();
+    } else {
+      land = new cLandscape(m_world, m_world->GetClassificationManager().GetBestGenotype()->GetGenome(),
+                            m_world->GetHardwareManager().GetInstSet());
+      m_batch.PushRear(land);
+      land->SetTrials(m_sample_size);
+      land->SampleProcess(ctx);
+      update = m_world->GetStats().GetUpdate();      
+    }
+    
+    std::ofstream& outfile = m_world->GetDataFileOFStream(m_filename);
+    while (land = m_batch.Pop()) {
+      land->PrintStats(outfile, update);
+      delete land;
+    }
+  }
+};
+
+
+void RegisterLandscapeActions(cActionLibrary* action_lib)
+{
+  action_lib->Register<cActionSampleLandscape>("SAMPLE_LANDSCAPE");
+}


Property changes on: development/source/actions/LandscapeActions.cc
___________________________________________________________________
Name: svn:eol-style
   + native

Added: development/source/actions/LandscapeActions.h
===================================================================
--- development/source/actions/LandscapeActions.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/actions/LandscapeActions.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -0,0 +1,17 @@
+/*
+ *  LandscapeActions.h
+ *  Avida
+ *
+ *  Created by David on 4/10/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef LandscapeActions_h
+#define LandscapeActions_h
+
+class cActionLibrary;
+
+void RegisterLandscapeActions(cActionLibrary* action_lib);
+
+#endif


Property changes on: development/source/actions/LandscapeActions.h
___________________________________________________________________
Name: svn:eol-style
   + native

Added: development/source/actions/cAction.h
===================================================================
--- development/source/actions/cAction.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/actions/cAction.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -0,0 +1,40 @@
+/*
+ *  cAction.h
+ *  Avida
+ *
+ *  Created by David on 4/8/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cAction_h
+#define cAction_h
+
+#ifndef cString_h
+#include "cString.h"
+#endif
+
+class cAvidaContext;
+class cWorld;
+
+class cAction
+{
+private:
+  cAction();  // @not_implemented
+  cAction(const cAction&); // @not_implemented
+  cAction& operator=(const cAction&); // @not_implemented
+  
+protected:
+  cWorld* m_world;
+  cString m_args;
+  
+public:
+  cAction(cWorld* world, const cString& args) : m_world(world), m_args(args) { ; }
+  virtual ~cAction() { ; }
+  
+  const cString& GetArgs() const { return m_args; }
+  
+  virtual void Process(cAvidaContext& ctx) = 0;
+};
+
+#endif


Property changes on: development/source/actions/cAction.h
___________________________________________________________________
Name: svn:eol-style
   + native

Added: development/source/actions/cActionLibrary.h
===================================================================
--- development/source/actions/cActionLibrary.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/actions/cActionLibrary.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -0,0 +1,29 @@
+/*
+ *  cActionLibrary.h
+ *  Avida
+ *
+ *  Created by David on 4/8/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cActionLibrary_h
+#define cActionLibrary_h
+
+#ifndef cAction_h
+#include "cAction.h"
+#endif
+#ifndef tObjectFactory_h
+#include "tObjectFactory.h"
+#endif
+
+class cWorld;
+class cString;
+
+class cActionLibrary : public tObjectFactory<cAction* (cWorld*, const cString&)>
+{
+public:
+  cActionLibrary() { ; }
+};
+
+#endif


Property changes on: development/source/actions/cActionLibrary.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyze.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -16,14 +16,15 @@
 #include <queue>
 #include <stack>
 
+#include "cActionLibrary.h"
 #include "cAnalyzeCommand.h"
+#include "cAnalyzeCommandAction.h"
 #include "cAnalyzeCommandDef.h"
 #include "cAnalyzeCommandDefBase.h"
 #include "cAnalyzeFlowCommand.h"
 #include "cAnalyzeFlowCommandDef.h"
 #include "cAnalyzeFunction.h"
 #include "cAnalyzeGenotype.h"
-#include "cAnalyzeJobQueue.h"
 #include "tAnalyzeJob.h"
 #include "cAvidaContext.h"
 #include "cDataFile.h"
@@ -66,7 +67,8 @@
 : cur_batch(0)
 , m_world(world)
 , inst_set(world->GetHardwareManager().GetInstSet())
-, m_ctx(world->GetRandom())
+, m_ctx(world->GetDefaultContext())
+, m_jobqueue(world)
 , verbose(nAnalyze::VERBOSE_QUIET)
 , interactive_depth(0)
 {
@@ -96,17 +98,11 @@
 
   m_testcpu = m_world->GetHardwareManager().CreateTestCPU();
   
-  cInitFile analyze_file(m_world->GetConfig().ANALYZE_FILE.Get());
-  analyze_file.Load();
-  analyze_file.Compress();
-  analyze_file.Close();
-  
-  LoadCommandList(analyze_file, command_list);
-  ProcessCommands(command_list);
-  
-  return;
+  RunFile(m_world->GetConfig().ANALYZE_FILE.Get());
 }
 
+
+
 cAnalyze::~cAnalyze()
 {
   while (genotype_data_list.GetSize()) delete genotype_data_list.Pop();
@@ -115,6 +111,17 @@
 }
 
 
+void cAnalyze::RunFile(cString filename)
+{
+  cInitFile analyze_file(filename);
+  analyze_file.Load();
+  analyze_file.Compress();
+  analyze_file.Close();
+  
+  LoadCommandList(analyze_file, command_list);
+  ProcessCommands(command_list);
+}
+
 //////////////// Loading methods...
 
 void cAnalyze::LoadOrganism(cString cur_string)
@@ -1659,15 +1666,14 @@
 
 void cAnalyze::CommandCalcLandscape(cString cur_string)
 {
-  cAnalyzeJobQueue queue(m_world);
   tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
-
+  
   cout << "Calculating Landscape..." << endl;
 
   for (cAnalyzeGenotype* cur_genotype = batch_it.Next(); cur_genotype; cur_genotype = batch_it.Next()) {
-    queue.AddJob(new tAnalyzeJob<cAnalyzeGenotype>(cur_genotype, &cAnalyzeGenotype::CalcLandscape));
+    m_jobqueue.AddJob(new tAnalyzeJob<cAnalyzeGenotype>(cur_genotype, &cAnalyzeGenotype::CalcLandscape));
   }
-  queue.Execute();
+  m_jobqueue.Execute();
 }
 
 void cAnalyze::CommandDetail(cString cur_string)
@@ -7050,19 +7056,6 @@
   RunInteractive();
 }
 
-//void cAnalyze::PrintTestCPUResources(cString cur_string)
-//{
-//  cout << "TestCPU is using resources: ";
-//  cout << m_world->GetTestCPU().GetUseResources() << endl;
-//  cout << "Resources currently in TestCPU: ";
-//  const tArray<double> &quantity = m_world->GetTestCPU().GetResources();
-//  for(int i=0; i<quantity.GetSize(); i++) {
-//    cout << quantity.ElementAt(i) << " ";
-//  }
-//  cout << endl;
-//  
-//  return;
-//}
 
 void cAnalyze::FunctionCreate(cString cur_string,
                               tList<cAnalyzeCommand> & clist)
@@ -7325,8 +7318,9 @@
     cString command = cur_string.PopWord();
     command.ToUpper();
     
-    cAnalyzeCommand * cur_command;
-    cAnalyzeCommandDefBase * command_def = FindAnalyzeCommandDef(command);
+    cAnalyzeCommand* cur_command;
+    cAnalyzeCommandDefBase* command_def = FindAnalyzeCommandDef(command);
+    
     if (command == "END") {
       // We are done with this section of code; break out...
       break;
@@ -7800,7 +7794,6 @@
   AddLibraryDef("INCLUDE", &cAnalyze::IncludeFile);
   AddLibraryDef("SYSTEM", &cAnalyze::CommandSystem);
   AddLibraryDef("INTERACTIVE", &cAnalyze::CommandInteractive);
-//  AddLibraryDef("PRINT_TEST_CPU_RESOURCES", &cAnalyze::PrintTestCPUResources);
   AddLibraryDef("CALC_LANDSCAPE", &cAnalyze::CommandCalcLandscape);
   
   // Functions...
@@ -7811,7 +7804,7 @@
   AddLibraryDef("FORRANGE", &cAnalyze::CommandForRange);
 }
 
-cAnalyzeCommandDefBase * cAnalyze::FindAnalyzeCommandDef(const cString & name)
+cAnalyzeCommandDefBase* cAnalyze::FindAnalyzeCommandDef(const cString& name)
 {
   SetupCommandDefLibrary();
   
@@ -7819,8 +7812,14 @@
   while (lib_it.Next() != (void *) NULL) {
     if (lib_it.Get()->GetName() == name) break;
   }
+  cAnalyzeCommandDefBase* command_def = lib_it.Get();
   
-  return lib_it.Get();
+  if (command_def == NULL && m_world->GetActionLibrary().Supports(name)) {
+    command_def = new cAnalyzeCommandAction(name, m_world);
+    command_lib.PushRear(command_def);
+  }
+  
+  return command_def;
 }
 
 void cAnalyze::RunInteractive()
@@ -7841,17 +7840,14 @@
     if (command == "") {
       // Don't worry about blank lines...
       continue;
-    }
-    else if (command == "END" || command == "QUIT" || command == "EXIT") {
+    } else if (command == "END" || command == "QUIT" || command == "EXIT") {
       // We are done with interactive mode...
       break;
-    }
-    else if (command_def != NULL && command_def->IsFlowCommand() == true) {
+    } else if (command_def != NULL && command_def->IsFlowCommand() == true) {
       // This code has a body to it... fill it out!
       cur_command = new cAnalyzeFlowCommand(command, cur_input);
       InteractiveLoadCommandList(*(cur_command->GetCommandList()));
-    }
-    else {
+    } else {
       // This is a normal command...
       cur_command = new cAnalyzeCommand(command, cur_input);
     }

Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyze.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -13,7 +13,10 @@
 
 #include <vector>
 
-#ifndef cAvidaContex_h
+#ifndef cAnalyzeJobQueue_h
+#include "cAnalyzeJobQueue.h"
+#endif
+#ifndef cAvidaContext_h
 #include "cAvidaContext.h"
 #endif
 #ifndef cGenotypeBatch_h
@@ -65,7 +68,8 @@
 class cTestCPU;
 class cWorld;
 
-class cAnalyze {
+class cAnalyze
+{
 private:
   int cur_batch;
   cGenotypeBatch batch[MAX_BATCHES];
@@ -80,6 +84,7 @@
   cInstSet& inst_set;
   cTestCPU* m_testcpu;
   cAvidaContext m_ctx;
+  cAnalyzeJobQueue m_jobqueue;
 
 
   // This is the storage for the resource information from resource.dat.  It 
@@ -93,7 +98,7 @@
 
   cRandom random;
 
-private:
+
   // Pop specific types of arguments from an arg list.
   cString PopDirectory(cString & in_string, const cString & default_dir);
   int PopBatch(const cString & in_string);
@@ -134,7 +139,6 @@
   void CommandHistogram_Body(std::ostream& fp, int format_type,
             tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it);
 
-private:
   // Loading methods...
   void LoadOrganism(cString cur_string);
   void LoadBasicDump(cString cur_string);
@@ -234,7 +238,6 @@
   void IncludeFile(cString cur_string);
   void CommandSystem(cString cur_string);
   void CommandInteractive(cString cur_string);
-//  void PrintTestCPUResources(cString cur_string);
   void CommandCalcLandscape(cString cur_string);
 
   // Functions...
@@ -264,14 +267,18 @@
   void CommandForeach(cString cur_string, tList<cAnalyzeCommand> & clist);
   void CommandForRange(cString cur_string, tList<cAnalyzeCommand> & clist);
 
-private:
-  // disabled copy constructor.
-  cAnalyze(const cAnalyze &);
+  cAnalyze(const cAnalyze &); // @not_implemented
+
+
 public:
   cAnalyze(cWorld* world);
   ~cAnalyze();
 
+  void RunFile(cString filename);
   void RunInteractive();
+  
+  cGenotypeBatch& GetCurrentBatch() { return batch[cur_batch]; }
+  cAnalyzeJobQueue& GetJobQueue() { return m_jobqueue; }
 };
 
 #endif

Added: development/source/analyze/cAnalyzeCommandAction.h
===================================================================
--- development/source/analyze/cAnalyzeCommandAction.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyzeCommandAction.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -0,0 +1,47 @@
+/*
+ *  cAnalyzeCommandAction.h
+ *  Avida
+ *
+ *  Created by David on 4/10/06.
+ *  Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cAnalyzeCommandAction_h
+#define cAnalyzeCommandAction_h
+
+#ifndef cAction_h
+#include "cAction.h"
+#endif
+#ifndef cActionLibrary_h
+#include "cActionLibrary.h"
+#endif
+#ifndef cAnalyzeCommandDefBase_h
+#include "cAnalyzeCommandDefBase.h"
+#endif
+#ifndef cWorld_h
+#include "cWorld.h"
+#endif
+
+class cAnalyze;
+class cAnalyzeCommand;
+
+class cAnalyzeCommandAction : public cAnalyzeCommandDefBase
+{
+private:
+  cWorld* m_world;
+
+public:
+  cAnalyzeCommandAction(const cString& in_name, cWorld* world)
+    : cAnalyzeCommandDefBase(in_name), m_world(world) { ; }
+  ~cAnalyzeCommandAction() { ; }
+  
+  void Run(cAnalyze* analyze, const cString& args, cAnalyzeCommand& command) const
+  {
+    cAction* action = m_world->GetActionLibrary().Create(name, m_world, args);
+    cAvidaContext& ctx = m_world->GetDefaultContext();
+    action->Process(ctx);
+  }
+};
+
+#endif


Property changes on: development/source/analyze/cAnalyzeCommandAction.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: development/source/analyze/cAnalyzeCommandDef.h
===================================================================
--- development/source/analyze/cAnalyzeCommandDef.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyzeCommandDef.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -27,10 +27,10 @@
 public:
   cAnalyzeCommandDef(const cString & _name, void (cAnalyze::*_cf)(cString))
     : cAnalyzeCommandDefBase(_name), CommandFunction(_cf) { ; }
-  virtual ~cAnalyzeCommandDef() { ; }
+  ~cAnalyzeCommandDef() { ; }
 
-  virtual void Run(cAnalyze * analyze, const cString & args,
-		   cAnalyzeCommand & command) const {
+  void Run(cAnalyze * analyze, const cString & args, cAnalyzeCommand & command) const
+  {
     (void) command; // used in other types of command defininitions.
     (analyze->*CommandFunction)(args);
   }

Modified: development/source/analyze/cAnalyzeCommandDefBase.h
===================================================================
--- development/source/analyze/cAnalyzeCommandDefBase.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyzeCommandDefBase.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -22,14 +22,13 @@
 protected:
   cString name;
 public:
-  cAnalyzeCommandDefBase(const cString & _name) : name(_name) { ; }
+  cAnalyzeCommandDefBase(const cString& _name) : name(_name) { ; }
   virtual ~cAnalyzeCommandDefBase() { ; }
 
-  virtual void Run(cAnalyze * analyze, const cString & args,
-		   cAnalyzeCommand & command) const = 0;
+  virtual void Run(cAnalyze* analyze, const cString & args, cAnalyzeCommand& command) const = 0;
   virtual bool IsFlowCommand() { return false; }
 
-  const cString & GetName() const { return name; }
+  const cString& GetName() const { return name; }
 };
 
 #endif

Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyzeGenotype.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -191,8 +191,7 @@
   
   cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
 
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
   
   // Calculate the base fitness for the genotype we're working with...
   // (This may not have been run already, and cost negligiably more time

Modified: development/source/analyze/cAnalyzeJobQueue.h
===================================================================
--- development/source/analyze/cAnalyzeJobQueue.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyzeJobQueue.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -44,7 +44,7 @@
   cAnalyzeJobQueue& operator=(const cAnalyzeJobQueue&); // @not_implemented
   
 public:
-    cAnalyzeJobQueue(cWorld* world);
+  cAnalyzeJobQueue(cWorld* world);
   ~cAnalyzeJobQueue();
 
   void AddJob(cAnalyzeJob* job) { job->SetID(m_last_jobid++); m_queue.PushRear(job); } // @DMB - Warning: NOT thread safe

Modified: development/source/analyze/cAnalyzeUtil.cc
===================================================================
--- development/source/analyze/cAnalyzeUtil.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/analyze/cAnalyzeUtil.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -43,10 +43,8 @@
                               ofstream& fp, int update)
 {
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
+  cAvidaContext& ctx = world->GetDefaultContext();
   
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
-  
   cCPUTestInfo test_info;
   testcpu->TestGenome(ctx, test_info, genome);
   delete testcpu;
@@ -69,9 +67,7 @@
                                                int num_trials, int update)
 {
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
-  
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
 
   cCPUTestInfo test_info;
   const cInstruction inst_none = inst_set.GetInst("instruction_none");
@@ -120,8 +116,7 @@
 cGenome cAnalyzeUtil::CalcLandscape(cWorld* world, int dist, const cGenome & genome,
                                     cInstSet & inst_set)
 {
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
 
   cLandscape landscape(world, genome, inst_set);
   landscape.Process(ctx, dist);
@@ -160,8 +155,7 @@
 void cAnalyzeUtil::AnalyzeLandscape(cWorld* world, const cGenome & genome, cInstSet &inst_set,
                                     int sample_size, int min_found, int max_sample_size, int update)
 {
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
 
   cLandscape landscape(world, genome, inst_set);
   ofstream& fp = world->GetDataFileOFStream("land_analyze.dat");
@@ -196,8 +190,7 @@
 void cAnalyzeUtil::PairTestLandscape(cWorld* world, const cGenome &genome, cInstSet &inst_set,
                                      int sample_size, int update)
 {
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
 
   cLandscape landscape(world, genome, inst_set);
   
@@ -342,9 +335,7 @@
   }
   else {
     cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
-
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(world->GetRandom());
+    cAvidaContext& ctx = world->GetDefaultContext();
     
     cCPUTestInfo test_info;
     testcpu->TestGenome(ctx, test_info, con_genome);
@@ -406,8 +397,7 @@
   cPopulation* pop = &world->GetPopulation();
   fp << "# (1) cell number (2) genotype name (3) length (4) fitness [test-cpu] (5) fitness (actual) (6) merit (7) no of breed trues occurred (8) lineage label (9) neutral metric (10) -... landscape data" << endl;
   
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
 
   const double skip_prob = 1.0 - sample_prob;
   for (int i = 0; i < pop->GetSize(); i++) {
@@ -501,10 +491,8 @@
   cGenotype * max_f_genotype = NULL;
   
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
+  cAvidaContext& ctx = world->GetDefaultContext();
 
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
-
   for (int i = 0; i < pop->GetSize(); i++) {
     if (pop->GetCell(i).IsOccupied() == false) continue;  // One use organisms.
     
@@ -724,10 +712,8 @@
   fp << "# (1) cell number\n# (2) number of rewarded tasks done so far\n# (3) total number of tasks done so far\n# (4) same as 2, but right before divide\n# (5) same as 3, but right before divide\n# (6) same as 2, but for parent\n# (7) same as 3, but for parent\n# (8) genotype fitness\n# (9) genotype name" << endl;
   
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
+  cAvidaContext& ctx = world->GetDefaultContext();
 
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
-
   for (int i = 0; i < pop->GetSize(); i++) {
     if (pop->GetCell(i).IsOccupied() == false) continue;
     cOrganism * organism = pop->GetCell(i).GetOrganism();
@@ -783,10 +769,8 @@
 { 
   cPopulation* pop = &world->GetPopulation();
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
+  cAvidaContext& ctx = world->GetDefaultContext();
 
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
-
   for (int i = 0; i < pop->GetWorldX(); i++) {
     for (int j = 0; j < pop->GetWorldY(); j++) {
       int task_sum = 0;

Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/classification/cGenotype.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -189,9 +189,7 @@
 void cGenotype::CalcTestStats() const
 {
   cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
-  
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
 
   cCPUTestInfo test_info;
   testcpu->TestGenome(ctx, test_info, genome);

Modified: development/source/classification/cSpecies.cc
===================================================================
--- development/source/classification/cSpecies.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/classification/cSpecies.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -78,9 +78,7 @@
 int cSpecies::Compare(const cGenome & test_genome, int max_fail_count)
 {
   cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
-  
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
 
   cCPUTestInfo test_info;
 

Modified: development/source/cpu/cTestUtil.cc
===================================================================
--- development/source/cpu/cTestUtil.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/cpu/cTestUtil.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -40,9 +40,7 @@
 
   // Build the test info for printing.
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
-
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
   
   cCPUTestInfo test_info;
   test_info.TestThreads();
@@ -146,9 +144,7 @@
 
   // Build the test info for printing.
   cTestCPU* testcpu = world->GetHardwareManager().CreateTestCPU();
-  
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
 
   cCPUTestInfo test_info;
   test_info.TestThreads();

Modified: development/source/drivers/cDefaultAnalyzeDriver.cc
===================================================================
--- development/source/drivers/cDefaultAnalyzeDriver.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/drivers/cDefaultAnalyzeDriver.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -36,7 +36,7 @@
 void cDefaultAnalyzeDriver::Run()
 {
   cout << "In analyze mode!!" << endl;
-  cAnalyze analyze(m_world);
+  cAnalyze& analyze = m_world->GetAnalyze();
   if (m_interactive == true) {
     analyze.RunInteractive();
   }

Modified: development/source/drivers/cDefaultRunDriver.cc
===================================================================
--- development/source/drivers/cDefaultRunDriver.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/drivers/cDefaultRunDriver.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -51,7 +51,7 @@
   const int ave_time_slice = m_world->GetConfig().AVE_TIME_SLICE.Get();
   const double point_mut_prob = m_world->GetConfig().POINT_MUT_PROB.Get();
   
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
 
   while (!m_done) {
     if (cChangeList* change_list = population.GetChangeList()) {

Modified: development/source/drivers/cDriverManager.cc
===================================================================
--- development/source/drivers/cDriverManager.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/drivers/cDriverManager.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -12,6 +12,7 @@
 #include "cAvidaDriver.h"
 #include "cWorldDriver.h"
 
+#include <assert.h>
 #include <stdlib.h>
 
 
@@ -28,12 +29,13 @@
   while (wdrv = m_wdrvs.Pop()) {
     delete wdrv;
   }
+  
+  pthread_mutex_destroy(&m_mutex);
 }
 
 void cDriverManager::Initialize()
 {
-  if (m_dm == NULL)
-  {
+  if (m_dm == NULL) {
     m_dm = new cDriverManager();
     if (atexit(cDriverManager::Destroy)) {
       // Failed to register with atexit, this is bad, very bad.
@@ -49,21 +51,33 @@
 
 void cDriverManager::Register(cAvidaDriver* drv)
 {
-  if (m_dm) m_dm->m_adrvs.Push(drv);
+  assert(m_dm);
+  pthread_mutex_lock(&m_dm->m_mutex);
+  m_dm->m_adrvs.Push(drv);
+  pthread_mutex_unlock(&m_dm->m_mutex);
 }
 
 void cDriverManager::Register(cWorldDriver* drv)
 {
-  if (m_dm) m_dm->m_wdrvs.Push(drv);
+  assert(m_dm);
+  pthread_mutex_lock(&m_dm->m_mutex);
+  m_dm->m_wdrvs.Push(drv);
+  pthread_mutex_unlock(&m_dm->m_mutex);
 }
 
 void cDriverManager::Unregister(cAvidaDriver* drv)
 {
-  if (m_dm) m_dm->m_adrvs.Remove(drv);
+  assert(m_dm);
+  pthread_mutex_lock(&m_dm->m_mutex);
+  m_dm->m_adrvs.Remove(drv);
+  pthread_mutex_unlock(&m_dm->m_mutex);
 }
 
 void cDriverManager::Unregister(cWorldDriver* drv)
 {
-  if (m_dm) m_dm->m_wdrvs.Remove(drv);
+  assert(m_dm);
+  pthread_mutex_lock(&m_dm->m_mutex);
+  m_dm->m_wdrvs.Remove(drv);
+  pthread_mutex_unlock(&m_dm->m_mutex);
 }
 

Modified: development/source/drivers/cDriverManager.h
===================================================================
--- development/source/drivers/cDriverManager.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/drivers/cDriverManager.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -14,9 +14,12 @@
 #include "tList.h"
 #endif
 
+#include <pthread.h>
+
 class cAvidaDriver;
 class cWorldDriver;
 
+
 class cDriverManager
 {
 private:
@@ -25,15 +28,18 @@
   tList<cAvidaDriver> m_adrvs;
   tList<cWorldDriver> m_wdrvs;
   
-  cDriverManager() { ; }
+  pthread_mutex_t m_mutex;
+  
+  cDriverManager() { pthread_mutex_init(&m_mutex, NULL); }
   ~cDriverManager();
 
   cDriverManager(const cDriverManager&); // @not_implemented
   cDriverManager& operator=(const cDriverManager&); // @not_implemented
 
+  static void Destroy();    // destory the driver manager, and all registered drivers.  Registered with atexit(). 
+
 public:
   static void Initialize(); // initialize static driver manager.  This method is NOT thread-safe.
-  static void Destroy();    // destory the driver manager, and all registered drivers.  Registered with atexit(). 
 
   static void Register(cAvidaDriver* drv);
   static void Register(cWorldDriver* drv);

Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/event/cEventManager.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -10,6 +10,8 @@
 
 #include "cEventManager.h"
 
+#include "cAction.h"
+#include "cActionLibrary.h"
 #include "cAnalyzeUtil.h"
 #include "cAvidaContext.h"
 #include "avida.h"
@@ -1393,8 +1395,7 @@
   void Process(){
     if (cell_id == -1) cell_id = m_world->GetRandom().GetUInt(m_world->GetPopulation().GetSize());
     
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
     
     cGenome genome =
       cInstUtil::RandomGenome(ctx, length, m_world->GetHardwareManager().GetInstSet());
@@ -1816,8 +1817,7 @@
   }
   ///// predict_w_landscape /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome & genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -1846,9 +1846,8 @@
     if (args == "") datafile="land-predict.dat"; else datafile=args.PopWord();
   }
   ///// predict_nu_landscape /////
-  void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+  void Process() {
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -1878,13 +1877,13 @@
   }
   ///// sample_landscape /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
     if (sample_size == 0) sample_size = m_world->GetHardwareManager().GetInstSet().GetSize() - 1;
-    landscape.SampleProcess(ctx, sample_size);
+    landscape.SetTrials(sample_size);
+    landscape.SampleProcess(ctx);
     landscape.PrintStats(m_world->GetDataFileOFStream("land-sample.dat"), m_world->GetStats().GetUpdate());
   }
 };
@@ -1919,8 +1918,7 @@
   }
   ///// random_landscape /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome & genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2427,8 +2425,7 @@
     m_args = in_args; }
   ///// hillclimb /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2455,8 +2452,7 @@
     m_args = in_args; }
   ///// hillclimb_neut /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2483,8 +2479,7 @@
     m_args = in_args; }
   ///// hillclimb_rand /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cGenome& genome = m_world->GetClassificationManager().GetBestGenotype()->GetGenome();
     cLandscape landscape(m_world, genome, m_world->GetHardwareManager().GetInstSet());
@@ -2688,8 +2683,7 @@
   
   ///// test_threads /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
     testcpu->TestThreads(ctx, m_world->GetClassificationManager().GetBestGenotype()->GetGenome());
@@ -2716,8 +2710,7 @@
   }
   ///// print_threads /////
   void Process(){
-    // @DMB - Warning: Creating context out of band.
-    cAvidaContext ctx(m_world->GetRandom());
+    cAvidaContext& ctx = m_world->GetDefaultContext();
 
     cTestCPU* testcpu = m_world->GetHardwareManager().CreateTestCPU();
     testcpu->PrintThreads(ctx, m_world->GetClassificationManager().GetBestGenotype()->GetGenome() );
@@ -3537,6 +3530,29 @@
   }
 };
 
+class cEventAction : public cEvent
+{
+private:
+  cAction* m_action;
+
+public:
+  cEventAction(cWorld* world, cAction* action, const cString& args)
+    : m_action(action) { Configure(world, args); }
+  ~cEventAction() { delete m_action; }
+  
+  const cString GetName() const { return "action wrapper"; }
+  const cString GetDescription() const { return "action wrapper - description not available"; }
+  
+  void Configure(cWorld* world, const cString& in_args) { m_world = world; m_args = in_args; }
+  void Process()
+  {
+    cAvidaContext& ctx = m_world->GetDefaultContext();
+    m_action->Process(ctx);
+  }
+};
+
+
+
 #define REGISTER(EVENT_NAME) Register<cEvent_ ## EVENT_NAME>(#EVENT_NAME)
 
 cEventManager::cEventManager(cWorld* world) : m_world(world)
@@ -3656,7 +3672,14 @@
 cEvent* cEventManager::ConstructEvent(const cString name, const cString & args)
 {
   cEvent* event = Create(name);
-  event->Configure(m_world, args);
+  
+  if (event != NULL) {
+    event->Configure(m_world, args);
+  } else {
+    cAction* action = m_world->GetActionLibrary().Create(name, m_world, args);
+    if (action != NULL) event = new cEventAction(m_world, action, args);
+  }
+  
   return event;
 }
 

Modified: development/source/main/cAvidaContext.h
===================================================================
--- development/source/main/cAvidaContext.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cAvidaContext.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -16,15 +16,20 @@
 {
 private:
   cRandom* m_rng;
+  bool m_analyze;
   
 public:
-  cAvidaContext(cRandom& rng) : m_rng(&rng) { ; }
-  cAvidaContext(cRandom* rng) : m_rng(rng) { ; }
+  cAvidaContext(cRandom& rng) : m_rng(&rng), m_analyze(false) { ; }
+  cAvidaContext(cRandom* rng) : m_rng(rng), m_analyze(false) { ; }
   ~cAvidaContext() { ; }
   
   void SetRandom(cRandom& rng) { m_rng = &rng; }  
   void SetRandom(cRandom* rng) { m_rng = rng; }  
   cRandom& GetRandom() { return *m_rng; }
+  
+  void SetAnalyzeMode() { m_analyze = true; }
+  void ClearAnalyzeMode() { m_analyze = false; }
+  bool GetAnalyzeMode() { return m_analyze; }
 };
 
 #endif

Modified: development/source/main/cFitnessMatrix.cc
===================================================================
--- development/source/main/cFitnessMatrix.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cFitnessMatrix.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -21,8 +21,7 @@
   :  m_world(world), m_start_genotype(m_world, code), m_inst_set( inst_set ), m_DFS_MaxDepth(0),
      m_DFS_NumRecorded(0)
 {
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = world->GetDefaultContext();
   
   m_start_genotype.SetNumInstructions( m_inst_set->GetSize());
   m_start_genotype.CalcFitness(ctx);
@@ -125,8 +124,7 @@
 
   // MyCodeArrayLessThan myLess;
 
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
 
   for (list_iter = theMutants.begin(); list_iter != theMutants.end(); list_iter++)
     {

Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cLandscape.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -26,7 +26,7 @@
 
 
 cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set)
-: m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1)
+: m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1), trials(1)
 {
   site_count = NULL;
   Reset(in_genome);
@@ -492,9 +492,8 @@
 }
 
 
-void cLandscape::SampleProcess(cAvidaContext& ctx, int in_trials)
+void cLandscape::SampleProcess(cAvidaContext& ctx)
 {
-  trials = in_trials;  // Trials _per line_
   distance = 1;
   
   cGenome mod_genome(base_genome);

Modified: development/source/main/cLandscape.h
===================================================================
--- development/source/main/cLandscape.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cLandscape.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -31,7 +31,7 @@
 class cInstruction;
 class cWorld;
 
-struct cLandscape
+class cLandscape
 {
 private:
   cWorld* m_world;
@@ -112,8 +112,10 @@
   void ProcessInsert(cAvidaContext& ctx);
   void PredictWProcess(cAvidaContext& ctx, std::ostream& fp, int update = -1);
   void PredictNuProcess(cAvidaContext& ctx, std::ostream& fp, int update = -1);
+  
+  void SetTrials(int in_trials) { trials = in_trials; }
 
-  void SampleProcess(cAvidaContext& ctx, int in_trials);
+  void SampleProcess(cAvidaContext& ctx);
   int RandomProcess(cAvidaContext& ctx, int in_trials, int in_distance = 1, int min_found = 0,
                     int max_trials = 0, bool print_if_found = false);
 

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cPopulation.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -1840,8 +1840,7 @@
 {
   assert(cell_id >= 0 && cell_id < cell_array.GetSize());
   
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
   
   cOrganism* new_organism = new cOrganism(m_world, ctx, new_genotype->GetGenome());
   
@@ -1882,8 +1881,7 @@
 {
   assert(cell_id >= 0 && cell_id < cell_array.GetSize());
   
-  // @DMB - Warning: Creating context out of band.
-  cAvidaContext ctx(m_world->GetRandom());
+  cAvidaContext& ctx = m_world->GetDefaultContext();
   
   cOrganism* new_organism = new cOrganism(m_world, ctx, orig_org.GetGenome());
   

Modified: development/source/main/cWorld.cc
===================================================================
--- development/source/main/cWorld.cc	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cWorld.cc	2006-04-10 17:31:08 UTC (rev 603)
@@ -10,6 +10,8 @@
 #include "cWorld.h"
 
 #include "avida.h"
+#include "cActionLibrary.h"
+#include "cAnalyze.h"
 #include "cAvidaTriggers.h"
 #include "cClassificationManager.h"
 #include "cEnvironment.h"
@@ -23,11 +25,15 @@
 #include "cTools.h"
 #include "cFallbackWorldDriver.h"
 
+#include "LandscapeActions.h"
 
+
 cWorld::~cWorld()
 {
   m_data_mgr->FlushAll();
 
+  delete m_actlib;
+  delete m_analyze;
   delete m_conf;
   delete m_data_mgr;
   delete m_env;
@@ -53,6 +59,9 @@
   if (rand_seed != m_rng.GetSeed()) cout << " -> " << m_rng.GetSeed();
   cout << endl;
   
+  m_actlib = new cActionLibrary();
+  RegisterLandscapeActions(m_actlib);
+  
   // The data directory should end in a '/'
   cString dir = m_conf->DATA_DIR.Get();
   char dir_tail = dir[dir.GetSize() - 1];
@@ -96,6 +105,12 @@
   m_test_sterilize = (sterilize_fatal || sterilize_neg || sterilize_neut || sterilize_pos);
 }
 
+cAnalyze& cWorld::GetAnalyze()
+{
+  if (m_analyze == NULL) m_analyze = new cAnalyze(this);
+  return *m_analyze;
+}
+
 void cWorld::ReadEventListFile(const cString & filename)
 {
   cInitFile event_file(filename);

Modified: development/source/main/cWorld.h
===================================================================
--- development/source/main/cWorld.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/main/cWorld.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -13,6 +13,9 @@
 #ifndef cAvidaConfig_h
 #include "cAvidaConfig.h"
 #endif
+#ifndef cAvidaContext_h
+#include "cAvidaContext.h"
+#endif
 #ifndef cDataFileManager_h
 #include "cDataFileManager.h"
 #endif
@@ -20,6 +23,8 @@
 #include "cRandom.h"
 #endif
 
+class cActionLibrary;
+class cAnalyze;
 class cAvidaDriver;
 class cClassificationManager;
 class cEnvironment;
@@ -34,7 +39,10 @@
 class cWorld
 {
 protected:
+  cActionLibrary* m_actlib;
+  cAnalyze* m_analyze;
   cAvidaConfig* m_conf;
+  cAvidaContext m_ctx;
   cClassificationManager* m_class_mgr;
   cDataFileManager* m_data_mgr;
   cEnvironment* m_env;
@@ -59,15 +67,18 @@
   cWorld& operator=(const cWorld&); // @not_implemented
   
 public:
-  explicit cWorld() : m_conf(new cAvidaConfig()) { Setup(); }
-  cWorld(cAvidaConfig* cfg) : m_conf(cfg) { Setup(); }
+  explicit cWorld() : m_analyze(NULL), m_conf(new cAvidaConfig()), m_ctx(m_rng) { Setup(); }
+  cWorld(cAvidaConfig* cfg) : m_analyze(NULL), m_conf(cfg), m_ctx(m_rng) { Setup(); }
   ~cWorld();
   
   void SetConfig(cAvidaConfig* cfg) { delete m_conf; m_conf = cfg; }
   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; }
   cClassificationManager& GetClassificationManager() { return *m_class_mgr; }
   cDataFileManager& GetDataFileManager() { return *m_data_mgr; }
   cEnvironment& GetEnvironment() { return *m_env; }

Modified: development/source/targets/avida/CMakeLists.txt
===================================================================
--- development/source/targets/avida/CMakeLists.txt	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/targets/avida/CMakeLists.txt	2006-04-10 17:31:08 UTC (rev 603)
@@ -2,9 +2,9 @@
 
 ADD_EXECUTABLE(avida primitive.cc)
 IF(MSVC)
-  TARGET_LINK_LIBRARIES(avida main classification cpu event analyze drivers analyze cpu tools main)
+  TARGET_LINK_LIBRARIES(avida main classification cpu event analyze drivers analyze cpu tools actions main)
 ELSE(MSVC)
-  TARGET_LINK_LIBRARIES(avida main classification cpu event analyze drivers analyze cpu tools pthread main)
+  TARGET_LINK_LIBRARIES(avida main classification cpu event analyze drivers analyze cpu tools actions pthread main)
 ENDIF(MSVC)
 LINK_DIRECTORIES(${ALL_LIB_DIRS})
 INSTALL_TARGETS(/work avida)

Modified: development/source/targets/avida-viewer/CMakeLists.txt
===================================================================
--- development/source/targets/avida-viewer/CMakeLists.txt	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/targets/avida-viewer/CMakeLists.txt	2006-04-10 17:31:08 UTC (rev 603)
@@ -38,6 +38,7 @@
   main
   tools
   trio
+  actions
   ${NCURSES_LIBRARY}
 )
 ELSE(MSVC)
@@ -54,6 +55,7 @@
   main
   tools
   trio
+  actions
   ${NCURSES_LIBRARY}
   pthread
 )

Modified: development/source/tools/tDictionary.h
===================================================================
--- development/source/tools/tDictionary.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/tools/tDictionary.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -43,11 +43,11 @@
   int GetSize() { return m_hash.GetSize(); }
   void Add(const cString & name, T data) { m_hash.Add(name, data); }
   void SetValue(const cString & name, T data) { m_hash.SetValue(name, data); }
-  bool HasEntry(const cString & name) { return m_hash.HasEntry(name); }
-  bool Find(const cString & name, T & out_data) { return m_hash.Find(name, out_data); }
+  bool HasEntry(const cString & name) const { return m_hash.HasEntry(name); }
+  bool Find(const cString & name, T & out_data) const { return m_hash.Find(name, out_data); }
   T Remove(const cString & name) { return m_hash.Remove(name); }
   void SetHash(int _hash) { m_hash.SetTableSize(_hash); }
-  void AsLists(tList<cString> & name_list, tList<T> & value_list)
+  void AsLists(tList<cString> & name_list, tList<T> & value_list) const
   {
     m_hash.AsLists(name_list, value_list);
   }

Modified: development/source/tools/tHashTable.h
===================================================================
--- development/source/tools/tHashTable.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/tools/tHashTable.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -88,7 +88,7 @@
   tArray< tListNode< tHashEntry<HASH_TYPE, DATA_TYPE> > * > cell_array;
   
   // Create an iterator for entry_list
-  tListIterator< tHashEntry<HASH_TYPE, DATA_TYPE> > list_it;
+  mutable tListIterator< tHashEntry<HASH_TYPE, DATA_TYPE> > list_it;
   
   // Create a set of HashKey methods for each of the basic data types that
   // we allow:
@@ -104,7 +104,7 @@
   // that string and modding by the hash size.  For most applications this
   // will work fine (and reasonably fast!) but some patterns will cause all
   // strings to go into the same cell.  For example, "ABC"=="CBA"=="BBB".
-  int HashKey(const cString & key) const {
+  int HashKey(const cString& key) const {
     unsigned int out_hash = 0;
     for (int i = 0; i < key.GetSize(); i++)
       out_hash += (unsigned int) key[i];
@@ -113,7 +113,7 @@
   
   // Function to find the appropriate tHashEntry for a key that is passed
   // in and return it.
-  tHashEntry<HASH_TYPE, DATA_TYPE> * FindEntry(const HASH_TYPE & key) {
+  tHashEntry<HASH_TYPE, DATA_TYPE> * FindEntry(const HASH_TYPE& key) const {
     const int bin = HashKey(key);
     if (cell_array[bin] == NULL) return NULL;
     
@@ -156,7 +156,7 @@
   }
   
   
-  bool OK() {
+  bool OK() const {
     std::cout << "ENTRY_COUNT = " << entry_count << std::endl;
     std::cout << "TABLE_SIZE = " << table_size << std::endl;
     int count = 0;
@@ -186,7 +186,7 @@
     return true;
   }
   
-  int GetSize() { return entry_count; }
+  int GetSize() const { return entry_count; }
   
   // This function is used to add a new entry...
   void Add(const HASH_TYPE & key, DATA_TYPE data) {
@@ -225,11 +225,11 @@
   }
   
   
-  bool HasEntry(const HASH_TYPE & key) {
+  bool HasEntry(const HASH_TYPE & key) const {
     return FindEntry(key) != NULL;
   }
   
-  bool Find(const HASH_TYPE & key, DATA_TYPE & out_data) {
+  bool Find(const HASH_TYPE & key, DATA_TYPE & out_data) const {
     tHashEntry<HASH_TYPE, DATA_TYPE> * found_entry = FindEntry(key);
     if (found_entry != NULL) {
       out_data = found_entry->data;
@@ -304,7 +304,7 @@
   // The following method allows the user to convert the dictionary contents
   // into lists.  Empty lists show be passed in as arguments and the method
   // will fill in their contents.
-  void AsLists(tList<HASH_TYPE> & key_list, tList<DATA_TYPE> & value_list) {
+  void AsLists(tList<HASH_TYPE> & key_list, tList<DATA_TYPE> & value_list) const {
     // Setup the lists to fill in.
     assert(key_list.GetSize() == 0);
     assert(value_list.GetSize() == 0);

Modified: development/source/tools/tObjectFactory.h
===================================================================
--- development/source/tools/tObjectFactory.h	2006-04-08 13:28:45 UTC (rev 602)
+++ development/source/tools/tObjectFactory.h	2006-04-10 17:31:08 UTC (rev 603)
@@ -102,6 +102,8 @@
     for (int i = 0; names_it.Next() != NULL; i++)
       objects[i] = Create(*names_it.Get());
   }
+  
+  bool Supports(const cString& key) const { return m_create_funcs.HasEntry(key); }
 };
 
 template<typename BaseType, typename Arg1Type>
@@ -114,7 +116,7 @@
   int m_factory_id;
   
 public:
-    tObjectFactory() : m_factory_id(0) { ; }
+  tObjectFactory() : m_factory_id(0) { ; }
   virtual ~tObjectFactory() { ; }
   
   void SetFactoryId(int id) { m_factory_id = id; }
@@ -142,5 +144,92 @@
     
     return NULL;
   }
+
+  bool Supports(const cString& key) const { return m_create_funcs.HasEntry(key); }
 };
+
+template<typename BaseType, typename Arg1Type, typename Arg2Type>
+class tObjectFactory<BaseType (Arg1Type, Arg2Type)>
+{
+protected:
+  typedef BaseType (*CreateObjectFunction)(Arg1Type, Arg2Type);
+  
+  tDictionary<CreateObjectFunction> m_create_funcs;
+  int m_factory_id;
+  
+public:
+    tObjectFactory() : m_factory_id(0) { ; }
+  virtual ~tObjectFactory() { ; }
+  
+  void SetFactoryId(int id) { m_factory_id = id; }
+  int GetFactoryId() { return m_factory_id; }
+  
+  template<typename ClassType> bool Register(const cString& key)
+  {
+    CreateObjectFunction func;
+    if (m_create_funcs.Find(key, func)) return false;
+    
+    m_create_funcs.Add(key, &nObjectFactory::createObject<BaseType, ClassType, Arg1Type, Arg2Type>);
+    return true;
+  }
+  
+  bool Unregister(const cString& key)
+  {
+    return (m_create_funcs.Remove(key) != NULL);
+  }
+  
+  virtual BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2)
+  {
+    CreateObjectFunction func;
+    if (m_create_funcs.Find(key, func))
+      return func(arg1, arg2);
+    
+    return NULL;
+  }
+
+  bool Supports(const cString& key) const { return m_create_funcs.HasEntry(key); }
+};
+
+template<typename BaseType, typename Arg1Type, typename Arg2Type, typename Arg3Type>
+class tObjectFactory<BaseType (Arg1Type, Arg2Type, Arg3Type)>
+{
+protected:
+  typedef BaseType (*CreateObjectFunction)(Arg1Type, Arg2Type, Arg3Type);
+  
+  tDictionary<CreateObjectFunction> m_create_funcs;
+  int m_factory_id;
+  
+public:
+    tObjectFactory() : m_factory_id(0) { ; }
+  virtual ~tObjectFactory() { ; }
+  
+  void SetFactoryId(int id) { m_factory_id = id; }
+  int GetFactoryId() { return m_factory_id; }
+  
+  template<typename ClassType> bool Register(const cString& key)
+  {
+    CreateObjectFunction func;
+    if (m_create_funcs.Find(key, func)) return false;
+    
+    m_create_funcs.Add(key, &nObjectFactory::createObject<BaseType, ClassType, Arg1Type, Arg2Type, Arg3Type>);
+    return true;
+  }
+  
+  bool Unregister(const cString& key)
+  {
+    return (m_create_funcs.Remove(key) != NULL);
+  }
+  
+  virtual BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
+  {
+    CreateObjectFunction func;
+    if (m_create_funcs.Find(key, func))
+      return func(arg1, arg2, arg3);
+    
+    return NULL;
+  }
+
+  bool Supports(const cString& key) const { return m_create_funcs.HasEntry(key); }
+};
+
 #endif




More information about the Avida-cvs mailing list