PixelLightAPI  .
EnumType.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: EnumType.h                                     *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_ENUMTYPE_H__
00024 #define __PLCORE_ENUMTYPE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/PLCore.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Classes                                               ]
00042 //[-------------------------------------------------------]
00043 /**
00044 *  @brief
00045 *    Enum type wrapper (for plain enum types without RTTI interface)
00046 */
00047 template <typename ENUM>
00048 class EnumTypePlain {
00049 };
00050 
00051 
00052 /**
00053 *  @brief
00054 *    Enum type wrapper
00055 */
00056 template <typename ENUM>
00057 class EnumType {
00058 
00059 
00060     //[-------------------------------------------------------]
00061     //[ Public data types                                     ]
00062     //[-------------------------------------------------------]
00063     public:
00064         typedef typename ENUM::_BaseType _BaseType;
00065         typedef typename ENUM::_Type     _Type;         /**< Real type */
00066         typedef typename ENUM::_Type     _StorageType;  /**< Storage type, for this type identical to the real type */
00067 
00068 
00069     //[-------------------------------------------------------]
00070     //[ Public static functions                               ]
00071     //[-------------------------------------------------------]
00072     public:
00073         static int GetNumOfEnumValues() {
00074             String sEnum, sDesc;
00075             _Type nValue;
00076             int nIndex = 0;
00077             for (nIndex=0; ENUM::GetEnumValue(nIndex, nValue, sEnum, sDesc); nIndex++)
00078                 ;   // Nothing to do in here
00079             return nIndex;
00080         }
00081 
00082         static String GetEnumName(int nIndex) {
00083             String sEnum, sDesc;
00084             _Type nValue;
00085             ENUM::GetEnumValue(nIndex, nValue, sEnum, sDesc);
00086             return sEnum;
00087         }
00088 
00089         static _Type GetEnumValue(const String &sName) {
00090             String sEnum = sName;
00091             String sDesc;
00092             _Type nValue;
00093             ENUM::GetEnumValue(-1, nValue, sEnum, sDesc);
00094             return nValue;
00095         }
00096 
00097         static String GetEnumDescription(const String &sName) {
00098             String sEnum = sName;
00099             String sDesc;
00100             _Type nValue;
00101             ENUM::GetEnumValue(-1, nValue, sEnum, sDesc);
00102             return sDesc;
00103         }
00104 
00105 
00106 };
00107 
00108 
00109 /**
00110 *  @brief
00111 *    Flag type wrapper
00112 */
00113 template <typename ENUM>
00114 class FlagType {
00115 
00116 
00117     //[-------------------------------------------------------]
00118     //[ Public data types                                     ]
00119     //[-------------------------------------------------------]
00120     public:
00121         typedef typename PLCore::uint32     _BaseType;
00122         typedef typename ENUM::_Type       _Type;           /**< Real type */
00123         typedef typename ENUM::_Type       _StorageType;    /**< Storage type, for this type identical to the real type */
00124 
00125 
00126     //[-------------------------------------------------------]
00127     //[ Public static functions                               ]
00128     //[-------------------------------------------------------]
00129     public:
00130         static int GetNumOfEnumValues() {
00131             String sEnum, sDesc;
00132             _Type nValue;
00133             int nIndex = 0;
00134             for (nIndex=0; ENUM::GetEnumValue(nIndex, nValue, sEnum, sDesc); nIndex++)
00135                 ;   // Nothing to do in here
00136             return nIndex;
00137         }
00138 
00139         static String GetEnumName(int nIndex) {
00140             String sEnum, sDesc;
00141             _Type nValue;
00142             ENUM::GetEnumValue(nIndex, nValue, sEnum, sDesc);
00143             return sEnum;
00144         }
00145 
00146         static _Type GetEnumValue(const String &sName) {
00147             String sEnum = sName;
00148             String sDesc;
00149             _Type nValue;
00150             ENUM::GetEnumValue(-1, nValue, sEnum, sDesc);
00151             return nValue;
00152         }
00153 
00154         static String GetEnumDescription(const String &sName) {
00155             String sEnum = sName;
00156             String sDesc;
00157             _Type nValue;
00158             ENUM::GetEnumValue(-1, nValue, sEnum, sDesc);
00159             return sDesc;
00160         }
00161 
00162 
00163 };
00164 
00165 
00166 //[-------------------------------------------------------]
00167 //[ Namespace                                             ]
00168 //[-------------------------------------------------------]
00169 } // PLCore
00170 
00171 
00172 #endif // __PLCORE_ENUMTYPE_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:50:52
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported