[Avida-SVN] r2916 - in development: . Avida.xcodeproj source/analyze source/tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Mon Nov 3 20:54:19 PST 2008
Author: brysonda
Date: 2008-11-03 23:54:18 -0500 (Mon, 03 Nov 2008)
New Revision: 2916
Added:
development/source/analyze/cGenotypeBatch.cc
Modified:
development/Avida.xcodeproj/project.pbxproj
development/CMakeLists.txt
development/source/analyze/cGenotypeBatch.h
development/source/tools/tList.h
Log:
Clean up and reorganize tList.h. Add support for explicit copy construction of tLists.
Start migration of analyze batch functionality into the cGenotypeBatch object itself.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2008-11-02 02:21:30 UTC (rev 2915)
+++ development/Avida.xcodeproj/project.pbxproj 2008-11-04 04:54:18 UTC (rev 2916)
@@ -206,6 +206,7 @@
70BB2A2B0E9FA12F008269D2 /* ASAvidaLib.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70BB2A2A0E9FA12F008269D2 /* ASAvidaLib.cc */; };
70BB2AE20EA5303F008269D2 /* cDriverStatusConduit.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70BB2AC60EA52BD9008269D2 /* cDriverStatusConduit.cc */; };
70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
+ 70E60C4B0EC0088300718740 /* cGenotypeBatch.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70E60C4A0EC0088300718740 /* cGenotypeBatch.cc */; };
70EFD6600D975B6E00FAD32A /* cConstBurstSchedule.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70EFD65F0D975B5E00FAD32A /* cConstBurstSchedule.cc */; };
B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
@@ -842,6 +843,7 @@
70DCF58009CFBD3D00924128 /* tcmalloc-logging.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = "tcmalloc-logging.h"; sourceTree = "<group>"; };
70E130BF0C442B2900CE9249 /* cCoords.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cCoords.h; sourceTree = "<group>"; };
70E130E30C4551E900CE9249 /* cASTVisitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASTVisitor.h; sourceTree = "<group>"; };
+ 70E60C4A0EC0088300718740 /* cGenotypeBatch.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cGenotypeBatch.cc; sourceTree = "<group>"; };
70EFD65E0D975B5E00FAD32A /* cConstBurstSchedule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cConstBurstSchedule.h; sourceTree = "<group>"; };
70EFD65F0D975B5E00FAD32A /* cConstBurstSchedule.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cConstBurstSchedule.cc; sourceTree = "<group>"; };
70F7DAEF09290468009E311D /* cClassificationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cClassificationManager.h; sourceTree = "<group>"; };
@@ -1029,6 +1031,7 @@
7054A1B309A810CB00038658 /* cAnalyzeJobWorker.h */,
7054A1B409A810CB00038658 /* cAnalyzeJobWorker.cc */,
707AEF8C09EA8B2D001AEA89 /* cAnalyzeCommandAction.h */,
+ 70E60C4A0EC0088300718740 /* cGenotypeBatch.cc */,
);
path = analyze;
sourceTree = "<group>";
@@ -2056,6 +2059,7 @@
70EFD6600D975B6E00FAD32A /* cConstBurstSchedule.cc in Sources */,
70BB2AE20EA5303F008269D2 /* cDriverStatusConduit.cc in Sources */,
709A1EEC0EB6C42D006090AF /* cResourceHistory.cc in Sources */,
+ 70E60C4B0EC0088300718740 /* cGenotypeBatch.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt 2008-11-02 02:21:30 UTC (rev 2915)
+++ development/CMakeLists.txt 2008-11-04 04:54:18 UTC (rev 2916)
@@ -125,6 +125,7 @@
${ANALYZE_DIR}/cAnalyzeTreeStats_Gamma.cc
${ANALYZE_DIR}/cAnalyzeJobQueue.cc
${ANALYZE_DIR}/cAnalyzeJobWorker.cc
+ ${ANALYZE_DIR}/cGenotypeBatch.cc
${ANALYZE_DIR}/cMutationalNeighborhood.cc
)
SOURCE_GROUP(analyze FILES ${ANALYZE_SOURCES})
Added: development/source/analyze/cGenotypeBatch.cc
===================================================================
--- development/source/analyze/cGenotypeBatch.cc (rev 0)
+++ development/source/analyze/cGenotypeBatch.cc 2008-11-04 04:54:18 UTC (rev 2916)
@@ -0,0 +1,59 @@
+/*
+ * cGenotypeBatch.cc
+ * Avida
+ *
+ * Created by David Bryson on 11/3/08.
+ * Copyright 2008 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "cGenotypeBatch.h"
+
+#include "cAnalyzeGenotype.h"
+#include "cDriverManager.h"
+#include "cDriverStatusConduit.h"
+
+
+cAnalyzeGenotype* cGenotypeBatch::PopGenotype(const cString& desc)
+{
+ cString gen_desc(desc);
+ gen_desc.ToLower();
+
+ cAnalyzeGenotype* found_gen = NULL;
+
+ if (gen_desc == "num_cpus")
+ found_gen = m_list.PopIntMax(&cAnalyzeGenotype::GetNumCPUs);
+ else if (gen_desc == "total_cpus")
+ found_gen = m_list.PopIntMax(&cAnalyzeGenotype::GetTotalCPUs);
+ else if (gen_desc == "merit")
+ found_gen = m_list.PopDoubleMax(&cAnalyzeGenotype::GetMerit);
+ else if (gen_desc == "fitness")
+ found_gen = m_list.PopDoubleMax(&cAnalyzeGenotype::GetFitness);
+ else if (gen_desc.IsNumeric(0))
+ found_gen = m_list.PopIntValue(&cAnalyzeGenotype::GetID, gen_desc.AsInt());
+// @TODO - should add support for random, but cGenotypeBatch currently does not have access to the world object
+// else if (gen_desc == "random") {
+// int gen_pos = random.GetUInt(m_list.GetSize());
+// found_gen = m_list.PopPos(gen_pos);
+// }
+ else {
+ cDriverManager::Status().SignalError(cString("unknown type ") + gen_desc);
+ }
+
+ return found_gen;
+}
Modified: development/source/analyze/cGenotypeBatch.h
===================================================================
--- development/source/analyze/cGenotypeBatch.h 2008-11-02 02:21:30 UTC (rev 2915)
+++ development/source/analyze/cGenotypeBatch.h 2008-11-04 04:54:18 UTC (rev 2916)
@@ -39,25 +39,28 @@
class cGenotypeBatch {
private:
- tListPlus<cAnalyzeGenotype> genotype_list;
- cString name;
- bool is_lineage;
- bool is_aligned;
-private:
- // disabled copy constructor.
- cGenotypeBatch(const cGenotypeBatch &);
+ tListPlus<cAnalyzeGenotype> m_list;
+ cString m_name;
+ bool m_is_lineage;
+ bool m_is_aligned;
+
+ cGenotypeBatch(const cGenotypeBatch&); // @not_implemented
+ cGenotypeBatch& operator=(const cGenotypeBatch&); // @not_implemented
+
public:
- cGenotypeBatch() : name(""), is_lineage(false), is_aligned(false) { ; }
+ cGenotypeBatch() : m_name(""), m_is_lineage(false), m_is_aligned(false) { ; }
~cGenotypeBatch() { ; }
- tListPlus<cAnalyzeGenotype> & List() { return genotype_list; }
- cString& Name() { return name; }
- const cString& GetName() { return name; }
- bool IsLineage() { return is_lineage; }
- bool IsAligned() { return is_aligned; }
+ tListPlus<cAnalyzeGenotype>& List() { return m_list; }
+ cString& Name() { return m_name; }
+ const cString& GetName() { return m_name; }
+ bool IsLineage() { return m_is_lineage; }
+ bool IsAligned() { return m_is_aligned; }
- void SetLineage(bool _val=true) { is_lineage = _val; }
- void SetAligned(bool _val=true) { is_aligned = _val; }
+ void SetLineage(bool _val = true) { m_is_lineage = _val; }
+ void SetAligned(bool _val = true) { m_is_aligned = _val; }
+
+ cAnalyzeGenotype* PopGenotype(const cString& desc);
};
Modified: development/source/tools/tList.h
===================================================================
--- development/source/tools/tList.h 2008-11-02 02:21:30 UTC (rev 2915)
+++ development/source/tools/tList.h 2008-11-04 04:54:18 UTC (rev 2916)
@@ -26,24 +26,23 @@
#ifndef tList_h
#define tList_h
-#if USE_tMemTrack
-# ifndef tMemTrack_h
-# include "tMemTrack.h"
-# endif
-#endif
-
#ifndef NULL
#define NULL 0
#endif
-template <class T> class tListNode {
-#if USE_tMemTrack
- tMemTrack<tListNode<T> > mt;
-#endif
+template<class T> class tList;
+template<class T> class tBaseIterator;
+template<class T> class tListIterator;
+template<class T> class tConstListIterator;
+template<class T> class tLWConstListIterator;
+
+
+template <class T> class tListNode
+{
public:
- T * data;
- tListNode<T> * next;
- tListNode<T> * prev;
+ T* data;
+ tListNode<T>* next;
+ tListNode<T>* prev;
// @DMB - Visual Studio doesn't like usage of 'this' in initializers
// and throws a lot of useless warnings.
@@ -55,148 +54,22 @@
}
};
-template <class T> class tList;
-template <class T> class tBaseIterator {
-#if USE_tMemTrack
- tMemTrack<tBaseIterator<T> > mt;
-#endif
- friend class tList<T>;
-protected:
- virtual const tList<T> & GetConstList() = 0;
- virtual const tListNode<T> * GetConstNode() = 0;
-public:
- tBaseIterator() { ; }
- virtual ~tBaseIterator() { ; }
-
- virtual void Set(tListNode<T> * in_node) = 0;
- virtual void Reset() = 0;
-
- virtual const T * GetConst() = 0;
- virtual const T * NextConst() = 0;
- virtual const T * PrevConst() = 0;
-
- virtual bool AtRoot() const = 0;
- virtual bool AtEnd() const = 0;
-};
-
-template <class T> class tListIterator : public tBaseIterator<T> {
-#if USE_tMemTrack
- tMemTrack<tListIterator<T> > mt;
-#endif
- friend class tList<T>;
-private:
- tList<T> & list;
- tListNode<T> * node;
-
- const tList<T> & GetConstList() { return list; }
- const tListNode<T> * GetConstNode() { return node; }
-public:
- explicit tListIterator(tList<T>& _list);
- explicit tListIterator(tList<T>& _list, tListNode<T>* start_node);
- tListIterator(const tListIterator<T>& _tli);
- ~tListIterator();
-
- void Set(tListNode<T> * in_node) { node = in_node; }
- void Reset();
- tListNode<T> * GetPos() { return node; }
-
- T * Get();
- T * Next();
- T * Prev();
- const T * GetConst() { return Get(); }
- const T * NextConst() { return Next(); }
- const T * PrevConst() { return Prev(); }
-
- bool Find(T * test_data);
-
- bool AtRoot() const;
- bool AtEnd() const;
-
- // Unique methods...
- T * Remove();
-};
-
-template <class T> class tConstListIterator : public tBaseIterator<T> {
-#if USE_tMemTrack
- tMemTrack<tConstListIterator<T> > mt;
-#endif
- friend class tList<T>;
-private:
- const tList<T> & list;
- const tListNode<T> * node;
-
- const tList<T> & GetConstList() { return list; }
- const tListNode<T> * GetConstNode() { return node; }
-public:
- explicit tConstListIterator(const tList<T> & _list);
- explicit tConstListIterator(const tList<T> & _list,
- const tListNode<T> * start_node);
- ~tConstListIterator();
-
- void Set(tListNode<T> * in_node) { node = in_node; }
- void Reset();
-
- const T * Get();
- const T * Next();
- const T * Prev();
- const T * GetConst() { return Get(); }
- const T * NextConst() { return Next(); }
- const T * PrevConst() { return Prev(); }
- bool Find(const T * test_data);
-
- bool AtRoot() const;
- bool AtEnd() const;
-};
-
-template <class T> class tLWConstListIterator : public tBaseIterator<T>
+template <class T> class tList
{
-#if USE_tMemTrack
- tMemTrack<tLWConstListIterator<T> > mt;
-#endif
- friend class tList<T>;
-private:
- const tList<T>& list;
- const tListNode<T>* node;
-
- const tList<T>& GetConstList() { return list; }
- const tListNode<T>* GetConstNode() { return node; }
-
-public:
- explicit tLWConstListIterator(const tList<T>& _list) : list(_list), node(&(_list.root)) { ; }
- explicit tLWConstListIterator(const tList<T>& _list, const tListNode<T>* start_node) : list(_list), node(start_node) { ; }
- ~tLWConstListIterator() { ; }
-
- void Set(tListNode<T>* in_node) { node = in_node; }
- void Reset();
-
- const T* Get();
- const T* Next();
- const T* Prev();
- const T* GetConst() { return Get(); }
- const T* NextConst() { return Next(); }
- const T* PrevConst() { return Prev(); }
- bool Find(const T* test_data);
-
- bool AtRoot() const;
- bool AtEnd() const;
-};
-
-template <class T> class tList {
-#if USE_tMemTrack
- tMemTrack<tList<T> > mt;
-#endif
friend class tBaseIterator<T>;
friend class tListIterator<T>;
friend class tConstListIterator<T>;
friend class tLWConstListIterator<T>;
+
protected:
- tListNode<T> root; // Data root
+ tListNode<T> root; // Data root
int size;
- mutable tListNode< tBaseIterator<T> > it_root; // Iterator root
+ mutable tListNode<tBaseIterator<T> > it_root; // Iterator root
mutable int it_count;
- T * RemoveNode(tListNode<T> * out_node) {
+ T* RemoveNode(tListNode<T>* out_node)
+ {
// Make sure we're not trying to delete the root node!
if (out_node == &root) return NULL;
@@ -211,7 +84,7 @@
}
// Save the data and patch up the linked list.
- T * out_data = out_node->data;
+ T* out_data = out_node->data;
out_node->prev->next = out_node->next;
out_node->next->prev = out_node->prev;
@@ -222,8 +95,9 @@
}
// To be called from iterator constructor only!
- void AddIterator(tBaseIterator<T> * new_it) const {
- tListNode< tBaseIterator<T> > * new_node =
+ void AddIterator(tBaseIterator<T>* new_it) const
+ {
+ tListNode< tBaseIterator<T> >* new_node =
new tListNode< tBaseIterator<T> >;
new_node->data = new_it;
new_node->next = it_root.next;
@@ -234,8 +108,9 @@
}
// To be called from iterator destructor only!
- void RemoveIterator(tBaseIterator<T> * old_it) const {
- tListNode< tBaseIterator<T> > * test_it = it_root.next;
+ void RemoveIterator(tBaseIterator<T>* old_it) const
+ {
+ tListNode< tBaseIterator<T> >* test_it = it_root.next;
while (test_it->data != old_it) test_it = test_it->next;
test_it->prev->next = test_it->next;
test_it->next->prev = test_it->prev;
@@ -243,14 +118,20 @@
it_count--;
}
+
public:
- T * Pop() { return RemoveNode(root.next); }
- T * PopRear() { return RemoveNode(root.prev); }
+ tList() : size(0), it_count(0) { }
+ explicit tList(const tList& in_list) : size(0), it_count(0) { Append(in_list); }
+ ~tList() { Clear(); }
+
+ inline T* Pop() { return RemoveNode(root.next); }
+ inline T* PopRear() { return RemoveNode(root.prev); }
void Clear() { while (size > 0) Pop(); }
- void Append(const tList<T> & in_list) {
- tListNode<T> * cur_node = in_list.root.next;
+ void Append(const tList<T>& in_list)
+ {
+ tListNode<T>* cur_node = in_list.root.next;
while (cur_node != &(in_list.root)) {
PushRear(cur_node->data);
cur_node = cur_node->next;
@@ -262,8 +143,8 @@
Append(in_list);
}
- void Push(T * _in) {
- tListNode<T> * new_node = new tListNode<T>;
+ void Push(T* _in) {
+ tListNode<T>* new_node = new tListNode<T>;
new_node->data = _in;
new_node->next = root.next;
new_node->prev = &root;
@@ -272,8 +153,8 @@
size++;
}
- tListNode<T>* PushRear(T * _in) {
- tListNode<T> * new_node = new tListNode<T>;
+ tListNode<T>* PushRear(T* _in) {
+ tListNode<T>* new_node = new tListNode<T>;
new_node->data = _in;
new_node->next = &root;
new_node->prev = root.prev;
@@ -283,38 +164,36 @@
return new_node;
}
- const T * GetFirst() const { return root.next->data; }
- const T * GetLast() const { return root.prev->data; }
- T * GetFirst() { return root.next->data; }
- T * GetLast() { return root.prev->data; }
+ inline const T* GetFirst() const { return root.next->data; }
+ inline const T* GetLast() const { return root.prev->data; }
+ inline T* GetFirst() { return root.next->data; }
+ inline T* GetLast() { return root.prev->data; }
- T * GetPos(int pos) {
+ T* GetPos(int pos)
+ {
if (pos >= GetSize()) return NULL;
- tListNode<T> * test_node = root.next;
+ tListNode<T>* test_node = root.next;
for (int i = 0; i < pos; i++) test_node = test_node->next;
return test_node->data;
}
- const T * GetPos(int pos) const {
+ const T* GetPos(int pos) const
+ {
if (pos >= GetSize()) return NULL;
- tListNode<T> * test_node = root.next;
+ tListNode<T>* test_node = root.next;
for (int i = 0; i < pos; i++) test_node = test_node->next;
return test_node->data;
}
- void CircNext() { if (size > 0) PushRear(Pop()); }
- void CircPrev() { if (size > 0) Push(PopRear()); }
+ inline void CircNext() { if (size > 0) PushRear(Pop()); }
+ inline void CircPrev() { if (size > 0) Push(PopRear()); }
- T * Remove(tListIterator<T> & other) {
- if (&(other.list) != this) return NULL; // @CAO make this an assert?
- return RemoveNode(other.node);
- }
-
- T * Insert(tListIterator<T> & list_it, T * in_data) {
- tListNode<T> * cur_node = list_it.node;
+ T* Insert(tListIterator<T>& list_it, T* in_data)
+ {
+ tListNode<T>* cur_node = list_it.node;
// Build the new node for the list...
- tListNode<T> * new_node = new tListNode<T>;
+ tListNode<T>* new_node = new tListNode<T>;
new_node->data = in_data;
// Insert the new node before the iterator...
@@ -328,31 +207,33 @@
}
- //bool Remove(T * other) {
- T * Remove(T * other) {
- tListNode<T> * test = root.next;
+ T* Remove(tListIterator<T>& other)
+ {
+ if (&(other.list) != this) return NULL; // @CAO make this an assert?
+ return RemoveNode(other.node);
+ }
+
+
+ T* Remove(T* other)
+ {
+ tListNode<T>* test = root.next;
while (test != &root) {
if (test->data == other) {
RemoveNode(test);
- //return true;
return other;
}
test = test->next;
}
- //return false;
+
return NULL;
}
- int GetSize() const { return size; }
+ inline int GetSize() const { return size; }
- // Copy another list onto the end of this one.
- void Append(tList<T> & other_list) {
- tListIterator<T> other_it(other_list);
- while (other_it.Next() != NULL) PushRear(other_it.Get());
- }
// Empty out another list, transferring its contents to the end of this one.
- void Transfer(tList<T> & other_list) {
+ void Transfer(tList<T>& other_list)
+ {
// If the other list is empty, stop here.
if (other_list.GetSize() == 0) return;
@@ -379,8 +260,9 @@
}
// Find by value
- T * Find(T * _in) const {
- tListNode<T> * test = root.next;
+ T* Find(T* _in) const
+ {
+ tListNode<T>* test = root.next;
while (test != &root) {
if ( *(test->data) == *(_in) ) return test->data;
test = test->next;
@@ -389,8 +271,9 @@
}
// Find by Pointer
- T * FindPtr(T * _in) const {
- tListNode<T> * test = root.next;
+ T* FindPtr(T* _in) const
+ {
+ tListNode<T>* test = root.next;
while (test != &root) {
if ( test->data == _in ) return test->data;
test = test->next;
@@ -399,8 +282,9 @@
}
// Find the position of the node by its pointer
- int FindPosPtr(T * _in) const {
- tListNode<T> * test = root.next;
+ int FindPosPtr(T* _in) const
+ {
+ tListNode<T>* test = root.next;
int pos = 0;
while (test != &root) {
if ( test->data == _in ) return pos;
@@ -412,19 +296,16 @@
// Remove by position
- T * PopPos(int pos) {
+ T* PopPos(int pos)
+ {
if (pos >= GetSize()) return NULL;
- tListNode<T> * test_node = root.next;
+ tListNode<T>* test_node = root.next;
for (int i = 0; i < pos; i++) test_node = test_node->next;
return RemoveNode(test_node);
}
-public:
- tList() : size(0), it_count(0) { }
- ~tList() { Clear(); }
-
// Save to archive
template<class Archive>
void save(Archive & a, const unsigned int version) const {
@@ -466,25 +347,24 @@
void serialize(Archive & a, const unsigned int version){
a.SplitLoadSave(*this, version);
}
-
-private:
- tList(tList & _list) { ; } // Never should be used...
};
+
// This is an extended version of tList that contains extra functions to
// allow method pointers associated with the object type being listed.
-template <class T> class tListPlus : public tList<T> {
-#if USE_tMemTrack
- tMemTrack<tListPlus<T> > mt;
-#endif
-private:
+template <class T> class tListPlus : public tList<T>
+{
public:
+ tListPlus() : tList<T>() { ; }
+ explicit tListPlus(const tList<T>& in_list) : tList<T>(in_list) { ; }
+ explicit tListPlus(const tListPlus& in_list) : tList<T>(in_list) { ; }
// Find by summing values until a specified total is reached.
- T * FindSummedValue(int sum, int (T::*fun)() const) {
+ T* FindSummedValue(int sum, int (T::*fun)() const)
+ {
int total = 0;
- tListNode<T> * test = this->root.next;
+ tListNode<T>* test = this->root.next;
while (test != &(this->root) && total < sum) {
total += (test->data->*fun)();
test = test->next;
@@ -492,8 +372,9 @@
return test->data;
}
- T * PopIntValue(int (T::*fun)() const, int value) {
- tListNode<T> * test = this->root.next;
+ T* PopIntValue(int (T::*fun)() const, int value)
+ {
+ tListNode<T>* test = this->root.next;
while (test != &(this->root)) {
if ( (test->data->*fun)() == value) return RemoveNode(test);
test = test->next;
@@ -501,10 +382,11 @@
return NULL;
}
- T * PopIntMax(int (T::*fun)() const) {
+ T* PopIntMax(int (T::*fun)() const)
+ {
if (this->size == 0) return NULL;
- tListNode<T> * test = this->root.next;
- tListNode<T> * best = test;
+ tListNode<T>* test = this->root.next;
+ tListNode<T>* best = test;
int max_val = (test->data->*fun)();
while (test != &(this->root)) {
const int cur_val = (test->data->*fun)();
@@ -517,10 +399,11 @@
return RemoveNode(best);
}
- T * PopDoubleMax(double (T::*fun)() const) {
+ T* PopDoubleMax(double (T::*fun)() const)
+ {
if (this->size == 0) return NULL;
- tListNode<T> * test = this->root.next;
- tListNode<T> * best = test;
+ tListNode<T>* test = this->root.next;
+ tListNode<T>* best = test;
double max_val = (test->data->*fun)();
while (test != &(this->root)) {
const double cur_val = (test->data->*fun)();
@@ -533,7 +416,8 @@
return RemoveNode(best);
}
- int Count(int (T::*fun)() const) {
+ int Count(int (T::*fun)() const)
+ {
int total = 0;
tListNode<T> * test = this->root.next;
while (test != &(this->root)) {
@@ -542,189 +426,167 @@
}
return total;
}
-
};
-////////////////////
-// tListIterator
-template <class T> tListIterator<T>::tListIterator(tList<T> & _list)
-: list(_list), node(&(_list.root))
+template <class T> class tBaseIterator
{
- list.AddIterator(this);
-}
+ friend class tList<T>;
+
+protected:
+ virtual const tList<T>& GetConstList() = 0;
+ virtual const tListNode<T>* GetConstNode() = 0;
+
+public:
+ tBaseIterator() { ; }
+ virtual ~tBaseIterator() { ; }
+
+ virtual void Set(tListNode<T>* in_node) = 0;
+ virtual void Reset() = 0;
+
+ virtual const T* GetConst() = 0;
+ virtual const T* NextConst() = 0;
+ virtual const T* PrevConst() = 0;
+
+ virtual bool AtRoot() const = 0;
+ virtual bool AtEnd() const = 0;
+};
-template <class T> tListIterator<T>::tListIterator(tList<T> & _list,
- tListNode<T> * start_node)
-: list(_list), node(start_node)
-{
- list.AddIterator(this);
-}
-template <class T> tListIterator<T>::tListIterator(const tListIterator<T>& _tli)
-: tBaseIterator<T>(), list(_tli.list), node(_tli.node)
-{
- list.AddIterator(this);
-}
-
-
-template <class T> tListIterator<T>::~tListIterator()
+template <class T> class tListIterator : public tBaseIterator<T>
{
- list.RemoveIterator(this);
-}
-
-template <class T> void tListIterator<T>::Reset()
-{
- node = &(list.root);
-}
-
-template <class T> T * tListIterator<T>::Get()
-{
- return node->data;
-}
-
-template <class T> T * tListIterator<T>::Next()
-{
- node = node->next;
- return node->data;
-}
-
-template <class T> T * tListIterator<T>::Prev()
-{
- node = node->prev;
- return node->data;
-}
-
-template <class T> bool tListIterator<T>::Find(T * test_data)
-{
- for (node = list.root.next;
- node != &(list.root);
- node = node->next) {
- if (node->data == test_data) return true;
+ friend class tList<T>;
+
+private:
+ tList<T>& list;
+ tListNode<T>* node;
+
+ const tList<T>& GetConstList() { return list; }
+ const tListNode<T>* GetConstNode() { return node; }
+
+public:
+ explicit inline tListIterator(tList<T>& _list) : list(_list), node(&(_list.root)) { list.AddIterator(this); }
+ explicit inline tListIterator(tList<T>& _list, tListNode<T>* start) : list(_list), node(start) { list.AddIterator(this); }
+ inline tListIterator(const tListIterator<T>& _tli) : tBaseIterator<T>(), list(_tli.list), node(_tli.node)
+ {
+ list.AddIterator(this);
}
- return false;
-}
+
+ inline ~tListIterator() { list.RemoveIterator(this); }
+
+ void Set(tListNode<T>* in_node) { node = in_node; }
+ void Reset() { node = &(list.root); }
+ tListNode<T>* GetPos() { return node; }
+
+ T* Get() { return node->data; }
+ T* Next() { node = node->next; return node->data; }
+ T* Prev() { node = node->prev; return node->data; }
+
+ const T* GetConst() { return Get(); }
+ const T* NextConst() { return Next(); }
+ const T* PrevConst() { return Prev(); }
+
+ bool Find(T* test_data);
+
+ bool AtRoot() const { return (node == &(list.root)); }
+ bool AtEnd() const { return (node->next == &(list.root)); }
+
+ // Unique methods...
+ T* Remove() { return list.RemoveNode(node); }
+};
-template <class T> bool tListIterator<T>::AtRoot() const
-{
- return (node == &(list.root));
-}
-template <class T> bool tListIterator<T>::AtEnd() const
+template <class T> class tConstListIterator : public tBaseIterator<T>
{
- return (node->next == &(list.root));
-}
+ friend class tList<T>;
+
+private:
+ const tList<T>& list;
+ const tListNode<T>* node;
+
+ const tList<T>& GetConstList() { return list; }
+ const tListNode<T>* GetConstNode() { return node; }
+
+public:
+ explicit tConstListIterator(const tList<T>& _list) : list(_list), node(&(_list.root)) { list.AddIterator(this); }
+ explicit tConstListIterator(const tList<T>& _list, const tListNode<T>* start_node)
+ : list(_list), node(start_node) { list.AddIterator(this); }
+ ~tConstListIterator() { list.RemoveIterator(this); }
+
+ void Set(tListNode<T>* in_node) { node = in_node; }
+ void Reset() { node = &(list.root); }
+
+ T* Get() { return node->data; }
+ T* Next() { node = node->next; return node->data; }
+ T* Prev() { node = node->prev; return node->data; }
+
+ const T* GetConst() { return Get(); }
+ const T* NextConst() { return Next(); }
+ const T* PrevConst() { return Prev(); }
+ bool Find(const T * test_data);
+
+ bool AtRoot() const { return (node == &(list.root)); }
+ bool AtEnd() const { return (node->next == &(list.root)); }
+};
-template <class T> T* tListIterator<T>::Remove()
-{
- return list.RemoveNode(node);
-}
-/////////////////////////
-// tConstListIterator
-
-template <class T> tConstListIterator<T>::tConstListIterator(const tList<T> & _list)
-: list(_list), node(&(_list.root))
+template <class T> class tLWConstListIterator : public tBaseIterator<T>
{
- list.AddIterator(this);
-}
+ friend class tList<T>;
-template <class T> tConstListIterator<T>::tConstListIterator(const tList<T> & _list, const tListNode<T> * start_node)
-: list(_list), node(start_node)
-{
- list.AddIterator(this);
-}
+private:
+ const tList<T>& list;
+ const tListNode<T>* node;
+
+ const tList<T>& GetConstList() { return list; }
+ const tListNode<T>* GetConstNode() { return node; }
+
+public:
+ explicit tLWConstListIterator(const tList<T>& _list) : list(_list), node(&(_list.root)) { ; }
+ explicit tLWConstListIterator(const tList<T>& _list, const tListNode<T>* start_node) : list(_list), node(start_node) { ; }
+ ~tLWConstListIterator() { ; }
+
+ void Set(tListNode<T>* in_node) { node = in_node; }
+ void Reset() { node = &(list.root); }
+
+ T* Get() { return node->data; }
+ T* Next() { node = node->next; return node->data; }
+ T* Prev() { node = node->prev; return node->data; }
+
+ const T* GetConst() { return Get(); }
+ const T* NextConst() { return Next(); }
+ const T* PrevConst() { return Prev(); }
+ bool Find(const T* test_data);
+
+ bool AtRoot() const { return (node == &(list.root)); }
+ bool AtEnd() const { return (node->next == &(list.root)); }
+};
-template <class T> tConstListIterator<T>::~tConstListIterator()
-{
- list.RemoveIterator(this);
-}
-template <class T> void tConstListIterator<T>::Reset()
-{
- node = &(list.root);
-}
-template <class T> const T * tConstListIterator<T>::Get()
-{
- return node->data;
-}
-template <class T> const T * tConstListIterator<T>::Next()
+template <class T> bool tListIterator<T>::Find(T* test_data)
{
- node = node->next;
- return node->data;
-}
-
-template <class T> const T * tConstListIterator<T>::Prev()
-{
- node = node->prev;
- return node->data;
-}
-
-template <class T> bool tConstListIterator<T>::Find(const T * test_data)
-{
- for (node = list.root.next;
- node != &(list.root);
- node = node->next) {
- if (node->data == test_data) return true;
- }
+ for (node = list.root.next; node != &(list.root); node = node->next) if (node->data == test_data) return true;
return false;
}
-template <class T> bool tConstListIterator<T>::AtRoot() const
-{
- return (node == &(list.root));
-}
-template <class T> bool tConstListIterator<T>::AtEnd() const
-{
- return (node->next == &(list.root));
-}
-/////////////////////////
-// tLWConstListIterator
-
-template <class T> void tLWConstListIterator<T>::Reset()
+template <class T> bool tConstListIterator<T>::Find(const T* test_data)
{
- node = &(list.root);
+ for (node = list.root.next; node != &(list.root); node = node->next) if (node->data == test_data) return true;
+ return false;
}
-template <class T> const T* tLWConstListIterator<T>::Get()
-{
- return node->data;
-}
-template <class T> const T* tLWConstListIterator<T>::Next()
-{
- node = node->next;
- return node->data;
-}
-template <class T> const T* tLWConstListIterator<T>::Prev()
-{
- node = node->prev;
- return node->data;
-}
-
template <class T> bool tLWConstListIterator<T>::Find(const T* test_data)
{
- for (node = list.root.next; node != &(list.root); node = node->next) {
- if (node->data == test_data) return true;
- }
+ for (node = list.root.next; node != &(list.root); node = node->next) if (node->data == test_data) return true;
return false;
}
-template <class T> bool tLWConstListIterator<T>::AtRoot() const
-{
- return (node == &(list.root));
-}
-
-template <class T> bool tLWConstListIterator<T>::AtEnd() const
-{
- return (node->next == &(list.root));
-}
-
#endif
More information about the Avida-cvs
mailing list