Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafPortableDataType.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 3D-Radar 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 <string>
23 #include <typeinfo>
24 #include <vector>
25 
26 #define CONCAT( a, b ) a b
27 
28 namespace caffa
29 {
33 template <typename DataType>
35 {
36  static std::string name() { return typeid( DataType ).name(); }
37 };
38 
42 #define CAFFA_DEFINE_PORTABLE_TYPE( DataType ) \
43  template <> \
44  struct PortableDataType<DataType> \
45  { \
46  static std::string name() \
47  { \
48  return #DataType; \
49  } \
50  }; \
51  \
52  template <> \
53  struct PortableDataType<std::vector<DataType>> \
54  { \
55  static std::string name() \
56  { \
57  return CONCAT( #DataType, "[]" ); \
58  } \
59  }; \
60  \
61  template <> \
62  struct PortableDataType<std::vector<std::vector<DataType>>> \
63  { \
64  static std::string name() \
65  { \
66  return CONCAT( #DataType, "[][]" ); \
67  } \
68  };
69 
70 #define CAFFA_DEFINE_PORTABLE_TYPE_NAME( DataType, StringAlias ) \
71  template <> \
72  struct PortableDataType<DataType> \
73  { \
74  static std::string name() \
75  { \
76  return StringAlias; \
77  } \
78  }; \
79  \
80  template <> \
81  struct PortableDataType<std::vector<DataType>> \
82  { \
83  static std::string name() \
84  { \
85  return CONCAT( StringAlias, "[]" ); \
86  } \
87  }; \
88  \
89  template <> \
90  struct PortableDataType<std::vector<std::vector<DataType>>> \
91  { \
92  static std::string name() \
93  { \
94  return CONCAT( StringAlias, "[][]" ); \
95  } \
96  };
97 
98 CAFFA_DEFINE_PORTABLE_TYPE( double )
99 CAFFA_DEFINE_PORTABLE_TYPE( float )
100 CAFFA_DEFINE_PORTABLE_TYPE( bool )
101 CAFFA_DEFINE_PORTABLE_TYPE( char )
102 CAFFA_DEFINE_PORTABLE_TYPE_NAME( int, "int32" )
103 CAFFA_DEFINE_PORTABLE_TYPE_NAME( unsigned, "uint32" )
104 CAFFA_DEFINE_PORTABLE_TYPE_NAME( uint64_t, "uint64" )
105 CAFFA_DEFINE_PORTABLE_TYPE_NAME( int64_t, "int64" )
106 CAFFA_DEFINE_PORTABLE_TYPE_NAME( std::string, "string" )
107 CAFFA_DEFINE_PORTABLE_TYPE_NAME( void, "void" )
108 } // namespace caffa
Main Caffa namespace.
Definition: __init__.py:1
Definition: cafPortableDataType.h:35