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