Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
tuple.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012-2021 Euclid Science Ground Segment
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 3.0 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
25#ifndef GRIDCONTAINER_SERIALIZATION_TUPLE_H
26#define GRIDCONTAINER_SERIALIZATION_TUPLE_H
27
28#include <boost/serialization/split_free.hpp>
29#include <memory>
30#include <tuple>
31#include <type_traits>
32
33namespace boost {
34namespace serialization {
35
39template <size_t N>
40struct Save {
41
44 template <typename Archive, typename... Args>
45 static void save(Archive& ar, const std::tuple<Args...>& t, const unsigned int version,
47 typename std::tuple_element<N - 1, std::tuple<Args...>>::type>::value>::type* = 0) {
48 ar << std::get<N - 1>(t);
49 Save<N - 1>::save(ar, t, version);
50 }
51
55 template <typename Archive, typename... Args>
56 static void save(Archive& ar, const std::tuple<Args...>& t, const unsigned int version,
58 typename std::tuple_element<N - 1, std::tuple<Args...>>::type>::value>::type* = 0) {
59 // Do NOT delete this pointer! It points in the element of the tuple and
60 // the tuple will take care of the memory management
61 typename std::remove_reference<decltype(std::get<N - 1>(t))>::type* ptr = &std::get<N - 1>(t);
62 ar << ptr;
63 Save<N - 1>::save(ar, t, version);
64 }
65};
66
69template <>
70struct Save<0> {
72 template <typename Archive, typename... Args>
73 static void save(Archive&, const std::tuple<Args...>&, const unsigned int) {}
74};
75
80template <size_t N>
81struct Load {
82
86 template <typename Archive, typename... Args>
87 static void load(Archive& ar, std::tuple<Args...>& t, const unsigned int version,
89 typename std::tuple_element<N - 1, std::tuple<Args...>>::type>::value>::type* = 0) {
90 ar >> std::get<N - 1>(t);
91 Load<N - 1>::load(ar, t, version);
92 }
93
98 template <typename Archive, typename... Args>
99 static void load(Archive& ar, std::tuple<Args...>& t, const unsigned int version,
101 typename std::tuple_element<N - 1, std::tuple<Args...>>::type>::value>::type* = 0) {
102 typedef typename std::remove_reference<decltype(std::get<N - 1>(t))>::type ElementType;
103 ElementType* ptr;
104 ar >> ptr;
105 // We use a unique_ptr to guarantee deletion of the pointer
106 std::unique_ptr<ElementType> deleter{ptr};
107 std::get<N - 1>(t) = *deleter;
108 Load<N - 1>::load(ar, t, version);
109 }
110};
111
114template <>
115struct Load<0> {
117 template <typename Archive, typename... Args>
118 static void load(Archive&, std::tuple<Args...>&, const unsigned int) {}
119};
120
123template <typename Archive, typename... Args>
124void save(Archive& ar, const std::tuple<Args...>& t, const unsigned int version) {
125 Save<sizeof...(Args)>::save(ar, t, version);
126}
127
130template <typename Archive, typename... Args>
131void load(Archive& ar, std::tuple<Args...>& t, const unsigned int version) {
132 Load<sizeof...(Args)>::load(ar, t, version);
133}
134
137template <typename Archive, typename... Args>
138void serialize(Archive& ar, std::tuple<Args...>& t, const unsigned int version) {
139 split_free(ar, t, version);
140}
141
142} /* end of namespace serialization */
143} /* end of namespace boost */
144
145#endif /* GRIDCONTAINER_SERIALIZATION_TUPLE_H */
void serialize(Archive &archive, std::array< CellType, ND > &array, const unsigned int)
Definition array.h:37
void load(Archive &ar, Euclid::GridContainer::VectorValueProxy< T > &value_proxy, const unsigned int)
void save(Archive &ar, const Euclid::GridContainer::VectorValueProxy< T > &value_proxy, const unsigned int)
Definition array.h:33
static void load(Archive &, std::tuple< Args... > &, const unsigned int)
This method does nothing. It exists to break the recursion.
Definition tuple.h:118
static void load(Archive &ar, std::tuple< Args... > &t, const unsigned int version, typename std::enable_if< std::is_default_constructible< typename std::tuple_element< N - 1, std::tuple< Args... > >::type >::value >::type *=0)
Definition tuple.h:87
static void load(Archive &ar, std::tuple< Args... > &t, const unsigned int version, typename std::enable_if<!std::is_default_constructible< typename std::tuple_element< N - 1, std::tuple< Args... > >::type >::value >::type *=0)
Definition tuple.h:99
static void save(Archive &, const std::tuple< Args... > &, const unsigned int)
This method does nothing. It exists to break the recursion.
Definition tuple.h:73
static void save(Archive &ar, const std::tuple< Args... > &t, const unsigned int version, typename std::enable_if< std::is_default_constructible< typename std::tuple_element< N - 1, std::tuple< Args... > >::type >::value >::type *=0)
Definition tuple.h:45
static void save(Archive &ar, const std::tuple< Args... > &t, const unsigned int version, typename std::enable_if<!std::is_default_constructible< typename std::tuple_element< N - 1, std::tuple< Args... > >::type >::value >::type *=0)
Definition tuple.h:56