Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
GridAxis.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_GRIDAXIS_H
26#define GRIDCONTAINER_SERIALIZATION_GRIDAXIS_H
27
29#include <boost/serialization/utility.hpp>
30#include <memory>
31#include <type_traits>
32
33namespace boost {
34namespace serialization {
35
38template <typename Archive, typename T>
39void serialize(Archive&, Euclid::GridContainer::GridAxis<T>&, const unsigned int) {
40 // Nothing here as everything is done with the data passed to the constructor
41}
42
46template <typename Archive, typename T>
47void saveType(Archive& ar, const T& t, typename std::enable_if<std::is_default_constructible<T>::value>::type* = 0) {
48 ar << t;
49}
50
56template <typename Archive, typename T>
57void saveType(Archive& ar, const T& t, typename std::enable_if<!std::is_default_constructible<T>::value>::type* = 0) {
58 const T* ptr = &t;
59 ar << ptr;
60}
61
68template <typename Archive, typename T>
69void save_construct_data(Archive& ar, const Euclid::GridContainer::GridAxis<T>* t, const unsigned int) {
70 std::string name = t->name();
71 ar << name;
72 size_t size = t->size();
73 ar << size;
74 for (size_t i = 0; i < size; ++i) {
75 saveType(ar, (*t)[i]);
76 }
77}
78
82template <typename Archive, typename T>
84 T value;
85 ar >> value;
86 return value;
87}
88
94template <typename Archive, typename T>
96 T* ptr;
97 ar >> ptr;
98 // We use a unique_ptr to guarantee deletion of the pointer
99 std::unique_ptr<T> deleter{ptr};
100 T value{*deleter};
101 return value;
102}
103
110template <typename Archive, typename T>
111void load_construct_data(Archive& ar, Euclid::GridContainer::GridAxis<T>* t, const unsigned int) {
112 std::string name;
113 ar >> name;
114 size_t size;
115 ar >> size;
116 std::vector<T> values;
117 for (size_t i = 0; i < size; ++i) {
118 T value = loadType<Archive, T>(ar);
119 values.push_back(value);
120 }
121 ::new (t) Euclid::GridContainer::GridAxis<T>(name, values);
122}
123
124} /* end of namespace serialization */
125} /* end of namespace boost */
126
127#endif /* GRIDCONTAINER_SERIALIZATION_GRIDAXIS_H */
Provides information related with an axis of a GridContainer.
Definition GridAxis.h:49
size_t size() const
Returns the number of knots of the axis.
const std::string & name() const
Returns the name of the axis.
void saveType(Archive &ar, const T &t, typename std::enable_if< std::is_default_constructible< T >::value >::type *=0)
Definition GridAxis.h:47
void serialize(Archive &archive, std::array< CellType, ND > &array, const unsigned int)
Definition array.h:37
T loadType(Archive &ar, typename std::enable_if< std::is_default_constructible< T >::value >::type *=0)
Definition GridAxis.h:83
void save_construct_data(Archive &ar, const Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition GridAxis.h:69
void load_construct_data(Archive &ar, Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition GridAxis.h:111
Definition array.h:33
T push_back(T... args)