COMMS
Template library intended to help with implementation of communication protocols.
traits.h
Go to the documentation of this file.
1 //
2 // Copyright 2014 - 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 
11 
12 
13 #pragma once
14 
15 #include <ratio>
16 #include "util/access.h"
17 
18 namespace comms
19 {
20 
21 namespace traits
22 {
23 
24 namespace endian
25 {
26 
29 
32 
33 } // namespace endian
34 
35 namespace units
36 {
37 
39 struct Time {};
40 
42 struct Distance {};
43 
45 struct Speed {};
46 
48 struct Frequency {};
49 
51 struct Angle {};
52 
54 struct Current {};
55 
57 struct Voltage {};
58 
60 struct Memory {};
61 
63 using NanosecondsRatio = std::nano;
64 
66 using MicrosecondsRatio = std::micro;
67 
69 using MillisecondsRatio = std::milli;
70 
72 using SecondsRatio = std::ratio<1, 1>;
73 
75 using MinutesRatio = std::ratio<60>;
76 
78 using HoursRatio = std::ratio<60 * 60>;
79 
81 using DaysRatio = std::ratio<24L * 60 * 60>;
82 
84 using WeeksRatio = std::ratio<7L * 24 * 60 * 60>;
85 
87 using NanometersRatio = std::nano;
88 
90 using MicrometersRatio = std::micro;
91 
93 using MillimetersRatio = std::milli;
94 
96 using CentimetersRatio = std::centi;
97 
99 using MetersRatio = std::ratio<1, 1>;
100 
102 using KilometersRatio = std::kilo;
103 
106  typename std::ratio_divide<NanometersRatio, SecondsRatio>::type;
107 
110  typename std::ratio_divide<MicrometersRatio, SecondsRatio>::type;
111 
114  typename std::ratio_divide<MillimetersRatio, SecondsRatio>::type;
115 
118  typename std::ratio_divide<CentimetersRatio, SecondsRatio>::type;
119 
122  typename std::ratio_divide<MetersRatio, SecondsRatio>::type;
123 
126  typename std::ratio_divide<KilometersRatio, SecondsRatio>::type;
127 
130  typename std::ratio_divide<KilometersRatio, HoursRatio>::type;
131 
133 using HzRatio = std::ratio<1, 1>;
134 
136 using KiloHzRatio = std::kilo;
137 
139 using MegaHzRatio = std::mega;
140 
142 using GigaHzRatio = std::giga;
143 
145 using DegreesRatio = std::ratio<1, 1>;
146 
148 using RadiansRatio = std::ratio<180, 1>;
149 
151 using NanoampsRatio = std::nano;
152 
154 using MicroampsRatio = std::micro;
155 
157 using MilliampsRatio = std::milli;
158 
160 using AmpsRatio = std::ratio<1, 1>;
161 
163 using KiloampsRatio = std::kilo;
164 
166 using NanovoltsRatio = std::nano;
167 
169 using MicrovoltsRatio = std::micro;
170 
172 using MillivoltsRatio = std::milli;
173 
175 using VoltsRatio = std::ratio<1, 1>;
176 
178 using KilovoltsRatio = std::kilo;
179 
181 using BytesRatio = std::ratio<1, 1>;
182 
184 using KilobytesRatio = std::ratio<1024, 1>;
185 
187 using MegabytesRatio = std::ratio<1024UL * 1024, 1>;
188 
190 using GigabytesRatio = std::ratio<1024ULL * 1024 * 1024, 1>;
191 
193 using TerabytesRatio = std::ratio<1024ULL * 1024 * 1024 * 1024, 1>;
194 
195 } // namespace units
196 
197 namespace dispatch
198 {
199 
201 struct Polymorphic {};
202 
204 struct StaticBinSearch {};
205 
207 struct LinearSwitch {};
208 
209 } // namespace dispatch
210 
211 } // namespace traits
212 
213 } // namespace comms
214 
Contains functions for raw data access / (de)serialization.
util::traits::endian::Little Little
Empty class used in traits to indicate Little Endian.
Definition: traits.h:31
util::traits::endian::Big Big
Empty class used in traits to indicate Big Endian.
Definition: traits.h:28
std::kilo KiloHzRatio
Ratio for kilohertz.
Definition: traits.h:136
std::kilo KilovoltsRatio
Ratio for kilovolts.
Definition: traits.h:178
std::nano NanosecondsRatio
Ratio for nanoseconds.
Definition: traits.h:63
typename std::ratio_divide< MillimetersRatio, SecondsRatio >::type MillimetersPerSecondRatio
Ratio for millimeters / second.
Definition: traits.h:114
std::ratio< 180, 1 > RadiansRatio
Ratio for radians.
Definition: traits.h:148
std::nano NanometersRatio
Ratio for nanometers.
Definition: traits.h:87
std::micro MicroampsRatio
Ratio for microamperes.
Definition: traits.h:154
std::ratio< 1024ULL *1024 *1024, 1 > GigabytesRatio
Ratio for gigabytes.
Definition: traits.h:190
std::milli MillisecondsRatio
Ratio for milliseconds.
Definition: traits.h:69
typename std::ratio_divide< MicrometersRatio, SecondsRatio >::type MicrometersPerSecondRatio
Ratio for micrometers / second.
Definition: traits.h:110
std::ratio< 1, 1 > BytesRatio
Ratio for bytes.
Definition: traits.h:181
std::ratio< 1024, 1 > KilobytesRatio
Ratio for kilobytes.
Definition: traits.h:184
std::ratio< 60 *60 > HoursRatio
Ratio for hours.
Definition: traits.h:78
std::ratio< 1, 1 > SecondsRatio
Ratio for seconds.
Definition: traits.h:72
typename std::ratio_divide< MetersRatio, SecondsRatio >::type MetersPerSecondRatio
Ratio for meters / second.
Definition: traits.h:122
std::ratio< 60 > MinutesRatio
Ratio for minutes.
Definition: traits.h:75
typename std::ratio_divide< KilometersRatio, SecondsRatio >::type KilometersPerSecondRatio
Ratio for kilometers / second.
Definition: traits.h:126
typename std::ratio_divide< KilometersRatio, HoursRatio >::type KilometersPerHourRatio
Ratio for kilometers / hour.
Definition: traits.h:130
typename std::ratio_divide< CentimetersRatio, SecondsRatio >::type CentimetersPerSecondRatio
Ratio for centimeters / second.
Definition: traits.h:118
std::micro MicrosecondsRatio
Ratio for microseconds.
Definition: traits.h:66
std::ratio< 1, 1 > MetersRatio
Ratio for meters.
Definition: traits.h:99
std::ratio< 1, 1 > AmpsRatio
Ratio for amperes.
Definition: traits.h:160
std::kilo KilometersRatio
Ratio for kilometers.
Definition: traits.h:102
std::ratio< 1024UL *1024, 1 > MegabytesRatio
Ratio for megabytes.
Definition: traits.h:187
std::giga GigaHzRatio
Ratio for gigahertz.
Definition: traits.h:142
std::milli MilliampsRatio
Ratio for milliamperes.
Definition: traits.h:157
std::milli MillivoltsRatio
Ratio for millivolts.
Definition: traits.h:172
typename std::ratio_divide< NanometersRatio, SecondsRatio >::type NanometersPerSecondRatio
Ratio for nanometers / second.
Definition: traits.h:106
std::kilo KiloampsRatio
Ratio for kiloamperes.
Definition: traits.h:163
std::ratio< 7L *24 *60 *60 > WeeksRatio
Ratio for weeks.
Definition: traits.h:84
std::ratio< 1, 1 > DegreesRatio
Ratio for degrees.
Definition: traits.h:145
std::nano NanovoltsRatio
Ratio for nanovolts.
Definition: traits.h:166
std::centi CentimetersRatio
Ratio for centimeters.
Definition: traits.h:96
std::micro MicrovoltsRatio
Ratio for microvolts.
Definition: traits.h:169
std::ratio< 24L *60 *60 > DaysRatio
Ratio for days.
Definition: traits.h:81
std::ratio< 1, 1 > HzRatio
Ratio for hertz.
Definition: traits.h:133
std::nano NanoampsRatio
Ratio for nanoamperes.
Definition: traits.h:151
std::ratio< 1, 1 > VoltsRatio
Ratio for volts.
Definition: traits.h:175
std::ratio< 1024ULL *1024 *1024 *1024, 1 > TerabytesRatio
Ratio for terabytes.
Definition: traits.h:193
std::micro MicrometersRatio
Ratio for micrometers.
Definition: traits.h:90
std::mega MegaHzRatio
Ratio for megahertz.
Definition: traits.h:139
std::milli MillimetersRatio
Ratio for millimeters.
Definition: traits.h:93
Main namespace for all classes / functions of COMMS library.
Tag class used to indicate linear switch dispatch.
Definition: traits.h:207
Tag class used to indicate polymorphic dispatch.
Definition: traits.h:201
Tag class used to indicate static binary search dispatch.
Definition: traits.h:204
Tag class used to indicate angle value.
Definition: traits.h:51
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
Empty class used in traits to indicate Big Endian.
Definition: access.h:35
Empty class used in traits to indicate Little Endian.
Definition: access.h:38