Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cTypes.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cTypes_H
6 #define _INC_cTypes_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "GrayCore.h"
12 #include <math.h> // isnan()
13 
14 namespace Gray
15 {
17  {
23  CTYPE_FLAG_Time = 0x08,
29  };
30 
31  // like _WIN32 MAKELPARAM(), MAKELONG() and MAKEWORD()
32 #define MAKEDWORD(low, high) ((UINT32)(((WORD)(low)) | (((UINT32)((WORD)(high))) << 16)))
33 
34 #pragma pack(push,1)
36  {
41  BYTE u_b[2];
42  char u_c[2];
43  WORD u_w;
44  short u_s;
45  operator WORD() const noexcept
46  {
47  return u_w;
48  }
49  void operator = (WORD w) noexcept
50  {
51  u_w = w;
52  }
53  struct
54  {
55 #ifdef USE_LITTLE_ENDIAN
56  BYTE m_Lo; // LowPart
57  BYTE m_Hi; // HighPart
58 #else
59  BYTE m_Hi;
60  BYTE m_Lo;
61 #endif
62  } u2;
63  };
64 
66  {
72 
73  BYTE u_b[4];
74  char u_c[4];
75  signed char u_sc[4];
76  WORD u_w[2];
77  short u_s[2];
78  UINT32 u_dw;
79  float u_f;
80 
81  operator UINT32() const noexcept
82  {
83  return u_dw;
84  }
85  void operator = (UINT32 dw) noexcept
86  {
87  u_dw = dw;
88  }
89 
90  struct
91  {
92 #ifdef USE_LITTLE_ENDIAN
93  cUnion16 m_Lo; // LowPart
94  cUnion16 m_Hi; // HighPart
95 #else
98 #endif
99  } u2;
100  };
101 
102  union CATTR_PACKED cUnion64
103  {
111 
112  BYTE u_b[8];
113  char u_c[8];
114  signed char u_sc[8];
115  WORD u_w[4];
116  short u_s[4];
117  UINT32 u_dw[2];
118  float u_f[2];
119  double u_d;
120 
121 #ifdef USE_INT64
122  UINT64 u_qw;
123  INT64 u_iq;
124  operator UINT64() const noexcept
125  {
126  return u_qw;
127  }
128  void operator = (UINT64 qw) noexcept
129  {
130  u_qw = qw;
131  }
132 #endif
133 
134  struct
135  {
136 #ifdef USE_LITTLE_ENDIAN
137  cUnion32 m_Lo; // LowPart
138  cUnion32 m_Hi; // HighPart
139 #else
142 #endif
143  } u2;
144  };
145 
146  // __m128
147 
148 #pragma pack(pop)
149 
150  template< typename TYPE = int >
151  struct cTypeLimit // static
152  {
156  static const TYPE k_Min;
157  static const TYPE k_Max;
158  static const BYTE k_TypeFlags;
159 
160  static inline bool isNumSigned() noexcept
161  {
163  return (k_TypeFlags & CTYPE_FLAG_NumSigned) ? true : false;
164  }
165 
166  // TODO Use StrNum
167  // TYPE FromString(const char* pszInp);
168  // StrLen_t ToString(char* pszOut, TYPE val);
169  };
170 
171 #ifdef _MSC_VER // M$ this is not a redundant define.
172 #define CTYPE_DEF(a,_TYPE,c,d,e,f,g,h) template<> const _TYPE cTypeLimit<_TYPE>::k_Min = e; template<> const _TYPE cTypeLimit<_TYPE>::k_Max = f; const BYTE cTypeLimit<_TYPE>::k_TypeFlags = (c);
173 #include "cTypes.tbl"
174 #undef CTYPE_DEF
175 #endif // _MSC_VER
176 
178  {
183 
184  template< typename TYPE >
185  static inline bool IsNaN(TYPE a) noexcept
186  {
189  // return !(a >= 0 || a < 0);
190  return ::isnan(a); // k_NaN ! #NAN or #IND #INF similar to _isnan() but it works.
191  }
192 
193  template< typename TYPE >
194  static inline bool IsInfinite(TYPE a)
195  {
198  return ::isinf(a); // k_InfPos, k_InfNeg
199  }
200 
201  template< typename TYPE >
202  static inline bool IsFinite(TYPE a) noexcept
203  {
207  // return !IsNaN(a) && !IsInfinite(a);
208  return a == 0 || ::isnormal(a); // ! #NAN or #IND #INF/INFINITY similar to ! _isnan() but it works.
209  }
210  };
211 }
212 
213 #endif
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define CATTR_PACKED
Definition: GrayCore.h:87
#define TYPE
Definition: StrT.cpp:38
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
CTYPE_FLAG_TYPE_
Definition: cTypes.h:17
@ CTYPE_FLAG_Float
Floating point. double or float.
Definition: cTypes.h:22
@ CTYPE_FLAG_UNUSED
This type is just a placeholder. don't use it.
Definition: cTypes.h:28
@ CTYPE_FLAG_Time
Number represents a time. number of time units from some epoch.
Definition: cTypes.h:23
@ CTYPE_FLAG_NumSigned
a signed numeric value. float or int.
Definition: cTypes.h:21
@ CTYPE_FLAG_StringA
UTF8 format string.
Definition: cTypes.h:26
@ CTYPE_FLAG_Alloc
Contains pointer to allocated memory. variable length? Blob?
Definition: cTypes.h:25
@ CTYPE_FLAG_Numeric
A numeric value of some sort. (maybe time, float or int)
Definition: cTypes.h:20
@ CTYPE_FLAG_StringW
UNICODE format string.
Definition: cTypes.h:27
@ CTYPE_FLAG_Array
An array of stuff.
Definition: cTypes.h:24
Definition: cTypes.h:178
static bool IsFinite(TYPE a) noexcept
Definition: cTypes.h:202
static bool IsNaN(TYPE a) noexcept
Definition: cTypes.h:185
static bool IsInfinite(TYPE a)
Definition: cTypes.h:194
Definition: cTypes.h:152
static const TYPE k_Min
Min value TYPE can represent. negative if signed type. NOT EPSILON (near zero). e....
Definition: cTypes.h:156
static bool isNumSigned() noexcept
Definition: cTypes.h:160
static const BYTE k_TypeFlags
CTYPE_FLAG_TYPE_ = float, signed, etc ?
Definition: cTypes.h:158
static const TYPE k_Max
Max positive value. Can equal this value. inclusive. AKA INT_MAX, FLT_MAX, DBL_MAX.
Definition: cTypes.h:157
Definition: cTypes.h:36
short u_s
Definition: cTypes.h:44
BYTE m_Lo
Definition: cTypes.h:60
BYTE m_Hi
Definition: cTypes.h:59
WORD u_w
16 bit words
Definition: cTypes.h:43
Definition: cTypes.h:66
cUnion16 m_Lo
Definition: cTypes.h:97
float u_f
32 bit float.
Definition: cTypes.h:79
cUnion16 m_Hi
Definition: cTypes.h:96
UINT32 u_dw
32 bit unsigned
Definition: cTypes.h:78
INT64 u_iq
64 bits = QuadPart = LONGLONG.
Definition: cTypes.h:123
double u_d
assumed to be 64 bits.
Definition: cTypes.h:119
cUnion32 m_Hi
Definition: cTypes.h:140
cUnion32 m_Lo
Definition: cTypes.h:141
UINT64 u_qw
64 bits = QuadPart = ULONGLONG.
Definition: cTypes.h:122