siplasplas
A library for C++ reflection and introspection
sourceinfo.hpp
1 #ifndef SIPLASPLAS_REFLECTION_STATIC_SOURCEINFO_HPP
2 #define SIPLASPLAS_REFLECTION_STATIC_SOURCEINFO_HPP
3 
4 #include <siplasplas/utility/meta.hpp>
5 #include <array>
6 #include <string>
7 
8 namespace cpp
9 {
10 
11 namespace static_reflection
12 {
13 
22 enum class Kind
23 {
24  NAMESPACE,
25  FUNCTION,
26  ENUM,
27  CLASS,
28  FIELD,
29  UNKNOWN
30 };
31 
32 namespace meta
33 {
34 
43 template<
44  typename Entity_,
46  typename FullName,
47  typename Spelling,
48  typename DisplayName,
49  typename File,
50  std::size_t Line
51 >
53 {
54 public:
58  using Entity = Entity_;
59 
67  static constexpr static_reflection::Kind kind()
68  {
69  return Kind;
70  }
71 
79  static constexpr const char* fullName()
80  {
81  return ::cpp::meta::StringToArray<FullName>::c_str();
82  }
83 
93  static constexpr const char* spelling()
94  {
95  return ::cpp::meta::StringToArray<Spelling>::c_str();
96  }
97 
112  static constexpr const char* displayName()
113  {
114  return ::cpp::meta::StringToArray<DisplayName>::c_str();
115  }
116 
131  static constexpr const char* file()
132  {
133  return ::cpp::meta::StringToArray<File>::c_str();
134  }
135 
139  static constexpr std::size_t line()
140  {
141  return Line;
142  }
143 };
144 
145 template<typename T>
147  T,
148  (std::is_enum<T>::value ? Kind::ENUM : Kind::CLASS),
149  ::cpp::meta::string<>,
150  ::cpp::meta::string<>,
151  ::cpp::meta::string<>,
152  ::cpp::meta::string<>,
153  0
154 >;
155 
156 }
157 
158 }
159 
160 }
161 
162 #endif // SIPLASPLAS_REFLECTION_STATIC_SOURCEINFO_HPP
Definition: canary_allocator.hpp:7
static constexpr const char * displayName()
Returns the display name of the entity.
Definition: sourceinfo.hpp:112
static constexpr std::size_t line()
Returns the line number where the entity is declared.
Definition: sourceinfo.hpp:139
static constexpr static_reflection::Kind kind()
Returns the kind (category) of the entity.
Definition: sourceinfo.hpp:67
static constexpr const char * spelling()
Returns the name of the entity See clang_getCursorSpelling().
Definition: sourceinfo.hpp:93
static constexpr const char * fullName()
Returns the full qualified name of an entity.
Definition: sourceinfo.hpp:79
Entity_ Entity
Returns the entity (Or a type representation of the entity)
Definition: sourceinfo.hpp:58
Stores source information of an entity.
Definition: sourceinfo.hpp:52
Kind
Represents the different types of entities (namespaces, classes, functions, etc) the library can coll...
Definition: sourceinfo.hpp:22
static constexpr const char * file()
Returns the full path to the file where the entity is declared.
Definition: sourceinfo.hpp:131