diff --git a/include/boost/histogram/axis.hpp b/include/boost/histogram/axis.hpp index 547618df..976f4fdd 100644 --- a/include/boost/histogram/axis.hpp +++ b/include/boost/histogram/axis.hpp @@ -1,12 +1,15 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGRAM_AXIS_HPP_ #define _BOOST_HISTOGRAM_AXIS_HPP_ #include #include #include -#include -#include -#include #include #include #include @@ -37,14 +40,8 @@ private: int size_; std::string label_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - using namespace serialization; - ar & size_; - ar & label_; - } + friend void serialize(Archive& ar, axis_base & base, unsigned version); }; // mixin for real-valued axes @@ -73,7 +70,7 @@ public: const std::string& label = std::string(), bool uoflow = true); - regular_axis() {} + regular_axis() : min_(0), range_(0) {} regular_axis(const regular_axis&); regular_axis& operator=(const regular_axis&); @@ -87,15 +84,8 @@ public: private: double min_, range_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - using namespace serialization; - ar & boost::serialization::base_object(*this); - ar & min_; - ar & range_; - } + friend void serialize(Archive& ar, regular_axis & axis ,unsigned version); }; // real polar axis (constant bin widths, wraps around) @@ -105,7 +95,7 @@ public: polar_axis(int n, double start = 0.0, const std::string& label = std::string()); - polar_axis() {} + polar_axis() : start_(0) {} polar_axis(const polar_axis&); polar_axis& operator=(const polar_axis&); @@ -121,14 +111,8 @@ public: private: double start_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - using namespace serialization; - ar & boost::serialization::base_object(*this); - ar & start_; - } + friend void serialize(Archive& ar, polar_axis & axis, unsigned version); }; // real variable axis (varying bin widths) @@ -171,15 +155,8 @@ public: private: boost::scoped_array x_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - ar & boost::serialization::base_object(*this); - if (Archive::is_loading::value) - x_.reset(new double[bins() + 1]); - ar & serialization::make_array(x_.get(), bins() + 1); - } + friend void serialize(Archive& ar, variable_axis & axis, unsigned version); }; class category_axis { @@ -205,13 +182,8 @@ public: private: std::vector categories_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - using namespace serialization; - ar & categories_; - } + friend void serialize(Archive& ar, category_axis & axis, unsigned version); }; class integer_axis: public axis_base { @@ -234,14 +206,8 @@ public: private: int min_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - using namespace serialization; - ar & boost::serialization::base_object(*this); - ar & min_; - } + friend void serialize(Archive& ar, integer_axis & axis, unsigned version); }; namespace detail { diff --git a/include/boost/histogram/basic_histogram.hpp b/include/boost/histogram/basic_histogram.hpp index 0c00ca22..646c723e 100644 --- a/include/boost/histogram/basic_histogram.hpp +++ b/include/boost/histogram/basic_histogram.hpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGRAM_BASE_HPP_ #define _BOOST_HISTOGRAM_BASE_HPP_ @@ -5,10 +11,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include @@ -112,17 +114,8 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_BASE_CTOR private: axes_type axes_; - friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - using namespace serialization; - unsigned size = axes_.size(); - ar & size; - if (Archive::is_loading::value) - axes_.resize(size); - ar & serialization::make_array(&axes_[0], size); - } + friend void serialize(Archive& ar, basic_histogram & h, unsigned version); }; } diff --git a/include/boost/histogram/detail/nstore.hpp b/include/boost/histogram/detail/nstore.hpp index 713d1793..d077b898 100644 --- a/include/boost/histogram/detail/nstore.hpp +++ b/include/boost/histogram/detail/nstore.hpp @@ -1,10 +1,14 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGRAM_DETAIL_NSTORE_HPP_ #define _BOOST_HISTOGRAM_DETAIL_NSTORE_HPP_ #include #include -#include -#include #include #include #include @@ -178,68 +182,12 @@ private: uint64_t ivalue(size_type) const; template - void serialize_save_impl(Archive & ar, unsigned version) - { - std::vector buf; - if (zero_suppression_encode(buf, (T*)buffer_, size_)) { - bool is_zero_suppressed = true; - ar & is_zero_suppressed; - ar & buf; - } else { - bool is_zero_suppressed = false; - ar & is_zero_suppressed; - ar & serialization::make_array((T*)buffer_, size_); - } - } - + friend void serialize_save_impl(Archive & ar, const nstore &, unsigned version); template - void serialize_load_impl(Archive & ar, bool is_zero_suppressed, unsigned version) - { - if (is_zero_suppressed) { - std::vector buf; - ar & buf; - zero_suppression_decode((T*)buffer_, size_, buf); - } else { - ar & serialization::make_array((T*)buffer_, size_); - } - } - friend class serialization::access; + friend void serialize_load_impl(Archive & ar, nstore &, + bool is_zero_suppressed, unsigned version); template - void serialize(Archive& ar, unsigned version) - { - const size_type s = size_; - const unsigned d = depth_; - ar & size_; - ar & depth_; - if (s != size_ || d != depth_) { - // realloc is safe if buffer_ is null - buffer_ = std::realloc(buffer_, size_ * depth_); - } - if (buffer_ == 0 && size_ > 0) - throw std::bad_alloc(); - - if (Archive::is_saving::value) { - switch (depth_) { - case d1: serialize_save_impl (ar, version); break; - case d2: serialize_save_impl(ar, version); break; - case d4: serialize_save_impl(ar, version); break; - case d8: serialize_save_impl(ar, version); break; - case dw: serialize_save_impl (ar, version); break; - } - } - - if (Archive::is_loading::value) { - bool is_zero_suppressed = false; - ar & is_zero_suppressed; - switch (depth_) { - case d1 : serialize_load_impl (ar, is_zero_suppressed, version); break; - case d2 : serialize_load_impl(ar, is_zero_suppressed, version); break; - case d4 : serialize_load_impl(ar, is_zero_suppressed, version); break; - case d8 : serialize_load_impl(ar, is_zero_suppressed, version); break; - case dw : serialize_load_impl (ar, is_zero_suppressed, version); break; - } - } - } + friend void serialize(Archive& ar, nstore &, unsigned version); }; } diff --git a/include/boost/histogram/detail/wtype.hpp b/include/boost/histogram/detail/wtype.hpp index 0f608c9a..0053eb25 100644 --- a/include/boost/histogram/detail/wtype.hpp +++ b/include/boost/histogram/detail/wtype.hpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGRAM_DETAIL_WTYPE_HPP_ #define _BOOST_HISTOGRAM_DETAIL_WTYPE_HPP_ @@ -25,9 +31,7 @@ struct wtype { { return w == o.w && w2 == o.w2; } bool operator!=(const wtype& o) const { return w != o.w || w2 != o.w2; } - template - void serialize(Archive& ar, unsigned version) - { ar & w; ar & w2; } + }; static diff --git a/include/boost/histogram/detail/zero_suppression.hpp b/include/boost/histogram/detail/zero_suppression.hpp index b2fc3a03..9e056327 100644 --- a/include/boost/histogram/detail/zero_suppression.hpp +++ b/include/boost/histogram/detail/zero_suppression.hpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGRAM_DETAIL_ZERO_SUPPRESSION_HPP_ #define _BOOST_HISTOGRAM_DETAIL_ZERO_SUPPRESSION_HPP_ @@ -15,32 +21,39 @@ bool zero_suppression_encode(std::vector& output, const T* input, uintptr_t size) { - #define BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL { \ - if ((size - output.size()) < 2) \ - return false; \ - output.push_back(0); \ - output.push_back(nzero); \ - nzero = 0; \ - } - const T* input_end = input + size; T nzero = 0; for (; input != input_end; ++input) { if (*input != 0) { - if (nzero) - BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL + if (nzero) { + if ((size - output.size()) < 2) + return false; + output.push_back(0); + output.push_back(nzero); + nzero = 0; + } if (output.size() == size) return false; output.push_back(*input); } else { ++nzero; - if (nzero == 0) // overflowed to zero - BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL + if (nzero == 0) { // overflowed to zero + if ((size - output.size()) < 2) + return false; + output.push_back(0); + output.push_back(nzero); + nzero = 0; + } } } - if (nzero) - BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL + if (nzero){ + if ((size - output.size()) < 2) + return false; + output.push_back(0); + output.push_back(nzero); + nzero = 0; + } return true; } diff --git a/include/boost/histogram/histogram.hpp b/include/boost/histogram/histogram.hpp index 0e427e97..6c7b9ef5 100644 --- a/include/boost/histogram/histogram.hpp +++ b/include/boost/histogram/histogram.hpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGRAM_HISTOGRAM_HPP_ #define _BOOST_HISTOGRAM_HISTOGRAM_HPP_ @@ -171,16 +177,10 @@ private: friend class serialization::access; template - void serialize(Archive& ar, unsigned version) - { - ar & serialization::base_object(*this); - ar & data_; - } - - friend class histogram_access; + friend void serialize(Archive& ar, histogram & h, unsigned version); }; -histogram operator+(const histogram& a, const histogram& b) { +inline histogram operator+(const histogram& a, const histogram& b) { histogram result(a); return result += b; } diff --git a/include/boost/histogram/visitors.hpp b/include/boost/histogram/visitors.hpp index 0c8380d4..9b164bc3 100644 --- a/include/boost/histogram/visitors.hpp +++ b/include/boost/histogram/visitors.hpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_HISTOGARM_VISITORS_HPP_ #define _BOOST_HISTOGARM_VISITORS_HPP_ diff --git a/src/axis.cpp b/src/axis.cpp index f497fa61..ee12e04d 100644 --- a/src/axis.cpp +++ b/src/axis.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/src/basic_histogram.cpp b/src/basic_histogram.cpp index d1f28832..d11acda2 100644 --- a/src/basic_histogram.cpp +++ b/src/basic_histogram.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/src/histogram.cpp b/src/histogram.cpp index 0d05cea2..14e41d74 100644 --- a/src/histogram.cpp +++ b/src/histogram.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include diff --git a/src/nstore.cpp b/src/nstore.cpp index 210a192d..5c38451c 100644 --- a/src/nstore.cpp +++ b/src/nstore.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/src/python/axis.cpp b/src/python/axis.cpp index 4ebdd2ed..95ce613b 100644 --- a/src/python/axis.cpp +++ b/src/python/axis.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/src/python/basic_histogram.cpp b/src/python/basic_histogram.cpp index ff74a88a..3bdd6d3b 100644 --- a/src/python/basic_histogram.cpp +++ b/src/python/basic_histogram.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/src/python/histogram.cpp b/src/python/histogram.cpp index 72d527c0..e7d8a5cd 100644 --- a/src/python/histogram.cpp +++ b/src/python/histogram.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include "serialization_suite.hpp" #include #include diff --git a/src/python/module.cpp b/src/python/module.cpp index 8b264a64..703b5dbf 100644 --- a/src/python/module.cpp +++ b/src/python/module.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #ifdef HAVE_NUMPY # define PY_ARRAY_UNIQUE_SYMBOL boost_histogram_ARRAY_API diff --git a/src/python/serialization_suite.hpp b/src/python/serialization_suite.hpp index f7865841..6f52b0d1 100644 --- a/src/python/serialization_suite.hpp +++ b/src/python/serialization_suite.hpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #ifndef _BOOST_PYTHON_SERIALIZATION_SUITE_HPP_ #define _BOOST_PYTHON_SERIALIZATION_SUITE_HPP_ diff --git a/src/zero_suppression.cpp b/src/zero_suppression.cpp index 5da5a2c6..d2bbcfa6 100644 --- a/src/zero_suppression.cpp +++ b/src/zero_suppression.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include namespace boost { @@ -9,20 +15,18 @@ bool zero_suppression_encode(std::vector& output, const wtype* input, uintptr_t size) { - #define BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL { \ - if ((size - output.size()) < 2) \ - return false; \ - output.push_back(0); \ - output.push_back(nzero); \ - nzero = 0; \ - } const wtype* input_end = input + size; uint32_t nzero = 0; for (; input != input_end; ++input) { if (*input != 0) { - if (nzero) - BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL + if (nzero) { + if ((size - output.size()) < 2) + return false; + output.push_back(0); + output.push_back(nzero); + nzero = 0; + } if (output.size() == size) return false; output.push_back(*input); @@ -30,11 +34,22 @@ zero_suppression_encode(std::vector& output, const wtype* input, else { ++nzero; if (nzero == 0) // overflowed to zero - BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL + { + if ((size - output.size()) < 2) + return false; + output.push_back(0); + output.push_back(nzero); + nzero = 0; + } } } - if (nzero) - BOOST_HISTOGRAM_ZERO_SUPPRESSION_FILL + if (nzero){ + if ((size - output.size()) < 2) + return false; + output.push_back(0); + output.push_back(nzero); + nzero = 0; + } return true; } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5c404129..84c79a89 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -19,6 +19,7 @@ import os ; test-suite ts : [ compile check/sizeof.cpp ] + [ compile serialization.cpp ] #[ compile check/speed_vs_root.cpp ] //not in yet, cause it needs an external library [ run axis_test.cpp /boost//histogram /boost//test_exec_monitor : BOOST_TEST_DYN_LINK=1 ] [ run histogram_test.cpp /boost//histogram /boost//test_exec_monitor : BOOST_TEST_DYN_LINK=1 ] diff --git a/test/axis_test.cpp b/test/axis_test.cpp index 23a1cf3a..bb6bf071 100644 --- a/test/axis_test.cpp +++ b/test/axis_test.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #define BOOST_TEST_MODULE axis_test #include diff --git a/test/check/sizeof.cpp b/test/check/sizeof.cpp index 08f541c9..8e1f0cc1 100644 --- a/test/check/sizeof.cpp +++ b/test/check/sizeof.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/test/check/speed_vs_root.cpp b/test/check/speed_vs_root.cpp index 9ea2318f..77ec590f 100644 --- a/test/check/speed_vs_root.cpp +++ b/test/check/speed_vs_root.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #include diff --git a/test/histogram_test.cpp b/test/histogram_test.cpp index 0e9f7435..69d1be6c 100644 --- a/test/histogram_test.cpp +++ b/test/histogram_test.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #define BOOST_TEST_MODULE histogram_test #include diff --git a/test/nstore_test.cpp b/test/nstore_test.cpp index 594c51de..961b15ec 100644 --- a/test/nstore_test.cpp +++ b/test/nstore_test.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #include #define BOOST_TEST_MODULE nstore_test diff --git a/test/zero_suppression_test.cpp b/test/zero_suppression_test.cpp index 7b415eb6..bb158b17 100644 --- a/test/zero_suppression_test.cpp +++ b/test/zero_suppression_test.cpp @@ -1,3 +1,9 @@ +// Copyright 2015-2016 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + #include #define BOOST_TEST_MODULE zero_suppression_test #include