OnixS C++ CME MDP Conflated TCP Handler  1.3.1
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 
25 
26 #include <string>
27 
29 
30 #if defined (_MSC_VER)
31 
32 typedef signed char Int8;
33 typedef unsigned char UInt8;
34 
35 typedef signed short Int16;
36 typedef unsigned short UInt16;
37 
38 typedef signed int Int32;
39 typedef unsigned int UInt32;
40 
41 typedef signed long long Int64;
42 typedef unsigned long long UInt64;
43 
44 #elif defined (__GNUC__)
45 
46 typedef signed char Int8;
47 typedef unsigned char UInt8;
48 
49 typedef signed short Int16;
50 typedef unsigned short UInt16;
51 
52 #if defined (__LP64__)
53 
54 typedef signed int Int32;
55 typedef unsigned int UInt32;
56 
57 typedef signed long Int64;
58 typedef unsigned long UInt64;
59 
60 #else
61 
62 typedef signed int Int32;
63 typedef unsigned int UInt32;
64 
65 typedef signed long long Int64;
66 typedef unsigned long long UInt64;
67 
68 #endif
69 
70 #else
71 
72 // Compiler is not (yet) supported.
73 // Integral types must be defined explicitly.
74 
75 #error \
76  Cannot identify compiler toolset to define integral types. \
77  Please contact support@onixs.biz on further assistance.
78 
79 #endif
80 
81 /// Integral constant.
82 template
83 <
84  typename Type,
85  Type Constant
86 >
88 {
89  /// Type of the constant.
90  typedef Type Value;
91 
92  /// \return value of the constant.
94  operator Value() const ONIXS_CONFLATEDTCP_NOTHROW
95  {
96  return Constant;
97  }
98 
99  /// \return value of the constant.
102  {
103  return Constant;
104  }
105 
106  /// \return value of the constant.
109  {
110  return Constant;
111  }
112 };
113 
114 /// Serializes the given integer into a string.
116 void toStr(std::string&, Int8);
117 
118 /// Serializes the given integer into a string.
119 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 the given integer into a string.
134 void
135 toStr(
136  std::string&,
137  UInt8);
138 
139 /// Serializes the given integer into a string.
140 inline
142 std::string
144  UInt8 number)
145 {
146  std::string str;
147 
148  toStr(str, number);
149 
150  return str;
151 }
152 
153 /// Serializes the given integer into a string.
155 void
156 toStr(
157  std::string&,
158  Int16);
159 
160 /// Serializes the given integer into a string.
161 inline
163 std::string
165  Int16 number)
166 {
167  std::string str;
168 
169  toStr(str, number);
170 
171  return str;
172 }
173 
174 /// Serializes the given integer into a string.
176 void
177 toStr(
178  std::string&,
179  UInt16);
180 
181 /// Serializes the given integer into a string.
182 inline
184 std::string
186  UInt16 number)
187 {
188  std::string str;
189 
190  toStr(str, number);
191 
192  return str;
193 }
194 
195 /// Serializes the given integer into a string.
197 void
198 toStr(
199  std::string&,
200  Int32);
201 
202 /// Serializes the given integer into a string.
203 inline
205 std::string
207  Int32 number)
208 {
209  std::string str;
210 
211  toStr(str, number);
212 
213  return str;
214 }
215 
216 /// Serializes the given integer into a string.
218 void
219 toStr(
220  std::string&,
221  UInt32);
222 
223 /// Serializes the given integer into a string.
224 inline
226 std::string
228  UInt32 number)
229 {
230  std::string str;
231 
232  toStr(str, number);
233 
234  return str;
235 }
236 
237 /// Serializes the given integer into a string.
239 void
240 toStr(
241  std::string&,
242  Int64);
243 
244 /// Serializes the given integer into a string.
245 inline
247 std::string
249  Int64 number)
250 {
251  std::string str;
252 
253  toStr(str, number);
254 
255  return str;
256 }
257 
258 /// Serializes the given integer into a string.
260 void
261 toStr(
262  std::string&,
263  UInt64);
264 
265 /// Serializes the given integer into a string.
266 inline
268 std::string
270  UInt64 number)
271 {
272  std::string str;
273 
274  toStr(str, number);
275 
276  return str;
277 }
278 
279 /// Serializes the integer into the given buffer.
282 size_t
283 toStr(
284  Int8,
285  Char*,
286  size_t);
287 
288 
289 /// Serializes the integer into the given buffer.
292 size_t
293 toStr(
294  UInt8,
295  Char*,
296  size_t);
297 
298 /// Serializes the integer into the given buffer.
301 size_t
302 toStr(
303  Int16,
304  Char*,
305  size_t);
306 
307 
308 /// Serializes the integer into the given buffer.
311 size_t
312 toStr(
313  UInt16,
314  Char*,
315  size_t);
316 
317 
318 /// Serializes the integer into the given buffer.
321 size_t
322 toStr(
323  Int32,
324  Char*,
325  size_t);
326 
327 
328 /// Serializes the integer into the given buffer.
330 size_t
332 toStr(
333  UInt32,
334  Char*,
335  size_t);
336 
337 /// Serializes the integer into the given buffer.
340 size_t
341 toStr(
342  Int64,
343  Char*,
344  size_t);
345 
346 
347 /// Serializes the integer into the given buffer.
350 size_t
351 toStr(
352  UInt64,
353  Char*,
354  size_t);
355 
356 /// Serializes the given constant into a string.
357 template
358 <
359  typename Type,
360  Type Constant
361 >
362 inline
363 void
365  std::string& str,
367 {
368  toStr(str, constant());
369 }
370 
371 /// Serializes the given constant into a string.
372 template
373 <
374  typename Type,
375  Type Constant
376 >
377 inline
379 std::string
382  <Type, Constant> constant)
383 {
384  std::string str;
385 
386  toStr(str, constant);
387 
388  return str;
389 }
390 
391 /// Deserializes a numeric value from its text representation.
392 ///
393 /// \return `true` if the given buffer contains a valid representation
394 /// of a number. Otherwise, `false` is returned.
397 bool fromStr(Int8&, const Char*, size_t) ONIXS_CONFLATEDTCP_NOTHROW;
398 
399 /// Deserializes a numeric value from its text representation.
400 ///
401 /// \return `true` if the given buffer contains a valid representation
402 /// of a number. Otherwise, `false` is returned.
404 bool fromStr(Int8& value, const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
405 {
406  return
407  fromStr(
408  value,
409  str.c_str(),
410  str.size());
411 }
412 
413 /// Deserializes a numeric value from its text representation.
414 ///
415 /// \return `true` if the given buffer contains a valid representation
416 /// of a number. Otherwise, `false` is returned.
419 bool
420 fromStr(
421  UInt8&,
422  const Char*,
424 
425 /// Deserializes a numeric value from its text representation.
426 ///
427 /// \return `true` if the given buffer contains a valid representation
428 /// of a number. Otherwise, `false` is returned.
429 inline
431 bool fromStr(
432  UInt8& value,
433  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
434 {
435  return
436  fromStr(
437  value,
438  str.c_str(),
439  str.size());
440 }
441 
442 /// Deserializes a numeric value from its text representation.
443 ///
444 /// \return `true` if the given buffer contains a valid representation
445 /// of a number. Otherwise, `false` is returned.
448 bool
449 fromStr(
450  Int16&,
451  const Char*,
453 
454 /// Deserializes a numeric value from its text representation.
455 ///
456 /// \return `true` if the given buffer contains a valid representation
457 /// of a number. Otherwise, `false` is returned.
458 inline
460 bool fromStr(
461  Int16& value,
462  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
463 {
464  return
465  fromStr(
466  value,
467  str.c_str(),
468  str.size());
469 }
470 
471 /// Deserializes a numeric value from its text representation.
472 ///
473 /// \return `true` if the given buffer contains a valid representation
474 /// of a number. Otherwise, `false` is returned.
477 bool
478 fromStr(
479  UInt16&,
480  const Char*,
482 
483 /// Deserializes a numeric value from its text representation.
484 ///
485 /// \return `true` if the given buffer contains a valid representation
486 /// of a number. Otherwise, `false` is returned.
488 bool fromStr(
489  UInt16& value,
490  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
491 {
492  return
493  fromStr(
494  value,
495  str.c_str(),
496  str.size());
497 }
498 
499 /// Deserializes a numeric value from its text representation.
500 ///
501 /// \return `true` if the given buffer contains a valid representation
502 /// of a number. Otherwise, `false` is returned.
505 bool
506 fromStr(
507  Int32&,
508  const Char*,
510 
511 /// Deserializes a numeric value from its text representation.
512 ///
513 /// \return `true` if the given buffer contains a valid representation
514 /// of a number. Otherwise, `false` is returned.
515 inline
517 bool fromStr(
518  Int32& value,
519  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
520 {
521  return
522  fromStr(
523  value,
524  str.c_str(),
525  str.size());
526 }
527 
528 /// Deserializes a numeric value from its text representation.
529 ///
530 /// \return `true` if the given buffer contains a valid representation
531 /// of a number. Otherwise, `false` is returned.
534 bool
535 fromStr(
536  UInt32&,
537  const Char*,
539 
540 /// Deserializes a numeric value from its text representation.
541 ///
542 /// \return `true` if the given buffer contains a valid representation
543 /// of a number. Otherwise, `false` is returned.
544 inline
546 bool fromStr(
547  UInt32& value,
548  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
549 {
550  return
551  fromStr(
552  value,
553  str.c_str(),
554  str.size());
555 }
556 
557 /// Deserializes a numeric value from its text representation.
558 ///
559 /// \return `true` if the given buffer contains a valid representation
560 /// of a number. Otherwise, `false` is returned.
563 bool
564 fromStr(
565  Int64&,
566  const Char*,
568 
569 /// Deserializes a numeric value from its text representation.
570 ///
571 /// \return `true` if the given buffer contains a valid representation
572 /// of a number. Otherwise, `false` is returned.
573 inline
575 bool fromStr(
576  Int64& value,
577  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
578 {
579  return
580  fromStr(
581  value,
582  str.c_str(),
583  str.size());
584 }
585 
586 /// Deserializes a numeric value from its text representation.
587 ///
588 /// \return `true` if the given buffer contains a valid representation
589 /// of a number. Otherwise, `false` is returned.
592 bool
593 fromStr(
594  UInt64&,
595  const Char*,
597 
598 /// Deserializes a numeric value from its text representation.
599 ///
600 /// \return `true` if the given buffer contains a valid representation
601 /// of a number. Otherwise, `false` is returned.
602 inline
604 bool fromStr(
605  UInt64& value,
606  const std::string& str) ONIXS_CONFLATEDTCP_NOTHROW
607 {
608  return
609  fromStr(
610  value,
611  str.c_str(),
612  str.size());
613 }
614 
#define ONIXS_CONFLATEDTCP_MESSAGING_NAMESPACE_END
Definition: ABI.h:144
#define ONIXS_CONFLATEDTCP_NOTHROW
Definition: Compiler.h:189
#define ONIXS_CONFLATEDTCP_EXPORTED
Definition: Compiler.h:187
std::string toStr(IntegralConstant< Type, Constant > constant)
Serializes the given constant into a string.
Definition: Integral.h:380
constexpr Value operator()() const noexcept
Definition: Integral.h:101
#define ONIXS_CONFLATEDTCP_CONSTEXPR
Definition: Compiler.h:192
#define ONIXS_CONFLATEDTCP_NODISCARD
Definition: Compiler.h:198
static constexpr Value value() noexcept
Definition: Integral.h:108
bool fromStr(UInt64 &value, const std::string &str) noexcept
Deserializes a numeric value from its text representation.
Definition: Integral.h:604
#define ONIXS_CONFLATEDTCP_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:140
char Char
Character type alias.
Definition: String.h:30