X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fpersistence%2Fpersistent_vector.cpp;fp=src%2Fstlplus%2Fpersistence%2Fpersistent_vector.cpp;h=b983d378e3dec324837b80e51b8ef1ba19f54be2;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/persistence/persistent_vector.cpp b/src/stlplus/persistence/persistent_vector.cpp new file mode 100644 index 0000000..b983d37 --- /dev/null +++ b/src/stlplus/persistence/persistent_vector.cpp @@ -0,0 +1,56 @@ +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +//////////////////////////////////////////////////////////////////////////////// +#include "persistent_vector.hpp" + +//////////////////////////////////////////////////////////////////////////////// +// specialisation for a vector of bool which has a different implementation to a vector of anything else + +void stlplus::dump_vector_bool(stlplus::dump_context& context, const std::vector& data) + throw(stlplus::persistent_dump_failed) +{ + stlplus::dump_unsigned(context,data.size()); + unsigned size = data.size(); + unsigned bytes = ((size + 7) / 8); + for (unsigned b = 0; b < bytes; b++) + { + unsigned char byte = 0; + unsigned char mask = 1; + for (unsigned e = 0; e < 8; e++) + { + unsigned i = b*8 + e; + if (i >= size) break; + if (data[i]) byte |= mask; + mask <<= 1; + } + context.put(byte); + } +} + +void stlplus::restore_vector_bool(stlplus::restore_context& context, std::vector& data) + throw(stlplus::persistent_restore_failed) +{ + unsigned size = 0; + stlplus::restore_unsigned(context,size); + data.resize(size); + unsigned bytes = ((size + 7) / 8); + for (unsigned b = 0; b < bytes; b++) + { + unsigned char byte = context.get(); + unsigned char mask = 1; + for (unsigned e = 0; e < 8; e++) + { + unsigned i = b*8 + e; + if (i >= size) break; + data[i] = ((byte & mask) != 0); + mask <<= 1; + } + } +} + +////////////////////////////////////////////////////////////////////////////////