summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2012-07-09 15:34:11 -0600
committerMike Buland <mike@xagasoft.com>2012-07-09 15:34:11 -0600
commita48556c1c5c01892cf493cd3eb4ff969a2f548fd (patch)
treeafd36d14133069fed0fcfccefb827c92da51496c
parentd9dc8bda6278cc1f64b3656336d3f01472458303 (diff)
downloadlibgenetic-a48556c1c5c01892cf493cd3eb4ff969a2f548fd.tar.gz
libgenetic-a48556c1c5c01892cf493cd3eb4ff969a2f548fd.tar.bz2
libgenetic-a48556c1c5c01892cf493cd3eb4ff969a2f548fd.tar.xz
libgenetic-a48556c1c5c01892cf493cd3eb4ff969a2f548fd.zip
Simple saving/loading - consider this temporary.
It should be a little more compact, and have more header info so we can reconstruct the entire object from the file, right now you have to know the size in bits.
-rw-r--r--src/phenotypebinary.cpp10
-rw-r--r--src/phenotypebinary.h5
2 files changed, 15 insertions, 0 deletions
diff --git a/src/phenotypebinary.cpp b/src/phenotypebinary.cpp
index 68f9ebf..0d32c9f 100644
--- a/src/phenotypebinary.cpp
+++ b/src/phenotypebinary.cpp
@@ -133,3 +133,13 @@ void Genetic::PhenotypeBinary::extractBits( uint64_t &rTarget, int iStart,
133 } 133 }
134} 134}
135 135
136void Genetic::PhenotypeBinary::write( Bu::Stream &rStream )
137{
138 rStream.write( aGenes, sizeof(uint_fast32_t)*iWords );
139}
140
141void Genetic::PhenotypeBinary::read( Bu::Stream &rStream )
142{
143 rStream.read( aGenes, sizeof(uint_fast32_t)*iWords );
144}
145
diff --git a/src/phenotypebinary.h b/src/phenotypebinary.h
index cbae392..f312187 100644
--- a/src/phenotypebinary.h
+++ b/src/phenotypebinary.h
@@ -3,6 +3,8 @@
3 3
4#include "genetic/phenotype.h" 4#include "genetic/phenotype.h"
5 5
6#include <bu/stream.h>
7
6namespace Genetic 8namespace Genetic
7{ 9{
8 class PhenotypeBinary : public Phenotype 10 class PhenotypeBinary : public Phenotype
@@ -22,6 +24,9 @@ namespace Genetic
22 void extractBits( uint32_t &rTarget, int iStart, int iBits ); 24 void extractBits( uint32_t &rTarget, int iStart, int iBits );
23 void extractBits( uint64_t &rTarget, int iStart, int iBits ); 25 void extractBits( uint64_t &rTarget, int iStart, int iBits );
24 26
27 void write( Bu::Stream &rStream );
28 void read( Bu::Stream &rStream );
29
25 private: 30 private:
26 int iSize; 31 int iSize;
27 int iWords; 32 int iWords;