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<
45  typename FullName,
46  typename Spelling,
47  typename DisplayName,
48  typename File,
49  std::size_t Line
50 >
52 {
53 public:
61  static constexpr static_reflection::Kind kind()
62  {
63  return Kind;
64  }
65 
73  static constexpr const char* fullName()
74  {
75  return ::cpp::meta::StringToArray<FullName>::c_str();
76  }
77 
87  static constexpr const char* spelling()
88  {
89  return ::cpp::meta::StringToArray<Spelling>::c_str();
90  }
91 
106  static constexpr const char* displayName()
107  {
108  return ::cpp::meta::StringToArray<DisplayName>::c_str();
109  }
110 
125  static constexpr const char* file()
126  {
127  return ::cpp::meta::StringToArray<File>::c_str();
128  }
129 
133  static constexpr std::size_t line()
134  {
135  return Line;
136  }
137 };
138 
139 template<typename T>
141  (std::is_enum<T>::value ? Kind::ENUM : Kind::CLASS),
142  ::cpp::meta::string<>,
143  ::cpp::meta::string<>,
144  ::cpp::meta::string<>,
145  ::cpp::meta::string<>,
146  0
147 >;
148 
149 }
150 
151 }
152 
153 }
154 
155 #endif // SIPLASPLAS_REFLECTION_STATIC_SOURCEINFO_HPP
Definition: canary_allocator.hpp:7
static constexpr const char * fullName()
Returns the full qualified name of an entity.
Definition: sourceinfo.hpp:73
static constexpr const char * file()
Returns the full path to the file where the entity is declared.
Definition: sourceinfo.hpp:125
static constexpr const char * spelling()
Returns the name of the entity See clang_getCursorSpelling().
Definition: sourceinfo.hpp:87
static constexpr static_reflection::Kind kind()
Retrns the kind (category) of the entity.
Definition: sourceinfo.hpp:61
static constexpr const char * displayName()
Returns the display name of the entity.
Definition: sourceinfo.hpp:106
Stores source information of an entity.
Definition: sourceinfo.hpp:51
Kind
Represents the different types of entities (namespaces, classes, functions, etc) the library can coll...
Definition: sourceinfo.hpp:22
static constexpr std::size_t line()
Returns the line number where the entity is declared.
Definition: sourceinfo.hpp:133