[Avida-cvs] [avida-svn] r530 - in development/source: cpu main tools
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sun Mar 26 08:00:20 PST 2006
Author: brysonda
Date: 2006-03-26 11:00:20 -0500 (Sun, 26 Mar 2006)
New Revision: 530
Modified:
development/source/cpu/cHardware4Stack_Thread.h
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareCPU_Thread.h
development/source/cpu/cHardwareSMT_Thread.h
development/source/main/cOrganism.h
development/source/tools/tBuffer.h
Log:
Adjust tBuffer::Add to use a const-reference, rather than pass-by-value.
Modified: development/source/cpu/cHardware4Stack_Thread.h
===================================================================
--- development/source/cpu/cHardware4Stack_Thread.h 2006-03-25 18:04:58 UTC (rev 529)
+++ development/source/cpu/cHardware4Stack_Thread.h 2006-03-26 16:00:20 UTC (rev 530)
@@ -25,9 +25,6 @@
#ifndef nHardware4Stack_h
#include "nHardware4Stack.h"
#endif
-#ifndef tBuffer_h
-#include "tBuffer.h"
-#endif
/**
* This class is needed to run several threads on a single genome.
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2006-03-25 18:04:58 UTC (rev 529)
+++ development/source/cpu/cHardwareCPU.h 2006-03-26 16:00:20 UTC (rev 530)
@@ -61,7 +61,6 @@
class cInstSet;
class cMutation;
class cOrganism;
-template <class T> class tBuffer;
class cHardwareCPU : public cHardwareBase
{
Modified: development/source/cpu/cHardwareCPU_Thread.h
===================================================================
--- development/source/cpu/cHardwareCPU_Thread.h 2006-03-25 18:04:58 UTC (rev 529)
+++ development/source/cpu/cHardwareCPU_Thread.h 2006-03-26 16:00:20 UTC (rev 530)
@@ -28,9 +28,6 @@
#ifndef cCPUStack_h
#include "cCPUStack.h"
#endif
-#ifndef tBuffer_h
-#include "tBuffer.h"
-#endif
/**
* This class is needed to run several threads on a single genome.
Modified: development/source/cpu/cHardwareSMT_Thread.h
===================================================================
--- development/source/cpu/cHardwareSMT_Thread.h 2006-03-25 18:04:58 UTC (rev 529)
+++ development/source/cpu/cHardwareSMT_Thread.h 2006-03-26 16:00:20 UTC (rev 530)
@@ -24,9 +24,6 @@
#ifndef nHardwareSMT_h
#include "nHardwareSMT.h"
#endif
-#ifndef tBuffer_h
-#include "tBuffer.h"
-#endif
/**
* This class is needed to run several threads on a single genome.
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2006-03-25 18:04:58 UTC (rev 529)
+++ development/source/main/cOrganism.h 2006-03-26 16:00:20 UTC (rev 530)
@@ -90,6 +90,9 @@
tBuffer<cOrgMessage> inbox;
tBuffer<cOrgMessage> sent;
+
+ tBuffer<cOrgMessage*> m_net_pending;
+ t
#ifdef DEBUG
bool initialized; // Has this CPU been initialized yet, w/hardware.
Modified: development/source/tools/tBuffer.h
===================================================================
--- development/source/tools/tBuffer.h 2006-03-25 18:04:58 UTC (rev 529)
+++ development/source/tools/tBuffer.h 2006-03-26 16:00:20 UTC (rev 530)
@@ -21,19 +21,21 @@
#include "tArray.h"
#endif
-template <class T> class tBuffer {
+
+template <class T> class tBuffer
+{
private:
tArray<T> data; // Contents of buffer...
int offset; // Position in buffer to next write.
int total; // Total inputs ever...
int last_total; // Total inputs at time of last ZeroNumAdds.
public:
- tBuffer(const int size) : data(size), offset(0), total(0),
- last_total(0) { ; }
- tBuffer(const tBuffer<T> & in) : data(in.data), offset(in.offset),
- total(in.total), last_total(in.last_total) { ; }
+ tBuffer(const int size) : data(size), offset(0), total(0), last_total(0) { ; }
+ tBuffer(const tBuffer<T> & in) : data(in.data), offset(in.offset), total(in.total), last_total(in.last_total) { ; }
+ ~tBuffer() { ; }
- tBuffer & operator= (const tBuffer<T> & in) {
+ tBuffer& operator=(const tBuffer<T>& in)
+ {
data = in.data;
offset = in.offset;
total = in.total;
@@ -41,20 +43,19 @@
return *this;
}
- ~tBuffer() { ; }
-
void Clear() { offset = 0; total = 0; last_total = 0; }
+ void ZeroNumAdds() { last_total = total; total = 0; }
- void Add(T in){
- data[offset] = in;
+ void Add(const T& in_value)
+ {
+ data[offset] = in_value;
total++;
offset++;
while (offset >= data.GetSize()) offset -= data.GetSize();
}
- void ZeroNumAdds() { total = 0; }
-
- T operator[] (int i) const {
+ T operator[](int i) const
+ {
int index = offset - i - 1;
while (index < 0) index += data.GetSize();
return data[index];
@@ -62,11 +63,11 @@
int GetCapacity() const { return data.GetSize(); }
int GetTotal() const { return total; }
- int GetNumStored() const
- { return (total <= data.GetSize()) ? total : data.GetSize(); }
+ int GetNumStored() const { return (total <= data.GetSize()) ? total : data.GetSize(); }
int GetNum() const { return total - last_total; }
- void SaveState(std::ostream& fp) {
+ void SaveState(std::ostream& fp)
+ {
assert(fp.good());
fp << "tBuffer" << " ";
fp << data.GetSize() << " ";
@@ -74,7 +75,8 @@
fp << offset << " " << total << " " << last_total << " " << std::endl;
}
- void LoadState(std::istream & fp) {
+ void LoadState(std::istream& fp)
+ {
assert(fp.good());
cString foo; fp >> foo; assert(foo == "tBuffer");
int capacity; fp >> capacity;
More information about the Avida-cvs
mailing list