Alexandria  2.27.0
SDC-CH common library for the Euclid project
SOM.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2022 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 
28 #include "SOM/SOM.h"
29 #include <boost/serialization/split_free.hpp>
30 #include <boost/serialization/string.hpp>
31 #include <boost/serialization/vector.hpp>
32 #include <typeinfo>
33 
34 namespace boost {
35 namespace serialization {
36 
37 template <class Archive, typename DistFunc>
38 void save(Archive& ar, const Euclid::SOM::SOM<DistFunc>& som, const unsigned int) {
39  for (auto& cell : som) {
40  ar << cell;
41  }
42 }
43 
44 template <class Archive, typename DistFunc>
45 void load(Archive& ar, Euclid::SOM::SOM<DistFunc>& som, const unsigned int) {
46  for (auto cell : som) {
47  ar >> cell;
48  }
49 }
50 
51 template <class Archive, typename DistFunc>
52 void serialize(Archive& ar, Euclid::SOM::SOM<DistFunc>& som, const unsigned int version) {
53  split_free(ar, som, version);
54 }
55 
56 template <class Archive, typename DistFunc>
57 void save_construct_data(Archive& ar, const Euclid::SOM::SOM<DistFunc>* t, const unsigned int) {
58  std::string dist_func_type = typeid(DistFunc).name();
59  ar << dist_func_type;
60  auto dim = t->getDimensions();
61  ar << dim;
62  auto size = t->getSize();
63  ar << size.first;
64  ar << size.second;
65 }
66 
67 template <class Archive, typename DistFunc>
68 void load_construct_data(Archive& ar, Euclid::SOM::SOM<DistFunc>* t, const unsigned int) {
69  std::string dist_func_type;
70  ar >> dist_func_type;
71  if (dist_func_type != typeid(DistFunc).name()) {
72  throw Elements::Exception() << "Incompatible DistFunc parameter. File contains SOM with " << dist_func_type
73  << " and is read as " << typeid(DistFunc).name();
74  }
75  std::size_t dim;
76  ar >> dim;
77  std::size_t x;
78  ar >> x;
79  std::size_t y;
80  ar >> y;
81  ::new (t) Euclid::SOM::SOM<DistFunc>(dim, x, y);
82 }
83 
84 } // namespace serialization
85 } // namespace boost
86 
87 #endif /* SOM_SERIALIZATION_SOM_H */
const std::pair< std::size_t, std::size_t > & getSize() const
std::size_t getDimensions() const
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