Meta.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_Meta_h__
00021 #define __OpenKarto_Meta_h__
00022 
00023 #include <OpenKarto/MetaType.h>
00024 #include <OpenKarto/MetaClass.h>
00025 #include <OpenKarto/MetaClassManager.h>
00026 #include <OpenKarto/MetaEnum.h>
00027 #include <OpenKarto/MetaEnumManager.h>
00028 
00029 namespace karto
00030 {
00031 
00033 
00034 
00038 
00043   inline kt_size_t GetRegisteredMetaClassSize()
00044   {
00045     return MetaClassManager::GetInstance().GetSize();
00046   }
00047 
00054   inline const MetaClass& GetMetaClassByIndex(kt_size_t index)
00055   {
00056     return MetaClassManager::GetInstance()[index];
00057   }
00058 
00065   inline const MetaClass& GetMetaClassByName(const karto::String& rName)
00066   {
00067     return MetaClassManager::GetInstance().GetByName(rName);
00068   }
00069 
00076   template <typename T>
00077   const MetaClass& GetMetaClassByObject(const T& rObject)
00078   {
00079     return MetaClassManager::GetInstance().GetById(GetTypeId(rObject));
00080   }
00081 
00087   template <typename T>
00088   const MetaClass& GetMetaClassByType()
00089   {
00090     return MetaClassManager::GetInstance().GetById(GetTypeId<T>());
00091   }
00092 
00096 
00101   inline kt_size_t GetRegisteredMetaEnumSize()
00102   {
00103     return MetaEnumManager::GetInstance().GetSize();
00104   }
00105 
00112   inline const MetaEnum& GetMetaEnumByIndex(kt_size_t index)
00113   {
00114     return MetaEnumManager::GetInstance()[index];
00115   }
00116 
00123   inline const MetaEnum& GetMetaEnumByName(const karto::String& rName)
00124   {
00125     return MetaEnumManager::GetInstance().GetByName(rName);
00126   }
00127 
00134   template <typename T>
00135   const MetaEnum& GetMetaEnumByObject(const T& rObject)
00136   {
00137     return MetaEnumManager::GetInstance().GetById(GetTypeId<T>(rObject));
00138   }
00139 
00145   template <typename T>
00146   const MetaEnum& GetMetaEnumByType()
00147   {
00148     return MetaEnumManager::GetInstance().GetById(GetTypeId<T>());
00149   }
00150 
00154 
00155   //@cond EXCLUDE
00160   KARTO_EXPORT void CheckTypeRegistered(const char* pName, void (*registerFunc)());
00161   // @endcond
00162 
00166 
00170   #define KARTO_TYPE(type) \
00171     template <> struct KartoTypeId<type> \
00172     { \
00173       static const char* Get(kt_bool = true) {return #type;} \
00174     }; \
00175 
00176 
00180   #define KARTO_AUTO_TYPE(type, registerFunc) \
00181     template <> struct KartoTypeId<type> \
00182     { \
00183       static const char* Get(kt_bool checkRegister = true) \
00184       { \
00185         if (checkRegister) \
00186           CheckTypeRegistered(#type, registerFunc); \
00187         return #type; \
00188       } \
00189     }; \
00190 
00191 
00192 
00193 
00194 
00198   #define KARTO_RTTI() \
00199     public: virtual const char* GetKartoClassId() const {return GetKartoTypeIdTemplate(this);} \
00200     private:
00201   
00203 
00204 }
00205 
00206 #endif // __OpenKarto_Meta_h__


nav2d_karto
Author(s): Sebastian Kasperski
autogenerated on Mon Oct 6 2014 02:44:17