2 *****************************************************************************
4 Implementation of serialization routines.
6 See serialization.hpp .
8 *****************************************************************************
9 * @author This file is part of libff, developed by SCIPR Lab
10 * and contributors (see AUTHORS).
11 * @copyright MIT license (see LICENSE file)
12 *****************************************************************************/
14 #ifndef SERIALIZATION_TCC_
15 #define SERIALIZATION_TCC_
18 #include <libff/common/utils.hpp>
24 inline void consume_newline(std::istream &in)
30 inline void consume_OUTPUT_NEWLINE(std::istream &in)
41 inline void consume_OUTPUT_SEPARATOR(std::istream &in)
52 inline void output_bool(std::ostream &out, const bool b)
54 out << (b ? 1 : 0) << "\n";
57 inline void input_bool(std::istream &in, bool &b)
62 assert(tmp == 0 || tmp == 1);
64 b = (tmp == 1 ? true : false);
67 inline void output_bool_vector(std::ostream &out, const std::vector<bool> &v)
69 out << v.size() << "\n";
70 for (const bool b : v) {
75 inline void input_bool_vector(std::istream &in, std::vector<bool> &v)
81 for (size_t i = 0; i < size; ++i) {
88 template<typename T> T reserialize(const T &obj)
99 std::ostream &operator<<(std::ostream &out, const std::vector<T> &v)
102 !std::is_same<T, bool>::value,
103 "this does not work for std::vector<bool>");
104 out << v.size() << "\n";
105 for (const T &t : v) {
106 out << t << OUTPUT_NEWLINE;
113 std::istream &operator>>(std::istream &in, std::vector<T> &v)
116 !std::is_same<T, bool>::value,
117 "this does not work for std::vector<bool>");
123 for (size_t i = 0; i < size; ++i) {
126 consume_OUTPUT_NEWLINE(in);
133 template<typename T1, typename T2>
134 std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &m)
136 out << m.size() << "\n";
139 out << it.first << "\n";
140 out << it.second << "\n";
146 template<typename T1, typename T2>
147 std::istream &operator>>(std::istream &in, std::map<T1, T2> &m)
154 for (size_t i = 0; i < size; ++i) {
168 std::ostream &operator<<(std::ostream &out, const std::set<T> &s)
170 out << s.size() << "\n";
179 template<typename T> std::istream &operator>>(std::istream &in, std::set<T> &s)
186 for (size_t i = 0; i < size; ++i) {
198 #endif // SERIALIZATION_TCC_