[Avida-SVN] r1469 - in development: documentation/notes source/actions source/tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Apr 6 17:46:26 PDT 2007
Author: brysonda
Date: 2007-04-06 20:46:26 -0400 (Fri, 06 Apr 2007)
New Revision: 1469
Modified:
development/documentation/notes/release-milestones.txt
development/source/actions/cActionLibrary.h
development/source/tools/tDictionary.h
development/source/tools/tObjectFactory.h
Log:
Back by popular demand... Actions are now treated case-insensitively when instantiating (both in Analyze mode and Events).
Modified: development/documentation/notes/release-milestones.txt
===================================================================
--- development/documentation/notes/release-milestones.txt 2007-04-06 19:36:37 UTC (rev 1468)
+++ development/documentation/notes/release-milestones.txt 2007-04-07 00:46:26 UTC (rev 1469)
@@ -4,6 +4,7 @@
- Planned feature, to be implemented
+ Feature currently in development
* Feature completed, ready for release
+? Planned feature, but possibly delayed to next milestone
Visualized development/support timeline (* current):
@@ -42,20 +43,23 @@
Version 2.7 - development - Target: July 2007 - Status: Active Development
++ Consistency test support
+ * simplify development
+ * automatic expected results
+ + performance tests
++ Consistency test coverage
+ + mid-run (* classic, - transsmt)
+ + analyze mode
+ Transition all applicable output files to cDataFile objects, as opposed to raw ostream
-+ Serialization
-- environment named regions
++ Energy model
++ AvidaScript
+ + lexer
+ - parser
+ - threaded driver, multiple executing worlds via 'avida-s'
- Topology manager
-- Schedulable object framework (organism threads scheduled rather than organisms, events, etc.)
-- Energy model
-+ AvidaScript (AS) lexer
-- AS Parser
-- AS specific executable - 'avida-s'
-- Implement threaded driver, multiple executing worlds via 'avida-s'
-- Win32 Pthreads wrapper library
-+ Consistency test support
-- Make it easier to generate new tails
-- Support under SCons
+ - environment named regions
+? Schedulable object framework (organism threads scheduled rather than organisms, events, etc.)
+? Serialization
- Update documentation
- Code release cleanup
Modified: development/source/actions/cActionLibrary.h
===================================================================
--- development/source/actions/cActionLibrary.h 2007-04-06 19:36:37 UTC (rev 1468)
+++ development/source/actions/cActionLibrary.h 2007-04-07 00:46:26 UTC (rev 1469)
@@ -50,7 +50,7 @@
private:
typedef const cString (*ClassDescFunction)();
- tObjectFactory<cAction* (cWorld*, const cString&)> m_factory;
+ tObjectFactoryNoCase<cAction* (cWorld*, const cString&)> m_factory;
tDictionary<ClassDescFunction> m_desc_funcs;
public:
Modified: development/source/tools/tDictionary.h
===================================================================
--- development/source/tools/tDictionary.h 2007-04-06 19:36:37 UTC (rev 1468)
+++ development/source/tools/tDictionary.h 2007-04-07 00:46:26 UTC (rev 1469)
@@ -60,22 +60,22 @@
// disabled copy constructor.
tDictionary(const tDictionary &);
public:
- tDictionary() { ; }
- tDictionary(int in_hash_size) : m_hash(in_hash_size) { ; }
-
+ inline tDictionary() { ; }
+ inline tDictionary(int in_hash_size) : m_hash(in_hash_size) { ; }
+
// The following methods just call the encapsulated tHashTable
- bool OK() { return m_hash.OK(); }
- 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) 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) const {
+ inline bool OK() { return m_hash.OK(); }
+ inline int GetSize() { return m_hash.GetSize(); }
+ inline void Add(const cString& name, T data) { m_hash.Add(name, data); }
+ inline void SetValue(const cString& name, T data) { m_hash.SetValue(name, data); }
+ inline bool HasEntry(const cString& name) const { return m_hash.HasEntry(name); }
+ inline bool Find(const cString& name, T& out_data) const { return m_hash.Find(name, out_data); }
+ inline T Remove(const cString& name) { return m_hash.Remove(name); }
+ inline void SetHash(int _hash) { m_hash.SetTableSize(_hash); }
+ inline void AsLists(tList<cString>& name_list, tList<T>& value_list) const {
m_hash.AsLists(name_list, value_list);
}
-
+
// This function will take an input string and load its value into the
// dictionary; it will only work for types that cStringUtil can convert to.
void Load(cString load_string, char assign='=') {
@@ -115,4 +115,81 @@
}
};
+
+template <class T> class tDictionaryNoCase {
+#if USE_tMemTrack
+ tMemTrack<tDictionary<T> > mt;
#endif
+private:
+ tHashTable<cString, T> m_hash;
+
+ // disabled copy constructor.
+ tDictionaryNoCase(const tDictionaryNoCase &);
+
+public:
+ inline tDictionaryNoCase() { ; }
+ inline tDictionaryNoCase(int in_hash_size) : m_hash(in_hash_size) { ; }
+
+ // The following methods just call the encapsulated tHashTable
+ inline bool OK() { return m_hash.OK(); }
+ inline int GetSize() { return m_hash.GetSize(); }
+ inline void SetHash(int _hash) { m_hash.SetTableSize(_hash); }
+ inline void AsLists(tList<cString>& name_list, tList<T>& value_list) const {
+ m_hash.AsLists(name_list, value_list);
+ }
+
+
+ // Encapsulated tHashTable methods with No Case functionality
+ inline void Add(const cString& name, T data) { cString uname(name); uname.ToUpper(); m_hash.Add(uname, data); }
+ inline void SetValue(const cString& name, T data) { cString uname(name); uname.ToUpper(); m_hash.SetValue(uname, data); }
+ inline bool HasEntry(const cString& name) const { cString uname(name); uname.ToUpper(); return m_hash.HasEntry(uname); }
+ inline bool Find(const cString& name, T& out_data) const {
+ cString uname(name); uname.ToUpper(); return m_hash.Find(uname, out_data);
+ }
+ inline T Remove(const cString& name) { cString uname(name); uname.ToUpper(); return m_hash.Remove(uname); }
+
+
+ // Fast Accessor Methods - Calling method assumes responsibility for UCasing the key
+ inline bool HasEntryFast(const cString& name) const { return m_hash.HasEntry(name); }
+ inline bool FindFast(const cString& name, T& out_data) const { return m_hash.Find(name, out_data); }
+
+ // This function will take an input string and load its value into the
+ // dictionary; it will only work for types that cStringUtil can convert to.
+ void Load(cString load_string, char assign='=') {
+ // Break the string into two based on the assignment character.
+ cString key(load_string.Pop(assign));
+
+ // Convert the value to the correct type.
+ T value;
+ value = cStringUtil::Convert(load_string, value);
+
+ SetValue(key, value);
+ }
+
+ // This function has no direct implementation in tHashTable
+ // Grabs key/value lists, and processes the keys.
+ cString NearMatch(const cString name) const {
+ tList<cString> keys;
+ tList<T> values;
+ m_hash.AsLists(keys, values);
+
+ cString best_match("");
+ int best_dist = name.GetSize();
+ tListIterator<cString> list_it(keys);
+ while (list_it.Next() != NULL) {
+ int dist = cStringUtil::EditDistance(name, *list_it.Get());
+ if (dist < best_dist) {
+ best_dist = dist;
+ best_match = *list_it.Get();
+ }
+ }
+ return best_match;
+ }
+
+ template<class Archive>
+ void serialize(Archive& a, const unsigned int version){
+ a.ArkvObj("m_hash", m_hash);
+ }
+};
+
+#endif
Modified: development/source/tools/tObjectFactory.h
===================================================================
--- development/source/tools/tObjectFactory.h 2007-04-06 19:36:37 UTC (rev 1468)
+++ development/source/tools/tObjectFactory.h 2007-04-07 00:46:26 UTC (rev 1469)
@@ -42,6 +42,7 @@
template<typename CtorSignature> class tObjectFactory;
+template<typename CtorSignature> class tObjectFactoryNoCase;
namespace nObjectFactory
{
@@ -81,12 +82,12 @@
public:
tObjectFactory() { ; }
- virtual ~tObjectFactory() { ; }
+ ~tObjectFactory() { ; }
template<typename ClassType> bool Register(const cString& key)
{
cMutexAutoLock lock(m_mutex);
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
if (m_create_funcs.Find(key, func)) {
return false;
}
@@ -102,9 +103,9 @@
return (func != NULL);
}
- virtual BaseType Create(const cString& key)
+ BaseType Create(const cString& key)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return func();
@@ -112,7 +113,7 @@
return NULL;
}
- virtual void CreateAll(tArray<BaseType>& objects)
+ void CreateAll(tArray<BaseType>& objects)
{
tList<cString> names;
tList<CreateObjectFunction> funcs;
@@ -137,6 +138,75 @@
}
};
+
+template<typename BaseType>
+class tObjectFactoryNoCase<BaseType ()>
+{
+protected:
+ typedef BaseType (*CreateObjectFunction)();
+
+ tDictionaryNoCase<CreateObjectFunction> m_create_funcs;
+ mutable cMutex m_mutex;
+
+public:
+ tObjectFactoryNoCase() { ; }
+ ~tObjectFactoryNoCase() { ; }
+
+ template<typename ClassType> bool Register(const cString& key)
+ {
+ cMutexAutoLock lock(m_mutex);
+ CreateObjectFunction func = NULL;
+ if (m_create_funcs.Find(key, func)) {
+ return false;
+ }
+
+ m_create_funcs.Add(key, &nObjectFactory::createObject<BaseType, ClassType>);
+ return true;
+ }
+
+ bool Unregister(const cString& key)
+ {
+ cMutexAutoLock lock(m_mutex);
+ CreateObjectFunction func = m_create_funcs.Remove(key);
+ return (func != NULL);
+ }
+
+ BaseType Create(const cString& key)
+ {
+ CreateObjectFunction func = NULL;
+ cMutexAutoLock lock(m_mutex);
+ if (m_create_funcs.Find(key, func)) {
+ return func();
+ }
+ return NULL;
+ }
+
+ void CreateAll(tArray<BaseType>& objects)
+ {
+ tList<cString> names;
+ tList<CreateObjectFunction> funcs;
+ cMutexAutoLock lock(m_mutex);
+
+ m_create_funcs.AsLists(names, funcs);
+ objects.Resize(names.GetSize());
+
+ tListIterator<cString> names_it(names);
+ for (int i = 0; names_it.Next() != NULL; i++) {
+ CreateObjectFunction func = NULL;
+ m_create_funcs.Find(*names_it.Get(), func);
+ objects[i] = func();
+ }
+ }
+
+ bool Supports(const cString& key) const
+ {
+ cMutexAutoLock lock(m_mutex);
+ bool supports = m_create_funcs.HasEntry(key);
+ return supports;
+ }
+};
+
+
template<typename BaseType, typename Arg1Type>
class tObjectFactory<BaseType (Arg1Type)>
{
@@ -148,11 +218,11 @@
public:
tObjectFactory() { ; }
- virtual ~tObjectFactory() { ; }
+ ~tObjectFactory() { ; }
template<typename ClassType> bool Register(const cString& key)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return false;
@@ -169,9 +239,9 @@
return (func != NULL);
}
- virtual BaseType Create(const cString& key, Arg1Type arg1)
+ BaseType Create(const cString& key, Arg1Type arg1)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return func(arg1);
@@ -187,6 +257,59 @@
}
};
+
+template<typename BaseType, typename Arg1Type>
+class tObjectFactoryNoCase<BaseType (Arg1Type)>
+{
+protected:
+ typedef BaseType (*CreateObjectFunction)(Arg1Type);
+
+ tDictionaryNoCase<CreateObjectFunction> m_create_funcs;
+ mutable cMutex m_mutex;
+
+public:
+ tObjectFactoryNoCase() { ; }
+ ~tObjectFactoryNoCase() { ; }
+
+ template<typename ClassType> bool Register(const cString& key)
+ {
+ CreateObjectFunction func = NULL;
+ cMutexAutoLock lock(m_mutex);
+ if (m_create_funcs.Find(key, func)) {
+ return false;
+ }
+
+ m_create_funcs.Add(key, &nObjectFactory::createObject<BaseType, ClassType, Arg1Type>);
+ return true;
+ }
+
+ bool Unregister(const cString& key)
+ {
+ cMutexAutoLock lock(m_mutex);
+ CreateObjectFunction func = m_create_funcs.Remove(key);
+ return (func != NULL);
+ }
+
+ BaseType Create(const cString& key, Arg1Type arg1)
+ {
+ CreateObjectFunction func = NULL;
+ cMutexAutoLock lock(m_mutex);
+ if (m_create_funcs.Find(key, func)) {
+ return func(arg1);
+ }
+ return NULL;
+ }
+
+ bool Supports(const cString& key) const
+ {
+ cMutexAutoLock lock(m_mutex);
+ bool supports = m_create_funcs.HasEntry(key);
+ return supports;
+ }
+};
+
+
+
template<typename BaseType, typename Arg1Type, typename Arg2Type>
class tObjectFactory<BaseType (Arg1Type, Arg2Type)>
{
@@ -198,11 +321,11 @@
public:
tObjectFactory() { ; }
- virtual ~tObjectFactory() { ; }
+ ~tObjectFactory() { ; }
template<typename ClassType> bool Register(const cString& key)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return false;
@@ -219,9 +342,9 @@
return (func != NULL);
}
- virtual BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2)
+ BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return func(arg1, arg2);
@@ -237,6 +360,59 @@
}
};
+
+template<typename BaseType, typename Arg1Type, typename Arg2Type>
+class tObjectFactoryNoCase<BaseType (Arg1Type, Arg2Type)>
+{
+protected:
+ typedef BaseType (*CreateObjectFunction)(Arg1Type, Arg2Type);
+
+ tDictionaryNoCase<CreateObjectFunction> m_create_funcs;
+ mutable cMutex m_mutex;
+
+public:
+ tObjectFactoryNoCase() { ; }
+ ~tObjectFactoryNoCase() { ; }
+
+ template<typename ClassType> bool Register(const cString& key)
+ {
+ CreateObjectFunction func = NULL;
+ cMutexAutoLock lock(m_mutex);
+ 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)
+ {
+ cMutexAutoLock lock(m_mutex);
+ CreateObjectFunction func = m_create_funcs.Remove(key);
+ return (func != NULL);
+ }
+
+ BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2)
+ {
+ CreateObjectFunction func = NULL;
+ cMutexAutoLock lock(m_mutex);
+ if (m_create_funcs.Find(key, func)) {
+ return func(arg1, arg2);
+ }
+ return NULL;
+ }
+
+ bool Supports(const cString& key) const
+ {
+ cMutexAutoLock lock(m_mutex);
+ bool supports = m_create_funcs.HasEntry(key);
+ return supports;
+ }
+};
+
+
+
template<typename BaseType, typename Arg1Type, typename Arg2Type, typename Arg3Type>
class tObjectFactory<BaseType (Arg1Type, Arg2Type, Arg3Type)>
{
@@ -248,11 +424,11 @@
public:
tObjectFactory() { ; }
- virtual ~tObjectFactory() { ; }
+ ~tObjectFactory() { ; }
template<typename ClassType> bool Register(const cString& key)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return false;
@@ -269,9 +445,9 @@
return (func != NULL);
}
- virtual BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
+ BaseType Create(const cString& key, Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
{
- CreateObjectFunction func;
+ CreateObjectFunction func = NULL;
cMutexAutoLock lock(m_mutex);
if (m_create_funcs.Find(key, func)) {
return func(arg1, arg2, arg3);
More information about the Avida-cvs
mailing list