Commented most of src/serialization/ going to read up more on variant's and finish off the job/add last touchs next

This commit is contained in:
jebes 2014-10-13 16:00:09 -04:00
parent 6f65ab1904
commit b032619a9c
5 changed files with 315 additions and 97 deletions

View file

@ -28,6 +28,12 @@
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
/*! \file variant.h
*
* \brief for dealing with variants
*
* \detailed Variant: OOP Union
*/
#pragma once
#include <boost/variant/variant.hpp>
@ -39,11 +45,21 @@
#include <boost/mpl/pop_front.hpp>
#include "serialization.h"
/*! \struct variant_serialization_triats
*
* \brief used internally to contain a variant's traits/possible types
*
* \detailed see the macro VARIANT_TAG in serialization.h:140
*/
template <class Archive, class T>
struct variant_serialization_traits
{
};
/*! \struct variant_reader
*
* \brief reads a variant
*/
template <class Archive, class Variant, class TBegin, class TEnd>
struct variant_reader
{
@ -51,9 +67,10 @@ struct variant_reader
typedef typename boost::mpl::next<TBegin>::type TNext;
typedef typename boost::mpl::deref<TBegin>::type current_type;
// A tail recursive inline function.... okay...
static inline bool read(Archive &ar, Variant &v, variant_tag_type t)
{
if (variant_serialization_traits<Archive, current_type>::get_tag() == t) {
if(variant_serialization_traits<Archive, current_type>::get_tag() == t) {
current_type x;
if(!::do_serialize(ar, x))
{
@ -62,12 +79,15 @@ struct variant_reader
}
v = x;
} else {
// Tail recursive.... but no mutation is going on. Why?
return variant_reader<Archive, Variant, TNext, TEnd>::read(ar, v, t);
}
return true;
}
};
// This one just fails when you call it.... okay
// So the TEnd parameter must be specified/differnt from TBegin
template <class Archive, class Variant, class TBegin>
struct variant_reader<Archive, Variant, TBegin, TBegin>
{
@ -78,7 +98,6 @@ struct variant_reader<Archive, Variant, TBegin, TBegin>
ar.stream().setstate(std::ios::failbit);
return false;
}
};
@ -93,7 +112,9 @@ struct serializer<Archive<false>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
variant_tag_type t;
ar.begin_variant();
ar.read_variant_tag(t);
if(!variant_reader<Archive<false>, variant_type, typename boost::mpl::begin<types>::type, typename boost::mpl::end<types>::type>::read(ar, v, t))
if(!variant_reader<Archive<false>, variant_type,
typename boost::mpl::begin<types>::type,
typename boost::mpl::end<types>::type>::read(ar, v, t))
{
ar.stream().setstate(std::ios::failbit);
return false;