MetaType.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_MetaType_h__
21 #define __OpenKarto_MetaType_h__
22 
23 #include <OpenKarto/Types.h>
24 
25 namespace karto
26 {
27 
29 
30 
31  //@cond EXCLUDE
32 
36 
37  // The following code is from the boost library with the following license
38  // and modified to fit into the KartoSDK
39 
40  // Copyright 2003 (c) The Trustees of Indiana University.
41 
42  // Use, modification, and distribution is subject to the Boost Software
43  // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
44  // http://www.boost.org/LICENSE_1_0.txt)
45 
46  // Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
47  // Jeremiah Willcock (jewillco at osl.iu.edu)
48  // Andrew Lumsdaine (lums at osl.iu.edu)
49 
50  template <bool B, class T = void>
51  struct enable_if_c
52  {
53  typedef T type;
54  };
55 
56  template <class T>
57  struct enable_if_c<false, T>
58  {
59  };
60 
61  template <class Cond, class T = void>
62  struct enable_if : public enable_if_c<Cond::value, T>
63  {
64  };
65 
66  template <bool B, class T>
67  struct lazy_enable_if_c
68  {
69  typedef typename T::type type;
70  };
71 
72  template <class T>
73  struct lazy_enable_if_c<false, T>
74  {
75  };
76 
77  template <class Cond, class T>
78  struct lazy_enable_if : public lazy_enable_if_c<Cond::value, T>
79  {
80  };
81 
82  template <bool B, class T = void>
83  struct disable_if_c
84  {
85  typedef T type;
86  };
87 
88  template <class T>
89  struct disable_if_c<true, T>
90  {
91  };
92 
93  template <class Cond, class T = void>
94  struct disable_if : public disable_if_c<Cond::value, T>
95  {
96  };
97 
98  template <bool B, class T>
99  struct lazy_disable_if_c
100  {
101  typedef typename T::type type;
102  };
103 
104  template <class T>
105  struct lazy_disable_if_c<true, T>
106  {
107  };
108 
109  template <class Cond, class T>
110  struct lazy_disable_if : public lazy_disable_if_c<Cond::value, T>
111  {
112  };
113 
117 
118  // remove reference
119  template<class T>
120  struct remove_reference
121  {
122  typedef T Type;
123  };
124 
125  // remove reference
126  template<class T>
127  struct remove_reference<T&>
128  {
129  typedef T Type;
130  };
131 
133  //template<class T>
134  //struct remove_reference<T&&>
135  //{
136  // typedef T Type;
137  //};
138 
142 
143  // is_pointer template - value == false
144  template <typename T>
145  struct is_pointer
146  {
147  enum
148  {
149  value = false
150  };
151  };
152 
153  // is_pointer template - value == true
154  template <typename T>
155  struct is_pointer<T*>
156  {
157  enum
158  {
159  value = true
160  };
161  };
162 
166 
170  template <typename T>
171  struct KartoTypeId
172  {
173  static const char* Get(kt_bool = true)
174  {
175  // Remember to register your class/enum T with the KARTO_TYPE macro
176  return T::KARTO_REGISTER_ME_WITH_KARTO_TYPE();
177  }
178  };
179 
183 
189  template <typename T/*, typename E = void*/>
190  struct KartoType
191  {
192  typedef T Type;
193  };
194 
198  template <typename T>
199  struct KartoType<const T>
200  {
201  typedef typename KartoType<T>::Type Type;
202  };
203 
208  template <typename T>
209  struct KartoType<T&>
210  {
211  typedef typename KartoType<T>::Type Type;
212  };
213 
218  template <typename T>
219  struct KartoType<T*>
220  {
221  typedef typename KartoType<T>::Type Type;
222  };
223 
227 
231  template <typename T>
232  const char* GetKartoTypeIdTemplate()
233  {
234  return KartoTypeId<typename KartoType<T>::Type>::Get();
235  }
236 
240  template <typename T>
241  const char* GetKartoTypeIdTemplate(const T&)
242  {
243  return KartoTypeId<typename KartoType<T>::Type>::Get();
244  }
245 
249 
254  template <typename T, typename E = void>
255  struct KartoObjectTraits
256  {
257  typedef T& RefReturnType;
258 
259  static RefReturnType Get(void* pPointer)
260  {
261  return *static_cast<T*>(pPointer);
262  }
263  };
264 
268  template <typename T>
269  struct KartoObjectTraits<T*>
270  {
271  typedef T* RefReturnType;
272  typedef T* PointerType;
273 
274  static RefReturnType Get(void* pPointer)
275  {
276  return static_cast<T*>(pPointer);
277  }
278 
279  static PointerType GetPointer(T* rValue)
280  {
281  return rValue;
282  }
283  };
284 
288  template <typename T>
289  struct KartoObjectTraits<T&, typename disable_if<is_pointer<typename KartoObjectTraits<T>::RefReturnType> >::type>
290  {
291  typedef T& RefReturnType;
292  typedef T* PointerType;
293 
294  static RefReturnType Get(void* pPointer)
295  {
296  return *static_cast<T*>(pPointer);
297  }
298 
299  static PointerType GetPointer(T& rValue)
300  {
301  return &rValue;
302  }
303  };
304 
308  template <typename T>
309  struct KartoObjectTraits<T&, typename enable_if< is_pointer< typename KartoObjectTraits< T >::RefReturnType > >::type > : KartoObjectTraits<T>
310  {
311  };
312 
316  template <typename T>
317  struct KartoObjectTraits<const T> : KartoObjectTraits<T>
318  {
319  };
320 
324 
329  template <typename T>
330  struct KartoTypeHasRtti
331  {
332  typedef kt_int16s Yes;
333  typedef kt_int32s No;
334 
335  template <typename U, const char* (U::*)() const>
336  struct CheckForMember
337  {
338  };
339 
340  template <typename U> static Yes HasMemberFunction(CheckForMember<U, &U::GetKartoClassId>*);
341  template <typename U> static No HasMemberFunction(...);
342 
343  enum
344  {
345  value = sizeof(HasMemberFunction<typename KartoType<T>::Type>(0)) == sizeof(Yes)
346  };
347  };
348 
352 
357  template <typename T, typename E = void>
358  struct GetKartoTypeIdTemplateRTTI
359  {
360  typedef KartoObjectTraits<const T&> Traits;
361 
362  static const char* Get(const T& rObject)
363  {
364  typename Traits::PointerType pointer = Traits::GetPointer(rObject);
365  return pointer ? pointer->GetKartoClassId() : GetKartoTypeIdTemplate<T>();
366  }
367  };
368 
372  template <typename T>
373  struct GetKartoTypeIdTemplateRTTI< T, typename disable_if< KartoTypeHasRtti<T> >::type >
374  {
375  static const char* Get(const T&)
376  {
377  return GetKartoTypeIdTemplate<T>();
378  }
379  };
380 
384 
388  template <typename T> const char* GetTypeId()
389  {
390  return GetKartoTypeIdTemplate<T>();
391  }
392 
396  template <typename T> const char* GetTypeId(const T& rObject)
397  {
398  return GetKartoTypeIdTemplateRTTI<T>::Get(rObject);
399  }
400 
401  // @endcond
402 
404 
405 }
406 
407 #endif // __OpenKarto_MetaType_h__
bool kt_bool
Definition: Types.h:145
int16_t kt_int16s
Definition: Types.h:96
int32_t kt_int32s
Definition: Types.h:106
Definition: Any.cpp:20


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Tue Nov 7 2017 06:02:36