Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafPortableDataType.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) Kontur AS
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 
20 #pragma once
21 
22 #include <chrono>
23 #include <concepts>
24 #include <string>
25 #include <typeinfo>
26 #include <utility>
27 #include <vector>
28 
29 namespace caffa
30 {
34 template <typename DataType>
36 {
37  static std::string name() { return "object"; }
38 };
39 
40 template <>
41 struct PortableDataType<void>
42 {
43  static std::string name() { return "void"; }
44 };
45 
46 template <typename DataType>
47 struct PortableDataType<std::vector<DataType>>
48 {
49  static std::string name() { return PortableDataType<DataType>::name() + "[]"; }
50 };
51 
52 template <std::unsigned_integral DataType>
53 struct PortableDataType<DataType>
54 {
55  static std::string name() { return "uint" + std::to_string( sizeof( DataType ) * 8 ); }
56 };
57 
58 template <std::signed_integral DataType>
59 struct PortableDataType<DataType>
60 {
61  static std::string name() { return "int" + std::to_string( sizeof( DataType ) * 8 ); }
62 };
63 
64 template <>
65 struct PortableDataType<bool>
66 {
67  static std::string name() { return "boolean"; }
68 };
69 
70 template <>
71 struct PortableDataType<float>
72 {
73  static std::string name() { return "float"; }
74 };
75 
76 template <>
77 struct PortableDataType<double>
78 {
79  static std::string name() { return "double"; }
80 };
81 
82 template <>
83 struct PortableDataType<std::string>
84 {
85  static std::string name() { return "string"; }
86 };
87 
88 template <>
89 struct PortableDataType<std::chrono::steady_clock::time_point>
90 {
91  static std::string name() { return "timestamp_ns"; }
92 };
93 
94 template <>
95 struct PortableDataType<std::chrono::nanoseconds>
96 {
97  static std::string name() { return "nanoseconds"; }
98 };
99 
100 template <>
101 struct PortableDataType<std::chrono::microseconds>
102 {
103  static std::string name() { return "microseconds"; }
104 };
105 
106 template <>
107 struct PortableDataType<std::chrono::milliseconds>
108 {
109  static std::string name() { return "milliseconds"; }
110 };
111 
112 template <>
113 struct PortableDataType<std::chrono::seconds>
114 {
115  static std::string name() { return "seconds"; }
116 };
117 
118 } // namespace caffa
Definition: cafPortableDataType.h:35
Main Caffa namespace.
Definition: cafApplication.h:30