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/constexpr/string.hpp>
5 #include <siplasplas/constexpr/meta.hpp>
6 #include <siplasplas/utility/meta.hpp>
7 #include <array>
8 #include <string>
9 
10 namespace cpp
11 {
12 
13 namespace static_reflection
14 {
15 
24 enum class Kind
25 {
26  NAMESPACE,
27  FUNCTION,
28  ENUM,
29  CLASS,
30  FIELD,
31  UNKNOWN
32 };
33 
34 namespace meta
35 {
36 
45 template<
46  typename Entity_,
48  typename FullName,
49  typename Spelling,
50  typename DisplayName,
51  typename File,
52  std::size_t Line
53 >
55 {
56 private:
57 
58 public:
62  using Entity = Entity_;
63 
71  static constexpr static_reflection::Kind kind()
72  {
73  return Kind;
74  }
75 
82  static constexpr const cpp::constexp::String<FullName::size + 1>& fullName()
83  {
84  return cpp::constexp::SequenceToString<FullName>::str();
85  }
86 
95  static constexpr const cpp::constexp::String<Spelling::size + 1>& spelling()
96  {
97  return cpp::constexp::SequenceToString<Spelling>::str();
98  }
99 
114  static constexpr const char* displayName()
115  {
116  return ::cpp::constexp::SequenceToString<DisplayName>::c_str();
117  }
118 
133  static constexpr const char* file()
134  {
135  return ::cpp::constexp::SequenceToString<File>::c_str();
136  }
137 
141  static constexpr std::size_t line()
142  {
143  return Line;
144  }
145 };
146 
147 template<typename T>
149  T,
150  (std::is_enum<T>::value ? Kind::ENUM : Kind::CLASS),
151  ::cpp::meta::string<>,
152  ::cpp::meta::string<>,
153  ::cpp::meta::string<>,
154  ::cpp::meta::string<>,
155  0
156 >;
157 
158 }
159 
160 }
161 
162 }
163 
164 #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:114
static constexpr std::size_t line()
Returns the line number where the entity is declared.
Definition: sourceinfo.hpp:141
static constexpr const cpp::constexp::String< Spelling::size+1 > & spelling()
Returns the name of the entity See clang_getCursorSpelling().
Definition: sourceinfo.hpp:95
static constexpr static_reflection::Kind kind()
Returns the kind (category) of the entity.
Definition: sourceinfo.hpp:71
Entity_ Entity
Returns the entity (Or a type representation of the entity)
Definition: sourceinfo.hpp:62
Stores source information of an entity.
Definition: sourceinfo.hpp:54
Kind
Represents the different types of entities (namespaces, classes, functions, etc) the library can coll...
Definition: sourceinfo.hpp:24
static constexpr const char * file()
Returns the full path to the file where the entity is declared.
Definition: sourceinfo.hpp:133
static constexpr const cpp::constexp::String< FullName::size+1 > & fullName()
Returns the full qualified name of an entity.
Definition: sourceinfo.hpp:82