PSCF v1.2
serialize.h
1#ifndef UTIL_SERIALIZE_H
2#define UTIL_SERIALIZE_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/global.h>
12
13namespace Util
14{
15
28 template <class Archive, typename T>
29 inline void serialize(Archive& ar, T& data, const unsigned int version)
30 { data.serialize(ar, version); }
31
41 template <class Archive, typename T, size_t N>
42 inline void serialize(Archive& ar, T data[N], const unsigned int version)
43 {
44 for (size_t i = 0; i < N; ++i) {
45 serialize(ar, data[i], version);
46 }
47 }
48
58 template <class Archive, typename T>
59 inline void serializeEnum(Archive& ar, T& data, const unsigned int version = 0)
60 {
61 unsigned int i;
62 if (Archive::is_saving()) {
63 i = (unsigned int)data;
64 }
65 ar & i;
66 if (Archive::is_loading()) {
67 data = (T)i;
68 }
69 }
70
80 template <class Archive, typename T>
81 inline void serializeCheck(Archive& ar, T& data, const char* label = "")
82 {
83 T temp;
84 if (Archive::is_saving()) {
85 temp = data;
86 }
87 ar & temp;
88 if (Archive::is_loading()) {
89 if (temp != data) {
90 UTIL_THROW("Inconsistent data");
91 }
92 }
93 }
94
95}
96#endif
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition global.h:51
void serializeEnum(Archive &ar, T &data, const unsigned int version=0)
Serialize an enumeration value.
Definition serialize.h:59
void serializeCheck(Archive &ar, T &data, const char *label="")
Save a value, or save and check correctness on loading.
Definition serialize.h:81
Utility classes for scientific computation.