ice_conversions.cpp
Go to the documentation of this file.
1 #include "ice_conversions.h"
2 
3 #include <IceUtil/Time.h>
4 
6 
7 namespace armarx::core
8 {
9 
10  void
11  time::fromIce(const dto::ClockType::ClockTypeEnum& dto, ClockType& bo)
12  {
13  switch (dto)
14  {
15  case dto::ClockType::Realtime:
16  bo = ClockType::Realtime;
17  break;
18  case dto::ClockType::Monotonic:
19  bo = ClockType::Monotonic;
20  break;
21  case dto::ClockType::Virtual:
22  bo = ClockType::Virtual;
23  break;
24  case dto::ClockType::Unknown:
25  bo = ClockType::Unknown;
26  break;
27  }
28  }
29 
30  void
31  time::toIce(dto::ClockType::ClockTypeEnum& dto, const ClockType& bo)
32  {
33  switch (bo)
34  {
35  case ClockType::Realtime:
36  dto = dto::ClockType::Realtime;
37  break;
38  case ClockType::Monotonic:
39  dto = dto::ClockType::Monotonic;
40  break;
41  case ClockType::Virtual:
42  dto = dto::ClockType::Virtual;
43  break;
44  case ClockType::Unknown:
45  dto = dto::ClockType::Unknown;
46  break;
47  }
48  }
49 
50  void
52  {
53  bo = Duration::MicroSeconds(dto.microSeconds);
54  }
55 
56  void
58  {
59  dto.microSeconds = bo.toMicroSeconds();
60  }
61 
62  void
63  time::fromIce(const dto::Frequency& dto, Frequency& bo)
64  {
65  Duration cycleDuration;
66  fromIce(dto.cycleDuration, cycleDuration);
67  bo = Frequency(cycleDuration);
68  }
69 
70  void
71  time::toIce(dto::Frequency& dto, const Frequency& bo)
72  {
73  toIce(dto.cycleDuration, bo.toCycleDuration());
74  }
75 
76  void
77  time::fromIce(const dto::DateTime& dto, DateTime& bo)
78  {
79  Duration duration;
80  ClockType clockType;
81  fromIce(dto.timeSinceEpoch, duration);
82  fromIce(dto.clockType, clockType);
83  bo = DateTime(duration, clockType, dto.hostname);
84  }
85 
86  void
87  time::toIce(dto::DateTime& dto, const DateTime& bo)
88  {
89  toIce(dto.timeSinceEpoch, bo.toDurationSinceEpoch());
90  toIce(dto.clockType, bo.clockType());
91  dto.hostname = bo.hostname();
92  }
93 
94  void
96  {
97  bo = Duration::MicroSeconds(dto.toMicroSeconds());
98  }
99 
100  void
102  {
103  dto = IceUtil::Time::microSeconds(bo.toMicroSeconds());
104  }
105 
106  void
108  {
109  Duration duration;
110  fromIce(dto, duration);
111  bo = DateTime(duration, ClockType::Unknown, "unknown");
112  }
113 
114  void
116  {
117  dto = IceUtil::Time::microSeconds(bo.toMicroSecondsSinceEpoch());
118  }
119 
120 } // namespace armarx::core
121 
122 namespace armarx::core::time
123 {
124  std::ostream&
125  dto::operator<<(std::ostream& os, const DateTime& dto)
126  {
128  fromIce(dto, bo);
129  return os << bo;
130  }
131 
132  std::ostream&
133  dto::operator<<(std::ostream& os, const Duration& dto)
134  {
136  fromIce(dto, bo);
137  return os << bo;
138  return os;
139  }
140 
141  std::ostream&
142  dto::operator<<(std::ostream& os, const Frequency& dto)
143  {
144  time::Duration cycleDuration;
145  fromIce(dto.cycleDuration, cycleDuration);
146  return os << time::Frequency{cycleDuration};
147  }
148 } // namespace armarx::core::time
armarx::core::time::fromIce
void fromIce(const dto::ClockType::ClockTypeEnum &dto, ClockType &bo)
Definition: ice_conversions.cpp:11
armarx::core::time::toIce
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
Definition: ice_conversions.cpp:31
armarx::core::time::dto::operator<<
std::ostream & operator<<(std::ostream &os, const DateTime &dto)
Definition: ice_conversions.cpp:125
armarx::core::time
Definition: Clock.cpp:13
armarx::core::time::Frequency
Represents a frequency.
Definition: Frequency.h:16
ice_conversions.h
armarx::core
Definition: conversions.cpp:3
armarx::toIce
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:15
armarx::core::time::ClockType
ClockType
Describes the type of clock.
Definition: ClockType.h:9
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::fromIce
void fromIce(const std::map< IceKeyT, IceValueT > &iceMap, boost::container::flat_map< CppKeyT, CppValueT > &cppMap)
Definition: ice_conversions_boost_templates.h:27
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:16
time_minimal.h
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:24
armarx::armem::Duration
armarx::core::time::Duration Duration
Definition: forward_declarations.h:14
armarx::aron::bo
const std::optional< BoT > & bo
Definition: aron_conversions.h:174