-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathconstructor.h
More file actions
executable file
·107 lines (82 loc) · 4.51 KB
/
constructor.h
File metadata and controls
executable file
·107 lines (82 loc) · 4.51 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include "utils.h"
#include "qualified_type.h"
#include "param.h"
class Type;
class Constructor{
friend class Type;
protected:
const Type* type;
std::vector<QualifiedType> paramTypes;
Constructor(const Type* type, const std::vector<QualifiedType>& paramTypes){
this->type = type;
this->paramTypes = paramTypes;
}
public:
int GetParamCount() const{
return paramTypes.size();
}
const std::vector<QualifiedType> GetParamTypes() const{
return paramTypes;
}
const Type* GetType() const{
return type;
}
std::string GetDescription() const;
virtual Any Invoke() const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with no arguments");
}
virtual Any Invoke(Any p1) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2, Any p3) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ", " + p3.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2, Any p3, Any p4) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ", " + p3.GetType().ToString() + ", " + p4.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2, Any p3, Any p4, Any p5) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ", " + p3.GetType().ToString() + ", " + p4.GetType().ToString() + ", " + p5.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2, Any p3, Any p4, Any p5, Any p6) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ", " + p3.GetType().ToString() + ", " + p4.GetType().ToString() + ", " + p5.GetType().ToString() + ", " + p6.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ", " + p3.GetType().ToString() + ", " + p4.GetType().ToString() + ", " + p5.GetType().ToString() + ", " + p6.GetType().ToString() + ", " + p7.GetType().ToString() + ")");
}
virtual Any Invoke(Any p1, Any p2, Any p3, Any p4, Any p5, Any p6, Any p7, Any p8) const{
THROW_EXCEPTION(InvalidArguments, "tried to invoke constructor '" + GetDescription() + "' with arguments(" + p1.GetType().ToString() + ", " + p2.GetType().ToString() + ", " + p3.GetType().ToString() + ", " + p4.GetType().ToString() + ", " + p5.GetType().ToString() + ", " + p6.GetType().ToString() + ", " + p7.GetType().ToString() + ", " + p8.GetType().ToString() + ")");
}
};
template<class T, class... Args>
class ConstructorImpl : public Constructor{
private:
const Type* type;
public:
ConstructorImpl()
: Constructor(typeof(T), { GetQualifiedType<Args>::Value() ... }){
static_assert(std::is_constructible<T, Args...>::value, "tried to register an undeclared constructor");
}
virtual Any Invoke(typename AsType<Args, Any>::Value... params) const override{
return (Any)new T(std::forward<Args>((Args)params)...);
}
};
// doing partial specialization here to avoid a bug on Visual Studio which is fixed on Visual Studio 2015
#if defined(_MSC_VER) && _MSC_VER <= 1800
template<class T>
class ConstructorImpl<T> : public Constructor{
private:
const Type* type;
public:
ConstructorImpl()
: Constructor(typeof(T), { }){
static_assert(std::is_constructible<T>::value, "tried to register an undeclared constructor");
}
virtual Any Invoke() const override{
return (Any)new T();
}
};
#endif