Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
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
33#include <boost/serialization/split_free.hpp>
34#include <boost/serialization/vector.hpp>
35#include <memory>
36#include <type_traits>
37
38namespace boost {
39namespace serialization {
40
43template <class Archive, typename GridCellManager, typename... AxesTypes>
45 const unsigned int,
48 for (auto& cell : grid) {
49 ar << cell;
50 }
51}
52
55template <class Archive, typename GridCellManager, typename... AxesTypes>
57 const unsigned int,
60 for (auto& cell : grid) {
61 // Do NOT delete this pointer! It points to the cell of the grid and the
62 // grid will take care of the memory management
63 typename std::remove_reference<decltype(cell)>::type* ptr = &cell;
64 ar << ptr;
65 }
66}
67
70template <class Archive, typename GridCellManager, typename... AxesTypes>
74 for (auto& cell : grid) {
75 ar >> cell;
76 }
77}
78
81template <class Archive, typename GridCellManager, typename... AxesTypes>
85 for (auto& cell : grid) {
87 ar >> ptr;
88 // We use a unique_ptr to guarantee deletion of the pointer
90 cell = *deleter;
91 }
92}
93
98template <class Archive, typename GridCellManager, typename... AxesTypes>
100 const unsigned int version) {
102 "Boost serialization of GridContainer with unsupported GridCellManager");
103 split_free(ar, grid, version);
104}
105
111template <class Archive, typename GridCellManager, typename... AxesTypes>
118
119template <class Archive, typename GridCellManager, typename... AxesTypes>
121 Archive& ar, const Euclid::GridContainer::GridContainer<GridCellManager, AxesTypes...>* t, const unsigned int,
124 ar << axes_tuple;
125 ar << t->getCellManager().getConstructorParameters();
126}
127
130template <typename T>
134
140template <class Archive, typename GridCellManager, typename... AxesTypes>
144 // We create a tuple containing empty GridAxis objects. These will be replaced
145 // when we read from the stream with the real GridAxis objects. We have to do
146 // that because the GridAxis does not have a default constructor.
147 std::tuple<Euclid::GridContainer::GridAxis<AxesTypes>...> axes_tuple{(emptyGridAxis<AxesTypes>())...};
148 ar >> axes_tuple;
149 ::new (t) Euclid::GridContainer::GridContainer<GridCellManager, AxesTypes...>(axes_tuple);
150}
151
152template <class Archive, typename GridCellManager, typename... AxesTypes>
156 std::tuple<Euclid::GridContainer::GridAxis<AxesTypes>...> axes_tuple{(emptyGridAxis<AxesTypes>())...};
158 ar >> axes_tuple;
159 ar >> grid_cell_manager_args;
160 ::new (t) Euclid::GridContainer::GridContainer<GridCellManager, AxesTypes...>(axes_tuple, grid_cell_manager_args);
161}
162
163} /* end of namespace serialization */
164} /* end of namespace boost */
165
166#endif /* GRIDCONTAINER_SERIALIZATION_GRIDCONTAINER_H */
Provides information related with an axis of a GridContainer.
Definition GridAxis.h:49
Representation of a multi-dimensional grid which contains axis information.
const std::tuple< GridAxis< AxesTypes >... > & getAxesTuple() const
Returns a tuple containing the information of all the grid axes.
Euclid::GridContainer::GridAxis< T > emptyGridAxis()
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)
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.