siplasplas
A library for C++ reflection and introspection
entity.hpp
1 #ifndef SIPLASPLAS_REFLECTION_DYNAMIC_ENTITY_HPP
2 #define SIPLASPLAS_REFLECTION_DYNAMIC_ENTITY_HPP
3 
4 #include "sourceinfo.hpp"
5 #include "detail/runtime_forward.hpp"
6 #include <siplasplas/reflection/dynamic/export.hpp>
7 
8 #include <memory>
9 #include <unordered_set>
10 
11 namespace cpp
12 {
13 
14 namespace dynamic_reflection
15 {
16 
22 class SIPLASPLAS_REFLECTION_DYNAMIC_EXPORT Entity : public std::enable_shared_from_this<Entity>
23 {
24 public:
25  virtual ~Entity() = default;
26 
31  Entity& parent();
32 
38  Runtime& runtime();
39 
43  const SourceInfo& sourceInfo() const;
44 
48  const std::string& name() const;
49 
53  const std::string& fullName() const;
54 
58  const SourceInfo::Kind& kind() const;
59 
65  bool detached() const;
66 
72  bool orphan() const;
73 
81  void attach(Runtime& runtime);
82 
92  void attach(const std::weak_ptr<Entity>& parent);
93 
105  void addChild(const std::shared_ptr<Entity>& entity);
106 
114  bool isChild(const std::shared_ptr<Entity>& entity) const;
115 
123  bool isChild(const Entity& entity) const;
124 
134  bool isChildByName(const std::string& name) const;
135 
145  bool isChildByFullName(const std::string& fullName) const;
146 
157  Entity& getChildByFullName(const std::string& fullName);
158 
169  Entity& getChildByName(const std::string& name);
170 
191  std::vector<std::string> getChildrenNamesByKind(const SourceInfo::Kind& kind);
192 
196  std::shared_ptr<Entity> pointer();
197 
202  friend bool operator==(const Entity& lhs, const Entity& rhs);
203 
211  friend bool operator!=(const Entity& lhs, const Entity& rhs);
212 
213 protected:
214  Entity(const SourceInfo& sourceInfo);
215 
216 private:
217  std::weak_ptr<Entity> _parent;
218  Runtime* _runtime;
219  SourceInfo _sourceInfo;
220  std::unordered_set<std::string> _children;
221 };
222 
223 }
224 
225 }
226 
227 #endif // SIPLASPLAS_REFLECTION_DYNAMIC_ENTITY_HPP
Definition: canary_allocator.hpp:7
Provides access to dynamic type and function information at runtime.
Definition: runtime.hpp:16
Kind
Represents the different types of entities (namespaces, classes, functions, etc) the library can coll...
Definition: sourceinfo.hpp:24
Represents a C++ semantic entity (Class, function, namespace, etc) and manages its dynamic reflection...
Definition: entity.hpp:22