PixelLightAPI  .
DefaultValue.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: DefaultValue.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_DEFAULTVALUE_H__
00024 #define __PLCORE_DEFAULTVALUE_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/String/String.h"
00032 #include "PLCore/Base/Tools/TypeTraits.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLCore {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Forward declarations                                  ]
00043 //[-------------------------------------------------------]
00044 // Enum type
00045 template <typename T>
00046 class EnumType;
00047 
00048 // Flag type
00049 template <typename T>
00050 class FlagType;
00051 
00052 template <typename T>
00053 struct CheckType;
00054 
00055 
00056 //[-------------------------------------------------------]
00057 //[ Classes                                               ]
00058 //[-------------------------------------------------------]
00059 template <typename T>
00060 class DefaultValue : public DefaultValue< typename CheckType<T>::Type > {
00061 };
00062 
00063 template <>
00064 class DefaultValue<bool> {
00065     public:
00066         static bool Default() {
00067             return false;
00068         }
00069 };
00070 
00071 /*
00072 template <>
00073 class DefaultValue<int> {
00074     public:
00075         static int Default() {
00076             return 0;
00077         }
00078 };
00079 */
00080 
00081 template <>
00082 class DefaultValue<int8> {
00083     public:
00084         static int8 Default() {
00085             return 0;
00086         }
00087 };
00088 
00089 template <>
00090 class DefaultValue<int16> {
00091     public:
00092         static int16 Default() {
00093             return 0;
00094         }
00095 };
00096 
00097 template <>
00098 class DefaultValue<int32> {
00099     public:
00100         static int32 Default() {
00101             return 0;
00102         }
00103 };
00104 
00105 template <>
00106 class DefaultValue<int64> {
00107     public:
00108         static int64 Default() {
00109             return 0;
00110         }
00111 };
00112 
00113 template <>
00114 class DefaultValue<uint8> {
00115     public:
00116         static uint8 Default() {
00117             return 0;
00118         }
00119 };
00120 
00121 template <>
00122 class DefaultValue<uint16> {
00123     public:
00124         static uint16 Default() {
00125             return 0;
00126         }
00127 };
00128 
00129 template <>
00130 class DefaultValue<uint32> {
00131     public:
00132         static uint32 Default() {
00133             return 0;
00134         }
00135 };
00136 
00137 template <>
00138 class DefaultValue<uint64> {
00139     public:
00140         static uint64 Default() {
00141             return 0;
00142         }
00143 };
00144 
00145 template <>
00146 class DefaultValue<float> {
00147     public:
00148         static float Default() {
00149             return 0.0f;
00150         }
00151 };
00152 
00153 template <>
00154 class DefaultValue<double> {
00155     public:
00156         static double Default() {
00157             return 0.0;
00158         }
00159 };
00160 
00161 template <>
00162 class DefaultValue<String> {
00163     public:
00164         static String Default() {
00165             return "";
00166         }
00167 };
00168 
00169 template <typename T>
00170 class DefaultValue<T*> {
00171     public:
00172         static T* Default() {
00173             return nullptr;
00174         }
00175 };
00176 
00177 template <typename T>
00178 class DefaultValue<T&> {
00179     public:
00180         static T& Default() {
00181             return *static_cast<T*>(nullptr);
00182         }
00183 };
00184 
00185 template <typename ENUM>
00186 class DefaultValue< EnumTypePlain<ENUM> > {
00187     public:
00188         static ENUM Default() {
00189             return static_cast<ENUM>(0);
00190         }
00191 };
00192 
00193 template <typename ENUM>
00194 class DefaultValue< EnumType<ENUM> > {
00195     public:
00196         // Type
00197         typedef typename ENUM::_Type _Type;
00198 
00199         static _Type Default() {
00200             return DefaultValue<_Type>::Default();
00201         }
00202 };
00203 
00204 template <typename ENUM>
00205 class DefaultValue< FlagType<ENUM> > {
00206     public:
00207         // Type
00208         typedef typename ENUM::_Type _Type;
00209 
00210         static _Type Default() {
00211             return DefaultValue<_Type>::Default();
00212         }
00213 };
00214 
00215 
00216 //[-------------------------------------------------------]
00217 //[ Namespace                                             ]
00218 //[-------------------------------------------------------]
00219 } // PLCore
00220 
00221 
00222 #endif // __PLCORE_DEFAULTVALUE_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