MetaClassHelper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2011, SRI International (R)
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 #ifndef __OpenKarto_MetaClassHelper_h__
21 #define __OpenKarto_MetaClassHelper_h__
22 
23 namespace karto
24 {
25 
27 
28 
29  //@cond EXCLUDE
30 
34  template <typename T>
35  class MetaClassHelper
36  {
37  public:
41  MetaClassHelper(MetaClass& target)
42  : m_pMetaClass(&target)
43  , m_pAttributes(m_pMetaClass)
44  {
45  }
46 
50  template <typename U>
51  MetaClassHelper<T>& Base()
52  {
53  const MetaClass& baseClass = GetMetaClassByType<U>();
54  karto::String baseName = baseClass.GetName();
55 
56  karto_forEach(List<const MetaClass*>, &m_pMetaClass->m_BaseClasses)
57  {
58  assert((*iter)->GetName() != baseName);
59  }
60 
61  m_pMetaClass->m_BaseClasses.Add(&baseClass);
62 
63  return *this;
64  }
65 
69  MetaClassHelper<T>& Attribute(const karto::String& rAttributeName)
70  {
71  return Attribute(rAttributeName, "");
72  }
73 
77  template <typename U>
78  MetaClassHelper<T>& Attribute(const karto::String& rAttributeName, const U& rValue)
79  {
80  assert(m_pAttributes && !m_pAttributes->HasAttribute(rAttributeName));
81 
82  m_pAttributes->AddAttribute(rAttributeName, rValue);
83 
84  return *this;
85  }
86 
90  template <typename F1, typename F2>
91  MetaClassHelper<T>& Parameter(const karto::String& rParameterName, F1 accessor1, F2 accessor2)
92  {
93  return *this;
94  }
95 
99  MetaClassHelper<T>& Constructor0()
100  {
101  MetaConstructor* pConstructor = new MetaConstructorImpl0<T>;
102  m_pMetaClass->m_Constructors.Add(pConstructor);
103 
104  return *this;
105  }
106 
110  template <typename A0>
111  MetaClassHelper<T>& Constructor1()
112  {
113  MetaConstructor* pConstructor = new MetaConstructorImpl1<T, A0>;
114  m_pMetaClass->m_Constructors.Add(pConstructor);
115 
116  return *this;
117  }
118 
122  template <typename A0, typename A1>
123  MetaClassHelper<T>& Constructor2()
124  {
125  MetaConstructor* pConstructor = new MetaConstructorImpl2<T, A0, A1>;
126  m_pMetaClass->m_Constructors.Add(pConstructor);
127 
128  return *this;
129  }
130 
131  private:
132  MetaClass* m_pMetaClass;
133  MetaAttribute* m_pAttributes;
134  };
135 
136  // @endcond
137 
139 
140 }
141 
142 #endif // __OpenKarto_MetaClassHelper_h__
#define karto_forEach(listtype, list)
Definition: Macros.h:124
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Thu Jun 6 2019 19:20:24