basic_types.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_BASIC_TYPES_H
00047 #define LASS_GUARDIAN_OF_INCLUSION_NUM_BASIC_TYPES_H
00048
00049
00050 #include "../meta/meta_assert.h"
00051
00052 #if defined(LASS_NUM_BASIC_TYPES_HAVE_STDINT_H)
00053 # include <stdint.h>
00054 #endif
00055
00056 namespace lass
00057 {
00058 namespace num
00059 {
00060
00061 #if defined(LASS_NUM_BASIC_TYPES_HAVE_STDINT_H)
00062
00063 typedef int8_t Tint8;
00064 typedef uint8_t Tuint8;
00065 typedef int16_t Tint16;
00066 typedef uint16_t Tuint16;
00067 typedef int32_t Tint32;
00068 typedef uint32_t Tuint32;
00069 typedef int64_t Tint64;
00070 typedef uint64_t Tuint64;
00071
00072 #elif defined(LASS_NUM_BASIC_TYPES_HAVE_MSVC)
00073
00074 typedef signed __int8 Tint8;
00075 typedef unsigned __int8 Tuint8;
00076 typedef signed __int16 Tint16;
00077 typedef unsigned __int16 Tuint16;
00078 typedef signed __int32 Tint32;
00079 typedef unsigned __int32 Tuint32;
00080 typedef signed __int64 Tint64;
00081 typedef unsigned __int64 Tuint64;
00082
00083 #else
00084
00085 typedef signed char Tint8;
00086 typedef unsigned char Tuint8;
00087 typedef signed short Tint16;
00088 typedef unsigned short Tuint16;
00089 typedef signed int Tint32;
00090 typedef unsigned int Tuint32;
00091 typedef signed long long Tint64;
00092 typedef unsigned long long Tuint64;
00093
00094 #endif
00095
00096
00097
00098 typedef float Tfloat32;
00099 typedef double Tfloat64;
00100
00101
00102
00103
00104 template <size_t iNumberOfBits> struct BasicType {};
00105 template <> struct BasicType< 8> { typedef Tint8 Tint; typedef Tuint8 Tuint; };
00106 template <> struct BasicType<16> { typedef Tint16 Tint; typedef Tuint16 Tuint; };
00107 template <> struct BasicType<32> { typedef Tint32 Tint; typedef Tuint32 Tuint; typedef Tfloat32 Tfloat; };
00108 template <> struct BasicType<64> { typedef Tint64 Tint; typedef Tuint64 Tuint; typedef Tfloat64 Tfloat; };
00109
00110
00111
00112 typedef BasicType<sizeof(void*) * lass::bitsPerByte>::Tint TintPtr;
00113 typedef BasicType<sizeof(void*) * lass::bitsPerByte>::Tuint TuintPtr;
00114
00115
00116
00117 template <typename T> struct DoublePrecision { };
00118 template <> struct DoublePrecision<float> { typedef double Type; };
00119 template <> struct DoublePrecision<double> { typedef long double Type; };
00120 template <> struct DoublePrecision<long double> { typedef long double Type; };
00121
00122
00123
00124
00125
00126 namespace impl
00127 {
00128
00129 LASS_META_ASSERT(lass::bitsPerByte == 8, one_byte_is_not_8_bits);
00130 LASS_META_ASSERT(sizeof(lass::num::Tint8) * lass::bitsPerByte == 8, Tint8_must_be_8_bits_);
00131 LASS_META_ASSERT(sizeof(lass::num::Tuint8) * lass::bitsPerByte == 8, Tuint8_must_be_8_bits);
00132 LASS_META_ASSERT(sizeof(lass::num::Tint16) * lass::bitsPerByte == 16, Tint16_must_be_16_bits);
00133 LASS_META_ASSERT(sizeof(lass::num::Tuint16) * lass::bitsPerByte == 16, Tuint16_must_be_16_bits);
00134 LASS_META_ASSERT(sizeof(lass::num::Tint32) * lass::bitsPerByte == 32, Tint32_must_be_32_bits);
00135 LASS_META_ASSERT(sizeof(lass::num::Tuint32) * lass::bitsPerByte == 32, Tuint32_must_be_32_bits);
00136 LASS_META_ASSERT(sizeof(lass::num::Tint64) * lass::bitsPerByte == 64, Tint64_must_be_64_bits);
00137 LASS_META_ASSERT(sizeof(lass::num::Tuint64) * lass::bitsPerByte == 64, Tuint64_must_be_64_bits);
00138 LASS_META_ASSERT(sizeof(lass::num::Tfloat32) * lass::bitsPerByte == 32, Tfloat32_must_be_32_bits);
00139 LASS_META_ASSERT(sizeof(lass::num::Tfloat64) * lass::bitsPerByte == 64, Tfloat64_must_be_64_bits);
00140 LASS_META_ASSERT(sizeof(lass::num::TintPtr) == sizeof(void*), TintPtr_must_be_size_of_pointer);
00141 LASS_META_ASSERT(sizeof(lass::num::TuintPtr) == sizeof(void*), TuintPtr_must_be_size_of_pointer);
00142
00143 }
00144
00145 }
00146
00147 }
00148
00149 #endif