20 #ifndef __OpenKarto_MetaClass_h__ 21 #define __OpenKarto_MetaClass_h__ 41 struct MetaArgsPrivate;
58 MetaArguments(
const Any& a0);
65 MetaArguments(
const Any& a0,
const Any& a1);
73 MetaArguments(
const Any& a0,
const Any& a1,
const Any& a2);
82 MetaArguments(
const Any& a0,
const Any& a1,
const Any& a2,
const Any& a3);
92 MetaArguments(
const Any& a0,
const Any& a1,
const Any& a2,
const Any& a3,
const Any& a4);
111 const Any& operator[](
kt_size_t index)
const;
118 static const MetaArguments& Empty()
120 static MetaArguments dummy;
126 MetaArgsPrivate* m_pPrivate;
138 template <
typename T>
139 kt_bool CheckArgumentType(
const Any& rAny)
151 class MetaConstructor
157 virtual ~MetaConstructor()
168 virtual kt_bool CheckArguments(
const MetaArguments& rArgs)
const = 0;
176 virtual void* Create(
const MetaArguments& rArgs)
const = 0;
186 template <
typename T>
187 class MetaConstructorImpl0 :
public MetaConstructor
190 virtual kt_bool CheckArguments(
const MetaArguments& rArgs)
const 192 return (rArgs.GetCount() == 0);
195 virtual void* Create(
const MetaArguments&)
const 208 template <
typename T,
typename A0>
209 class MetaConstructorImpl1 :
public MetaConstructor
212 virtual kt_bool CheckArguments(
const MetaArguments& rArgs)
const 214 return (rArgs.GetCount() == 1) && CheckArgumentType<A0>(rArgs[0]);
217 virtual void* Create(
const MetaArguments& rArgs)
const 219 return new T(any_cast<A0>(rArgs[0]));
230 template <
typename T,
typename A0,
typename A1>
231 class MetaConstructorImpl2 :
public MetaConstructor
234 virtual kt_bool CheckArguments(
const MetaArguments& rArgs)
const 236 return (rArgs.GetCount() == 2) && CheckArgumentType<A0>(rArgs[0]) && CheckArgumentType<A1>(rArgs[1]);
239 virtual void* Create(
const MetaArguments& rArgs)
const 241 return new T(any_cast<A0>(rArgs[0]), any_cast<A1>(rArgs[1]));
251 template <
typename T>
class MetaClassHelper;
257 class MetaConstructor;
270 template <
typename T>
273 MetaClass& newClass = MetaClassManager::GetInstance().RegisterNew(rName, KartoTypeId<T>::Get(
false));
303 template <
typename T>
304 T*
Create(
const MetaArguments& rArgs = MetaArguments::Empty())
const 306 void* pObject = NULL;
310 const MetaConstructor* pConstructor = *iter;
312 if (pConstructor->CheckArguments(rArgs))
314 pObject = pConstructor->Create(rArgs);
320 throw karto::Exception(
"Unable to create object '" + GetName() +
"'. Please verify that .Constructor is defined for MetaClass");
323 return static_cast<T*
>(pObject);
329 template <
typename T>
356 friend class MetaClassManager;
368 #endif // __OpenKarto_MetaClass_h__
TFSIMD_FORCE_INLINE bool operator==(const Matrix3x3 &m1, const Matrix3x3 &m2)
TFSIMD_FORCE_INLINE bool operator!=(const Vector3 &other) const
#define karto_const_forEach(listtype, list)