mFrame
載入中...
搜尋中...
無符合項目
Number.h
1
8#ifndef MFRAME_C6CF2DB4_1F61_4562_8698_C0C22D0C69FA
9#define MFRAME_C6CF2DB4_1F61_4562_8698_C0C22D0C69FA
10
11/* ***************************************************************************************
12 * Include
13 */
14
15//----------------------------------------------------------------------------------------
16
17//----------------------------------------------------------------------------------------
18#include "./../lang/Object.h"
19
20/* ***************************************************************************************
21 * Namespace
22 */
23namespace mframe::numb {
24 class Number;
25} // namespace mframe::numb
26
27/* ***************************************************************************************
28 * Class Integer
29 */
31 /* *************************************************************************************
32 * Subclass
33 */
34 protected:
35 union Value {
36 bool b;
37 uint8 u8[4];
38 char s8[4];
39 uint16 u16[2];
40 short s16[2];
41 uint32 u32[2];
42 int s32[2];
43 float f32[2];
44 uint64_t u64;
45 int64_t s64;
46 double d64;
47 };
48
49 /* *************************************************************************************
50 * Variable
51 */
52 protected:
53 Value vValue;
54
55 /* *************************************************************************************
56 * Abstract Method
57 */
58
59 /* *************************************************************************************
60 * Construct Method
61 */
62 public:
67 Number(void);
68
73 virtual ~Number(void) override;
74
75 /* *************************************************************************************
76 * Operator Method
77 */
78 public:
79 inline operator bool&(void) {
80 return this->vValue.b;
81 }
82
83 inline operator const bool&(void) const {
84 return this->vValue.b;
85 }
86
87 inline operator int&(void) {
88 return this->vValue.s32[0];
89 }
90
91 inline operator const int&(void) const {
92 return this->vValue.s32[0];
93 }
94
95 inline operator uint32&(void) {
96#ifdef __GNUC__
97 return *reinterpret_cast<uint32*>(&this->vValue);
98#else
99 return this->vValue.u32[0];
100#endif
101 }
102
103 inline operator const uint32&(void) const {
104#ifdef __GNUC__
105 return *reinterpret_cast<uint32 const*>(&this->vValue);
106#else
107 return this->vValue.u32[0];
108#endif
109 }
110
111 inline operator float&(void) {
112 return this->vValue.f32[0];
113 }
114
115 inline operator const float&(void) const {
116 return this->vValue.f32[0];
117 }
118
119 inline operator double&(void) {
120 return this->vValue.d64;
121 }
122
123 inline operator const double&(void) const {
124 return this->vValue.d64;
125 }
126
134 inline bool operator==(Number& v) {
135 return (Number::vValue.u64 == v.vValue.u64);
136 }
137
138 /* *************************************************************************************
139 * Public Method <Override> - mframe::lang::Object
140 */
141 public:
147 virtual int hashcode(void) const override;
148
149 /* *************************************************************************************
150 * Public Method
151 */
152
153 /* *************************************************************************************
154 * Protected Method
155 */
156
157 /* *************************************************************************************
158 * Private Method
159 */
160
161 /* *************************************************************************************
162 * Static Variable
163 */
164
165 /* *************************************************************************************
166 * Static Method
167 */
168};
169
170/* ***************************************************************************************
171 * End of file
172 */
173
174#endif /* MFRAME_C6CF2DB4_1F61_4562_8698_C0C22D0C69FA */
Definition Object.h:34
Definition Number.h:30
bool operator==(Number &v)
Definition Number.h:134
Number(void)
Construct a new Number object.
virtual ~Number(void) override
Destroy the Number object.
virtual int hashcode(void) const override
返回對象的哈希碼值。支持這種方法是為了散列表,如HashMap提供的那樣。
Definition Boolean.h:23
Definition Number.h:35