43#ifdef SAWYER_HAVE_BOOST_SERIALIZATION
45 friend class boost::serialization::access;
48 void save(S &s,
const unsigned )
const {
49 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Super);
50 s & BOOST_SERIALIZATION_NVP(size_);
51 s & BOOST_SERIALIZATION_NVP(rdonly_);
52 s & boost::serialization::make_nvp(
"values", boost::serialization::make_array(values_, size_));
56 void load(S &s,
const unsigned ) {
57 s & BOOST_SERIALIZATION_BASE_OBJECT_NVP(
Super);
58 s & BOOST_SERIALIZATION_NVP(size_);
59 s & BOOST_SERIALIZATION_NVP(rdonly_);
60 values_ =
new Value[size_];
61 s & boost::serialization::make_nvp(
"values", boost::serialization::make_array(values_, size_));
64 BOOST_SERIALIZATION_SPLIT_MEMBER();
67#ifdef SAWYER_HAVE_CEREAL
69 friend class cereal::access;
71 template<
class Archive>
72 void CEREAL_SAVE_FUNCTION_NAME(Archive &archive)
const {
73 archive(cereal::base_class<Super>());
74 archive(CEREAL_NVP(size_));
75 archive(CEREAL_NVP(rdonly_));
76 archive(cereal::binary_data(values_, size_));
79 template<
class Archive>
80 void CEREAL_LOAD_FUNCTION_NAME(Archive &archive) {
81 archive(cereal::base_class<Super>());
82 archive(CEREAL_NVP(size_));
83 archive(CEREAL_NVP(rdonly_));
84 values_ =
new Value[size_];
85 archive(cereal::binary_data(values_, size_));
92 : values_(NULL), size_(0), rdonly_(false) {}
96 :
Super(
".StaticBuffer"), values_(values), size_(
size), rdonly_(false) {
97 ASSERT_require(
size==0 || values!=NULL);
100 :
Super(
".StaticBuffer"), values_(const_cast<
Value*>(values)), size_(
size), rdonly_(true) {
101 ASSERT_require(
size==0 || values!=NULL);
130 Address nWritten = newBuffer->write(values_, 0, size_);
131 if (nWritten != size_) {
132 throw std::runtime_error(
"StaticBuffer::copy() failed after copying " +
133 boost::lexical_cast<std::string>(nWritten) +
" of " +
134 boost::lexical_cast<std::string>(size_) +
135 (1==size_?
" value":
" values"));
141 return start < size_ ? size_-start : 0;
145 if (newSize != size_)
146 throw std::runtime_error(
"unable to resize StaticBuffer");
152 memcpy(buf, values_+address, n*
sizeof(values_[0]));
161 memcpy(values_+address, buf, n*
sizeof(values_[0]));