Alexandria  2.19
Please provide a description of the project.
GridContainer.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 
26 #ifndef GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H
27 #define GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H
28 
29 #include "GridContainer/GridAxis.h"
33 #include <boost/serialization/split_free.hpp>
34 #include <boost/serialization/vector.hpp>
35 #include <memory>
36 #include <type_traits>
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,
47  for (auto& cell : grid) {
48  ar << cell;
49  }
50 }
51 
54 template <class Archive, typename GridCellManager, typename... AxesTypes>
55 void save(Archive& ar, const Euclid::GridContainer::GridContainer<GridCellManager, AxesTypes...>& grid, const unsigned int,
58  for (auto& cell : grid) {
59  // Do NOT delete this pointer! It points to the cell of the grid and the
60  // grid will take care of the memory management
61  typename std::remove_reference<decltype(cell)>::type* ptr = &cell;
62  ar << ptr;
63  }
64 }
65 
68 template <class Archive, typename GridCellManager, typename... AxesTypes>
72  for (auto& cell : grid) {
73  ar >> cell;
74  }
75 }
76 
79 template <class Archive, typename GridCellManager, typename... AxesTypes>
83  for (auto& cell : grid) {
85  ar >> ptr;
86  // We use a unique_ptr to guarantee deletion of the pointer
88  cell = *deleter;
89  }
90 }
91 
96 template <class Archive, typename GridCellManager, typename... AxesTypes>
97 void serialize(Archive& ar, Euclid::GridContainer::GridContainer<GridCellManager, AxesTypes...>& grid, const unsigned int version) {
99  "Boost serialization of GridContainer with unsupported GridCellManager");
100  split_free(ar, grid, version);
101 }
102 
108 template <class Archive, typename GridCellManager, typename... AxesTypes>
110  const unsigned int) {
112  ar << axes_tuple;
113 }
114 
117 template <typename T>
119  return {"", {}};
120 }
121 
127 template <class Archive, typename GridCellManager, typename... AxesTypes>
129  // We create a tuple containing empty GridAxis objects. These will be replaced
130  // when we read from the stream with the real GridAxis objects. We have to do
131  // that because the GridAxis does not have a default constructor.
132  std::tuple<Euclid::GridContainer::GridAxis<AxesTypes>...> axes_tuple{(emptyGridAxis<AxesTypes>())...};
133  ar >> axes_tuple;
134  ::new (t) Euclid::GridContainer::GridContainer<GridCellManager, AxesTypes...>(axes_tuple);
135 }
136 
137 } /* end of namespace serialization */
138 } /* end of namespace boost */
139 
140 #endif /* GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H */
Provides information related with an axis of a GridContainer.
Definition: GridAxis.h:49
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
void serialize(Archive &archive, std::array< CellType, ND > &array, const unsigned int)
Definition: array.h:37
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:69
Euclid::GridContainer::GridAxis< T > emptyGridAxis()
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
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
Class used by the GridContainer to access the different CellManagers.
GridCellManager::data_type data_type
The type of the data kept by the GridCellManager.