json_conversions.cpp
Go to the documentation of this file.
1#include "json_conversions.h"
2
3#include <IceUtil/Time.h>
4
7
8namespace armarx::core
9{
10
11 void
12 time::to_json(simox::json::json& j, const ClockType& bo)
13 {
14 j = ClockTypeNames.to_name(bo);
15 }
16
17 void
18 time::from_json(const simox::json::json& j, ClockType& bo)
19 {
20 bo = ClockTypeNames.from_name(j);
21 }
22
23 void
24 time::to_json(simox::json::json& j, const Duration& bo)
25 {
26 j["microSeconds"] = bo.toMicroSeconds();
27 j["humanReadable"] = bo.toDurationString();
28 }
29
30 void
31 time::from_json(const simox::json::json& j, Duration& bo)
32 {
33 bo = Duration::MicroSeconds(j.at("microSeconds"));
34 }
35
36 void
37 time::to_json(simox::json::json& j, const Frequency& bo)
38 {
39 j["cycleDuration"] = bo.toCycleDuration();
40 j["hertz"] = bo.toHertzDouble();
41 }
42
43 void
44 time::from_json(const simox::json::json& j, Frequency& bo)
45 {
46 bo = Frequency(j.at("cycleDuration").get<Duration>());
47 }
48
49 void
50 time::to_json(simox::json::json& j, const DateTime& bo)
51 {
52 j["durationSinceEpoch"] = bo.toDurationSinceEpoch();
53 j["clockType"] = bo.clockType();
54 j["hostname"] = bo.hostname();
55 j["humanReadable"] = bo.toDateTimeString();
56 }
57
58 void
59 time::from_json(const simox::json::json& j, DateTime& bo)
60 {
61 bo = DateTime(j.at("durationSinceEpoch").get<Duration>(),
62 j.at("clockType").get<ClockType>(),
63 j.at("hostname").get<std::string>());
64 }
65
66} // namespace armarx::core
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition Duration.cpp:24
Represents a point in time.
Definition DateTime.h:25
std::string toDateTimeString() const
Definition DateTime.cpp:75
std::string hostname() const
Definition DateTime.cpp:117
Duration toDurationSinceEpoch() const
Definition DateTime.cpp:105
ClockType clockType() const
Definition DateTime.cpp:111
Represents a duration.
Definition Duration.h:17
std::int64_t toMicroSeconds() const
Returns the amount of microseconds.
Definition Duration.cpp:36
std::string toDurationString() const
String representation of the current duration in minimal/default format.
Definition Duration.cpp:180
Represents a frequency.
Definition Frequency.h:17
Duration toCycleDuration() const
Definition Frequency.cpp:60
void from_json(const simox::json::json &j, ClockType &bo)
void to_json(simox::json::json &j, const ClockType &bo)
const simox::meta::EnumNames< ClockType > ClockTypeNames
ClockType
Describes the type of clock.
Definition ClockType.h:10