Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/Type/Limits.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Simple Application Framework (Saf) library.
00003     Copyright (C) 2010 - 2012 Ondrej Danek <ondrej.danek@gmail.com>
00004 
00005     This library is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published 
00007     by the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     Saf is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Simple Application Framework library. If not, 
00017     see <http://www.gnu.org/licenses/>.
00018 */
00019 
00028 #ifndef SAF_TYPE_LIMITS_H
00029 #define SAF_TYPE_LIMITS_H
00030 
00031 #include "../NotImplementedException.h"
00032 
00033 namespace Saf
00034 {
00035     namespace Type
00036     {
00038         template <class T>
00039         class Limits
00040         {
00041         public:
00042             static T Min()
00043             {
00044                 throw NotImplementedException(SAF_SOURCE_LOCATION);
00045             }
00046 
00047             static T Max()
00048             {
00049                 throw NotImplementedException(SAF_SOURCE_LOCATION);
00050             }
00051 
00052             static bool IsIntegral()
00053             {
00054                 throw NotImplementedException(SAF_SOURCE_LOCATION);
00055             }
00056 
00057             static bool IsSigned()
00058             {
00059                 throw NotImplementedException(SAF_SOURCE_LOCATION);
00060             }
00061         };
00062 
00064         template <>
00065         class Limits<Uint8>
00066         {
00067         public:
00068             static Uint8 Min()
00069             {
00070                 return Uint8(0);
00071             }
00072 
00073             static Uint8 Max()
00074             {
00075                 return Uint8(0xff);
00076             }
00077 
00078             static bool IsIntegral()
00079             {
00080                 return true;
00081             }
00082 
00083             static bool IsSigned()
00084             {
00085                 return false;
00086             }
00087         };
00088 
00089         template <>
00090         class Limits<Uint16>
00091         {
00092         public:
00093             static Uint16 Min()
00094             {
00095                 return Uint16(0);
00096             }
00097 
00098             static Uint16 Max()
00099             {
00100                 return Uint16(0xffff);
00101             }
00102 
00103             static bool IsIntegral()
00104             {
00105                 return true;
00106             }
00107 
00108             static bool IsSigned()
00109             {
00110                 return false;
00111             }
00112         };
00113 
00114         template <>
00115         class Limits<Uint32>
00116         {
00117         public:
00118             static Uint32 Min()
00119             {
00120                 return Uint32(0);
00121             }
00122 
00123             static Uint32 Max()
00124             {
00125                 return Uint32(0xffffffff);
00126             }
00127 
00128             static bool IsIntegral()
00129             {
00130                 return true;
00131             }
00132 
00133             static bool IsSigned()
00134             {
00135                 return false;
00136             }
00137         };
00138 
00139         template <>
00140         class Limits<Uint64>
00141         {
00142         public:
00143             static Uint64 Min()
00144             {
00145                 return Uint64(0);
00146             }
00147 
00148             static Uint64 Max()
00149             {
00150                 return Uint64(0xffffffffffffffff);
00151             }
00152 
00153             static bool IsIntegral()
00154             {
00155                 return true;
00156             }
00157 
00158             static bool IsSigned()
00159             {
00160                 return false;
00161             }
00162         };
00163 
00164         template <>
00165         class Limits<Int8>
00166         {
00167         public:
00168             static Int8 Min()
00169             {
00170                 return Int8(-127) - 1;
00171             }
00172 
00173             static Int8 Max()
00174             {
00175                 return Int8(127);
00176             }
00177 
00178             static bool IsIntegral()
00179             {
00180                 return true;
00181             }
00182 
00183             static bool IsSigned()
00184             {
00185                 return true;
00186             }
00187         };
00188 
00189         template <>
00190         class Limits<Int16>
00191         {
00192         public:
00193             static Int16 Min()
00194             {
00195                 return Int16(-32767) - 1;
00196             }
00197 
00198             static Int16 Max()
00199             {
00200                 return Int16(32767);
00201             }
00202 
00203             static bool IsIntegral()
00204             {
00205                 return true;
00206             }
00207 
00208             static bool IsSigned()
00209             {
00210                 return true;
00211             }
00212         };
00213 
00214         template <>
00215         class Limits<Int32>
00216         {
00217         public:
00218             static Int32 Min()
00219             {
00220                 return Int32(-2147483647) - 1;
00221             }
00222 
00223             static Int32 Max()
00224             {
00225                 return Int32(2147483647);
00226             }
00227 
00228             static bool IsIntegral()
00229             {
00230                 return true;
00231             }
00232 
00233             static bool IsSigned()
00234             {
00235                 return true;
00236             }
00237         };
00238 
00239         template <>
00240         class Limits<Int64>
00241         {
00242         public:
00243             static Int64 Min()
00244             {
00245                 return Int64(-9223372036854775807) - 1;
00246             }
00247 
00248             static Int64 Max()
00249             {
00250                 return Int64(9223372036854775807);
00251             }
00252 
00253             static bool IsIntegral()
00254             {
00255                 return true;
00256             }
00257 
00258             static bool IsSigned()
00259             {
00260                 return true;
00261             }
00262         };
00263 
00264         template <>
00265         class Limits<Float32>
00266         {
00267         public:
00268             static Float32 Min()
00269             {
00270                 return -3.402823466e+38f;
00271             }
00272 
00273             static Float32 Max()
00274             {
00275                 return 3.402823466e+38f;
00276             }
00277 
00278             static bool IsIntegral()
00279             {
00280                 return false;
00281             }
00282 
00283             static bool IsSigned()
00284             {
00285                 return true;
00286             }
00287         };
00288 
00289         template <>
00290         class Limits<Float64>
00291         {
00292         public:
00293             static Float64 Min()
00294             {
00295                 return -1.7976931348623158e+308;
00296             }
00297 
00298             static Float64 Max()
00299             {
00300                 return 1.7976931348623158e+308;
00301             }
00302 
00303             static bool IsIntegral()
00304             {
00305                 return false;
00306             }
00307 
00308             static bool IsSigned()
00309             {
00310                 return true;
00311             }
00312         };
00317         template <class T>
00318         class Limits<const T>
00319             : public Limits<T>
00320         {};
00321 
00323         template <class T>
00324         class Limits<volatile T>
00325             : public Limits<T>
00326         {};
00327 
00329         template <class T>
00330         class Limits<const volatile T>
00331             : public Limits<T>
00332         {};
00334     }
00335 }
00336 
00337 #endif