MetaEnum.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_MetaEnum_h__
00021 #define __OpenKarto_MetaEnum_h__
00022 
00023 #include <OpenKarto/MetaType.h>
00024 #include <OpenKarto/MetaEnumHelper.h>
00025 #include <OpenKarto/MetaEnumManager.h>
00026 #include <OpenKarto/String.h>
00027 #include <OpenKarto/Referenced.h>
00028 #include <OpenKarto/List.h>
00029 
00030 namespace karto
00031 {
00032 
00034 
00035 
00039 
00043   struct EnumPair
00044   {
00050     kt_bool operator == (const EnumPair& rOther) const
00051     {
00052       return rOther.name == name && rOther.value == value;
00053     }
00054 
00058     karto::String name;
00059 
00063     kt_int64s value;
00064   };
00065 
00066 
00070   typedef List< EnumPair > EnumPairList;
00071 
00075 
00076   struct FindByName
00077   {
00078     FindByName(const karto::String& rName)
00079       : m_name(rName) 
00080     {
00081 
00082     }
00083 
00084     kt_bool operator()(const EnumPair& rOther) const
00085     {
00086       return rOther.name == m_name;
00087     }
00088 
00089     karto::String m_name;
00090   };
00091 
00095 
00096   struct FindByValue
00097   {
00098     FindByValue(kt_int64s value) 
00099       : m_value(value) 
00100     {
00101     }
00102 
00103     kt_bool operator()(const EnumPair& rOther) const
00104     {
00105       return rOther.value == m_value;
00106     }
00107 
00108     kt_int64s m_value;
00109   };
00110 
00114 
00115   struct MetaEnumPrivate;
00116 
00121   class KARTO_EXPORT MetaEnum : public Referenced
00122   {
00123   public:
00129     template <typename T>
00130     static MetaEnumHelper Register(const karto::String& rName)
00131     {
00132       MetaEnum& newEnum = MetaEnumManager::GetInstance().RegisterNew(rName, KartoTypeId<T>::Get(false));
00133       return MetaEnumHelper(newEnum);
00134     }
00135 
00136   public:
00141     const karto::String& GetName() const;
00142 
00148     kt_bool HasName(const karto::String& rName) const;
00149 
00155     kt_bool HasValue(kt_int64s value) const;
00156 
00163     const karto::String& GetName(kt_int64s value) const;
00164     
00171     kt_int64s GetValue(const karto::String& rName) const;
00172 
00177     kt_size_t GetSize() const;
00178     
00185     const EnumPair& GetPair(kt_size_t index) const;
00186 
00187   public:
00193     kt_bool operator==(const MetaEnum& rOther) const;
00194 
00200     kt_bool operator!=(const MetaEnum& rOther) const;
00201 
00202   protected:
00207     void AddEnumPair(const EnumPair& rPair);
00208 
00209   private:
00210     friend class MetaEnumHelper;
00211     friend class MetaEnumManager;
00212 
00213   private:
00214     MetaEnum(const karto::String& rName);
00215     ~MetaEnum();
00216 
00217   private:
00218     MetaEnumPrivate* m_pPrivate;
00219   };
00220 
00222 
00223 }
00224 
00225 #endif // __OpenKarto_MetaEnum_h__


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