siplasplas
A library for C++ reflection and introspection
function.hpp
1 #ifndef SIPLASPLAS_REFLECTION_DYNAMIC_FUNCTION_HPP
2 #define SIPLASPLAS_REFLECTION_DYNAMIC_FUNCTION_HPP
3 
4 #include "entity.hpp"
5 #include <siplasplas/typeerasure/function.hpp>
6 
7 namespace cpp
8 {
9 
10 namespace dynamic_reflection
11 {
12 
17 class SIPLASPLAS_REFLECTION_DYNAMIC_EXPORT Function : public Entity
18 {
19 public:
23  template<typename... Args>
24  auto operator()(Args&&... args) const
25  {
26  return _functionPointer(std::forward<Args>(args)...);
27  }
28 
32  template<typename... Args>
33  auto operator()(Args&&... args)
34  {
35  return _functionPointer(std::forward<Args>(args)...);
36  }
37 
41  const cpp::typeerasure::Function32& getFunction() const;
42 
51  static std::shared_ptr<Function> create(const SourceInfo& sourceInfo, const cpp::typeerasure::Function32& function);
52 
64  static Function& fromEntity(const std::shared_ptr<Entity>& entity);
65 
66 private:
67  Function(const SourceInfo& sourceInfo, const cpp::typeerasure::Function32& function);
68 
69  cpp::typeerasure::Function32 _functionPointer;
70 };
71 
72 }
73 
74 }
75 
76 #endif // SIPLASPLAS_REFLECTION_DYNAMIC_FUNCTION_HPP
Definition: canary_allocator.hpp:7
Stires dynamic reflection information of a function.
Definition: function.hpp:17
auto operator()(Args &&... args) const
Invokes the function with the given arguments.
Definition: function.hpp:24
Stores a type-erased callable of any signature and kind.
Definition: function.hpp:58
Represents a C++ semantic entity (Class, function, namespace, etc) and manages its dynamic reflection...
Definition: entity.hpp:22
auto operator()(Args &&... args)
Invokes the function with the given arguments.
Definition: function.hpp:33