COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
units.h
Go to the documentation of this file.
1//
2// Copyright 2017 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
10
11#pragma once
12
13#include <ratio>
14#include <type_traits>
15
17#include "comms/traits.h"
19#include "comms/details/tag.h"
20
21COMMS_MSVC_WARNING_PUSH
22COMMS_MSVC_WARNING_DISABLE(4100) // Disable unreferenced parameter warning
23COMMS_MSVC_WARNING_DISABLE(4127) // Disable warning about constant conditional expressions
24
25namespace comms
26{
27
28namespace units
29{
30
31namespace details
32{
33
34template <typename TField>
35using ScalingRatioOf = typename TField::ScalingRatio;
36
37template <typename TField, typename TConvRatio>
38using FullUnitsRatioOf =
39 typename std::ratio_divide<
40 typename std::ratio_multiply<
41 ScalingRatioOf<TField>,
42 typename TField::UnitsRatio
43 >::type,
44 TConvRatio
45 >::type;
46
47template <typename...>
48struct UnitsValueConverter
49{
50 template <typename TRet, typename TConvRatio, typename TField>
51 static TRet getValue(const TField& field)
52 {
53 using Ratio = FullUnitsRatioOf<TField, TConvRatio>;
54 using Tag = RatioTag<TField, TConvRatio>;
55 return getValueInternal<TRet, Ratio>(field, Tag());
56 }
57
58 template <typename TConvRatio, typename TField, typename TVal>
59 static void setValue(TField& field, TVal&& value)
60 {
61 using Ratio = FullUnitsRatioOf<TField, TConvRatio>;
62 using Tag = RatioTag<TField, TConvRatio>;
63 return setValueInternal<Ratio>(field, std::forward<TVal>(value), Tag());
64 }
65
66private:
67 template <typename...>
68 using HasConversionTag = comms::details::tag::Tag1<>;
69
70 template <typename...>
71 using NoConversionTag = comms::details::tag::Tag2<>;
72
73 template <typename...>
74 using ConvertToFpTag = comms::details::tag::Tag3<>;
75
76 template <typename...>
77 using ConvertToIntTag = comms::details::tag::Tag4<>;
78
79 template <typename TField, typename TConvRatio>
80 using RatioTag =
81 typename comms::util::LazyShallowConditional<
82 std::is_same<FullUnitsRatioOf<TField, TConvRatio>, std::ratio<1, 1> >::value
83 >::template Type<
84 NoConversionTag,
85 HasConversionTag
86 >;
87
88 template <typename TRet>
89 using TypeTag =
90 typename comms::util::LazyShallowConditional<
91 std::is_floating_point<TRet>::value
92 >::template Type<
93 ConvertToFpTag,
94 ConvertToIntTag
95 >;
96
97 template <typename TRet, typename TRatio, typename TField, typename... TParams>
98 static TRet getValueInternal(const TField& field, NoConversionTag<TParams...>)
99 {
100 return static_cast<TRet>(field.value());
101 }
102
103 template <typename TRet, typename TRatio, typename TField, typename... TParams>
104 static TRet getValueInternal(const TField& field, HasConversionTag<TParams...>)
105 {
106 using Tag = TypeTag<TRet>;
107 return getValueInternal<TRet, TRatio>(field, Tag());
108 }
109
110 template <typename TRet, typename TRatio, typename TField, typename... TParams>
111 static TRet getValueInternal(const TField& field, ConvertToFpTag<TParams...>)
112 {
113 static_assert(std::is_floating_point<TRet>::value,
114 "TRet is expected to be floating point type");
115 return static_cast<TRet>(field.value()) * (static_cast<TRet>(TRatio::num) / static_cast<TRet>(TRatio::den));
116 }
117
118 template <typename TRet, typename TRatio, typename TField, typename... TParams>
119 static TRet getValueInternal(const TField& field, ConvertToIntTag<TParams...>)
120 {
121 static_assert(std::is_integral<TRet>::value,
122 "TRet is expected to be integral type");
123
124 using FieldType = typename std::decay<decltype(field)>::type;
125 using ValueType = typename FieldType::ValueType;
126
127 static_assert(
128 std::is_integral<ValueType>::value ||
129 std::is_floating_point<ValueType>::value ||
130 std::is_enum<ValueType>::value,
131 "Unexpected field in units conversion");
132
133 using CastType =
135 std::is_floating_point<ValueType>::value
136 >::template Type<
138 std::is_same<ValueType, float>::value
139 >::template Type<
140 double,
141 ValueType
142 >,
144 std::is_signed<TRet>::value
145 >::template Type<
146 std::intmax_t,
147 std::uintmax_t
148 >
149 >;
150
151 return
152 static_cast<TRet>(
153 (static_cast<CastType>(field.value()) * TRatio::num) / TRatio::den);
154 }
155
156 template <typename TRatio, typename TField, typename TVal, typename... TParams>
157 static void setValueInternal(TField& field, TVal&& value, NoConversionTag<TParams...>)
158 {
159 using FieldType = typename std::decay<decltype(field)>::type;
160 using ValueType = typename FieldType::ValueType;
161 field.value() = static_cast<ValueType>(value);
162 }
163
164 template <typename TRatio, typename TField, typename TVal, typename... TParams>
165 static void setValueInternal(TField& field, TVal&& value, HasConversionTag<TParams...>)
166 {
167 using Tag = TypeTag<typename std::decay<decltype(value)>::type>;
168 setValueInternal<TRatio>(field, std::forward<TVal>(value), Tag());
169 }
170
171 template <typename TRatio, typename TField, typename TVal, typename... TParams>
172 static void setValueInternal(TField& field, TVal&& value, ConvertToIntTag<TParams...>)
173 {
174 using FieldType = typename std::decay<decltype(field)>::type;
175 using ValueType = typename FieldType::ValueType;
176
177 static_assert(
178 std::is_integral<ValueType>::value ||
179 std::is_floating_point<ValueType>::value ||
180 std::is_enum<ValueType>::value,
181 "Unexpected field in units conversion");
182
183 using CastType =
185 std::is_floating_point<ValueType>::value
186 >::template Type<
188 std::is_same<ValueType, float>::value
189 >::template Type<
190 double,
191 ValueType
192 >,
194 std::is_signed<typename std::decay<decltype(value)>::type>::value
195 >::template Type<
196 std::intmax_t,
197 std::uintmax_t
198 >
199 >;
200
201 field.value() =
202 static_cast<ValueType>(
203 (static_cast<CastType>(value) * TRatio::den) / static_cast<CastType>(TRatio::num));
204 }
205
206 template <typename TRatio, typename TField, typename TVal, typename... TParams>
207 static void setValueInternal(TField& field, TVal&& value, ConvertToFpTag<TParams...>)
208 {
209 using DecayedType = typename std::decay<decltype(value)>::type;
210 using FieldType = typename std::decay<decltype(field)>::type;
211 using ValueType = typename FieldType::ValueType;
212
213 auto epsilon = DecayedType(0);
214 if ((TRatio::num < TRatio::den) && std::is_integral<ValueType>::value) {
215 epsilon = static_cast<DecayedType>(TRatio::num) / static_cast<DecayedType>(TRatio::den + 1);
216 }
217
218 if (epsilon < DecayedType(0)) {
219 epsilon = -epsilon;
220 }
221
222 if (value < DecayedType(0)) {
223 epsilon = -epsilon;
224 }
225
226 field.value() =
227 static_cast<ValueType>(
228 ((value + epsilon) * static_cast<DecayedType>(TRatio::den)) / static_cast<DecayedType>(TRatio::num));
229 }
230
231};
232
233template <typename TField, typename TType>
234constexpr bool hasExpectedUnits()
235{
236 return std::is_same<typename TField::UnitsType, TType>::value;
237}
238
239template <typename TRet, typename TConvRatio, typename TField>
240TRet getTime(const TField& field)
241{
242 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Time>(),
243 "The field is expected to contain \"time\" units.");
244 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
245}
246
247template <typename TConvRatio, typename TField, typename TVal>
248void setTime(TField& field, TVal&& val)
249{
250 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Time>(),
251 "The field is expected to contain \"time\" units.");
252 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
253}
254
255template <typename TRet, typename TConvRatio, typename TField>
256TRet getDistance(const TField& field)
257{
258 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Distance>(),
259 "The field is expected to contain \"distance\" units.");
260 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
261}
262
263template <typename TConvRatio, typename TField, typename TVal>
264void setDistance(TField& field, TVal&& val)
265{
266 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Distance>(),
267 "The field is expected to contain \"distance\" units.");
268 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
269}
270
271template <typename TRet, typename TConvRatio, typename TField>
272TRet getSpeed(const TField& field)
273{
274 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Speed>(),
275 "The field is expected to contain \"speed\" units.");
276 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
277}
278
279template <typename TConvRatio, typename TField, typename TVal>
280void setSpeed(TField& field, TVal&& val)
281{
282 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Speed>(),
283 "The field is expected to contain \"speed\" units.");
284 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
285}
286
287template <typename TRet, typename TConvRatio, typename TField>
288TRet getFrequency(const TField& field)
289{
290 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Frequency>(),
291 "The field is expected to contain \"frequency\" units.");
292 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
293}
294
295template <typename TConvRatio, typename TField, typename TVal>
296void setFrequency(TField& field, TVal&& val)
297{
298 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Frequency>(),
299 "The field is expected to contain \"frequency\" units.");
300 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
301}
302
303template <typename T>
304struct PI
305{
306 static constexpr T Value = static_cast<T>(3.14159265358979323846264338327950288419716939937510582097494459230781640628620899L);
307};
308
309template <typename...>
310struct AngleValueConverter
311{
312 template <typename TRet, typename TConvRatio, typename TField>
313 static TRet getValue(const TField& field)
314 {
315 using FieldType = typename std::decay<decltype(field)>::type;
316 static_assert(details::hasExpectedUnits<FieldType, comms::traits::units::Angle>(),
317 "The field is expected to contain \"angle\" units.");
318
319 using Tag = GetTag<FieldType, TConvRatio>;
320 return getValueInternal<TRet, TConvRatio>(field, Tag());
321 }
322
323 template <typename TConvRatio, typename TField, typename TVal>
324 static void setValue(TField& field, TVal&& val)
325 {
326 using FieldType = typename std::decay<decltype(field)>::type;
327 static_assert(details::hasExpectedUnits<FieldType, comms::traits::units::Angle>(),
328 "The field is expected to contain \"angle\" units.");
329
330 using Tag = SetTag<FieldType, TConvRatio>;
331 setValueInternal<TConvRatio>(field, std::forward<TVal>(val), Tag());
332 }
333
334private:
335 template <typename... TParams>
336 using SameUnitsTag = comms::details::tag::Tag1<>;
337
338 template <typename... TParams>
339 using DegreesToRadiansTag = comms::details::tag::Tag2<>;
340
341 template <typename... TParams>
342 using RadiansToDegreesTag = comms::details::tag::Tag3<>;
343
344 template <typename TConvRatio>
345 using SetUnitsTag =
346 typename comms::util::LazyShallowConditional<
347 std::is_same<TConvRatio, typename comms::traits::units::RadiansRatio>::value
348 >::template Type<
349 RadiansToDegreesTag,
350 DegreesToRadiansTag
351 >;
352
353 template <typename TConvRatio>
354 using GetUnitsTag =
355 typename comms::util::LazyShallowConditional<
356 std::is_same<TConvRatio, typename comms::traits::units::RadiansRatio>::value
357 >::template Type<
358 DegreesToRadiansTag,
359 RadiansToDegreesTag
360 >;
361
362 template <typename TField, typename TConvRatio>
363 using GetTag =
364 typename comms::util::LazyShallowConditional<
365 std::is_same<TConvRatio, typename TField::UnitsRatio>::value
366 >::template Type<
367 SameUnitsTag,
368 GetUnitsTag,
369 TConvRatio
370 >;
371
372 template <typename TField, typename TConvRatio>
373 using SetTag =
374 typename comms::util::LazyShallowConditional<
375 std::is_same<TConvRatio, typename TField::UnitsRatio>::value
376 >::template Type<
377 SameUnitsTag,
378 SetUnitsTag,
379 TConvRatio
380 >;
381
382 template <typename TRet, typename TConvRatio, typename TField, typename... TParams>
383 static TRet getValueInternal(const TField& field, SameUnitsTag<TParams...>)
384 {
385 return field.template getScaled<TRet>();
386 }
387
388 template <typename TRet, typename TConvRatio, typename TField, typename... TParams>
389 static TRet getValueInternal(const TField& field, DegreesToRadiansTag<TParams...>)
390 {
391 using FieldType = typename std::decay<decltype(field)>::type;
392 static_assert(std::is_same<typename FieldType::UnitsRatio, comms::traits::units::DegreesRatio>::value,
393 "The field is expected to contain degrees.");
394
395 return PI<TRet>::Value * UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
396 }
397
398 template <typename TRet, typename TConvRatio, typename TField, typename... TParams>
399 static TRet getValueInternal(const TField& field, RadiansToDegreesTag<TParams...>)
400 {
401 using FieldType = typename std::decay<decltype(field)>::type;
402 static_assert(std::is_same<typename FieldType::UnitsRatio, comms::traits::units::RadiansRatio>::value,
403 "The field is expected to contain radians.");
404
405 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field) / PI<TRet>::Value;
406 }
407
408 template <typename TConvRatio, typename TField, typename TVal, typename... TParams>
409 static void setValueInternal(TField& field, TVal&& val, SameUnitsTag<TParams...>)
410 {
411 field.setScaled(std::forward<TVal>(val));
412 }
413
414 template <typename TConvRatio, typename TField, typename TVal, typename... TParams>
415 static void setValueInternal(TField& field, TVal&& val, DegreesToRadiansTag<TParams...>)
416 {
417 using FieldType = typename std::decay<decltype(field)>::type;
418 static_assert(std::is_same<typename FieldType::UnitsRatio, comms::traits::units::RadiansRatio>::value,
419 "The field is expected to contain radians.");
420
421 using ValueType = typename std::decay<decltype(val)>::type;
422 using PiType =
424 std::is_floating_point<ValueType>::value
425 >::template Type<
426 ValueType,
427 double
428 >;
429
430 UnitsValueConverter<>::setValue<TConvRatio>(field, val * PI<PiType>::Value);
431 }
432
433 template <typename TConvRatio, typename TField, typename TVal, typename... TParams>
434 static void setValueInternal(TField& field, TVal&& val, RadiansToDegreesTag<TParams...>)
435 {
436 using FieldType = typename std::decay<decltype(field)>::type;
437 static_assert(std::is_same<typename FieldType::UnitsRatio, comms::traits::units::DegreesRatio>::value,
438 "The field is expected to contain degrees.");
439
440 using ValueType = typename std::decay<decltype(val)>::type;
441 using PiType =
443 std::is_floating_point<ValueType>::value
444 >::template Type<
445 ValueType,
446 double
447 >;
448
449 UnitsValueConverter<>::setValue<TConvRatio>(field, static_cast<PiType>(val) / PI<PiType>::Value);
450 }
451};
452
453template <typename TRet, typename TConvRatio, typename TField>
454TRet getAngle(const TField& field)
455{
456 return AngleValueConverter<>::getValue<TRet, TConvRatio>(field);
457}
458
459template <typename TConvRatio, typename TField, typename TVal>
460void setAngle(TField& field, TVal&& val)
461{
462 AngleValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
463}
464
465template <typename TRet, typename TConvRatio, typename TField>
466TRet getCurrent(const TField& field)
467{
468 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Current>(),
469 "The field is expected to contain \"current\" units.");
470 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
471}
472
473template <typename TConvRatio, typename TField, typename TVal>
474void setCurrent(TField& field, TVal&& val)
475{
476 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Current>(),
477 "The field is expected to contain \"current\" units.");
478 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
479}
480
481template <typename TRet, typename TConvRatio, typename TField>
482TRet getVoltage(const TField& field)
483{
484 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Voltage>(),
485 "The field is expected to contain \"voltage\" units.");
486 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
487}
488
489template <typename TConvRatio, typename TField, typename TVal>
490void setVoltage(TField& field, TVal&& val)
491{
492 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Voltage>(),
493 "The field is expected to contain \"voltage\" units.");
494 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
495}
496
497template <typename TRet, typename TConvRatio, typename TField>
498TRet getMemory(const TField& field)
499{
500 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Memory>(),
501 "The field is expected to contain \"memory\" units.");
502 return UnitsValueConverter<>::getValue<TRet, TConvRatio>(field);
503}
504
505template <typename TConvRatio, typename TField, typename TVal>
506void setMemory(TField& field, TVal&& val)
507{
508 static_assert(details::hasExpectedUnits<typename std::decay<decltype(field)>::type, comms::traits::units::Memory>(),
509 "The field is expected to contain \"memory\" units.");
510 UnitsValueConverter<>::setValue<TConvRatio>(field, std::forward<TVal>(val));
511}
512
513} // namespace details
514
525template <typename TRet, typename TField>
526TRet getNanoseconds(const TField& field)
527{
528 return details::getTime<TRet, comms::traits::units::NanosecondsRatio>(field);
529}
530
541template <typename TField, typename TVal>
542void setNanoseconds(TField& field, TVal&& val)
543{
544 details::setTime<comms::traits::units::NanosecondsRatio>(field, std::forward<TVal>(val));
545}
546
549template <typename TField>
550constexpr bool isNanoseconds()
551{
552 return
553 TField::hasUnits() &&
554 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
555 std::is_same<typename TField::UnitsRatio, comms::traits::units::NanosecondsRatio>::value;
556}
557
562template <typename TField>
563constexpr bool isNanoseconds(const TField& field)
564{
565 return isNanoseconds<typename std::decay<decltype(field)>::type>();
566}
567
578template <typename TRet, typename TField>
579TRet getMicroseconds(const TField& field)
580{
581 return details::getTime<TRet, comms::traits::units::MicrosecondsRatio>(field);
582}
583
594template <typename TField, typename TVal>
595void setMicroseconds(TField& field, TVal&& val)
596{
597 details::setTime<comms::traits::units::MicrosecondsRatio>(field, std::forward<TVal>(val));
598}
599
602template <typename TField>
603constexpr bool isMicroseconds()
604{
605 return
606 TField::hasUnits() &&
607 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
608 std::is_same<typename TField::UnitsRatio, comms::traits::units::MicrosecondsRatio>::value;
609}
610
615template <typename TField>
616constexpr bool isMicroseconds(const TField& field)
617{
618 return isMicroseconds<typename std::decay<decltype(field)>::type>();
619}
620
631template <typename TRet, typename TField>
632TRet getMilliseconds(const TField& field)
633{
634 return details::getTime<TRet, comms::traits::units::MillisecondsRatio>(field);
635}
636
647template <typename TField, typename TVal>
648void setMilliseconds(TField& field, TVal&& val)
649{
650 details::setTime<comms::traits::units::MillisecondsRatio>(field, std::forward<TVal>(val));
651}
652
655template <typename TField>
656constexpr bool isMilliseconds()
657{
658 return
659 TField::hasUnits() &&
660 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
661 std::is_same<typename TField::UnitsRatio, comms::traits::units::MillisecondsRatio>::value;
662}
663
668template <typename TField>
669constexpr bool isMilliseconds(const TField& field)
670{
671 return isMilliseconds<typename std::decay<decltype(field)>::type>();
672}
673
684template <typename TRet, typename TField>
685TRet getSeconds(const TField& field)
686{
687 return details::getTime<TRet, comms::traits::units::SecondsRatio>(field);
688}
689
700template <typename TField, typename TVal>
701void setSeconds(TField& field, TVal&& val)
702{
703 details::setTime<comms::traits::units::SecondsRatio>(field, std::forward<TVal>(val));
704}
705
708template <typename TField>
709constexpr bool isSeconds()
710{
711 return
712 TField::hasUnits() &&
713 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
714 std::is_same<typename TField::UnitsRatio, comms::traits::units::SecondsRatio>::value;
715}
716
721template <typename TField>
722constexpr bool isSeconds(const TField& field)
723{
724 return isSeconds<typename std::decay<decltype(field)>::type>();
725}
726
737template <typename TRet, typename TField>
738TRet getMinutes(const TField& field)
739{
740 return details::getTime<TRet, comms::traits::units::MinutesRatio>(field);
741}
742
753template <typename TField, typename TVal>
754void setMinutes(TField& field, TVal&& val)
755{
756 details::setTime<comms::traits::units::MinutesRatio>(field, std::forward<TVal>(val));
757}
758
761template <typename TField>
762constexpr bool isMinutes()
763{
764 return
765 TField::hasUnits() &&
766 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
767 std::is_same<typename TField::UnitsRatio, comms::traits::units::MinutesRatio>::value;
768}
769
774template <typename TField>
775constexpr bool isMinutes(const TField& field)
776{
777 return isMinutes<typename std::decay<decltype(field)>::type>();
778}
779
790template <typename TRet, typename TField>
791TRet getHours(const TField& field)
792{
793 return details::getTime<TRet, comms::traits::units::HoursRatio>(field);
794}
795
806template <typename TField, typename TVal>
807void setHours(TField& field, TVal&& val)
808{
809 details::setTime<comms::traits::units::HoursRatio>(field, std::forward<TVal>(val));
810}
811
814template <typename TField>
815constexpr bool isHours()
816{
817 return
818 TField::hasUnits() &&
819 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
820 std::is_same<typename TField::UnitsRatio, comms::traits::units::HoursRatio>::value;
821}
822
827template <typename TField>
828constexpr bool isHours(const TField& field)
829{
830 return isHours<typename std::decay<decltype(field)>::type>();
831}
832
843template <typename TRet, typename TField>
844TRet getDays(const TField& field)
845{
846 return details::getTime<TRet, comms::traits::units::DaysRatio>(field);
847}
848
859template <typename TField, typename TVal>
860void setDays(TField& field, TVal&& val)
861{
862 details::setTime<comms::traits::units::DaysRatio>(field, std::forward<TVal>(val));
863}
864
867template <typename TField>
868constexpr bool isDays()
869{
870 return
871 TField::hasUnits() &&
872 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
873 std::is_same<typename TField::UnitsRatio, comms::traits::units::DaysRatio>::value;
874}
875
880template <typename TField>
881constexpr bool isDays(const TField& field)
882{
883 return isDays<typename std::decay<decltype(field)>::type>();
884}
885
896template <typename TRet, typename TField>
897TRet getWeeks(const TField& field)
898{
899 return details::getTime<TRet, comms::traits::units::WeeksRatio>(field);
900}
901
912template <typename TField, typename TVal>
913void setWeeks(TField& field, TVal&& val)
914{
915 details::setTime<comms::traits::units::WeeksRatio>(field, std::forward<TVal>(val));
916}
917
920template <typename TField>
921constexpr bool isWeeks()
922{
923 return
924 TField::hasUnits() &&
925 std::is_same<typename TField::UnitsType, comms::traits::units::Time>::value &&
926 std::is_same<typename TField::UnitsRatio, comms::traits::units::WeeksRatio>::value;
927}
928
933template <typename TField>
934constexpr bool isWeeks(const TField& field)
935{
936 return isWeeks<typename std::decay<decltype(field)>::type>();
937}
938
949template <typename TRet, typename TField>
950TRet getNanometers(const TField& field)
951{
952 return details::getDistance<TRet, comms::traits::units::NanometersRatio>(field);
953}
954
965template <typename TField, typename TVal>
966void setNanometers(TField& field, TVal&& val)
967{
968 details::setDistance<comms::traits::units::NanometersRatio>(field, std::forward<TVal>(val));
969}
970
973template <typename TField>
974constexpr bool isNanometers()
975{
976 return
977 TField::hasUnits() &&
978 std::is_same<typename TField::UnitsType, comms::traits::units::Distance>::value &&
979 std::is_same<typename TField::UnitsRatio, comms::traits::units::NanometersRatio>::value;
980}
981
986template <typename TField>
987constexpr bool isNanometers(const TField& field)
988{
989 return isNanometers<typename std::decay<decltype(field)>::type>();
990}
991
1002template <typename TRet, typename TField>
1003TRet getMicrometers(const TField& field)
1004{
1005 return details::getDistance<TRet, comms::traits::units::MicrometersRatio>(field);
1006}
1007
1018template <typename TField, typename TVal>
1019void setMicrometers(TField& field, TVal&& val)
1020{
1021 details::setDistance<comms::traits::units::MicrometersRatio>(field, std::forward<TVal>(val));
1022}
1023
1026template <typename TField>
1027constexpr bool isMicrometers()
1028{
1029 return
1030 TField::hasUnits() &&
1031 std::is_same<typename TField::UnitsType, comms::traits::units::Distance>::value &&
1032 std::is_same<typename TField::UnitsRatio, comms::traits::units::MicrometersRatio>::value;
1033}
1034
1039template <typename TField>
1040constexpr bool isMicrometers(const TField& field)
1041{
1042 return isMicrometers<typename std::decay<decltype(field)>::type>();
1043}
1044
1055template <typename TRet, typename TField>
1056TRet getMillimeters(const TField& field)
1057{
1058 return details::getDistance<TRet, comms::traits::units::MillimetersRatio>(field);
1059}
1060
1071template <typename TField, typename TVal>
1072void setMillimeters(TField& field, TVal&& val)
1073{
1074 details::setDistance<comms::traits::units::MillimetersRatio>(field, std::forward<TVal>(val));
1075}
1076
1079template <typename TField>
1080constexpr bool isMillimeters()
1081{
1082 return
1083 TField::hasUnits() &&
1084 std::is_same<typename TField::UnitsType, comms::traits::units::Distance>::value &&
1085 std::is_same<typename TField::UnitsRatio, comms::traits::units::MillimetersRatio>::value;
1086}
1087
1092template <typename TField>
1093constexpr bool isMillimeters(const TField& field)
1094{
1095 return isMillimeters<typename std::decay<decltype(field)>::type>();
1096}
1097
1108template <typename TRet, typename TField>
1109TRet getCentimeters(const TField& field)
1110{
1111 return details::getDistance<TRet, comms::traits::units::CentimetersRatio>(field);
1112}
1113
1124template <typename TField, typename TVal>
1125void setCentimeters(TField& field, TVal&& val)
1126{
1127 details::setDistance<comms::traits::units::CentimetersRatio>(field, std::forward<TVal>(val));
1128}
1129
1132template <typename TField>
1133constexpr bool isCentimeters()
1134{
1135 return
1136 TField::hasUnits() &&
1137 std::is_same<typename TField::UnitsType, comms::traits::units::Distance>::value &&
1138 std::is_same<typename TField::UnitsRatio, comms::traits::units::CentimetersRatio>::value;
1139}
1140
1145template <typename TField>
1146constexpr bool isCentimeters(const TField& field)
1147{
1148 return isCentimeters<typename std::decay<decltype(field)>::type>();
1149}
1150
1161template <typename TRet, typename TField>
1162TRet getMeters(const TField& field)
1163{
1164 return details::getDistance<TRet, comms::traits::units::MetersRatio>(field);
1165}
1166
1177template <typename TField, typename TVal>
1178void setMeters(TField& field, TVal&& val)
1179{
1180 details::setDistance<comms::traits::units::MetersRatio>(field, std::forward<TVal>(val));
1181}
1182
1185template <typename TField>
1186constexpr bool isMeters()
1187{
1188 return
1189 TField::hasUnits() &&
1190 std::is_same<typename TField::UnitsType, comms::traits::units::Distance>::value &&
1191 std::is_same<typename TField::UnitsRatio, comms::traits::units::MetersRatio>::value;
1192}
1193
1198template <typename TField>
1199constexpr bool isMeters(const TField& field)
1200{
1201 return isMeters<typename std::decay<decltype(field)>::type>();
1202}
1203
1214template <typename TRet, typename TField>
1215TRet getKilometers(const TField& field)
1216{
1217 return details::getDistance<TRet, comms::traits::units::KilometersRatio>(field);
1218}
1219
1230template <typename TField, typename TVal>
1231void setKilometers(TField& field, TVal&& val)
1232{
1233 details::setDistance<comms::traits::units::KilometersRatio>(field, std::forward<TVal>(val));
1234}
1235
1238template <typename TField>
1239constexpr bool isKilometers()
1240{
1241 return
1242 TField::hasUnits() &&
1243 std::is_same<typename TField::UnitsType, comms::traits::units::Distance>::value &&
1244 std::is_same<typename TField::UnitsRatio, comms::traits::units::KilometersRatio>::value;
1245}
1246
1251template <typename TField>
1252constexpr bool isKilometers(const TField& field)
1253{
1254 return isKilometers<typename std::decay<decltype(field)>::type>();
1255}
1256
1267template <typename TRet, typename TField>
1268TRet getNanometersPerSecond(const TField& field)
1269{
1270 return details::getSpeed<TRet, comms::traits::units::NanometersPerSecondRatio>(field);
1271}
1272
1283template <typename TField, typename TVal>
1284void setNanometersPerSecond(TField& field, TVal&& val)
1285{
1286 details::setSpeed<comms::traits::units::NanometersPerSecondRatio>(field, std::forward<TVal>(val));
1287}
1288
1291template <typename TField>
1293{
1294 return
1295 TField::hasUnits() &&
1296 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1297 std::is_same<typename TField::UnitsRatio, comms::traits::units::NanometersPerSecondRatio>::value;
1298}
1299
1304template <typename TField>
1305constexpr bool isNanometersPerSecond(const TField& field)
1306{
1307 return isNanometersPerSecond<typename std::decay<decltype(field)>::type>();
1308}
1309
1320template <typename TRet, typename TField>
1321TRet getMicrometersPerSecond(const TField& field)
1322{
1323 return details::getSpeed<TRet, comms::traits::units::MicrometersPerSecondRatio>(field);
1324}
1325
1336template <typename TField, typename TVal>
1337void setMicrometersPerSecond(TField& field, TVal&& val)
1338{
1339 details::setSpeed<comms::traits::units::MicrometersPerSecondRatio>(field, std::forward<TVal>(val));
1340}
1341
1344template <typename TField>
1346{
1347 return
1348 TField::hasUnits() &&
1349 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1350 std::is_same<typename TField::UnitsRatio, comms::traits::units::MicrometersPerSecondRatio>::value;
1351}
1352
1357template <typename TField>
1358constexpr bool isMicrometersPerSecond(const TField& field)
1359{
1360 return isMicrometersPerSecond<typename std::decay<decltype(field)>::type>();
1361}
1362
1373template <typename TRet, typename TField>
1374TRet getMillimetersPerSecond(const TField& field)
1375{
1376 return details::getSpeed<TRet, comms::traits::units::MillimetersPerSecondRatio>(field);
1377}
1378
1389template <typename TField, typename TVal>
1390void setMillimetersPerSecond(TField& field, TVal&& val)
1391{
1392 details::setSpeed<comms::traits::units::MillimetersPerSecondRatio>(field, std::forward<TVal>(val));
1393}
1394
1397template <typename TField>
1399{
1400 return
1401 TField::hasUnits() &&
1402 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1403 std::is_same<typename TField::UnitsRatio, comms::traits::units::MillimetersPerSecondRatio>::value;
1404}
1405
1410template <typename TField>
1411constexpr bool isMillimetersPerSecond(const TField& field)
1412{
1413 return isMillimetersPerSecond<typename std::decay<decltype(field)>::type>();
1414}
1415
1426template <typename TRet, typename TField>
1427TRet getCentimetersPerSecond(const TField& field)
1428{
1429 return details::getSpeed<TRet, comms::traits::units::CentimetersPerSecondRatio>(field);
1430}
1431
1442template <typename TField, typename TVal>
1443void setCentimetersPerSecond(TField& field, TVal&& val)
1444{
1445 details::setSpeed<comms::traits::units::CentimetersPerSecondRatio>(field, std::forward<TVal>(val));
1446}
1447
1450template <typename TField>
1452{
1453 return
1454 TField::hasUnits() &&
1455 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1456 std::is_same<typename TField::UnitsRatio, comms::traits::units::CentimetersPerSecondRatio>::value;
1457}
1458
1463template <typename TField>
1464constexpr bool isCentimetersPerSecond(const TField& field)
1465{
1466 return isCentimetersPerSecond<typename std::decay<decltype(field)>::type>();
1467}
1468
1479template <typename TRet, typename TField>
1480TRet getMetersPerSecond(const TField& field)
1481{
1482 return details::getSpeed<TRet, comms::traits::units::MetersPerSecondRatio>(field);
1483}
1484
1495template <typename TField, typename TVal>
1496void setMetersPerSecond(TField& field, TVal&& val)
1497{
1498 details::setSpeed<comms::traits::units::MetersPerSecondRatio>(field, std::forward<TVal>(val));
1499}
1500
1503template <typename TField>
1504constexpr bool isMetersPerSecond()
1505{
1506 return
1507 TField::hasUnits() &&
1508 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1509 std::is_same<typename TField::UnitsRatio, comms::traits::units::MetersPerSecondRatio>::value;
1510}
1511
1516template <typename TField>
1517constexpr bool isMetersPerSecond(const TField& field)
1518{
1519 return isMetersPerSecond<typename std::decay<decltype(field)>::type>();
1520}
1521
1532template <typename TRet, typename TField>
1533TRet getKilometersPerSecond(const TField& field)
1534{
1535 return details::getSpeed<TRet, comms::traits::units::KilometersPerSecondRatio>(field);
1536}
1537
1548template <typename TField, typename TVal>
1549void setKilometersPerSecond(TField& field, TVal&& val)
1550{
1551 details::setSpeed<comms::traits::units::KilometersPerSecondRatio>(field, std::forward<TVal>(val));
1552}
1553
1556template <typename TField>
1558{
1559 return
1560 TField::hasUnits() &&
1561 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1562 std::is_same<typename TField::UnitsRatio, comms::traits::units::KilometersPerSecondRatio>::value;
1563}
1564
1569template <typename TField>
1570constexpr bool isKilometersPerSecond(const TField& field)
1571{
1572 return isKilometersPerSecond<typename std::decay<decltype(field)>::type>();
1573}
1574
1585template <typename TRet, typename TField>
1586TRet getKilometersPerHour(const TField& field)
1587{
1588 return details::getSpeed<TRet, comms::traits::units::KilometersPerHourRatio>(field);
1589}
1590
1601template <typename TField, typename TVal>
1602void setKilometersPerHour(TField& field, TVal&& val)
1603{
1604 details::setSpeed<comms::traits::units::KilometersPerHourRatio>(field, std::forward<TVal>(val));
1605}
1606
1609template <typename TField>
1610constexpr bool isKilometersPerHour()
1611{
1612 return
1613 TField::hasUnits() &&
1614 std::is_same<typename TField::UnitsType, comms::traits::units::Speed>::value &&
1615 std::is_same<typename TField::UnitsRatio, comms::traits::units::KilometersPerHourRatio>::value;
1616}
1617
1622template <typename TField>
1623constexpr bool isKilometersPerHour(const TField& field)
1624{
1625 return isKilometersPerHour<typename std::decay<decltype(field)>::type>();
1626}
1627
1638template <typename TRet, typename TField>
1639TRet getHertz(const TField& field)
1640{
1641 return details::getFrequency<TRet, comms::traits::units::HzRatio>(field);
1642}
1643
1654template <typename TField, typename TVal>
1655void setHertz(TField& field, TVal&& val)
1656{
1657 details::setFrequency<comms::traits::units::HzRatio>(field, std::forward<TVal>(val));
1658}
1659
1662template <typename TField>
1663constexpr bool isHertz()
1664{
1665 return
1666 TField::hasUnits() &&
1667 std::is_same<typename TField::UnitsType, comms::traits::units::Frequency>::value &&
1668 std::is_same<typename TField::UnitsRatio, comms::traits::units::HzRatio>::value;
1669}
1670
1675template <typename TField>
1676constexpr bool isHertz(const TField& field)
1677{
1678 return isHertz<typename std::decay<decltype(field)>::type>();
1679}
1680
1691template <typename TRet, typename TField>
1692TRet getKilohertz(const TField& field)
1693{
1694 return details::getFrequency<TRet, comms::traits::units::KiloHzRatio>(field);
1695}
1696
1707template <typename TField, typename TVal>
1708void setKilohertz(TField& field, TVal&& val)
1709{
1710 details::setFrequency<comms::traits::units::KiloHzRatio>(field, std::forward<TVal>(val));
1711}
1712
1715template <typename TField>
1716constexpr bool isKilohertz()
1717{
1718 return
1719 TField::hasUnits() &&
1720 std::is_same<typename TField::UnitsType, comms::traits::units::Frequency>::value &&
1721 std::is_same<typename TField::UnitsRatio, comms::traits::units::KiloHzRatio>::value;
1722}
1723
1728template <typename TField>
1729constexpr bool isKilohertz(const TField& field)
1730{
1731 return isKilohertz<typename std::decay<decltype(field)>::type>();
1732}
1733
1744template <typename TRet, typename TField>
1745TRet getMegahertz(const TField& field)
1746{
1747 return details::getFrequency<TRet, comms::traits::units::MegaHzRatio>(field);
1748}
1749
1760template <typename TField, typename TVal>
1761void setMegahertz(TField& field, TVal&& val)
1762{
1763 details::setFrequency<comms::traits::units::MegaHzRatio>(field, std::forward<TVal>(val));
1764}
1765
1768template <typename TField>
1769constexpr bool isMegahertz()
1770{
1771 return
1772 TField::hasUnits() &&
1773 std::is_same<typename TField::UnitsType, comms::traits::units::Frequency>::value &&
1774 std::is_same<typename TField::UnitsRatio, comms::traits::units::MegaHzRatio>::value;
1775}
1776
1781template <typename TField>
1782constexpr bool isMegahertz(const TField& field)
1783{
1784 return isMegahertz<typename std::decay<decltype(field)>::type>();
1785}
1786
1797template <typename TRet, typename TField>
1798TRet getGigahertz(const TField& field)
1799{
1800 return details::getFrequency<TRet, comms::traits::units::GigaHzRatio>(field);
1801}
1802
1813template <typename TField, typename TVal>
1814void setGigahertz(TField& field, TVal&& val)
1815{
1816 details::setFrequency<comms::traits::units::GigaHzRatio>(field, std::forward<TVal>(val));
1817}
1818
1821template <typename TField>
1822constexpr bool isGigahertz()
1823{
1824 return
1825 TField::hasUnits() &&
1826 std::is_same<typename TField::UnitsType, comms::traits::units::Frequency>::value &&
1827 std::is_same<typename TField::UnitsRatio, comms::traits::units::GigaHzRatio>::value;
1828}
1829
1834template <typename TField>
1835constexpr bool isGigahertz(const TField& field)
1836{
1837 return isGigahertz<typename std::decay<decltype(field)>::type>();
1838}
1839
1850template <typename TRet, typename TField>
1851TRet getDegrees(const TField& field)
1852{
1853 return details::getAngle<TRet, comms::traits::units::DegreesRatio>(field);
1854}
1855
1866template <typename TField, typename TVal>
1867void setDegrees(TField& field, TVal&& val)
1868{
1869 details::setAngle<comms::traits::units::DegreesRatio>(field, std::forward<TVal>(val));
1870}
1871
1874template <typename TField>
1875constexpr bool isDegrees()
1876{
1877 return
1878 TField::hasUnits() &&
1879 std::is_same<typename TField::UnitsType, comms::traits::units::Angle>::value &&
1880 std::is_same<typename TField::UnitsRatio, comms::traits::units::DegreesRatio>::value;
1881}
1882
1887template <typename TField>
1888constexpr bool isDegrees(const TField& field)
1889{
1890 return isDegrees<typename std::decay<decltype(field)>::type>();
1891}
1892
1903template <typename TRet, typename TField>
1904TRet getRadians(const TField& field)
1905{
1906 return details::getAngle<TRet, comms::traits::units::RadiansRatio>(field);
1907}
1908
1919template <typename TField, typename TVal>
1920void setRadians(TField& field, TVal&& val)
1921{
1922 details::setAngle<comms::traits::units::RadiansRatio>(field, std::forward<TVal>(val));
1923}
1924
1927template <typename TField>
1928constexpr bool isRadians()
1929{
1930 return
1931 TField::hasUnits() &&
1932 std::is_same<typename TField::UnitsType, comms::traits::units::Angle>::value &&
1933 std::is_same<typename TField::UnitsRatio, comms::traits::units::RadiansRatio>::value;
1934}
1935
1940template <typename TField>
1941constexpr bool isRadians(const TField& field)
1942{
1943 return isRadians<typename std::decay<decltype(field)>::type>();
1944}
1945
1956template <typename TRet, typename TField>
1957TRet getNanoamps(const TField& field)
1958{
1959 return details::getCurrent<TRet, comms::traits::units::NanoampsRatio>(field);
1960}
1961
1972template <typename TField, typename TVal>
1973void setNanoamps(TField& field, TVal&& val)
1974{
1975 details::setCurrent<comms::traits::units::NanoampsRatio>(field, std::forward<TVal>(val));
1976}
1977
1980template <typename TField>
1981constexpr bool isNanoamps()
1982{
1983 return
1984 TField::hasUnits() &&
1985 std::is_same<typename TField::UnitsType, comms::traits::units::Current>::value &&
1986 std::is_same<typename TField::UnitsRatio, comms::traits::units::NanoampsRatio>::value;
1987}
1988
1993template <typename TField>
1994constexpr bool isNanoamps(const TField& field)
1995{
1996 return isNanoamps<typename std::decay<decltype(field)>::type>();
1997}
1998
2009template <typename TRet, typename TField>
2010TRet getMicroamps(const TField& field)
2011{
2012 return details::getCurrent<TRet, comms::traits::units::MicroampsRatio>(field);
2013}
2014
2025template <typename TField, typename TVal>
2026void setMicroamps(TField& field, TVal&& val)
2027{
2028 details::setCurrent<comms::traits::units::MicroampsRatio>(field, std::forward<TVal>(val));
2029}
2030
2033template <typename TField>
2034constexpr bool isMicroamps()
2035{
2036 return
2037 TField::hasUnits() &&
2038 std::is_same<typename TField::UnitsType, comms::traits::units::Current>::value &&
2039 std::is_same<typename TField::UnitsRatio, comms::traits::units::MicroampsRatio>::value;
2040}
2041
2046template <typename TField>
2047constexpr bool isMicroamps(const TField& field)
2048{
2049 return isMicroamps<typename std::decay<decltype(field)>::type>();
2050}
2051
2052
2063template <typename TRet, typename TField>
2064TRet getMilliamps(const TField& field)
2065{
2066 return details::getCurrent<TRet, comms::traits::units::MilliampsRatio>(field);
2067}
2068
2079template <typename TField, typename TVal>
2080void setMilliamps(TField& field, TVal&& val)
2081{
2082 details::setCurrent<comms::traits::units::MilliampsRatio>(field, std::forward<TVal>(val));
2083}
2084
2087template <typename TField>
2088constexpr bool isMilliamps()
2089{
2090 return
2091 TField::hasUnits() &&
2092 std::is_same<typename TField::UnitsType, comms::traits::units::Current>::value &&
2093 std::is_same<typename TField::UnitsRatio, comms::traits::units::MilliampsRatio>::value;
2094}
2095
2100template <typename TField>
2101constexpr bool isMilliamps(const TField& field)
2102{
2103 return isMilliamps<typename std::decay<decltype(field)>::type>();
2104}
2105
2116template <typename TRet, typename TField>
2117TRet getAmps(const TField& field)
2118{
2119 return details::getCurrent<TRet, comms::traits::units::AmpsRatio>(field);
2120}
2121
2132template <typename TField, typename TVal>
2133void setAmps(TField& field, TVal&& val)
2134{
2135 details::setCurrent<comms::traits::units::AmpsRatio>(field, std::forward<TVal>(val));
2136}
2137
2140template <typename TField>
2141constexpr bool isAmps()
2142{
2143 return
2144 TField::hasUnits() &&
2145 std::is_same<typename TField::UnitsType, comms::traits::units::Current>::value &&
2146 std::is_same<typename TField::UnitsRatio, comms::traits::units::AmpsRatio>::value;
2147}
2148
2153template <typename TField>
2154constexpr bool isAmps(const TField& field)
2155{
2156 return isAmps<typename std::decay<decltype(field)>::type>();
2157}
2158
2169template <typename TRet, typename TField>
2170TRet getKiloamps(const TField& field)
2171{
2172 return details::getCurrent<TRet, comms::traits::units::KiloampsRatio>(field);
2173}
2174
2185template <typename TField, typename TVal>
2186void setKiloamps(TField& field, TVal&& val)
2187{
2188 details::setCurrent<comms::traits::units::KiloampsRatio>(field, std::forward<TVal>(val));
2189}
2190
2193template <typename TField>
2194constexpr bool isKiloamps()
2195{
2196 return
2197 TField::hasUnits() &&
2198 std::is_same<typename TField::UnitsType, comms::traits::units::Current>::value &&
2199 std::is_same<typename TField::UnitsRatio, comms::traits::units::KiloampsRatio>::value;
2200}
2201
2206template <typename TField>
2207constexpr bool isKiloamps(const TField& field)
2208{
2209 return isKiloamps<typename std::decay<decltype(field)>::type>();
2210}
2211
2222template <typename TRet, typename TField>
2223TRet getNanovolts(const TField& field)
2224{
2225 return details::getVoltage<TRet, comms::traits::units::NanovoltsRatio>(field);
2226}
2227
2238template <typename TField, typename TVal>
2239void setNanovolts(TField& field, TVal&& val)
2240{
2241 details::setVoltage<comms::traits::units::NanovoltsRatio>(field, std::forward<TVal>(val));
2242}
2243
2246template <typename TField>
2247constexpr bool isNanovolts()
2248{
2249 return
2250 TField::hasUnits() &&
2251 std::is_same<typename TField::UnitsType, comms::traits::units::Voltage>::value &&
2252 std::is_same<typename TField::UnitsRatio, comms::traits::units::NanovoltsRatio>::value;
2253}
2254
2259template <typename TField>
2260constexpr bool isNanovolts(const TField& field)
2261{
2262 return isNanovolts<typename std::decay<decltype(field)>::type>();
2263}
2264
2275template <typename TRet, typename TField>
2276TRet getMicrovolts(const TField& field)
2277{
2278 return details::getVoltage<TRet, comms::traits::units::MicrovoltsRatio>(field);
2279}
2280
2291template <typename TField, typename TVal>
2292void setMicrovolts(TField& field, TVal&& val)
2293{
2294 details::setVoltage<comms::traits::units::MicrovoltsRatio>(field, std::forward<TVal>(val));
2295}
2296
2299template <typename TField>
2300constexpr bool isMicrovolts()
2301{
2302 return
2303 TField::hasUnits() &&
2304 std::is_same<typename TField::UnitsType, comms::traits::units::Voltage>::value &&
2305 std::is_same<typename TField::UnitsRatio, comms::traits::units::MicrovoltsRatio>::value;
2306}
2307
2312template <typename TField>
2313constexpr bool isMicrovolts(const TField& field)
2314{
2315 return isMicrovolts<typename std::decay<decltype(field)>::type>();
2316}
2317
2328template <typename TRet, typename TField>
2329TRet getMillivolts(const TField& field)
2330{
2331 return details::getVoltage<TRet, comms::traits::units::MillivoltsRatio>(field);
2332}
2333
2344template <typename TField, typename TVal>
2345void setMillivolts(TField& field, TVal&& val)
2346{
2347 details::setVoltage<comms::traits::units::MillivoltsRatio>(field, std::forward<TVal>(val));
2348}
2349
2352template <typename TField>
2353constexpr bool isMillivolts()
2354{
2355 return
2356 TField::hasUnits() &&
2357 std::is_same<typename TField::UnitsType, comms::traits::units::Voltage>::value &&
2358 std::is_same<typename TField::UnitsRatio, comms::traits::units::MillivoltsRatio>::value;
2359}
2360
2365template <typename TField>
2366constexpr bool isMillivolts(const TField& field)
2367{
2368 return isMillivolts<typename std::decay<decltype(field)>::type>();
2369}
2370
2381template <typename TRet, typename TField>
2382TRet getVolts(const TField& field)
2383{
2384 return details::getVoltage<TRet, comms::traits::units::VoltsRatio>(field);
2385}
2386
2397template <typename TField, typename TVal>
2398void setVolts(TField& field, TVal&& val)
2399{
2400 details::setVoltage<comms::traits::units::VoltsRatio>(field, std::forward<TVal>(val));
2401}
2402
2405template <typename TField>
2406constexpr bool isVolts()
2407{
2408 return
2409 TField::hasUnits() &&
2410 std::is_same<typename TField::UnitsType, comms::traits::units::Voltage>::value &&
2411 std::is_same<typename TField::UnitsRatio, comms::traits::units::VoltsRatio>::value;
2412}
2413
2418template <typename TField>
2419constexpr bool isVolts(const TField& field)
2420{
2421 return isVolts<typename std::decay<decltype(field)>::type>();
2422}
2423
2434template <typename TRet, typename TField>
2435TRet getKilovolts(const TField& field)
2436{
2437 return details::getVoltage<TRet, comms::traits::units::KilovoltsRatio>(field);
2438}
2439
2450template <typename TField, typename TVal>
2451void setKilovolts(TField& field, TVal&& val)
2452{
2453 details::setVoltage<comms::traits::units::KilovoltsRatio>(field, std::forward<TVal>(val));
2454}
2455
2458template <typename TField>
2459constexpr bool isKilovolts()
2460{
2461 return
2462 TField::hasUnits() &&
2463 std::is_same<typename TField::UnitsType, comms::traits::units::Voltage>::value &&
2464 std::is_same<typename TField::UnitsRatio, comms::traits::units::KilovoltsRatio>::value;
2465}
2466
2471template <typename TField>
2472constexpr bool isKilovolts(const TField& field)
2473{
2474 return isKilovolts<typename std::decay<decltype(field)>::type>();
2475}
2476
2487template <typename TRet, typename TField>
2488TRet getBytes(const TField& field)
2489{
2490 return details::getMemory<TRet, comms::traits::units::BytesRatio>(field);
2491}
2492
2503template <typename TField, typename TVal>
2504void setBytes(TField& field, TVal&& val)
2505{
2506 details::setMemory<comms::traits::units::BytesRatio>(field, std::forward<TVal>(val));
2507}
2508
2511template <typename TField>
2512constexpr bool isBytes()
2513{
2514 return
2515 TField::hasUnits() &&
2516 std::is_same<typename TField::UnitsType, comms::traits::units::Memory>::value &&
2517 std::is_same<typename TField::UnitsRatio, comms::traits::units::BytesRatio>::value;
2518}
2519
2524template <typename TField>
2525constexpr bool isBytes(const TField& field)
2526{
2527 return isBytes<typename std::decay<decltype(field)>::type>();
2528}
2529
2540template <typename TRet, typename TField>
2541TRet getKilobytes(const TField& field)
2542{
2543 return details::getMemory<TRet, comms::traits::units::KilobytesRatio>(field);
2544}
2545
2556template <typename TField, typename TVal>
2557void setKilobytes(TField& field, TVal&& val)
2558{
2559 details::setMemory<comms::traits::units::KilobytesRatio>(field, std::forward<TVal>(val));
2560}
2561
2564template <typename TField>
2565constexpr bool isKilobytes()
2566{
2567 return
2568 TField::hasUnits() &&
2569 std::is_same<typename TField::UnitsType, comms::traits::units::Memory>::value &&
2570 std::is_same<typename TField::UnitsRatio, comms::traits::units::KilobytesRatio>::value;
2571}
2572
2577template <typename TField>
2578constexpr bool isKilobytes(const TField& field)
2579{
2580 return isKilobytes<typename std::decay<decltype(field)>::type>();
2581}
2582
2593template <typename TRet, typename TField>
2594TRet getMegabytes(const TField& field)
2595{
2596 return details::getMemory<TRet, comms::traits::units::MegabytesRatio>(field);
2597}
2598
2609template <typename TField, typename TVal>
2610void setMegabytes(TField& field, TVal&& val)
2611{
2612 details::setMemory<comms::traits::units::MegabytesRatio>(field, std::forward<TVal>(val));
2613}
2614
2617template <typename TField>
2618constexpr bool isMegabytes()
2619{
2620 return
2621 TField::hasUnits() &&
2622 std::is_same<typename TField::UnitsType, comms::traits::units::Memory>::value &&
2623 std::is_same<typename TField::UnitsRatio, comms::traits::units::MegabytesRatio>::value;
2624}
2625
2630template <typename TField>
2631constexpr bool isMegabytes(const TField& field)
2632{
2633 return isMegabytes<typename std::decay<decltype(field)>::type>();
2634}
2635
2636
2647template <typename TRet, typename TField>
2648TRet getGigabytes(const TField& field)
2649{
2650 return details::getMemory<TRet, comms::traits::units::GigabytesRatio>(field);
2651}
2652
2663template <typename TField, typename TVal>
2664void setGigabytes(TField& field, TVal&& val)
2665{
2666 details::setMemory<comms::traits::units::GigabytesRatio>(field, std::forward<TVal>(val));
2667}
2668
2671template <typename TField>
2672constexpr bool isGigabytes()
2673{
2674 return
2675 TField::hasUnits() &&
2676 std::is_same<typename TField::UnitsType, comms::traits::units::Memory>::value &&
2677 std::is_same<typename TField::UnitsRatio, comms::traits::units::GigabytesRatio>::value;
2678}
2679
2684template <typename TField>
2685constexpr bool isGigabytes(const TField& field)
2686{
2687 return isGigabytes<typename std::decay<decltype(field)>::type>();
2688}
2689
2700template <typename TRet, typename TField>
2701TRet getTerabytes(const TField& field)
2702{
2703 return details::getMemory<TRet, comms::traits::units::TerabytesRatio>(field);
2704}
2705
2716template <typename TField, typename TVal>
2717void setTerabytes(TField& field, TVal&& val)
2718{
2719 details::setMemory<comms::traits::units::TerabytesRatio>(field, std::forward<TVal>(val));
2720}
2721
2724template <typename TField>
2725constexpr bool isTerabytes()
2726{
2727 return
2728 TField::hasUnits() &&
2729 std::is_same<typename TField::UnitsType, comms::traits::units::Memory>::value &&
2730 std::is_same<typename TField::UnitsRatio, comms::traits::units::TerabytesRatio>::value;
2731}
2732
2737template <typename TField>
2738constexpr bool isTerabytes(const TField& field)
2739{
2740 return isTerabytes<typename std::decay<decltype(field)>::type>();
2741}
2742
2743} // namespace units
2744
2745} // namespace comms
2746
2747COMMS_MSVC_WARNING_POP
Contains various compiler related definitions.
comms::option::def::FieldType< TMsg > FieldType
Same as comms::option::def::FieldType.
Definition options.h:1463
constexpr bool isMinutes()
Compile time check whether the field type holds minutes.
Definition units.h:762
TRet getNanovolts(const TField &field)
Retrieve field's value as nanovolts.
Definition units.h:2223
constexpr bool isMillimetersPerSecond()
Compile time check whether the field type holds millimeters per second.
Definition units.h:1398
TRet getMicrovolts(const TField &field)
Retrieve field's value as microvolts.
Definition units.h:2276
void setMicroamps(TField &field, TVal &&val)
Update field's value accordingly, while providing microamps value.
Definition units.h:2026
TRet getMilliseconds(const TField &field)
Retrieve field's value as milliseconds.
Definition units.h:632
constexpr bool isMegahertz()
Compile time check whether the field type holds megahertz.
Definition units.h:1769
void setBytes(TField &field, TVal &&val)
Update field's value accordingly, while providing bytes value.
Definition units.h:2504
void setMillimetersPerSecond(TField &field, TVal &&val)
Update field's value accordingly, while providing millimeters per second value.
Definition units.h:1390
TRet getGigabytes(const TField &field)
Retrieve field's value as gigabytes.
Definition units.h:2648
TRet getVolts(const TField &field)
Retrieve field's value as volts.
Definition units.h:2382
void setHours(TField &field, TVal &&val)
Update field's value accordingly, while providing hours value.
Definition units.h:807
void setMillivolts(TField &field, TVal &&val)
Update field's value accordingly, while providing millivolts value.
Definition units.h:2345
constexpr bool isMegabytes()
Compile time check whether the field type holds megabytes.
Definition units.h:2618
void setNanometersPerSecond(TField &field, TVal &&val)
Update field's value accordingly, while providing nanometers per second value.
Definition units.h:1284
TRet getCentimeters(const TField &field)
Retrieve field's value as centimeters.
Definition units.h:1109
constexpr bool isMeters()
Compile time check whether the field type holds meters.
Definition units.h:1186
constexpr bool isMillimeters()
Compile time check whether the field type holds millimeters.
Definition units.h:1080
TRet getMillivolts(const TField &field)
Retrieve field's value as millivolts.
Definition units.h:2329
TRet getHertz(const TField &field)
Retrieve field's value as hertz.
Definition units.h:1639
void setKilobytes(TField &field, TVal &&val)
Update field's value accordingly, while providing kilobytes value.
Definition units.h:2557
TRet getNanoamps(const TField &field)
Retrieve field's value as nanoamps.
Definition units.h:1957
constexpr bool isKilovolts()
Compile time check whether the field type holds kilovolts.
Definition units.h:2459
constexpr bool isCentimetersPerSecond()
Compile time check whether the field type holds centimeters per second.
Definition units.h:1451
constexpr bool isBytes()
Compile time check whether the field type holds bytes.
Definition units.h:2512
TRet getDays(const TField &field)
Retrieve field's value as days.
Definition units.h:844
constexpr bool isNanometers()
Compile time check whether the field type holds nanometers.
Definition units.h:974
void setWeeks(TField &field, TVal &&val)
Update field's value accordingly, while providing weeks value.
Definition units.h:913
TRet getMinutes(const TField &field)
Retrieve field's value as minutes.
Definition units.h:738
void setGigahertz(TField &field, TVal &&val)
Update field's value accordingly, while providing gigahertz value.
Definition units.h:1814
void setGigabytes(TField &field, TVal &&val)
Update field's value accordingly, while providing gigabytes value.
Definition units.h:2664
void setMicrometersPerSecond(TField &field, TVal &&val)
Update field's value accordingly, while providing micrometers per second value.
Definition units.h:1337
TRet getNanometersPerSecond(const TField &field)
Retrieve field's value as nanometers per second.
Definition units.h:1268
TRet getNanometers(const TField &field)
Retrieve field's value as nanometers.
Definition units.h:950
void setTerabytes(TField &field, TVal &&val)
Update field's value accordingly, while providing terabytes value.
Definition units.h:2717
TRet getMilliamps(const TField &field)
Retrieve field's value as milliamps.
Definition units.h:2064
TRet getMicroseconds(const TField &field)
Retrieve field's value as microseconds.
Definition units.h:579
TRet getMicrometers(const TField &field)
Retrieve field's value as micrometers.
Definition units.h:1003
constexpr bool isMicrometersPerSecond()
Compile time check whether the field type holds micrometers per second.
Definition units.h:1345
constexpr bool isKilometers()
Compile time check whether the field type holds kilometers.
Definition units.h:1239
constexpr bool isKilometersPerHour()
Compile time check whether the field type holds kilometers per hour.
Definition units.h:1610
TRet getMicroamps(const TField &field)
Retrieve field's value as microamps.
Definition units.h:2010
TRet getKiloamps(const TField &field)
Retrieve field's value as kiloamps.
Definition units.h:2170
constexpr bool isTerabytes()
Compile time check whether the field type holds terabytes.
Definition units.h:2725
void setMilliamps(TField &field, TVal &&val)
Update field's value accordingly, while providing milliamps value.
Definition units.h:2080
void setAmps(TField &field, TVal &&val)
Update field's value accordingly, while providing amps value.
Definition units.h:2133
TRet getKilohertz(const TField &field)
Retrieve field's value as kilohertz.
Definition units.h:1692
constexpr bool isMetersPerSecond()
Compile time check whether the field type holds meters per second.
Definition units.h:1504
constexpr bool isMicrometers()
Compile time check whether the field type holds micrometers.
Definition units.h:1027
void setDays(TField &field, TVal &&val)
Update field's value accordingly, while providing days value.
Definition units.h:860
constexpr bool isGigabytes()
Compile time check whether the field type holds gigabytes.
Definition units.h:2672
constexpr bool isVolts()
Compile time check whether the field type holds volts.
Definition units.h:2406
TRet getKilometersPerSecond(const TField &field)
Retrieve field's value as kilometers per second.
Definition units.h:1533
constexpr bool isHours()
Compile time check whether the field type holds hours.
Definition units.h:815
TRet getHours(const TField &field)
Retrieve field's value as hours.
Definition units.h:791
void setMetersPerSecond(TField &field, TVal &&val)
Update field's value accordingly, while providing meters per second value.
Definition units.h:1496
TRet getWeeks(const TField &field)
Retrieve field's value as weeks.
Definition units.h:897
TRet getNanoseconds(const TField &field)
Retrieve field's value as nanoseconds.
Definition units.h:526
constexpr bool isMicroamps()
Compile time check whether the field type holds microamps.
Definition units.h:2034
TRet getMeters(const TField &field)
Retrieve field's value as meters.
Definition units.h:1162
void setCentimeters(TField &field, TVal &&val)
Update field's value accordingly, while providing centimeters value.
Definition units.h:1125
void setKilovolts(TField &field, TVal &&val)
Update field's value accordingly, while providing kilovolts value.
Definition units.h:2451
void setMilliseconds(TField &field, TVal &&val)
Update field's value accordingly, while providing milliseconds value.
Definition units.h:648
constexpr bool isNanometersPerSecond()
Compile time check whether the field type holds nanometers per second.
Definition units.h:1292
TRet getKilometersPerHour(const TField &field)
Retrieve field's value as kilometers per hour.
Definition units.h:1586
void setSeconds(TField &field, TVal &&val)
Update field's value accordingly, while providing seconds value.
Definition units.h:701
void setMillimeters(TField &field, TVal &&val)
Update field's value accordingly, while providing millimeters value.
Definition units.h:1072
constexpr bool isMicrovolts()
Compile time check whether the field type holds microvolts.
Definition units.h:2300
constexpr bool isMicroseconds()
Compile time check whether the field type holds microseconds.
Definition units.h:603
TRet getTerabytes(const TField &field)
Retrieve field's value as terabytes.
Definition units.h:2701
constexpr bool isNanoamps()
Compile time check whether the field type holds nanoamps.
Definition units.h:1981
void setKilometers(TField &field, TVal &&val)
Update field's value accordingly, while providing kilometers value.
Definition units.h:1231
void setKiloamps(TField &field, TVal &&val)
Update field's value accordingly, while providing kiloamps value.
Definition units.h:2186
TRet getAmps(const TField &field)
Retrieve field's value as amps.
Definition units.h:2117
constexpr bool isMilliseconds()
Compile time check whether the field type holds milliseconds.
Definition units.h:656
constexpr bool isWeeks()
Compile time check whether the field type holds weeks.
Definition units.h:921
void setCentimetersPerSecond(TField &field, TVal &&val)
Update field's value accordingly, while providing centimeters per second value.
Definition units.h:1443
void setNanoamps(TField &field, TVal &&val)
Update field's value accordingly, while providing nanoamps value.
Definition units.h:1973
constexpr bool isKilohertz()
Compile time check whether the field type holds kilohertz.
Definition units.h:1716
constexpr bool isGigahertz()
Compile time check whether the field type holds gigahertz.
Definition units.h:1822
TRet getKilovolts(const TField &field)
Retrieve field's value as kilovolts.
Definition units.h:2435
TRet getBytes(const TField &field)
Retrieve field's value as bytes.
Definition units.h:2488
TRet getMetersPerSecond(const TField &field)
Retrieve field's value as meters per second.
Definition units.h:1480
void setMegahertz(TField &field, TVal &&val)
Update field's value accordingly, while providing megahertz value.
Definition units.h:1761
constexpr bool isNanoseconds()
Compile time check whether the field type holds nanoseconds.
Definition units.h:550
constexpr bool isKilobytes()
Compile time check whether the field type holds kilobytes.
Definition units.h:2565
void setHertz(TField &field, TVal &&val)
Update field's value accordingly, while providing hertz value.
Definition units.h:1655
TRet getMillimetersPerSecond(const TField &field)
Retrieve field's value as millimeters per second.
Definition units.h:1374
constexpr bool isMilliamps()
Compile time check whether the field type holds milliamps.
Definition units.h:2088
constexpr bool isKiloamps()
Compile time check whether the field type holds kiloamps.
Definition units.h:2194
TRet getKilobytes(const TField &field)
Retrieve field's value as kilobytes.
Definition units.h:2541
TRet getGigahertz(const TField &field)
Retrieve field's value as gigahertz.
Definition units.h:1798
void setMinutes(TField &field, TVal &&val)
Update field's value accordingly, while providing minutes value.
Definition units.h:754
void setDegrees(TField &field, TVal &&val)
Update field's value accordingly, while providing degrees value.
Definition units.h:1867
void setNanometers(TField &field, TVal &&val)
Update field's value accordingly, while providing nanometers value.
Definition units.h:966
void setMicroseconds(TField &field, TVal &&val)
Update field's value accordingly, while providing microseconds value.
Definition units.h:595
TRet getSeconds(const TField &field)
Retrieve field's value as seconds.
Definition units.h:685
void setMicrometers(TField &field, TVal &&val)
Update field's value accordingly, while providing micrometers value.
Definition units.h:1019
TRet getMicrometersPerSecond(const TField &field)
Retrieve field's value as micrometers per second.
Definition units.h:1321
void setMeters(TField &field, TVal &&val)
Update field's value accordingly, while providing meters value.
Definition units.h:1178
void setNanoseconds(TField &field, TVal &&val)
Update field's value accordingly, while providing nanoseconds value.
Definition units.h:542
void setRadians(TField &field, TVal &&val)
Update field's value accordingly, while providing radians value.
Definition units.h:1920
constexpr bool isDegrees()
Compile time check whether the field type holds degrees.
Definition units.h:1875
TRet getKilometers(const TField &field)
Retrieve field's value as kilometers.
Definition units.h:1215
TRet getCentimetersPerSecond(const TField &field)
Retrieve field's value as centimeters per second.
Definition units.h:1427
TRet getMegahertz(const TField &field)
Retrieve field's value as megahertz.
Definition units.h:1745
void setMegabytes(TField &field, TVal &&val)
Update field's value accordingly, while providing megabytes value.
Definition units.h:2610
void setKilometersPerSecond(TField &field, TVal &&val)
Update field's value accordingly, while providing kilometers per second value.
Definition units.h:1549
void setNanovolts(TField &field, TVal &&val)
Update field's value accordingly, while providing nanovolts value.
Definition units.h:2239
void setVolts(TField &field, TVal &&val)
Update field's value accordingly, while providing volts value.
Definition units.h:2398
constexpr bool isRadians()
Compile time check whether the field type holds radians.
Definition units.h:1928
constexpr bool isCentimeters()
Compile time check whether the field type holds centimeters.
Definition units.h:1133
void setKilometersPerHour(TField &field, TVal &&val)
Update field's value accordingly, while providing kilometers per hour value.
Definition units.h:1602
void setMicrovolts(TField &field, TVal &&val)
Update field's value accordingly, while providing microvolts value.
Definition units.h:2292
TRet getMegabytes(const TField &field)
Retrieve field's value as megabytes.
Definition units.h:2594
constexpr bool isDays()
Compile time check whether the field type holds days.
Definition units.h:868
constexpr bool isHertz()
Compile time check whether the field type holds hertz.
Definition units.h:1663
constexpr bool isSeconds()
Compile time check whether the field type holds seconds.
Definition units.h:709
void setKilohertz(TField &field, TVal &&val)
Update field's value accordingly, while providing kilohertz value.
Definition units.h:1708
constexpr bool isNanovolts()
Compile time check whether the field type holds nanovolts.
Definition units.h:2247
TRet getDegrees(const TField &field)
Retrieve field's value as degrees.
Definition units.h:1851
TRet getRadians(const TField &field)
Retrieve field's value as radians.
Definition units.h:1904
constexpr bool isMillivolts()
Compile time check whether the field type holds millivolts.
Definition units.h:2353
TRet getMillimeters(const TField &field)
Retrieve field's value as millimeters.
Definition units.h:1056
constexpr bool isAmps()
Compile time check whether the field type holds amps.
Definition units.h:2141
constexpr bool isKilometersPerSecond()
Compile time check whether the field type holds kilometers per second.
Definition units.h:1557
Main namespace for all classes / functions of COMMS library.
Tag class used to indicate electrical current value.
Definition traits.h:54
Tag class used to indicate distance value.
Definition traits.h:42
Tag class used to indicate frequency value.
Definition traits.h:48
Tag class used to indicate memory size value.
Definition traits.h:60
Tag class used to indicate speed value.
Definition traits.h:45
Tag class used to indicate time value.
Definition traits.h:39
Tag class used to indicate electrical voltage value.
Definition traits.h:57
Replacement to std::conditional.
Definition type_traits.h:28
This file contains all the classes necessary to properly define message traits.
Replacement to some types from standard type_traits.