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