Alexandria  2.16
Please provide a description of the project.
GridAxis.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2020 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 
28 #include <type_traits>
29 #include <memory>
30 #include <boost/serialization/utility.hpp>
31 #include "GridContainer/GridAxis.h"
32 
33 namespace boost {
34 namespace serialization {
35 
38 template<typename Archive, typename T>
39 void 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 
46 template<typename Archive, typename T>
47 void saveType(Archive& ar, const T& t, typename std::enable_if<std::is_default_constructible<T>::value>::type* = 0) {
48  ar << t;
49 }
50 
56 template<typename Archive, typename T>
57 void 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 
68 template<typename Archive, typename T>
70  const unsigned int) {
71  std::string name = t->name();
72  ar << name;
73  size_t size = t->size();
74  ar << size;
75  for (size_t i=0; i<size; ++i) {
76  saveType(ar, (*t)[i]);
77  }
78 }
79 
83 template<typename Archive, typename T>
84 T loadType(Archive& ar, typename std::enable_if<std::is_default_constructible<T>::value>::type* = 0) {
85  T value;
86  ar >> value;
87  return value;
88 }
89 
95 template<typename Archive, typename T>
96 T loadType(Archive& ar, typename std::enable_if<!std::is_default_constructible<T>::value>::type* = 0) {
97  T* ptr;
98  ar >> ptr;
99  // We use a unique_ptr to guarantee deletion of the pointer
100  std::unique_ptr<T> deleter {ptr};
101  T value {*deleter};
102  return value;
103 }
104 
111 template<typename Archive, typename T>
113  const unsigned int) {
114  std::string name;
115  ar >> name;
116  size_t size;
117  ar >> size;
118  std::vector<T> values;
119  for (size_t i=0; i<size; ++i) {
120  T value = loadType<Archive, T>(ar);
121  values.push_back(value);
122  }
123  ::new(t) Euclid::GridContainer::GridAxis<T>(name, values);
124 }
125 
126 } /* end of namespace serialization */
127 } /* end of namespace boost */
128 
129 #endif /* GRIDCONTAINER_SERIALIZATION_GRIDAXIS_H */
130 
void save_construct_data(Archive &ar, const Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition: GridAxis.h:69
Definition: array.h:34
size_t size() const
Returns the number of knots 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
const std::string & name() const
Returns the name of the axis.
STL class.
T push_back(T... args)
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
void serialize(Archive &archive, std::array< CellType, ND > &array, const unsigned int)
Definition: array.h:38
STL class.
STL class.
T loadType(Archive &ar, typename std::enable_if< std::is_default_constructible< T >::value >::type *=0)
Definition: GridAxis.h:84
void load_construct_data(Archive &ar, Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition: GridAxis.h:112