[Avida-SVN] [avida-svn] r1032 - in development: documentation source/analyze source/main support/config
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Oct 9 17:27:01 PDT 2006
Author: brysonda
Date: 2006-10-09 20:27:00 -0400 (Mon, 09 Oct 2006)
New Revision: 1032
Modified:
development/documentation/analyze.html
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyze.h
development/source/main/cAvidaConfig.cc
development/source/main/cAvidaConfig.h
development/support/config/avida.cfg
Log:
Add in two new analysis commands for manipulating and retrieving configuration values, CONFIG_GET and CONFIG_SET.
CONFIG_GET <config var name> <analyze mode var name>
This will retrieve the value of the supplied configuration variable and place it into the supplied analyze mode variable. For example, 'CONFIG_GET RANDOM_SEED r' will place the value of the random number seed (as specified in the configuration settings) into the variable r.
CONFIG_SET <config var name> <value>
This will set the supplied configuration variable to the value specified with the command.
Additionally, added two string variables into the configuration file, ANALYZE_OPTION_1 and ANALYZE_OPTION_2. These variables are for exclusive use in passing values into analysis scripts.
Updated analyze documentation with the newly added commands.
Modified: development/documentation/analyze.html
===================================================================
--- development/documentation/analyze.html 2006-10-06 20:25:22 UTC (rev 1031)
+++ development/documentation/analyze.html 2006-10-10 00:27:00 UTC (rev 1032)
@@ -654,6 +654,16 @@
<dd>
Sets the variable to the value...
</dd>
+<dt><strong>CONFIG_GET [<span class="cmdarg">config variable</span>] [<span class="cmdarg">variable</span>]</strong></dt>
+<dd>
+ Retrieves the value of the supplied configuration variable and places it into the supplied analyze mode variable.
+ For example, 'CONFIG_GET RANDOM_SEED r' will place the value of the random number seed (as specified in the
+ configuration settings) into the variable r.
+</dd>
+<dt><strong>CONFIG_SET [<span class="cmdarg">config variable</span>] [<span class="cmdarg">value</span>]</strong></dt>
+<dd>
+ Sets the supplied configuration variable to the value specified with the command.
+</dd>
<dt><strong>
FOREACH [<span class="cmdarg">variable</span>] [<span class="cmdarg">value</span>]
[<span class="cmdargopt">value ...</span>]
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2006-10-06 20:25:22 UTC (rev 1031)
+++ development/source/analyze/cAnalyze.cc 2006-10-10 00:27:00 UTC (rev 1032)
@@ -6760,7 +6760,7 @@
return;
}
- cString & cur_variable = GetVariable(var);
+ cString& cur_variable = GetVariable(var);
cur_variable = cur_string.PopWord();
if (m_world->GetVerbosity() >= VERBOSE_ON) {
@@ -6768,6 +6768,49 @@
}
}
+void cAnalyze::ConfigGet(cString cur_string)
+{
+ cString cvar = cur_string.PopWord();
+ cString var = cur_string.PopWord();
+
+ if (cvar.GetSize() == 0 || var.GetSize() == 0) {
+ cerr << "Error: Missing variable in CONFIG_GET command" << endl;
+ return;
+ }
+
+ cString& cur_variable = GetVariable(var);
+
+ // Get Config Variable
+ if (!m_world->GetConfig().Get(cvar, cur_variable)) {
+ cerr << "Error: Configuration Variable '" << var << "' was not found." << endl;
+ return;
+ }
+
+ if (m_world->GetVerbosity() >= VERBOSE_ON)
+ cout << "Setting variable " << var << " to " << cur_variable << endl;
+}
+
+void cAnalyze::ConfigSet(cString cur_string)
+{
+ cString cvar = cur_string.PopWord();
+
+ if (cvar.GetSize() == 0) {
+ cerr << "Error: No variable provided in CONFIG_SET command" << endl;
+ return;
+ }
+
+ // Get Config Variable
+ cString val = cur_string.PopWord();
+ if (!m_world->GetConfig().Set(cvar, val)) {
+ cerr << "Error: Configuration Variable '" << cvar << "' was not found." << endl;
+ return;
+ }
+
+ if (m_world->GetVerbosity() >= VERBOSE_ON)
+ cout << "Setting configuration variable " << cvar << " to " << val << endl;
+}
+
+
void cAnalyze::BatchSet(cString cur_string)
{
int next_batch = 0;
@@ -7203,7 +7246,7 @@
}
-cString & cAnalyze::GetVariable(const cString & var)
+cString& cAnalyze::GetVariable(const cString & var)
{
if (var.GetSize() != 1 ||
(var.IsLetter(0) == false && var.IsNumeric(0) == false)) {
@@ -7686,6 +7729,8 @@
// Control commands...
AddLibraryDef("SET", &cAnalyze::VarSet);
+ AddLibraryDef("CONFIG_GET", &cAnalyze::ConfigGet);
+ AddLibraryDef("CONFIG_SET", &cAnalyze::ConfigSet);
AddLibraryDef("SET_BATCH", &cAnalyze::BatchSet);
AddLibraryDef("NAME_BATCH", &cAnalyze::BatchName);
AddLibraryDef("TAG_BATCH", &cAnalyze::BatchTag);
Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h 2006-10-06 20:25:22 UTC (rev 1031)
+++ development/source/analyze/cAnalyze.h 2006-10-10 00:27:00 UTC (rev 1032)
@@ -208,6 +208,8 @@
// Control...
void VarSet(cString cur_string);
+ void ConfigGet(cString cur_string);
+ void ConfigSet(cString cur_string);
void BatchSet(cString cur_string);
void BatchName(cString cur_string);
void BatchTag(cString cur_string);
Modified: development/source/main/cAvidaConfig.cc
===================================================================
--- development/source/main/cAvidaConfig.cc 2006-10-06 20:25:22 UTC (rev 1031)
+++ development/source/main/cAvidaConfig.cc 2006-10-10 00:27:00 UTC (rev 1032)
@@ -30,7 +30,9 @@
// If the default value was originally a string, it will begin and end with
// quotes. We should make sure to remove those.
if (default_value[0] == '"') {
- default_value = default_value.Substring(1, default_value.GetSize() - 2);
+ if (default_value.GetSize() > 2)
+ default_value = default_value.Substring(1, default_value.GetSize() - 2);
+ else default_value = "";
}
}
@@ -384,7 +386,7 @@
arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
}
- // Loop through all groups, then all entrys, and try to load each one.
+ // Loop through all groups, then all entries, and try to load each one.
tListIterator<cBaseConfigGroup> group_it(cfg->group_list);
cBaseConfigGroup* cur_group;
cString val;
@@ -406,3 +408,40 @@
return cfg;
}
+bool cAvidaConfig::Get(const cString& entry, cString& ret) const
+{
+ // Loop through all groups, then all entries, searching for the specified entry.
+ tConstListIterator<cBaseConfigGroup> group_it(group_list);
+ const cBaseConfigGroup* cur_group;
+ while ((cur_group = group_it.Next()) != NULL) {
+ // Loop through entries for this group...
+ tConstListIterator<cBaseConfigEntry> entry_it(cur_group->GetEntryList());
+ const cBaseConfigEntry* cur_entry;
+ while ((cur_entry = entry_it.Next()) != NULL) {
+ if (cur_entry->GetName() == entry) {
+ ret = cur_entry->AsString();
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool cAvidaConfig::Set(const cString& entry, const cString& val)
+{
+ // Loop through all groups, then all entries, searching for the specified entry.
+ tListIterator<cBaseConfigGroup> group_it(group_list);
+ cBaseConfigGroup* cur_group;
+ while ((cur_group = group_it.Next()) != NULL) {
+ // Loop through entries for this group...
+ tListIterator<cBaseConfigEntry> entry_it(cur_group->GetEntryList());
+ cBaseConfigEntry* cur_entry;
+ while ((cur_entry = entry_it.Next()) != NULL) {
+ if (cur_entry->GetName() == entry) {
+ cur_entry->LoadString(val);
+ return true;
+ }
+ }
+ }
+ return false;
+}
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2006-10-06 20:25:22 UTC (rev 1031)
+++ development/source/main/cAvidaConfig.h 2006-10-10 00:27:00 UTC (rev 1032)
@@ -49,22 +49,22 @@
// accessors were declared above, we can refer to this setting by the
// setting name inside of config.
-#define CONFIG_ADD_VAR(NAME, TYPE, DEFAULT, DESC) /* 1 */ \
-class cEntry_ ## NAME : public cBaseConfigEntry { /* 2 */ \
-private: \
- TYPE value; /* 3 */ \
-public: \
- void LoadString(const cString & str_value) { /* 4 */ \
- value = cStringUtil::Convert(str_value, value); \
- } \
- cEntry_ ## NAME() : cBaseConfigEntry(#NAME, #TYPE, #DEFAULT, DESC) {/* 5 */ \
- LoadString(GetDefault()); /* 6 */ \
- global_group_list.GetLast()->AddEntry(this); /* 7 */ \
- } \
- TYPE Get() const { return value; } /* 8 */ \
- void Set(TYPE in_value) { value = in_value; } \
- cString AsString() { return cStringUtil::Convert(value); } /* 9 */ \
-} NAME /* 10 */ \
+#define CONFIG_ADD_VAR(NAME, TYPE, DEFAULT, DESC) /* 1 */ \
+class cEntry_ ## NAME : public cBaseConfigEntry { /* 2 */ \
+private: \
+ TYPE value; /* 3 */ \
+public: \
+ void LoadString(const cString& str_value) { /* 4 */ \
+ value = cStringUtil::Convert(str_value, value); \
+ } \
+ cEntry_ ## NAME() : cBaseConfigEntry(#NAME, #TYPE, #DEFAULT, DESC) { /* 5 */ \
+ LoadString(GetDefault()); /* 6 */ \
+ global_group_list.GetLast()->AddEntry(this); /* 7 */ \
+ } \
+ TYPE Get() const { return value; } /* 8 */ \
+ void Set(TYPE in_value) { value = in_value; } \
+ cString AsString() const { return cStringUtil::Convert(value); } /* 9 */ \
+} NAME /* 10 */ \
// Now we're going to make another macro to deal with groups. This time its
@@ -95,20 +95,21 @@
// values (not changeable at run time). Should this instance be one of
// those classes?
bool use_overide;
+
public:
- cBaseConfigEntry(const cString & _name, const cString & _type,
- const cString & _def, const cString & _desc);
+ cBaseConfigEntry(const cString& _name, const cString& _type,
+ const cString& _def, const cString& _desc);
virtual ~cBaseConfigEntry() { ; }
- virtual void LoadString(const cString & str_value) = 0;
+ virtual void LoadString(const cString& str_value) = 0;
- const cString & GetName() { return config_name; }
- const cString & GetType() { return type; }
- const cString & GetDefault() { return default_value; }
- const cString & GetDesc() { return description; }
- bool GetUseOveride() { return use_overide; }
+ const cString& GetName() const { return config_name; }
+ const cString& GetType() const { return type; }
+ const cString& GetDefault() const { return default_value; }
+ const cString& GetDesc() const { return description; }
+ bool GetUseOveride() const { return use_overide; }
- virtual cString AsString() = 0;
+ virtual cString AsString() const = 0;
};
// The cBaseConfigGroup class is a bass class for objects that collect the
@@ -119,15 +120,16 @@
cString description;
tList<cBaseConfigEntry> entry_list;
public:
- cBaseConfigGroup(const cString & _name, const cString & _desc)
+ cBaseConfigGroup(const cString& _name, const cString& _desc)
: group_name(_name), description(_desc) { global_group_list.PushRear(this); }
~cBaseConfigGroup() { ; }
- const cString & GetName() { return group_name; }
- const cString & GetDesc() { return description; }
- tList<cBaseConfigEntry> & GetEntryList() { return entry_list; }
+ const cString& GetName() const { return group_name; }
+ const cString& GetDesc() const { return description; }
+ tList<cBaseConfigEntry>& GetEntryList() { return entry_list; }
+ const tList<cBaseConfigEntry>& GetEntryList() const { return entry_list; }
- void AddEntry(cBaseConfigEntry * _entry) { entry_list.PushRear(_entry); }
+ void AddEntry(cBaseConfigEntry* _entry) { entry_list.PushRear(_entry); }
};
// We need to keep track of all configuration groups and the entry objects
@@ -153,7 +155,6 @@
CONFIG_ADD_VAR(ANALYZE_MODE, int, 0, "0 = Disabled\n1 = Enabled\n2 = Interactive");
CONFIG_ADD_VAR(VIEW_MODE, int, 0, "Initial viewer screen");
CONFIG_ADD_VAR(CLONE_FILE, cString, "-", "Clone file to load");
- CONFIG_ADD_VAR(MT_CONCURRENCY, int, 1, "Number of concurrent analyze threads");
CONFIG_ADD_VAR(VERBOSITY, int, 1, "Control output verbosity");
CONFIG_ADD_GROUP(ARCH_GROUP, "Architecture Variables");
@@ -275,6 +276,11 @@
CONFIG_ADD_VAR(SAVE_RECEIVED, bool, 0, "Enable storage of all inputs bought from other orgs");
CONFIG_ADD_VAR(BUY_PRICE, int, 0, "price offered by organisms attempting to buy");
CONFIG_ADD_VAR(SELL_PRICE, int, 0, "price offered by organisms attempting to sell");
+
+ CONFIG_ADD_GROUP(ANALYZE_GROUP, "Analysis Settings");
+ CONFIG_ADD_VAR(MT_CONCURRENCY, int, 1, "Number of concurrent analyze threads");
+ CONFIG_ADD_VAR(ANALYZE_OPTION_1, cString, "", "String variable accessible from analysis scripts");
+ CONFIG_ADD_VAR(ANALYZE_OPTION_2, cString, "", "String variable accessible from analysis scripts");
#endif
@@ -282,6 +288,9 @@
void Print(const cString& filename);
void Status();
+ bool Get(const cString& entry, cString& ret) const;
+ bool Set(const cString& entry, const cString& val);
+
void GenerateOverides();
};
Modified: development/support/config/avida.cfg
===================================================================
--- development/support/config/avida.cfg 2006-10-06 20:25:22 UTC (rev 1031)
+++ development/support/config/avida.cfg 2006-10-10 00:27:00 UTC (rev 1032)
@@ -7,13 +7,12 @@
### GENERAL_GROUP ###
# General Settings
-ANALYZE_MODE 0 # 0 = Disabled
- # 1 = Enabled
- # 2 = Interactive
-VIEW_MODE 0 # Initial viewer screen
-CLONE_FILE - # Clone file to load
-MT_CONCURRENCY 1 # Number of concurrent analyze threads
-VERBOSITY 1 # Control output verbosity
+ANALYZE_MODE 0 # 0 = Disabled
+ # 1 = Enabled
+ # 2 = Interactive
+VIEW_MODE 0 # Initial viewer screen
+CLONE_FILE - # Clone file to load
+VERBOSITY 1 # Control output verbosity
### ARCH_GROUP ###
# Architecture Variables
@@ -204,3 +203,9 @@
SAVE_RECEIVED 0 # Enable storage of all inputs bought from other orgs
BUY_PRICE 0 # price offered by organisms attempting to buy
SELL_PRICE 0 # price offered by organisms attempting to sell
+
+### ANALYZE_GROUP ###
+# Analysis Settings
+MT_CONCURRENCY 1 # Number of concurrent analyze threads
+ANALYZE_OPTION_1 # String variable accessible from analysis scripts
+ANALYZE_OPTION_2 # String variable accessible from analysis scripts
More information about the Avida-cvs
mailing list