-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inspectable.h
60 lines (44 loc) · 1.21 KB
/
Inspectable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "forwarddeclarations.h"
#include <string>
#include <vector>
#include <functional>
#include <forward_list>
#if defined(__GNUG__)
#define HAS_RTTI
#elif defined(__has_feature)
#if __has_feature(cxx_rtti)
#define HAS_RTTI
#endif
#endif
#ifdef HAS_RTTI
#include <typeinfo>
#endif
namespace MagnumInspector {
class InspectableDestroyListener {
protected:
virtual void onDestroy(Inspectable* ) = 0;
friend class Inspectable;
};
class Inspectable
{
public:
typedef InspectableDestroyListener DestroyListener;
virtual ~Inspectable();
static std::string getDemangledNameFor(const void* ptr, const char* typenam);
template<typename T>
static std::string getNameFor(const T* ptr) {
return getDemangledNameFor(ptr, ptr ? typeid(*ptr).name() : typeid(T*).name());
}
virtual std::string getName() const {
return getNameFor<Inspectable>(this);
}
virtual void getChildren(std::vector<Inspectable*>& children) {}
virtual void getComponents(std::vector<Inspectable*>& children) {}
virtual void onInspect(Inspector& inspector) {};
void addDestroyListener(DestroyListener* listener);
void removeDestroyListener(DestroyListener* listener);
private:
std::forward_list<DestroyListener*> onDestroy;
};
}