PALISADE Lattice Crypto Library  1.11.9
A lattice crypto library for software engineers by software engineers.
serializable.h
1 // @file serializable.h Legacy Serialization utilities.
2 // @author TPOC: contact@palisade-crypto.org
3 //
4 // @copyright Copyright (c) 2019, New Jersey Institute of Technology (NJIT)
5 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution. THIS SOFTWARE IS
13 // PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
14 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 // EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 #ifndef LBCRYPTO_SERIALIZABLE_H
25 #define LBCRYPTO_SERIALIZABLE_H
26 
27 // TODO (dsuponit): purge the headers below and combine #pragma for GNU and clang
28 #include <iostream>
29 #include <string>
30 
31 #ifndef CEREAL_RAPIDJSON_HAS_STDSTRING
32 #define CEREAL_RAPIDJSON_HAS_STDSTRING 1
33 #endif
34 #ifndef CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS
35 #define CEREAL_RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
36 #endif
37 #define CEREAL_RAPIDJSON_HAS_CXX11_NOEXCEPT 0
38 
39 #ifdef __GNUC__
40 #if __GNUC__ >= 8
41 #pragma GCC diagnostic ignored "-Wclass-memaccess"
42 #endif
43 #endif
44 
45 #ifdef __clang__
46 #pragma clang diagnostic push
47 #pragma clang diagnostic ignored "-Wunused-private-field"
48 #endif
49 
50 #include "cereal/cereal.hpp"
51 #include "cereal/types/polymorphic.hpp"
52 
53 #ifdef __GNUC__
54 #if __GNUC__ >= 8
55 #pragma GCC diagnostic pop
56 #endif
57 #endif
58 
59 #ifdef __clang__
60 #pragma clang diagnostic pop
61 #endif
62 
63 namespace lbcrypto {
64 
65 using Serialized = void*;
66 
76 class Serializable {
77  public:
78  virtual ~Serializable() {}
79 
80  virtual std::string SerializedObjectName() const = 0;
81 
82 };
83 
84 // helper template to stream vector contents provided T has an stream operator<<
85 template <typename T>
86 std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
87  os << "[";
88  for (auto i = v.begin(); i != v.end(); ++i) {
89  os << " " << *i;
90  }
91  os << " ]";
92  return os;
93 }
94 
95 } // namespace lbcrypto
96 
97 #endif
Base class for PALISADE serialization.
Definition: serializable.h:76
Definition: binfhecontext.h:36