-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSysUtils.h
More file actions
63 lines (52 loc) · 1.89 KB
/
SysUtils.h
File metadata and controls
63 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#if !defined(SYS_UTILS_H)
#define SYS_UTILS_H
#include <cmath>
#include <cfloat>
namespace SysUtils {
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline bool isFuzzyEqual(double x1, double x2, double tol = 0.02) {
if (fabs(x1 - x2) / (x2 + DBL_EPSILON) > tol)
return false;
else
return true;
}
//-----------------------------------------------------------------------------
template<typename T> class TypeTraits
{
private:
template <typename U> struct PointerTraits
{
enum { result = false };
};
template <typename U> struct PointerTraits<U*>
{
enum { result = true };
};
public:
enum { isPointer = PointerTraits<T>::result };
};
//****************************************************************************************
// Enumerator - generate unique classId for class type
//
//
// The special class (Enumerator family) for this action is need because
// classId's must be the same for all TMsgWrappers which are differenced
// only by MsgDeletor type
//****************************************************************************************
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class TBaseTypeEnumerator
{
protected:
static int generateClassId() { static int classId; return ++classId; }
};
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
template<typename T> class TTypeEnumerator : public TBaseTypeEnumerator
{
public:
static int classId() { static const int classId = TBaseTypeEnumerator::generateClassId(); return classId; }
};
}
#endif // SYS_UTILS_H