mFrame
載入中...
搜尋中...
無符合項目
Pointer.h
1
8#ifndef MFRAME_D6412968_F88E_43C3_9B72_FA8611376187
9#define MFRAME_D6412968_F88E_43C3_9B72_FA8611376187
10
11/* ***************************************************************************************
12 * Include
13 */
14#include "./../lang/Object.h"
15#include "./../lang/Pointers.h"
16
17/* ***************************************************************************************
18 * Namespace
19 */
20namespace mframe::lang {
21 class Pointer;
22 class Memory;
23} // namespace mframe::lang
24
25/* ***************************************************************************************
26 * Class/struct/Struct
27 */
28
57 friend Memory;
58 /* *************************************************************************************
59 * Variable
60 */
61 private:
63 void* mPointer;
64
65 /* *************************************************************************************
66 * Abstract Method
67 */
68
69 /* *************************************************************************************
70 * Construct Method
71 */
72 public:
78 Pointer(void);
79
87 Pointer(const void* pointer);
88
95
102
108 Pointer(const Pointer& other);
109
115 virtual ~Pointer(void) override;
116
117 /* *************************************************************************************
118 * Operator Method
119 */
120 public:
126 inline operator void*(void) {
127 return this->mPointer;
128 }
129
135 inline operator const char*(void) {
136 return reinterpret_cast<const char*>(this->mPointer);
137 }
138
146 inline bool operator==(const void* pointer) {
147 return (this->mPointer == pointer);
148 }
149
157 inline bool operator==(const Pointer& pointer) {
158 return (this->mPointer == pointer.mPointer);
159 }
160
167 template <typename E>
168 inline operator E*(void) {
169 return static_cast<E*>(this->mPointer);
170 }
171
178 template <typename E>
179 inline operator E*(void) const {
180 return static_cast<E*>(this->mPointer);
181 }
182
183 /* *************************************************************************************
184 * Public Method <Inline>
185 */
186 public:
197 inline int copyTo(void* destination, int length) const {
198 return this->copyTo(destination, 0, 0, length);
199 }
200
209 inline int copyTo(void* destination, int start, int length) const {
210 return this->copyTo(destination, 0, start, length);
211 }
212
220 inline bool compairStrings(const char* str) const {
221 return this->compairStrings(str, 0);
222 }
223
232 inline bool compairStrings(const char* str, int start) const {
233 return this->compair(str, 0, start, static_cast<int>(Pointers::getStringLength(str)));
234 }
235
244 inline bool compair(const void* source, int length) const {
245 return this->compair(source, 0, 0, length);
246 }
247
257 inline bool compair(const void* source, int start, int length) const {
258 return this->compair(source, 0, start, length);
259 }
260
269 inline int indexOf(char ch, int start, int limit) const {
270 return this->indexOfData(&ch, 1, start, limit);
271 }
272
280 inline int indexOfStrings(const char* str, int limit) const {
281 return this->indexOfStrings(str, 0, limit);
282 }
283
292 inline int indexOfStrings(const char* str, int start, int limit) const {
293 return this->indexOfData(str, static_cast<int>(Pointers::getStringLength(str)),
294 start, limit);
295 }
296
304 inline int copy(const void* source, int length) {
305 return this->copy(source, 0, 0, length);
306 }
307
316 inline int copy(const void* source, int offset, int length) {
317 return this->copy(source, offset, 0, length);
318 }
319
326 inline char getByte(int shift) const {
327 const char* p = (*this);
328 return p[shift];
329 }
330
337 inline int getInteger(int shift) const {
338 const int* p = (*this);
339 return p[shift];
340 }
341
348 inline short getShort(int shift) const {
349 const short* p = (*this);
350 return p[shift];
351 }
352
359 inline Pointer getPointer(int offset) const {
360 return Pointer(&(static_cast<char*>(this->mPointer))[offset]);
361 }
362
368 inline uint32 getAddress(void) const {
369 return reinterpret_cast<uint32>(this->mPointer);
370 }
371
378 inline bool isAlignment32Bit(void) {
379 return ((this->getAddress() & 0x00000003) == 0);
380 }
381
388 inline bool isAlignment64Bit(void) {
389 return ((this->getAddress() & 0x00000007) == 0);
390 }
391
398 inline bool isNull(void) const {
399 return (this->mPointer == nullptr);
400 }
401
408 template <typename E = void*>
409 inline E* pointer(void) const {
410 return static_cast<E*>(this->mPointer);
411 }
412
420 template <typename E = void*>
421 inline E* pointer(int offset) const {
422 return reinterpret_cast<E*>(static_cast<char*>(this->mPointer) + offset);
423 }
424
432 template <typename E = void*>
433 inline E* pointer(uint32 offset) const {
434 return reinterpret_cast<E*>(static_cast<char*>(this->mPointer) + offset);
435 }
436
437 /* *************************************************************************************
438 * Public Method
439 */
440 public:
452 virtual int copy(const void* source, int offset, int sourceOffset, int length);
453
465 virtual int copyTo(void* destination, int offset, int destinationOffset, int length) const;
466
479 virtual bool compair(const void* source, int offset, int sourceOffset, int length) const;
480
509 virtual int indexOfData(const void* destination, int destinationLen, int start = 0, int limit = 0) const;
510
529 virtual void move(int head, int offset, int length);
530
531 /* *************************************************************************************
532 * Protected Method
533 */
534
535 /* *************************************************************************************
536 * Private Method
537 */
538
539 /* *************************************************************************************
540 * Static Variable
541 */
542
543 /* *************************************************************************************
544 * Static Method
545 */
546};
547
548#endif /* MFRAME_D6412968_F88E_43C3_9B72_FA8611376187 */
Definition Memory.h:29
Definition Object.h:34
Pointer 類別,提供記憶體位址存取、資料複製、資料比較與查找等基本功能。
Definition Pointer.h:56
Pointer(const void *pointer)
建立一個 Pointer 物件,並以 const void* 初始化內部指標
bool isNull(void) const
檢查內部指標是否為空
Definition Pointer.h:398
virtual ~Pointer(void) override
解構子,釋放 Pointer 物件
bool compair(const void *source, int length) const
比較內部資料與來源資料是否相等(從起始位置開始比較)
Definition Pointer.h:244
bool isAlignment32Bit(void)
檢查內部位址是否 32 位元對齊
Definition Pointer.h:378
virtual int copy(const void *source, int offset, int sourceOffset, int length)
將來源資料複製至內部記憶體區塊,可指定來源與目標的起始偏移
int copy(const void *source, int offset, int length)
複製來源資料至內部資料區塊,可指定目標位址偏移
Definition Pointer.h:316
virtual int indexOfData(const void *destination, int destinationLen, int start=0, int limit=0) const
尋找指定 pattern 是否存在於內部資料中,並返回第一個符合條件的偏移量
E * pointer(void) const
模板方法,取得內部指標並轉換為指定型態(不指定偏移)
Definition Pointer.h:409
Pointer(void)
預設建構子,建立一個空的 Pointer 物件
uint32 getAddress(void) const
取得內部記憶體位址的整數表示
Definition Pointer.h:368
Pointer(void *pointer)
建立一個 Pointer 物件,並以 void* 初始化內部指標
bool compair(const void *source, int start, int length) const
比較內部資料與來源資料是否相等,可指定來源資料的起始偏移
Definition Pointer.h:257
int copyTo(void *destination, int start, int length) const
複製內部資料至目標記憶體區塊,可指定來源起始位置
Definition Pointer.h:209
bool operator==(const Pointer &pointer)
比較兩個 Pointer 物件的內部指標是否相同
Definition Pointer.h:157
Pointer(uint32 pointer)
建立一個 Pointer 物件,並以 32 位元整數表示的位址初始化
int getInteger(int shift) const
取得指定偏移處的整數值
Definition Pointer.h:337
Pointer(const Pointer &other)
複製建構子,從另一個 Pointer 物件複製內部位址
E * pointer(int offset) const
模板方法,取得內部指標並轉換為指定型態(指定偏移)
Definition Pointer.h:421
Pointer getPointer(int offset) const
以指定偏移建立新的 Pointer 物件
Definition Pointer.h:359
virtual int copyTo(void *destination, int offset, int destinationOffset, int length) const
將內部資料複製到目標記憶體區塊,可指定來源與目標的起始偏移
int copy(const void *source, int length)
複製來源資料至內部資料區塊,使用預設偏移參數
Definition Pointer.h:304
bool operator==(const void *pointer)
比較內部指標與外部指標是否相同
Definition Pointer.h:146
bool compairStrings(const char *str) const
比較內部資料與傳入字串是否相同(從起始位置開始比較)
Definition Pointer.h:220
virtual void move(int head, int offset, int length)
將來源位置的資料以中間緩衝區方式移動至新的位置
bool isAlignment64Bit(void)
檢查內部位址是否 64 位元對齊
Definition Pointer.h:388
virtual bool compair(const void *source, int offset, int sourceOffset, int length) const
比較內部資料與來源資料是否相等,可指定各自的起始偏移與比較長度
int indexOfStrings(const char *str, int limit) const
在內部資料中查找指定字串,回傳該字串的偏移位置(使用預設起始位置)
Definition Pointer.h:280
char getByte(int shift) const
取得指定偏移處的 byte 值
Definition Pointer.h:326
int copyTo(void *destination, int length) const
複製內部資料至目標記憶體區塊
Definition Pointer.h:197
bool compairStrings(const char *str, int start) const
比較內部資料與傳入字串是否相同,可指定來源資料起始位置
Definition Pointer.h:232
E * pointer(uint32 offset) const
模板方法,取得內部指標並轉換為指定型態(指定偏移,使用 uint32 參數)
Definition Pointer.h:433
int indexOf(char ch, int start, int limit) const
在內部資料中查找指定字元 ch,回傳該字元的偏移位置
Definition Pointer.h:269
short getShort(int shift) const
取得指定偏移處的 short 值
Definition Pointer.h:348
int indexOfStrings(const char *str, int start, int limit) const
在內部資料中查找指定字串,回傳該字串的偏移位置
Definition Pointer.h:292
static int getStringLength(const char *src)
Definition Appendable.h:23