Alexandria  2.16
Please provide a description of the project.
GridContainer.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 
26 #ifndef GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H
27 #define GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H
28 
29 #include <type_traits>
30 #include <memory>
31 #include <boost/serialization/vector.hpp>
32 #include <boost/serialization/split_free.hpp>
33 #include "GridContainer/GridAxis.h"
37 
38 namespace boost {
39 namespace serialization {
40 
43 template<class Archive, typename GridCellManager, typename... AxesTypes>
44 void save(Archive& ar, const Euclid::GridContainer::GridContainer<GridCellManager,AxesTypes...>& grid, const unsigned int,
46  for (auto& cell : grid) {
47  ar << cell;
48  }
49 }
50 
53 template<class Archive, typename GridCellManager, typename... AxesTypes>
54 void save(Archive& ar, const Euclid::GridContainer::GridContainer<GridCellManager,AxesTypes...>& grid, const unsigned int,
56  for (auto& cell : grid) {
57  // Do NOT delete this pointer! It points to the cell of the grid and the
58  // grid will take care of the memory management
59  typename std::remove_reference<decltype(cell)>::type* ptr = &cell;
60  ar << ptr;
61  }
62 }
63 
66 template<class Archive, typename GridCellManager, typename... AxesTypes>
69  for (auto& cell : grid) {
70  ar >> cell;
71  }
72 }
73 
76 template<class Archive, typename GridCellManager, typename... AxesTypes>
79  for (auto& cell : grid) {
81  ar >> ptr;
82  // We use a unique_ptr to guarantee deletion of the pointer
84  cell = *deleter;
85  }
86 }
87 
92 template<class Archive, typename GridCellManager, typename... AxesTypes>
93 void serialize(Archive& ar, Euclid::GridContainer::GridContainer<GridCellManager,AxesTypes...>& grid, const unsigned int version) {
95  "Boost serialization of GridContainer with unsupported GridCellManager");
96  split_free(ar, grid, version);
97 }
98 
104 template<class Archive, typename GridCellManager, typename... AxesTypes>
106  const unsigned int) {
108  ar << axes_tuple;
109 }
110 
113 template <typename T>
115  return {"", {}};
116 }
117 
123 template<class Archive, typename GridCellManager, typename... AxesTypes>
125  const unsigned int) {
126  // We create a tuple containing empty GridAxis objects. These will be replaced
127  // when we read from the stream with the real GridAxis objects. We have to do
128  // that because the GridAxis does not have a default constructor.
129  std::tuple<Euclid::GridContainer::GridAxis<AxesTypes>...> axes_tuple {(emptyGridAxis<AxesTypes>())...};
130  ar >> axes_tuple;
131  ::new(t) Euclid::GridContainer::GridContainer<GridCellManager,AxesTypes...>(axes_tuple);
132 }
133 
134 } /* end of namespace serialization */
135 } /* end of namespace boost */
136 
137 #endif /* GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H */
138 
void save_construct_data(Archive &ar, const Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition: GridAxis.h:69
Definition: array.h:34
Class used by the GridContainer to access the different CellManagers.
void load(Archive &ar, Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes... > &grid, const unsigned int, typename std::enable_if< std::is_default_constructible< typename Euclid::GridContainer::GridCellManagerTraits< GridCellManager >::data_type >::value >::type *=0)
Definition: GridContainer.h:67
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
void save(Archive &ar, const Euclid::GridContainer::GridContainer< GridCellManager, AxesTypes... > &grid, const unsigned int, typename std::enable_if< std::is_default_constructible< typename Euclid::GridContainer::GridCellManagerTraits< GridCellManager >::data_type >::value >::type *=0)
Definition: GridContainer.h:44
STL class.
void load_construct_data(Archive &ar, Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition: GridAxis.h:112
GridCellManager::data_type data_type
The type of the data kept by the GridCellManager.
Euclid::GridContainer::GridAxis< T > emptyGridAxis()
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.