RefleX
Build DDS Applications in Modern C++ without IDL
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
member_names.h
Go to the documentation of this file.
1 /*********************************************************************************************
2 (c) 2005-2014 Copyright, Real-Time Innovations, Inc. All rights reserved.
3 RTI grants Licensee a license to use, modify, compile, and create derivative works
4 of the Software. Licensee has the right to distribute object form only for use with RTI
5 products. The Software is provided "as is", with no warranty of any type, including
6 any warranty for fitness for any purpose. RTI is under no obligation to maintain or
7 support the Software. RTI shall not be liable for any incidental or consequential
8 damages arising out of the use or inability to use the software.
9 **********************************************************************************************/
10 
11 #ifndef RTIREFLEX_MEMBER_NAMES_H
12 #define RTIREFLEX_MEMBER_NAMES_H
13 
14 #include <string>
15 #include <typeinfo>
16 #include <boost/preprocessor/seq/for_each.hpp>
17 #include <boost/preprocessor/seq/size.hpp>
18 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
19 #include <boost/fusion/include/adapt_struct.hpp>
20 
21 #include "ndds/ndds_cpp.h"
22 
23 #include "reflex/dllexport.h"
24 #include "reflex/enable_if.h"
25 #include "reflex/dd_extra.h"
26 #include "reflex/adapt_macros.h"
27 
28 namespace reflex {
29 
30  namespace detail {
31 
32  REFLEX_DLL_EXPORT std::string remove_parenthesis(std::string);
33 
34  } // namespace detail
35 
36  namespace match {
37 
38  template <class... Args>
39  struct Sparse;
40 
41  template <class TagType, class... Cases>
42  struct Union;
43  } // namespace match
44 
45  namespace codegen
46  {
47  struct MemberInfo
48  {
49  std::string name;
50  unsigned char value;
51 
53  REFLEX_DLL_EXPORT MemberInfo(const std::string & n, unsigned char v);
54  };
55  } // namespace codegen
56 
57  namespace detail {
58 
59  struct NameHelper
60  {
61  REFLEX_DLL_EXPORT static reflex::codegen::MemberInfo get_member_info(int i);
62  REFLEX_DLL_EXPORT static const char * basename(const char *);
63  REFLEX_DLL_EXPORT static std::string type_name(const char * prefix);
64  REFLEX_DLL_EXPORT static std::string demangle(const char* name);
65  };
66 
67  } // namespace detail
68 
69  namespace codegen
70  {
71 
72  // specialize this trait for every user-defined type
73  template <class T, unsigned I>
74  struct MemberTraits
75  {
77  return reflex::detail::NameHelper::get_member_info(I);
78  }
79  };
80 
81  template <class First, class Second>
82  struct MemberTraits<std::pair<First, Second>, 0>
83  {
85  return MemberInfo("first", DDS_TYPECODE_NONKEY_REQUIRED_MEMBER);
86  }
87  };
88 
89  template <class First, class Second>
90  struct MemberTraits<std::pair<First, Second>, 1>
91  {
93  return MemberInfo("second", DDS_TYPECODE_NONKEY_REQUIRED_MEMBER);
94  }
95  };
96 
97 
98  template <class T>
99  struct StructName
100  {
101  static std::string get()
102  {
103 #ifdef HAVE_CXA_DEMANGLE
104  return reflex::detail::NameHelper::demangle(typeid(T).name());
105 #else
106  return reflex::detail::NameHelper::type_name("DefaultTypeName");
107 #endif
108  }
109  };
110 
111  template <class First, class Second>
112  struct StructName<std::pair<First, Second>>
113  {
114  static std::string get()
115  {
116  return reflex::detail::NameHelper::type_name("DefaultPairTypeName");
117  }
118  };
119 
120  template <class... Args>
121  struct StructName<match::Sparse<Args...>>
122  {
123  static std::string get()
124  {
125  return reflex::detail::NameHelper::type_name("DefaultSparseTypeName");
126  }
127  };
128 
129  template <class TagType, class... Cases>
130  struct StructName<match::Union<TagType, Cases...>>
131  {
132  static std::string get()
133  {
134  return reflex::detail::NameHelper::type_name("DefaultUnionName");
135  }
136  };
137 
138  template <class... Args>
139  struct StructName<std::tuple<Args...>>
140  {
141  static std::string get()
142  {
143  return reflex::detail::NameHelper::type_name("DefaultTupleName");
144  }
145  };
146 
147  } // namespace codegen
148 
149 
150 } // namespace reflex
151 
152 #ifndef REFLEX_NO_HEADER_ONLY
153 #include "reflex/../../src/member_names.cxx"
154 #endif
155 
156 #endif // RTIREFLEX_MEMBER_NAMES_H
157 
std::string name
Definition: member_names.h:49
unsigned char value
Definition: member_names.h:50
Definition: member_names.h:47
#define REFLEX_DLL_EXPORT
Definition: dllexport.h:35
Definition: member_names.h:99
static MemberInfo member_info()
Definition: member_names.h:76
static MemberInfo member_info()
Definition: member_names.h:92
REFLEX_DLL_EXPORT MemberInfo()
Definition: member_names.cxx:88
static MemberInfo member_info()
Definition: member_names.h:84
Macros to adapt user-defined types (classes, structs, and enums) to allow RefleX to extract type-spec...
Definition: member_names.h:74