-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_utils.h
158 lines (120 loc) · 5.81 KB
/
my_utils.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**********************************************************************************
** ENVIROMENT VARIABILE
**********************************************************************************/
#ifndef MY_UTILS_H_
#define MY_UTILS_H_
/**********************************************************************************
** GLOBAL INCLUDES
**********************************************************************************/
/**********************************************************************************
** DEFINES
**********************************************************************************/
//Rnge at which a floating point interpolation is used inside get_rand<int>
#define GET_RAND_INTERPOLATION_THRESHOLD 256
/**********************************************************************************
** MACROS
**********************************************************************************/
#define ABS(x) \
(((x) < 0.0)?(-(x)):(x))
#define CLIP_PI( x, pi ) \
(x>pi/2)?(x -pi):((x<-pi/2)?(pi +x):(x))
//Return a C style string of an engineering style number
#define ENG_NUM_CSTR( x ) \
(&User::My_utils::eng_num( (x) )[0])
/**********************************************************************************
** TYPEDEF
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: STRUCTURE
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: GLOBAL VARIABILE
**********************************************************************************/
/**********************************************************************************
** NAMESPACE
**********************************************************************************/
//Assign class to a namespace
namespace User
{
/**********************************************************************************
** PROTOTYPE: CLASS
**********************************************************************************/
/****************************************************************************
** Class
**
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
class My_utils
{
//Visible to all
public:
///--------------------------------------------------------------------------
/// CONSTRUCTORS
///--------------------------------------------------------------------------
//Empty constructor
My_utils( void );
///--------------------------------------------------------------------------
/// DESTRUCTORS
///--------------------------------------------------------------------------
//Default constructor
~My_utils( void );
///--------------------------------------------------------------------------
/// SETTERS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// GETTERS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// TESTERS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// PUBLIC METHODS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// RANDOM NUMBER UTILITIES
///--------------------------------------------------------------------------
//Initialize random number generator
static bool rand_init( void );
//Template get random for types that do not need range. (bool) probability to get a true
template <typename T>
static T get_rand( float p );
//Template get random for given types. Overload get_rand<T>(void)
template <typename T>
static T get_rand( T min, T max );
///--------------------------------------------------------------------------
/// STRING UTILITIES
///--------------------------------------------------------------------------
//From number to engineering format number
static std::string eng_num( double num );
///--------------------------------------------------------------------------
/// PUBLIC VARS
///--------------------------------------------------------------------------
//Visible to derived classes
protected:
///--------------------------------------------------------------------------
/// PROTECTED METHODS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// PROTECTED VARS
///--------------------------------------------------------------------------
//Visible only inside the class
private:
///--------------------------------------------------------------------------
/// PRIVATE METHODS
///--------------------------------------------------------------------------
//Here so that i can easily copy the code.
bool dummy( void );
///--------------------------------------------------------------------------
/// PRIVATE VARS
///--------------------------------------------------------------------------
}; //End Class: My_utils
/**********************************************************************************
** NAMESPACE
**********************************************************************************/
} //End Namespace
#else
#warning "Multiple inclusion of header file"
#endif