MetaClassHelper.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006-2011, SRI International (R)
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU Lesser General Public License as published by
00006  * the Free Software Foundation, either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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   //@cond EXCLUDE
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   // @endcond
00137 
00139 
00140 }
00141 
00142 #endif // __OpenKarto_MetaClassHelper_h__


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Sun Apr 2 2017 03:53:08