Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
serialize.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_SERIALIZE_H
26#define GRIDCONTAINER_SERIALIZE_H
27
30#include <boost/archive/binary_iarchive.hpp>
31#include <boost/archive/binary_oarchive.hpp>
32#include <boost/filesystem.hpp>
33#include <iostream>
34#include <memory>
35
36namespace Euclid {
37namespace GridContainer {
38
57template <typename OArchive, typename GridCellManager, typename... AxesTypes>
59 // Do NOT delete this pointer!!! It points to the actual grid
60 const GridContainer<GridCellManager, AxesTypes...>* ptr = &grid;
61 OArchive boa{out};
62 boa << ptr;
63}
64
82template <typename GridType, typename IArchive>
83GridType gridImport(std::istream& in) {
84 IArchive bia{in};
85 // Do NOT delete manually this pointer. It is wrapped with a unique_ptr later.
86 GridType* ptr;
87 bia >> ptr;
88 std::unique_ptr<GridType> matr_ptr{ptr};
89 // We move out to the result the grid pointed by the pointer. The unique_ptr
90 // will delete the (now empty) pointed object
91 return std::move(*matr_ptr);
92}
93
102template <typename GridCellManager, typename... AxesTypes>
104 gridExport<boost::archive::binary_oarchive>(out, grid);
105}
106
114template <typename GridType>
116 return gridImport<GridType, boost::archive::binary_iarchive>(in);
117}
118
142template <typename GridCellManager, typename... AxesTypes>
143void gridFitsExport(const boost::filesystem::path& filename, const std::string& hdu_name,
145
157template <typename GridType>
158GridType gridFitsImport(const boost::filesystem::path& filename, int hdu_index);
159
160} // end of namespace GridContainer
161} // end of namespace Euclid
162
164
165#endif /* GRIDCONTAINER_SERIALIZE_H */
Representation of a multi-dimensional grid which contains axis information.
T move(T... args)
GridType gridFitsImport(const boost::filesystem::path &filename, int hdu_index)
Imports a Grid from a FITS file.
void gridBinaryExport(std::ostream &out, const GridContainer< GridCellManager, AxesTypes... > &grid)
Exports to the given output stream the given grid.
Definition serialize.h:103
GridType gridImport(std::istream &in)
Imports from the given stream a grid.
Definition serialize.h:83
GridType gridBinaryImport(std::istream &in)
Imports from the given stream a grid.
Definition serialize.h:115
void gridFitsExport(const boost::filesystem::path &filename, const std::string &hdu_name, const GridContainer< GridCellManager, AxesTypes... > &grid)
Exports a Grid as a FITS file.
void gridExport(std::ostream &out, const GridContainer< GridCellManager, AxesTypes... > &grid)
Export to the given output stream the given grid. The archive type is templated.
Definition serialize.h:58