siplasplas
A library for C++ reflection and introspection
field.hpp
1 #ifndef SIPLASPLAS_REFLECTION_STATIC_FIELD_HPP
2 #define SIPLASPLAS_REFLECTION_STATIC_FIELD_HPP
3 
4 #include <siplasplas/utility/meta.hpp>
5 
6 namespace cpp
7 {
8 
9 namespace static_reflection
10 {
11 
12 namespace meta
13 {
14 
15 template<typename SourceInfo, typename F, F field>
16 class Field;
17 
18 #ifndef SIPLASPLAS_DOXYGEN_RUNNING
19 template<typename SourceInfo_, typename Class, typename T, T Class::*field>
20 class Field<SourceInfo_, T Class::*, field>
21 #else
22 
26 class Field
27 #endif // SIPLASPLAS_DOXYGEN_RUNNING
28 {
29 public:
33  using type = T Class::*;
37  using value_type = T;
41  using class_type = Class;
45  using decay_t = cpp::meta::decay_t<value_type>;
49  using SourceInfo = SourceInfo_;
50 
51  constexpr Field() = default;
52 
56  static constexpr type get()
57  {
58  return _field;
59  }
60 
69  static constexpr const decay_t& get(const Class& object)
70  {
71  return object.*_field;
72  }
73 
82  static constexpr decay_t& get(Class& object)
83  {
84  return object.*_field;
85  }
86 
87 private:
88  static constexpr type _field = field;
89 };
90 
91 }
92 
93 namespace codegen
94 {
95 
96 template<typename FieldType, FieldType field>
97 class Field :
99  static_reflection::meta::EmptySourceInfo<Field<FieldType, field>>,
100  FieldType,
101  field
102  >
103 {};
104 
105 }
106 
117 template<typename FieldType, FieldType field>
118 class Field : public codegen::Field<FieldType, field>
119 {};
120 
121 }
122 
123 }
124 #endif // SIPLASPLAS_REFLECTION_STATIC_FIELD_HPP
Stores static reflection information of a member object.
Definition: field.hpp:16
Definition: canary_allocator.hpp:7
SourceInfo_ SourceInfo
Source information of the member object. See cpp::static_reflection::meta::SourceInfo.
Definition: field.hpp:49
cpp::meta::decay_t< value_type > decay_t
Type of the member value without cv nor reference qualifiers.
Definition: field.hpp:45
Returns static reflection information of a given pointer to member object.
Definition: field.hpp:118
Stores static reflection information of a given class.
Definition: class.hpp:31