OnixS C++ CME MDP Conflated UDP Handler  1.1.2
API documentation
Integral.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <string>
24 
26 
28 
29 #if defined (_MSC_VER)
30 
31 typedef signed char Int8;
32 typedef unsigned char UInt8;
33 
34 typedef signed short Int16;
35 typedef unsigned short UInt16;
36 
37 typedef signed int Int32;
38 typedef unsigned int UInt32;
39 
40 typedef signed long long Int64;
41 typedef unsigned long long UInt64;
42 
43 #elif defined (__GNUC__)
44 
45 typedef signed char Int8;
46 typedef unsigned char UInt8;
47 
48 typedef signed short Int16;
49 typedef unsigned short UInt16;
50 
51 #if defined (__LP64__)
52 
53 typedef signed int Int32;
54 typedef unsigned int UInt32;
55 
56 typedef signed long Int64;
57 typedef unsigned long UInt64;
58 
59 #else
60 
61 typedef signed int Int32;
62 typedef unsigned int UInt32;
63 
64 typedef signed long long Int64;
65 typedef unsigned long long UInt64;
66 
67 #endif
68 
69 #else
70 
71 // Compiler is not (yet) supported.
72 // Integral types must be defined explicitly.
73 
74 #error \
75  Cannot identify compiler toolset to define integral types. \
76  Please contact support@onixs.biz on further assistance.
77 
78 #endif
79 
80 //
81 
82 /// Integral constant.
83 template
84 <
85  typename Type,
86  Type Constant
87 >
89 {
90  /// Type of the constant.
91  typedef Type Value;
92 
93  /// Returns value of the constant.
94  operator Value() const
95  {
96  return Constant;
97  }
98 
99  /// Returns value of the constant.
100  Value operator()() const
101  {
102  return Constant;
103  }
104 
105  /// Returns value of the constant.
106  static Value value()
107  {
108  return Constant;
109  }
110 };
111 
112 /// Serializes given integer into a string.
113 ONIXS_CONFLATEDUDP_EXPORTED
114 void
115 toStr(
116  std::string&,
117  Int8);
118 
119 /// Serializes given integer into a string.
120 inline
121 std::string
123  Int8 number)
124 {
125  std::string str;
126 
127  toStr(str, number);
128 
129  return str;
130 }
131 
132 /// Serializes given integer into a string.
133 ONIXS_CONFLATEDUDP_EXPORTED
134 void
135 toStr(
136  std::string&,
137  UInt8);
138 
139 /// Serializes given integer into a string.
140 inline
141 std::string
143  UInt8 number)
144 {
145  std::string str;
146 
147  toStr(str, number);
148 
149  return str;
150 }
151 
152 /// Serializes given integer into a string.
153 ONIXS_CONFLATEDUDP_EXPORTED
154 void
155 toStr(
156  std::string&,
157  Int16);
158 
159 /// Serializes given integer into a string.
160 inline
161 std::string
163  Int16 number)
164 {
165  std::string str;
166 
167  toStr(str, number);
168 
169  return str;
170 }
171 
172 /// Serializes given integer into a string.
173 ONIXS_CONFLATEDUDP_EXPORTED
174 void
175 toStr(
176  std::string&,
177  UInt16);
178 
179 /// Serializes given integer into a string.
180 inline
181 std::string
183  UInt16 number)
184 {
185  std::string str;
186 
187  toStr(str, number);
188 
189  return str;
190 }
191 
192 /// Serializes given integer into a string.
193 ONIXS_CONFLATEDUDP_EXPORTED
194 void
195 toStr(
196  std::string&,
197  Int32);
198 
199 /// Serializes given integer into a string.
200 inline
201 std::string
203  Int32 number)
204 {
205  std::string str;
206 
207  toStr(str, number);
208 
209  return str;
210 }
211 
212 /// Serializes given integer into a string.
213 ONIXS_CONFLATEDUDP_EXPORTED
214 void
215 toStr(
216  std::string&,
217  UInt32);
218 
219 /// Serializes given integer into a string.
220 inline
221 std::string
223  UInt32 number)
224 {
225  std::string str;
226 
227  toStr(str, number);
228 
229  return str;
230 }
231 
232 /// Serializes given integer into a string.
233 ONIXS_CONFLATEDUDP_EXPORTED
234 void
235 toStr(
236  std::string&,
237  Int64);
238 
239 /// Serializes given integer into a string.
240 inline
241 std::string
243  Int64 number)
244 {
245  std::string str;
246 
247  toStr(str, number);
248 
249  return str;
250 }
251 
252 /// Serializes given integer into a string.
253 ONIXS_CONFLATEDUDP_EXPORTED
254 void
255 toStr(
256  std::string&,
257  UInt64);
258 
259 /// Serializes given integer into a string.
260 inline
261 std::string
263  UInt64 number)
264 {
265  std::string str;
266 
267  toStr(str, number);
268 
269  return str;
270 }
271 
272 /// Serializes given constant into a string.
273 template
274 <
275  typename Type,
276  Type Constant
277 >
278 inline
279 void
281  std::string& str,
283 {
284  toStr(str, constant());
285 }
286 
287 /// Serializes given constant into a string.
288 template
289 <
290  typename Type,
291  Type Constant
292 >
293 inline
294 std::string
297  <Type, Constant> constant)
298 {
299  std::string str;
300 
301  toStr(str, constant);
302 
303  return str;
304 }
305 
306 //
307 
308 /// Deserializes numeric value
309 /// from its text representation.
310 ///
311 /// Returns 'true' if the given buffer
312 /// contains a valid representation of a
313 /// number. Otherwise, 'false' is returned.
314 ONIXS_CONFLATEDUDP_EXPORTED
315 bool
316 fromStr(
317  Int8&,
318  const Char*,
319  size_t);
320 
321 /// Deserializes numeric value
322 /// from its text representation.
323 ///
324 /// Returns 'true' if the given buffer
325 /// contains a valid representation of a
326 /// number. Otherwise, 'false' is returned.
327 ONIXS_CONFLATEDUDP_EXPORTED
328 bool
329 fromStr(
330  UInt8&,
331  const Char*,
332  size_t);
333 
334 /// Deserializes numeric value
335 /// from its text representation.
336 ///
337 /// Returns 'true' if the given buffer
338 /// contains a valid representation of a
339 /// number. Otherwise, 'false' is returned.
340 ONIXS_CONFLATEDUDP_EXPORTED
341 bool
342 fromStr(
343  Int16&,
344  const Char*,
345  size_t);
346 
347 /// Deserializes numeric value
348 /// from its text representation.
349 ///
350 /// Returns 'true' if the given buffer
351 /// contains a valid representation of a
352 /// number. Otherwise, 'false' is returned.
353 ONIXS_CONFLATEDUDP_EXPORTED
354 bool
355 fromStr(
356  UInt16&,
357  const Char*,
358  size_t);
359 
360 /// Deserializes numeric value
361 /// from its text representation.
362 ///
363 /// Returns 'true' if the given buffer
364 /// contains a valid representation of a
365 /// number. Otherwise, 'false' is returned.
366 ONIXS_CONFLATEDUDP_EXPORTED
367 bool
368 fromStr(
369  Int32&,
370  const Char*,
371  size_t);
372 
373 /// Deserializes numeric value
374 /// from its text representation.
375 ///
376 /// Returns 'true' if the given buffer
377 /// contains a valid representation of a
378 /// number. Otherwise, 'false' is returned.
379 ONIXS_CONFLATEDUDP_EXPORTED
380 bool
381 fromStr(
382  UInt32&,
383  const Char*,
384  size_t);
385 
386 /// Deserializes numeric value
387 /// from its text representation.
388 ///
389 /// Returns 'true' if the given buffer
390 /// contains a valid representation of a
391 /// number. Otherwise, 'false' is returned.
392 ONIXS_CONFLATEDUDP_EXPORTED
393 bool
394 fromStr(
395  Int64&,
396  const Char*,
397  size_t);
398 
399 /// Deserializes numeric value
400 /// from its text representation.
401 ///
402 /// Returns 'true' if the given buffer
403 /// contains a valid representation of a
404 /// number. Otherwise, 'false' is returned.
405 ONIXS_CONFLATEDUDP_EXPORTED
406 bool
407 fromStr(
408  UInt64&,
409  const Char*,
410  size_t);
411 
UInt64 UInt64
uInt64.
Definition: Fields.h:265
std::string toStr(IntegralConstant< Type, Constant > constant)
Serializes given constant into a string.
Definition: Integral.h:295
ONIXS_CONFLATEDUDP_EXPORTED bool fromStr(UInt64 &, const Char *, size_t)
Int32 Int32
int32.
Definition: Fields.h:69
UInt32 UInt32
uInt32.
Definition: Fields.h:261
char Char
Character type alias.
Definition: String.h:36
static Value value()
Returns value of the constant.
Definition: Integral.h:106
Value operator()() const
Returns value of the constant.
Definition: Integral.h:100
Int16 Int16
int16.
Definition: Fields.h:65
Type Value
Type of the constant.
Definition: Integral.h:91
#define ONIXS_CONFLATEDUDP_NAMESPACE_END
Definition: Bootstrap.h:157
UInt16 UInt16
uInt16.
Definition: Fields.h:257
UInt8 UInt8
uInt8.
Definition: Fields.h:269
#define ONIXS_CONFLATEDUDP_NAMESPACE_BEGIN
Definition: Bootstrap.h:153