DUDS
Distributed Update of Data from Something
Serialize.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
15 #include <boost/serialization/split_free.hpp>
16 #include <boost/serialization/nvp.hpp>
17 
18 namespace boost { namespace serialization {
19 
24 #define TIMESER(IST, INT, GET, SETOP, FLD) \
25 template <class Archive> \
26 void save(Archive &ar, const duds::time::interstellar::IST &t, const unsigned int) { \
27  INT val(t.GET()); \
28  ar & boost::serialization::make_nvp(#FLD, val); \
29 } \
30 template <class Archive> \
31 void load(Archive &ar, duds::time::interstellar::IST &t, const unsigned int) { \
32  INT val; \
33  ar & boost::serialization::make_nvp(#FLD, val); \
34  t = duds::time::interstellar::IST(SET ## SETOP(val)); \
35 } \
36 template <class Archive> \
37 void serialize(Archive &a, duds::time::interstellar::IST &t, const unsigned int v) { \
38  split_free(a, t, v); \
39 }
40 
41 #define SETDUR(val) val.value
42 #define SETPTR(val) duds::time::interstellar::Femtoseconds(val.value)
43 #define SETSELF(val) val
44 #define SETMILLI(val) duds::time::interstellar::Milliseconds(val)
45 #define SETNANO(val) duds::time::interstellar::Nanoseconds(val)
46 #define SETSEC(val) duds::time::interstellar::Seconds(val)
47 
48 TIMESER(Femtoseconds, duds::data::int128_w, count, DUR, duration)
49 TIMESER(Milliseconds, std::int64_t, count, SELF, duration)
50 TIMESER(Nanoseconds, std::uint64_t, count, SELF, duration)
51 TIMESER(Seconds, std::int64_t, count, SELF, duration)
52 
53 TIMESER(FemtoTime, duds::data::int128_w, time_since_epoch().count, PTR, time)
54 TIMESER(MilliTime, std::int64_t, time_since_epoch().count, MILLI, time)
55 TIMESER(NanoTime, std::uint64_t, time_since_epoch().count, NANO, time)
56 TIMESER(SecondTime, std::int64_t, time_since_epoch().count, SEC, time)
57 
58 #undef TIMESER
59 #undef SETDUR
60 #undef SETPTR
61 #undef SETSELF
62 #undef SETMILLI
63 #undef SETNANO
64 #undef SETSEC
65 
66 } }
67 
Wraps an integer to allow the Boost multiprecision library to provide insertion and extraction operat...
Definition: Int128.hpp:85
MilliClock::time_point MilliTime
A point in time in Interstellar Time stored in Milliseconds.
std::chrono::duration< std::int64_t > Seconds
Stores a duration in seconds.
SecondClock::time_point SecondTime
A point in time in Interstellar Time stored in Seconds.
std::chrono::duration< int128_t, std::femto > Femtoseconds
Stores a duration in femtoseconds.
FemtoClock::time_point FemtoTime
A point in time in Interstellar Time stored in Femtoseconds.
std::chrono::duration< std::int64_t, std::milli > Milliseconds
Stores a duration in milliseconds.
std::chrono::duration< std::uint64_t, std::nano > Nanoseconds
Stores a duration in nanoseconds.
#define TIMESER(IST, INT, GET, SETOP, FLD)
Makes serialization functions.
Definition: Serialize.hpp:24
NanoClock::time_point NanoTime
A point in time in Interstellar Time stored in Nanoseconds.