Newer
Older
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#pragma once
#include <ext/variant>
#include <object/Object.h>
#include <object/AnyObject.h>
namespace object {
template < class Type >
class ObjectFactoryImpl {
public:
/**
* \brief
* Specialisation of the make method for objects that are not from the object hierarchy of Algorithms library
*/
static Object construct ( Type && data ) {
return ObjectFactoryImpl < object::AnyObject < typename std::decay < Type >::type > >::construct ( object::AnyObject < typename std::decay < Type >::type > ( std::forward < Type > ( data ) ) );
}
};
template < >
class ObjectFactoryImpl < Object > {
public:
static Object construct ( Object && object ) {
return std::move ( object );
}
};
template < >
class ObjectFactoryImpl < const Object & > {
public:
static Object construct ( const Object & object ) {
return object;
}
};
template < >
class ObjectFactoryImpl < Object & > {
public:
static Object construct ( Object & object ) {
return object;
}
};
template < >
class ObjectFactoryImpl < const char * const & > {
public:
static Object construct ( const char * const string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < char * const & > {
public:
static Object construct ( char * const string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < const char * & > {
public:
static Object construct ( const char * const string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < char * & > {
public:
static Object construct ( char * const string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < const char * const > {
public:
static Object construct ( const char * const string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < char * const > {
public:
static Object construct ( char * const string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < const char * > {
public:
static Object construct ( const char * string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
template < >
class ObjectFactoryImpl < char * > {
public:
static Object construct ( char * string ) {
return ObjectFactoryImpl < std::string >::construct ( std::string ( string ) );
}
};
namespace details {
/**
* \brief
* Helper method to detect variant content and call make method on the object from inside of the variant.
*/
template < class Variant >
static Object processVariant ( Variant && data ) {
auto visitor = [] < class Type > ( Type && element ) {
return ObjectFactoryImpl < Type >::construct ( std::forward < Type > ( element ) );
};
return ext::visit ( visitor, std::forward < Variant > ( data ) );
}
}
/**
* \brief
* Specialisation of the make method for variants.
*
* \details
* The resulting object is not constructed from the variant itself but from the value stored inside. If the value stored inside the variant is variant again, the process is repeated.
*/
template < class ... Types >
class ObjectFactoryImpl < ext::variant < Types ... > > {
public:
static Object construct ( ext::variant < Types ... > && data ) {
return details::processVariant ( std::move ( data ) );
}
};
/**
* \brief
* Specialisation of the make method for variants.
*
* \details
* The resulting object is not constructed from the variant itself but from the value stored inside. If the value stored inside the variant is variant again, the process is repeated.
*/
template < class ... Types >
class ObjectFactoryImpl < const ext::variant < Types ... > & > {
public:
static Object construct ( const ext::variant < Types ... > & data ) {
return details::processVariant ( data );
}
};
/**
* \brief
* Specialisation of the make method for variants.
*
* \details
* The resulting object is not constructed from the variant itself but from the value stored inside. If the value stored inside the variant is variant again, the process is repeated.
*/
template < class ... Types >
class ObjectFactoryImpl < ext::variant < Types ... > & > {
public:
static Object construct ( ext::variant < Types ... > & data ) {
return details::processVariant ( data );
}
};
/**
* Constructor that wraps an object given by a constant reference. Uses clone of the parameter internally.
*/
template < class Type >
class ObjectFactoryImpl < const AnyObject < Type > & > {
public:
static Object construct ( const AnyObject < Type > & data ) {
return Object ( data.clone ( ) );
}
};
/**
* Constructor that wraps an object given by a reference. Uses clone of the parameter internally.
*/
template < class Type >
class ObjectFactoryImpl < AnyObject < Type > & > {
public:
static Object construct ( AnyObject < Type > & data ) {
return Object ( data.clone ( ) );
}
};
/**
* Constructor that wraps an object given by an r-value reference. Uses clone of the parameter internally.
*/
template < class Type >
class ObjectFactoryImpl < AnyObject < Type > > {
public:
static Object construct ( AnyObject < Type > && data ) {
return Object ( std::move ( data ).clone ( ) );
}
};
template < class Type = Object >
class ObjectFactory {
public:
template < class Param >
static Type construct ( Param && param ) {
return Type ( std::forward < Param > ( param ) );;
}
};
template < >
class ObjectFactory < Object > {
public:
template < class Param >
static Object construct ( Param && param ) {
return ObjectFactoryImpl < typename ext::array_to_ptr < Param >::type >::construct ( std::forward < Param > ( param ) );;
}
};
} /* namespace core */