Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #pragma once
00019
00020 #ifndef __OpenKarto_MetaClassHelper_h__
00021 #define __OpenKarto_MetaClassHelper_h__
00022
00023 namespace karto
00024 {
00025
00027
00028
00029
00030
00034 template <typename T>
00035 class MetaClassHelper
00036 {
00037 public:
00041 MetaClassHelper(MetaClass& target)
00042 : m_pMetaClass(&target)
00043 , m_pAttributes(m_pMetaClass)
00044 {
00045 }
00046
00050 template <typename U>
00051 MetaClassHelper<T>& Base()
00052 {
00053 const MetaClass& baseClass = GetMetaClassByType<U>();
00054 karto::String baseName = baseClass.GetName();
00055
00056 karto_forEach(List<const MetaClass*>, &m_pMetaClass->m_BaseClasses)
00057 {
00058 assert((*iter)->GetName() != baseName);
00059 }
00060
00061 m_pMetaClass->m_BaseClasses.Add(&baseClass);
00062
00063 return *this;
00064 }
00065
00069 MetaClassHelper<T>& Attribute(const karto::String& rAttributeName)
00070 {
00071 return Attribute(rAttributeName, "");
00072 }
00073
00077 template <typename U>
00078 MetaClassHelper<T>& Attribute(const karto::String& rAttributeName, const U& rValue)
00079 {
00080 assert(m_pAttributes && !m_pAttributes->HasAttribute(rAttributeName));
00081
00082 m_pAttributes->AddAttribute(rAttributeName, rValue);
00083
00084 return *this;
00085 }
00086
00090 template <typename F1, typename F2>
00091 MetaClassHelper<T>& Parameter(const karto::String& rParameterName, F1 accessor1, F2 accessor2)
00092 {
00093 return *this;
00094 }
00095
00099 MetaClassHelper<T>& Constructor0()
00100 {
00101 MetaConstructor* pConstructor = new MetaConstructorImpl0<T>;
00102 m_pMetaClass->m_Constructors.Add(pConstructor);
00103
00104 return *this;
00105 }
00106
00110 template <typename A0>
00111 MetaClassHelper<T>& Constructor1()
00112 {
00113 MetaConstructor* pConstructor = new MetaConstructorImpl1<T, A0>;
00114 m_pMetaClass->m_Constructors.Add(pConstructor);
00115
00116 return *this;
00117 }
00118
00122 template <typename A0, typename A1>
00123 MetaClassHelper<T>& Constructor2()
00124 {
00125 MetaConstructor* pConstructor = new MetaConstructorImpl2<T, A0, A1>;
00126 m_pMetaClass->m_Constructors.Add(pConstructor);
00127
00128 return *this;
00129 }
00130
00131 private:
00132 MetaClass* m_pMetaClass;
00133 MetaAttribute* m_pAttributes;
00134 };
00135
00136
00137
00139
00140 }
00141
00142 #endif // __OpenKarto_MetaClassHelper_h__