-
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding MPark's variant (V1.4.0) to HPX
- adding serialization support for hpx::util::variant - flyby: add support for skipping whole files to inspect (without modifying them)
- Loading branch information
Showing
9 changed files
with
2,989 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,52 @@ | ||
// copyright (c) 2005 | ||
// troy d. straszheim <[email protected]> | ||
// http://www.resophonic.com | ||
// Copyright (c) 2015 Anton Bikineev | ||
// Copyright (c) 2017-2019 Hartmut Kaiser | ||
// | ||
// 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 HPX_SERIALIZATION_VARIANT_HPP | ||
#define HPX_SERIALIZATION_VARIANT_HPP | ||
#if !defined(HPX_DATASTRUCTURES_VARIANT_SERIALIZATION_HPP) | ||
#define HPX_DATASTRUCTURES_VARIANT_SERIALIZATION_HPP | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/runtime/serialization/serialization_fwd.hpp> | ||
#include <hpx/errors.hpp> | ||
#include <hpx/datastructures/variant.hpp> | ||
|
||
#include <boost/variant.hpp> | ||
#include <hpx/runtime/serialization/serialization_fwd.hpp> | ||
#include <hpx/runtime/serialization/boost_variant.hpp> | ||
#include <hpx/errors/throw_exception.hpp> | ||
|
||
#include <cstddef> | ||
#include <utility> | ||
|
||
namespace hpx { namespace serialization | ||
{ | ||
struct variant_save_visitor : boost::static_visitor<> | ||
{ | ||
variant_save_visitor(output_archive& ar) | ||
: m_ar(ar) | ||
{} | ||
|
||
template <typename T> | ||
void operator()(T const& value) const | ||
{ | ||
m_ar << value; | ||
} | ||
|
||
private: | ||
output_archive & m_ar; | ||
}; | ||
|
||
template <typename ... Ts> | ||
struct variant_impl; | ||
|
||
template <typename T, typename ... Ts> | ||
struct variant_impl<T, Ts...> | ||
{ | ||
template <typename V> | ||
static void load(input_archive& ar, int which, V& v) | ||
{ | ||
if (which == 0) | ||
{ | ||
// note: A non-intrusive implementation (such as this one) | ||
// necessary has to copy the value. This wouldn't be necessary | ||
// with an implementation that de-serialized to the address of the | ||
// aligned storage included in the variant. | ||
T value; | ||
ar >> value; | ||
v = std::move(value); | ||
return; | ||
} | ||
variant_impl<Ts...>::load(ar, which - 1, v); | ||
} | ||
}; | ||
|
||
template <> | ||
struct variant_impl<> | ||
{ | ||
template <typename V> | ||
static void load(input_archive& /*ar*/, int /*which*/, V& /*v*/) | ||
{ | ||
} | ||
}; | ||
|
||
template <typename ... T> | ||
void save(output_archive& ar, boost::variant<T...> const& v, unsigned) | ||
/////////////////////////////////////////////////////////////////////////// | ||
template <typename... Ts> | ||
void save(output_archive& ar, hpx::util::variant<Ts...> const& v, unsigned) | ||
{ | ||
int which = v.which(); | ||
std::size_t which = v.index(); | ||
ar << which; | ||
variant_save_visitor visitor(ar); | ||
v.apply_visitor(visitor); | ||
detail::variant_save_visitor visitor(ar); | ||
hpx::util::visit(visitor, v); | ||
} | ||
|
||
template <typename ... T> | ||
void load(input_archive& ar, boost::variant<T...>& v, unsigned) | ||
template <typename... Ts> | ||
void load(input_archive& ar, hpx::util::variant<Ts...>& v, unsigned) | ||
{ | ||
int which; | ||
std::size_t which; | ||
ar >> which; | ||
if (which >= static_cast<int>(sizeof...(T))) | ||
if (which >= sizeof...(Ts)) | ||
{ | ||
// this might happen if a type was removed from the list of variant | ||
// types | ||
HPX_THROW_EXCEPTION(serialization_error | ||
, "load<Archive, Variant, version>" | ||
, "type was removed from the list of variant types"); | ||
} | ||
variant_impl<T...>::load(ar, which, v); | ||
detail::variant_impl<Ts...>::load(ar, which, v); | ||
} | ||
|
||
HPX_SERIALIZATION_SPLIT_FREE_TEMPLATE( | ||
(template<typename ... T>), (boost::variant<T...>)); | ||
(template <typename ... Ts>), (hpx::util::variant<Ts...>)); | ||
}} | ||
|
||
#endif //HPX_SERIALIZATION_VARIANT_HPP | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
libs/datastructures/include/hpx/datastructures/detail/hpx-no-inspect-files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
variant.hpp |
Oops, something went wrong.