1#ifndef VISTLE_ARCHIVES_H
2#define VISTLE_ARCHIVES_H
17#ifdef USE_BOOST_ARCHIVE
18#include <boost/archive/binary_oarchive.hpp>
19#include <boost/archive/binary_iarchive.hpp>
21#include <boost/archive/detail/oserializer.hpp>
22#include <boost/archive/detail/iserializer.hpp>
24#include <boost/archive/basic_binary_oprimitive.hpp>
25#include <boost/archive/basic_binary_iprimitive.hpp>
27#include <boost/serialization/nvp.hpp>
28#include <boost/serialization/array.hpp>
29#include <boost/serialization/string.hpp>
30#include <boost/serialization/vector.hpp>
31#include <boost/serialization/access.hpp>
32#include <boost/serialization/version.hpp>
33#if BOOST_VERSION >= 106400
34#include <boost/serialization/array_wrapper.hpp>
39#include <yas/mem_streams.hpp>
42#include <boost/mpl/vector.hpp>
62#ifdef USE_BOOST_ARCHIVE
65extern template class basic_binary_oprimitive<vistle::boost_oarchive, std::ostream::char_type,
66 std::ostream::traits_type>;
67extern template class basic_binary_iprimitive<vistle::boost_iarchive, std::istream::char_type,
68 std::istream::traits_type>;
69extern template class detail::common_oarchive<vistle::boost_oarchive>;
75#ifndef ARCHIVES_IMPL_H
76#define ARCHIVES_IMPL_H
92 bool is_array =
false;
93 size_t size = 0, compressedSize = 0;
96 message::CompressionMode compression = message::CompressionNone;
100 : name(name), is_array(is_array), size(size), data(data)
104 template<
class Archive>
112 template<
class Archive>
113 void serialize(Archive &ar,
unsigned version) {
123 virtual void saveArray(
const std::string &name,
int type,
const void *array) = 0;
128#ifdef USE_BOOST_ARCHIVE
130:
public boost::archive::binary_oarchive_impl<boost_oarchive, std::ostream::char_type, std::ostream::traits_type> {
131 typedef boost::archive::binary_oarchive_impl<boost_oarchive, std::ostream::char_type, std::ostream::traits_type>
135 boost_oarchive(std::streambuf &bsb,
unsigned int flags = 0);
138 void setCompressionMode(vistle::FieldCompressionMode mode);
141 void setSaver(std::shared_ptr<Saver> saver);
147 m_saver->saveArray(t.
name(), t->type(), &t);
157 std::shared_ptr<Saver> m_saver;
163template<
class Archive,
typename OS, std::
size_t F = detail::yas_flags>
171 yas_binary_oarchive(OS &os): yas::detail::binary_ostream<OS, F>(os), yas::detail::oarchive_header<F>(os) {}
176 using namespace yas::detail;
177 return serializer<type_properties<T>::value, serialization_method<T, this_type>::value, F, T>::save(
183 template<
typename Head,
typename... Tail>
186 return operator&(head).serialize(tail...);
189 template<
typename... Args>
200 FieldCompressionMode m_compress = Uncompressed;
201 double m_zfpRate = 8.;
202 int m_zfpPrecision = 8;
203 double m_zfpAccuracy = 1e-20;
204 std::shared_ptr<Saver> m_saver;
208 void setCompressionMode(vistle::FieldCompressionMode mode);
209 FieldCompressionMode compressionMode()
const;
211 void setZfpRate(
double rate);
212 double zfpRate()
const;
213 void setZfpAccuracy(
double rate);
214 double zfpAccuracy()
const;
215 void setZfpPrecision(
int precision);
216 int zfpPrecision()
const;
222 void setSaver(std::shared_ptr<Saver> saver);
228 std::size_t sz = m_os.
get_vector().capacity();
229 m_os.
get_vector().reserve(sz +
sizeof(T) * t->size() + 10000);
230 m_saver->saveArray(t.
name(), t->type(), &t);
250 virtual bool renameObjects()
const;
251 virtual std::string translateObjectName(
const std::string &name)
const;
252 virtual std::string translateArrayName(
const std::string &name)
const;
253 virtual void registerObjectNameTranslation(
const std::string &arname,
const std::string &name);
254 virtual void registerArrayNameTranslation(
const std::string &arname,
const std::string &name);
258#ifdef USE_BOOST_ARCHIVE
260:
public boost::archive::binary_iarchive_impl<boost_iarchive, std::istream::char_type, std::istream::traits_type> {
261 typedef boost::archive::binary_iarchive_impl<boost_iarchive, std::istream::char_type, std::istream::traits_type>
265 boost_iarchive(std::streambuf &bsb,
unsigned int flags = 0);
268 std::string translateObjectName(
const std::string &name)
const;
269 std::string translateArrayName(
const std::string &name)
const;
270 void registerObjectNameTranslation(
const std::string &arname,
const std::string &name)
const;
271 void registerArrayNameTranslation(
const std::string &arname,
const std::string &name)
const;
273 void setFetcher(std::shared_ptr<Fetcher> fetcher);
276 std::shared_ptr<Fetcher> fetcher()
const;
281 std::string name = translateArrayName(arname);
283 if (
auto arr = Shm::the().getArrayFromName<T>(name)) {
284 if (completeCallback)
285 completeCallback(name);
290 m_fetcher->requestArray(arname, shm<T>::array::typeId(), completeCallback);
294 const std::function<
void(Object::const_ptr)> &completeCallback)
const;
295 void setObjectCompletionHandler(
const std::function<
void()> &completer);
296 const std::function<void()> &objectCompletionHandler()
const;
299 bool m_rename =
false;
300 std::shared_ptr<Fetcher> m_fetcher;
301 ObjectData *m_currentObject =
nullptr;
302 std::function<void()> m_completer;
303 std::map<std::string, std::string> m_transObject, m_transArray;
308template<
class Archive,
typename IS, std::
size_t F = detail::yas_flags>
316 yas_binary_iarchive(IS &is): yas::detail::binary_istream<IS, F>(is), yas::detail::iarchive_header<F>(is) {}
321 using namespace yas::detail;
322 using real_type =
typename std::remove_reference<typename std::remove_const<T>::type>::type;
323 return serializer<type_properties<real_type>::value, serialization_method<real_type, this_type>::value, F,
324 real_type>::load(*
static_cast<this_type *
>(
this), v);
329 template<
typename Head,
typename... Tail>
332 return operator&(std::forward<Head>(head)).serialize(std::forward<Tail>(tail)...);
335 template<
typename... Args>
338 return serialize(std::forward<Args>(args)...);
350 std::string translateObjectName(
const std::string &name)
const;
351 std::string translateArrayName(
const std::string &name)
const;
352 void registerObjectNameTranslation(
const std::string &arname,
const std::string &name)
const;
353 void registerArrayNameTranslation(
const std::string &arname,
const std::string &name)
const;
355 void setFetcher(std::shared_ptr<Fetcher> fetcher);
358 std::shared_ptr<Fetcher> fetcher()
const;
363 std::string name = translateArrayName(arname);
365 if (
auto arr = Shm::the().getArrayFromName<T>(name)) {
366 if (completeCallback)
367 completeCallback(name);
376 void setObjectCompletionHandler(
const std::function<
void()> &completer);
377 const std::function<void()> &objectCompletionHandler()
const;
380 std::shared_ptr<Fetcher> m_fetcher;
382 std::function<void()> m_completer;
383 std::map<std::string, std::string> m_transObject, m_transArray;
387typedef boost::mpl::vector<
388#ifdef USE_BOOST_ARCHIVE
402typedef boost::mpl::vector<
403#ifdef USE_BOOST_ARCHIVE
420#ifdef USE_BOOST_ARCHIVE
421BOOST_SERIALIZATION_REGISTER_ARCHIVE(vistle::boost_oarchive)
422BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(vistle::boost_oarchive)
423BOOST_SERIALIZATION_REGISTER_ARCHIVE(vistle::boost_iarchive)
424BOOST_SERIALIZATION_USE_ARRAY_OPTIMIZATION(vistle::boost_iarchive)
#define ARCHIVE_ACCESS
Definition: archives_config.h:465
Definition: archives.h:244
virtual void requestObject(const std::string &name, const ObjectCompletionHandler &completeCallback)=0
virtual void requestArray(const std::string &name, int type, const ArrayCompletionHandler &completeCallback)=0
std::shared_ptr< const Object > const_ptr
Definition: object.h:68
Definition: archives.h:120
virtual void saveArray(const std::string &name, int type, const void *array)=0
virtual void saveObject(const std::string &name, obj_const_ptr obj)=0
Definition: shm_reference.h:15
const shm_name_t & name() const
Definition: shm_reference_impl.h:129
Definition: shm_obj_ref.h:15
ObjType::const_ptr getObject() const
Definition: shm_obj_ref_impl.h:110
const shm_name_t & name() const
Definition: shm_obj_ref_impl.h:128
Definition: vecstreambuf.h:52
Definition: vecstreambuf.h:12
const Vector & get_vector() const
Definition: vecstreambuf.h:42
Definition: archives.h:342
void fetchArray(const std::string &arname, const ArrayCompletionHandler &completeCallback) const
Definition: archives.h:361
Definition: archives.h:197
void saveArray(const vistle::ShmVector< T > &t)
Definition: archives.h:225
void saveObject(const vistle::shm_obj_ref< T > &t)
Definition: archives.h:235
#define V_COREEXPORT
Definition: export.h:9
void serialize(Archive &ar, vistle::Vector1 &v, const unsigned int version)
Definition: vector.h:105
Definition: serialize.h:35
Definition: allobjects.cpp:30
std::function< void(Object::const_ptr)> ObjectCompletionHandler
Definition: archives.h:88
boost::mpl::vector< yas_oarchive > OutputArchives
Definition: archives.h:415
std::vector< SubArchiveDirectoryEntry > SubArchiveDirectory
Definition: archives.h:118
std::shared_ptr< const Object > obj_const_ptr
Definition: archives.h:86
std::function< void(const std::string &name)> ArrayCompletionHandler
Definition: archives.h:87
boost::mpl::vector< yas_iarchive > InputArchives
Definition: archives.h:400
std::shared_ptr< Object > obj_ptr
Definition: archives.h:84
Definition: archives.h:51
double m_zfpAccuracy
Definition: archives.h:55
int m_zfpPrecision
Definition: archives.h:54
FieldCompressionMode m_compress
Definition: archives.h:52
double m_zfpRate
Definition: archives.h:53
Definition: archives.h:90
std::unique_ptr< buffer > storage
Definition: archives.h:95
SubArchiveDirectoryEntry(const std::string &name, bool is_array, size_t size, char *data)
Definition: archives.h:99
SubArchiveDirectoryEntry()
Definition: archives.h:98
std::string name
Definition: archives.h:91
ARCHIVE_ACCESS void serialize(Archive &ar)
Definition: archives.h:105
Definition: archives.h:309
this_type & operator&(T &&v)
Definition: archives.h:319
this_type & serialize()
Definition: archives.h:327
this_type & operator()(Args &&...args)
Definition: archives.h:336
Archive this_type
Definition: archives.h:314
this_type & serialize(Head &&head, Tail &&...tail)
Definition: archives.h:330
IS stream_type
Definition: archives.h:313
Definition: archives.h:164
this_type & operator()(const Args &...args)
Definition: archives.h:190
this_type & operator&(const T &v)
Definition: archives.h:174
Archive this_type
Definition: archives.h:169
OS stream_type
Definition: archives.h:168
this_type & serialize(const Head &head, const Tail &...tail)
Definition: archives.h:184
this_type & serialize()
Definition: archives.h:181