aboutsummaryrefslogtreecommitdiff
path: root/src/serialization/variant.h
diff options
context:
space:
mode:
authorjebes <psteidelprogramming@gmail.com>2014-10-13 16:00:09 -0400
committerjebes <psteidelprogramming@gmail.com>2014-10-13 16:00:09 -0400
commitb032619a9cb1850dcbb1381b1e77ca1d7c2a00a7 (patch)
tree5e13ac793a68ab974ff173b4d9892386f40267c2 /src/serialization/variant.h
parentMerge pull request #175 (diff)
downloadmonero-b032619a9cb1850dcbb1381b1e77ca1d7c2a00a7.tar.xz
Commented most of src/serialization/ going to read up more on variant's and finish off the job/add last touchs next
Diffstat (limited to '')
-rw-r--r--src/serialization/variant.h27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/serialization/variant.h b/src/serialization/variant.h
index 3b03f1ba5..9b5d54237 100644
--- a/src/serialization/variant.h
+++ b/src/serialization/variant.h
@@ -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;