diff options
Diffstat (limited to 'src/phenotypebinary.cpp')
-rw-r--r-- | src/phenotypebinary.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/phenotypebinary.cpp b/src/phenotypebinary.cpp index 9d9e26c..8ecd394 100644 --- a/src/phenotypebinary.cpp +++ b/src/phenotypebinary.cpp | |||
@@ -155,6 +155,38 @@ Bu::String Genetic::PhenotypeBinary::toString() | |||
155 | return sRet; | 155 | return sRet; |
156 | } | 156 | } |
157 | 157 | ||
158 | void Genetic::PhenotypeBinary::write( Bu::Stream &rStream ) | ||
159 | { | ||
160 | uint32_t uSize = htobe32( iSize ); | ||
161 | rStream.write( &uSize, 4 ); | ||
162 | uSize = (iSize/8) + ((iSize%8)?1:0); | ||
163 | for( int j = 0; j < uSize; j++ ) | ||
164 | { | ||
165 | rStream.write( | ||
166 | &((char *)&aGenes[j/sizeof(uint_fast32_t)])[j%sizeof(uint_fast32_t)], | ||
167 | 1 | ||
168 | ); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | void Genetic::PhenotypeBinary::read( Bu::Stream &rStream ) | ||
173 | { | ||
174 | uint32_t uSize; | ||
175 | rStream.read( &uSize, 4 ); | ||
176 | iSize = be32toh( uSize ); | ||
177 | iWords = wordsForBits(iSize); | ||
178 | delete[] aGenes; | ||
179 | aGenes = new uint_fast32_t[iWords]; | ||
180 | uSize = (iSize/8) + ((iSize%8)?1:0); | ||
181 | for( int j = 0; j < uSize; j++ ) | ||
182 | { | ||
183 | rStream.read( | ||
184 | &((char *)&aGenes[j/sizeof(uint_fast32_t)])[j%sizeof(uint_fast32_t)], | ||
185 | 1 | ||
186 | ); | ||
187 | } | ||
188 | } | ||
189 | |||
158 | void Genetic::PhenotypeBinary::extractBits( uint32_t &rTarget, int iStart, | 190 | void Genetic::PhenotypeBinary::extractBits( uint32_t &rTarget, int iStart, |
159 | int iBits ) | 191 | int iBits ) |
160 | { | 192 | { |
@@ -189,13 +221,3 @@ void Genetic::PhenotypeBinary::extractBits( uint64_t &rTarget, int iStart, | |||
189 | } | 221 | } |
190 | } | 222 | } |
191 | 223 | ||
192 | void Genetic::PhenotypeBinary::write( Bu::Stream &rStream ) | ||
193 | { | ||
194 | rStream.write( aGenes, sizeof(uint_fast32_t)*iWords ); | ||
195 | } | ||
196 | |||
197 | void Genetic::PhenotypeBinary::read( Bu::Stream &rStream ) | ||
198 | { | ||
199 | rStream.read( aGenes, sizeof(uint_fast32_t)*iWords ); | ||
200 | } | ||
201 | |||