1 /*******************************************************************************
2 * File : ..\utils\HLH_RoundU32.h
5 * Created : 2009-10-14 14:26:15
7 ******************************************************************************/
9 #ifndef __HLH_ROUNDU32_INC_20091014_142615_HENRY__
10 #define __HLH_ROUNDU32_INC_20091014_142615_HENRY__
13 /*******************************************************************************
14 * Desc : Includes Files
15 ******************************************************************************/
16 #include "utils/typedef.h"
19 /*******************************************************************************
20 * Desc : Macro Definations
21 ******************************************************************************/
22 #define HLH_ROUNDU32_RANGE ( ~ ( (UINT32) 0 ) )
23 #define HLH_ROUNDU32_HALF ( HLH_ROUNDU32_RANGE / 2 )
26 /*******************************************************************************
27 * Desc : Type Definations
28 ******************************************************************************/
31 /*******************************************************************************
32 * Desc : Global Variables
33 ******************************************************************************/
36 /*******************************************************************************
38 ******************************************************************************/
40 ////////////////////////////////////////////////////////////////////////////////
41 // Class to handle round up counter
46 /******************************************************************************
47 * Desc : Constructor / Deconstructor
48 ******************************************************************************/
49 HLH_RoundU32 (UINT32 unVal
= 0) { m_unVal
= unVal
; }
54 /******************************************************************************
56 ******************************************************************************/
58 operator UINT32 () const { return m_unVal
; }
59 operator float () const { return (float) m_unVal
; }
60 operator double () const { return (double) m_unVal
; }
63 /******************************************************************************
65 ******************************************************************************/
67 HLH_RoundU32
&operator ++ () { ++m_unVal
; return *this; }
70 HLH_RoundU32
&operator -- () { --m_unVal
; return *this; }
73 HLH_RoundU32
operator ++ (int) { return HLH_RoundU32 (m_unVal
++); }
76 HLH_RoundU32
operator -- (int) { return HLH_RoundU32 (m_unVal
--); }
78 HLH_RoundU32
operator + (const HLH_RoundU32
&zhrVal
) const { return HLH_RoundU32 (m_unVal
+ zhrVal
.m_unVal
); }
79 HLH_RoundU32
operator - (const HLH_RoundU32
&zhrVal
) const { return HLH_RoundU32 (m_unVal
- zhrVal
.m_unVal
); }
80 HLH_RoundU32
operator * (const HLH_RoundU32
&zhrVal
) const { return HLH_RoundU32 (m_unVal
* zhrVal
.m_unVal
); }
81 HLH_RoundU32
operator / (const HLH_RoundU32
&zhrVal
) const { return HLH_RoundU32 (m_unVal
/ zhrVal
.m_unVal
); }
82 HLH_RoundU32
operator % (const HLH_RoundU32
&zhrVal
) const { return HLH_RoundU32 (m_unVal
% zhrVal
.m_unVal
); }
84 HLH_RoundU32
&operator = (UINT32 unVal
) { m_unVal
= unVal
; return *this; }
86 HLH_RoundU32
&operator += (const HLH_RoundU32
&zhrVal
) { m_unVal
+= zhrVal
.m_unVal
; return *this; }
87 HLH_RoundU32
&operator -= (const HLH_RoundU32
&zhrVal
) { m_unVal
-= zhrVal
.m_unVal
; return *this; }
88 HLH_RoundU32
&operator *= (const HLH_RoundU32
&zhrVal
) { m_unVal
*= zhrVal
.m_unVal
; return *this; }
89 HLH_RoundU32
&operator /= (const HLH_RoundU32
&zhrVal
) { m_unVal
/= zhrVal
.m_unVal
; return *this; }
90 HLH_RoundU32
&operator %= (const HLH_RoundU32
&zhrVal
) { m_unVal
%= zhrVal
.m_unVal
; return *this; }
92 bool operator < (const HLH_RoundU32
&zhrVal
) const;
93 bool operator > (const HLH_RoundU32
&zhrVal
) const;
94 bool operator <= (const HLH_RoundU32
&zhrVal
) const;
95 bool operator >= (const HLH_RoundU32
&zhrVal
) const;
97 bool operator == (const HLH_RoundU32
&zhrVal
) const { return ( m_unVal
== zhrVal
.m_unVal
); }
98 bool operator != (const HLH_RoundU32
&zhrVal
) const { return ( m_unVal
!= zhrVal
.m_unVal
); }
107 /******************************************************************************
109 ******************************************************************************/
112 inline bool HLH_RoundU32::operator < (const HLH_RoundU32
&zhrVal
) const
118 unVal
= zhrVal
.m_unVal
;
119 unDivide
= unVal
+ HLH_ROUNDU32_HALF
;
121 if (unVal
< unDivide
) {
122 return ( (m_unVal
< unVal
) || (m_unVal
> unDivide
) );
124 return (m_unVal
> unDivide
&& m_unVal
< unVal
);
129 inline bool HLH_RoundU32::operator > (const HLH_RoundU32
&zhrVal
) const
135 unVal
= zhrVal
.m_unVal
;
136 unDivide
= unVal
+ HLH_ROUNDU32_HALF
;
138 if (unVal
< unDivide
) {
139 return ( m_unVal
> unVal
&& m_unVal
<= unDivide
);
141 return ( m_unVal
<= unDivide
|| m_unVal
> unVal
);
146 inline bool HLH_RoundU32::operator <= (const HLH_RoundU32
&zhrVal
) const
152 unVal
= zhrVal
.m_unVal
;
153 unDivide
= unVal
+ HLH_ROUNDU32_HALF
;
155 if (unVal
< unDivide
) {
156 return ( (m_unVal
<= unVal
) || (m_unVal
> unDivide
) );
158 return (m_unVal
> unDivide
&& m_unVal
<= unVal
);
163 inline bool HLH_RoundU32::operator >= (const HLH_RoundU32
&zhrVal
) const
169 unVal
= zhrVal
.m_unVal
;
170 unDivide
= unVal
+ HLH_ROUNDU32_HALF
;
172 if (unVal
< unDivide
) {
173 return ( m_unVal
>= unVal
&& m_unVal
<= unDivide
);
175 return ( m_unVal
<= unDivide
|| m_unVal
>= unVal
);
184 #endif /* __HLH_ROUNDU32_INC_20091014_142615_HENRY__ */