Alexandria  2.16
Please provide a description of the project.
SOM.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 
19 /*
20  * @file SOM.h
21  * @author nikoapos
22  */
23 
24 #ifndef SOM_SERIALIZATION_SOM_H
25 #define SOM_SERIALIZATION_SOM_H
26 
27 #include <typeinfo>
28 #include <boost/serialization/string.hpp>
29 #include <boost/serialization/split_free.hpp>
32 #include "SOM/SOM.h"
33 
34 namespace boost {
35 namespace serialization {
36 
37 template <class Archive, std::size_t ND, typename DistFunc>
38 void save(Archive& ar, const Euclid::SOM::SOM<ND, DistFunc>& som, const unsigned int) {
39  for (auto& cell : som) {
40  ar << cell;
41  }
42 }
43 
44 template <class Archive, std::size_t ND, typename DistFunc>
45 void load(Archive& ar, Euclid::SOM::SOM<ND, DistFunc>& som, const unsigned int) {
46  for (auto& cell : som) {
47  ar >> cell;
48  }
49 }
50 
51 template <class Archive, std::size_t ND, typename DistFunc>
52 void serialize(Archive& ar, Euclid::SOM::SOM<ND, DistFunc>& som, const unsigned int version) {
53  split_free(ar, som, version);
54 }
55 
56 template <class Archive, std::size_t ND, typename DistFunc>
57 void save_construct_data(Archive& ar, const Euclid::SOM::SOM<ND, DistFunc>* t, const unsigned int) {
58  std::string dist_func_type = typeid(DistFunc).name();
59  ar << dist_func_type;
60  auto size = t->getSize();
61  ar << size.first;
62  ar << size.second;
63 }
64 
65 template <class Archive, std::size_t ND, typename DistFunc>
66 void load_construct_data(Archive& ar, Euclid::SOM::SOM<ND, DistFunc>* t, const unsigned int) {
67  std::string dist_func_type;
68  ar >> dist_func_type;
69  if (dist_func_type != typeid(DistFunc).name()) {
70  throw Elements::Exception() << "Incompatible DistFunc parameter. File contains SOM with "
71  << dist_func_type << " and is read as " << typeid(DistFunc).name();
72  }
73  std::size_t x;
74  ar >> x;
75  std::size_t y;
76  ar >> y;
77  ::new(t) Euclid::SOM::SOM<ND, DistFunc>(x, y);
78 }
79 
80 }
81 }
82 
83 #endif /* SOM_SERIALIZATION_SOM_H */
84 
boost::serialization::save_construct_data
void save_construct_data(Archive &ar, const Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition: GridAxis.h:69
std::string
STL class.
boost
Definition: array.h:34
array.h
Euclid::SOM::SOM::getSize
const std::pair< std::size_t, std::size_t > & getSize() const
Exception.h
Euclid::SOM::SOM
Definition: SOM.h:46
boost::serialization::load
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
Elements::Exception
SOM.h
boost::serialization::save
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
boost::serialization::serialize
void serialize(Archive &archive, std::array< CellType, ND > &array, const unsigned int)
Definition: array.h:38
std::size_t
boost::serialization::load_construct_data
void load_construct_data(Archive &ar, Euclid::GridContainer::GridAxis< T > *t, const unsigned int)
Definition: GridAxis.h:112