|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58023 - sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example
From: erwann.rogard_at_[hidden]
Date: 2009-11-28 18:05:34
Author: e_r
Date: 2009-11-28 18:05:34 EST (Sat, 28 Nov 2009)
New Revision: 58023
URL: http://svn.boost.org/trac/boost/changeset/58023
Log:
m
Text files modified:
sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp | 51 +++++++++++++++++++++++++++++++++++++--
1 files changed, 48 insertions(+), 3 deletions(-)
Modified: sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp
==============================================================================
--- sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp (original)
+++ sandbox/statistics/detail/multi_array/libs/statistics/detail/multi_array/example/serialize.cpp 2009-11-28 18:05:34 EST (Sat, 28 Nov 2009)
@@ -9,8 +9,12 @@
#include <vector>
#include <string>
#include <fstream>
+#include <boost/mpl/int.hpp>
+#include <boost/fusion/include/make_map.hpp>
+#include <boost/fusion/include/at_key.hpp>
#include <boost/multi_array.hpp>
#include <boost/statistics/detail/multi_array/serialization/serialize.hpp>
+#include <boost/statistics/detail/fusion/serialization/include.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
@@ -29,13 +33,16 @@
typedef std::ifstream ifs_;
typedef boost::archive::text_oarchive oa_;
typedef boost::archive::text_iarchive ia_;
- typedef double val_;
+ typedef unsigned val_;
typedef std::vector<val_> vec_;
+ typedef boost::mpl::int_<0> tag_;
+ typedef boost::fusion::result_of::make_map<tag_,val_>::type map_;
typedef boost::multi_array<val_, 2> array_;
typedef boost::multi_array<vec_,2> array_vec_;
+ typedef boost::multi_array<map_,2> array_map_;
typedef boost::array<ma::multi_array_base::index,2> extents_;
- unsigned n0 = 2;
- unsigned n1 = 2;
+ const unsigned n0 = 2;
+ const unsigned n1 = 2;
{
const str_ path = "./multi_array_serialization";
{
@@ -111,6 +118,44 @@
}
}
}
+ {
+ const str_ path = "./multi_array_serialization3";
+ {
+
+
+ ofs_ ofs(path.c_str());
+ oa_ oa(ofs);
+ extents_ extents = {{ n0, n1 }};
+ array_map_ a(extents);
+ for(unsigned i = 0; i<n0; i++)
+ {
+ for(unsigned j = 0; j<n1; j++)
+ {
+ map_ map = boost::fusion::make_map<tag_>(i * n1 + j);
+ a[i][j] = map;
+ }
+ }
+ oa << a;
+ }
+ {
+ ifs_ ifs(path.c_str());
+ ia_ ia(ifs);
+ array_map_ a;
+ ia >> a;
+ for(unsigned i = 0; i<n0; i++)
+ {
+ for(unsigned j = 0; j<n1; j++)
+ {
+ map_ map = a[i][j];
+ val_ val = boost::fusion::at_key<tag_>(map);
+ BOOST_ASSERT(
+ val == i * n1 + j
+ );
+ os << val << ' ';
+ }
+ }
+ }
+ }
os << "<-" << std::endl;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk