siplasplas
A library for C++ reflection and introspection
field.hpp
1 #ifndef SIPLASPLAS_REFLECTION_DYNAMIC_FIELD_HPP
2 #define SIPLASPLAS_REFLECTION_DYNAMIC_FIELD_HPP
3 
4 #include "entity.hpp"
5 #include <siplasplas/typeerasure/field.hpp>
6 #include <siplasplas/typeerasure/simpleany.hpp>
7 #include <siplasplas/typeerasure/any.hpp>
8 
9 #include <type_traits>
10 #include <string>
11 #include <cstddef>
12 
13 namespace cpp
14 {
15 
16 namespace dynamic_reflection
17 {
18 
23 class SIPLASPLAS_REFLECTION_DYNAMIC_EXPORT Field : public Entity
24 {
25 public:
34  static std::shared_ptr<Field> create(const SourceInfo& sourceInfo, const cpp::typeerasure::Field32& field);
35 
47  static Field& fromEntity(const std::shared_ptr<Entity>& entity);
48 
52  const cpp::typeerasure::Field32& getField() const;
53 
61  template<typename Object>
62  decltype(auto) get(Object&& object) const
63  {
64  return _field.get(std::forward<Object>(object));
65  }
66 
76  template<typename T, typename Object>
77  decltype(auto) get(Object&& object) const
78  {
79  return _field.getAs<T>(std::forward<Object>(object));
80  }
81 
82 private:
83  Field(const SourceInfo& sourceInfo, const cpp::typeerasure::Field32& field);
84 
86 };
87 
88 }
89 }
90 
91 #endif // SIPLASPLAS_REFLECTION_DYNAMIC_FIELD_HPP
Definition: canary_allocator.hpp:7
Stores a type erased member object pointer.
Definition: field.hpp:25
Stores dynamic reflection information of a member object.
Definition: field.hpp:23
Represents a C++ semantic entity (Class, function, namespace, etc) and manages its dynamic reflection...
Definition: entity.hpp:22