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 ufm::lang {
21 class Pointer;
22 class Memory;
23} // namespace ufm::lang
24
25/* ***************************************************************************************
26 * Class/struct/Struct
27 */
28
45 friend Memory;
46 /* *************************************************************************************
47 * Variable
48 */
49 private:
50 void* vPointer;
51
52 /* *************************************************************************************
53 * Abstract Method
54 */
55
56 /* *************************************************************************************
57 * Construct Method
58 */
59 public:
66 Pointer(void);
67
75 Pointer(const void* pointer);
76
83
89 explicit Pointer(uint32 pointer);
90
96 Pointer(const Pointer& other);
97
98 /* *************************************************************************************
99 * Operator Method
100 */
101 public:
107 inline operator void*(void) {
108 return this->vPointer;
109 }
110
116 inline operator const char*(void) {
117 return reinterpret_cast<const char*>(this->vPointer);
118 }
119
127 inline bool operator==(const void* pointer) {
128 return (this->vPointer == pointer);
129 }
130
138 inline bool operator==(const Pointer& pointer) {
139 return (this->vPointer == pointer.vPointer);
140 }
141
148 template <typename E>
149 inline operator E*(void) {
150 return static_cast<E*>(this->vPointer);
151 }
152
159 template <typename E>
160 inline operator E*(void) const {
161 return static_cast<E*>(this->vPointer);
162 }
163
170 inline Pointer& operator=(const Pointer& other) = default;
171
172 /* *************************************************************************************
173 * Public Method <Inline>
174 */
175 public:
186 inline int copyTo(void* destination, int length) const {
187 return this->copyTo(destination, 0, 0, length);
188 }
189
198 inline int copyTo(void* destination, int start, int length) const {
199 return this->copyTo(destination, 0, start, length);
200 }
201
209 inline bool compairStrings(const char* str) const {
210 return this->compairStrings(str, 0);
211 }
212
221 inline bool compairStrings(const char* str, int start) const {
222 return this->compair(str, 0, start, static_cast<int>(Pointers::getStringLength(str)));
223 }
224
233 inline bool compair(const void* source, int length) const {
234 return this->compair(source, 0, 0, length);
235 }
236
246 inline bool compair(const void* source, int start, int length) const {
247 return this->compair(source, 0, start, length);
248 }
249
258 inline int indexOf(char ch, int start, int limit) const {
259 return this->indexOfData(&ch, 1, start, limit);
260 }
261
269 inline int indexOfStrings(const char* str, int limit) const {
270 return this->indexOfStrings(str, 0, limit);
271 }
272
281 inline int indexOfStrings(const char* str, int start, int limit) const {
282 return this->indexOfData(
283 str, static_cast<int>(Pointers::getStringLength(str)), start, limit);
284 }
285
293 inline int copy(const void* source, int length) {
294 return this->copy(source, 0, 0, length);
295 }
296
305 inline int copy(const void* source, int offset, int length) {
306 return this->copy(source, offset, 0, length);
307 }
308
315 inline char getByte(int shift) const {
316 const char* p = static_cast<const char*>(this->vPointer);
317 return p[shift];
318 }
319
326 inline int getInteger(int shift) const {
327 const int* p = static_cast<const int*>(this->vPointer);
328 return p[shift];
329 }
330
337 inline short getShort(int shift) const {
338 const short* p = static_cast<const short*>(this->vPointer);
339 return p[shift];
340 }
341
348 inline Pointer getPointer(int offset) const {
349 return Pointer(&(static_cast<char*>(this->vPointer))[offset]);
350 }
351
357 inline uint32 getAddress(void) const {
358 return reinterpret_cast<uint32>(this->vPointer);
359 }
360
367 inline bool isAlignment32Bit(void) {
368 return ((this->getAddress() & 0x00000003) == 0);
369 }
370
377 inline bool isAlignment64Bit(void) {
378 return ((this->getAddress() & 0x00000007) == 0);
379 }
380
387 inline bool isNull(void) const {
388 return (this->vPointer == nullptr);
389 }
390
397 template <typename E = void*>
398 inline E* pointer(void) const {
399 return static_cast<E*>(this->vPointer);
400 }
401
409 template <typename E = void*>
410 inline E* pointer(int offset) const {
411 return reinterpret_cast<E*>(static_cast<char*>(this->vPointer) + offset);
412 }
413
421 template <typename E = void*>
422 inline E* pointer(uint32 offset) const {
423 return reinterpret_cast<E*>(static_cast<char*>(this->vPointer) + offset);
424 }
425
426 /* *************************************************************************************
427 * Public Method
428 */
429 public:
441 virtual int copy(const void* source, int offset, int sourceOffset, int length);
442
454 virtual int copyTo(void* destination,
455 int offset,
456 int destinationOffset,
457 int length) const;
458
471 virtual bool compair(const void* source,
472 int offset,
473 int sourceOffset,
474 int length) const;
475
504 virtual int indexOfData(const void* destination,
505 int destinationLen,
506 int start = 0,
507 int limit = 0) const;
508
540 virtual void move(int head, int offset, int length);
541
542 /* *************************************************************************************
543 * Protected Method
544 */
545
546 /* *************************************************************************************
547 * Private Method
548 */
549
550 /* *************************************************************************************
551 * Static Variable
552 */
553
554 /* *************************************************************************************
555 * Static Method
556 */
557};
558
559#endif /* MFRAME_D6412968_F88E_43C3_9B72_FA8611376187 */
存儲資料的類別,提供動態記憶體管理功能。
Definition Memory.h:44
物件基底類別
Definition Object.h:63
提供記憶體位址存取與操作功能
Definition Pointer.h:44
bool compairStrings(const char *str, int start) const
比較內部資料與傳入字串是否相同,可指定來源資料起始位置
Definition Pointer.h:221
virtual int indexOfData(const void *destination, int destinationLen, int start=0, int limit=0) const
尋找指定 pattern 是否存在於內部資料中,並返回第一個符合條件的偏移量
char getByte(int shift) const
取得指定偏移處的 byte 值
Definition Pointer.h:315
bool operator==(const Pointer &pointer)
比較兩個 Pointer 物件的內部指標是否相同
Definition Pointer.h:138
bool isAlignment64Bit(void)
檢查內部位址是否 64 位元對齊
Definition Pointer.h:377
int indexOfStrings(const char *str, int start, int limit) const
在內部資料中查找指定字串,回傳該字串的偏移位置
Definition Pointer.h:281
uint32 getAddress(void) const
取得內部記憶體位址的整數表示
Definition Pointer.h:357
virtual int copyTo(void *destination, int offset, int destinationOffset, int length) const
將內部資料複製到目標記憶體區塊,可指定來源與目標的起始偏移
bool operator==(const void *pointer)
比較內部指標與外部指標是否相同
Definition Pointer.h:127
virtual void move(int head, int offset, int length)
將來源位置的資料以中間緩衝區方式移動至新的位置
bool compair(const void *source, int length) const
比較內部資料與來源資料是否相等(從起始位置開始比較)
Definition Pointer.h:233
virtual bool compair(const void *source, int offset, int sourceOffset, int length) const
比較內部資料與來源資料是否相等,可指定各自的起始偏移與比較長度
Pointer(void)
儲存指標的內部成員變數
short getShort(int shift) const
取得指定偏移處的 short 值
Definition Pointer.h:337
Pointer(const Pointer &other)
複製建構子,從另一個 Pointer 物件複製內部位址
Pointer(const void *pointer)
建立一個 Pointer 物件,並以 const void* 初始化內部指標
int copyTo(void *destination, int length) const
複製內部資料至目標記憶體區塊
Definition Pointer.h:186
E * pointer(void) const
模板方法,取得內部指標並轉換為指定型態(不指定偏移)
Definition Pointer.h:398
Pointer getPointer(int offset) const
以指定偏移建立新的 Pointer 物件
Definition Pointer.h:348
int getInteger(int shift) const
取得指定偏移處的整數值
Definition Pointer.h:326
Pointer(uint32 pointer)
建立一個 Pointer 物件,並以 32 位元整數表示的位址初始化
Pointer(void *pointer)
建立一個 Pointer 物件,並以 void* 初始化內部指標
Pointer & operator=(const Pointer &other)=default
賦值運算子,將另一個 Pointer 物件的內部指標複製到當前物件
int copy(const void *source, int offset, int length)
複製來源資料至內部資料區塊,可指定目標位址偏移
Definition Pointer.h:305
bool compair(const void *source, int start, int length) const
比較內部資料與來源資料是否相等,可指定來源資料的起始偏移
Definition Pointer.h:246
int copyTo(void *destination, int start, int length) const
複製內部資料至目標記憶體區塊,可指定來源起始位置
Definition Pointer.h:198
int indexOf(char ch, int start, int limit) const
在內部資料中查找指定字元 ch,回傳該字元的偏移位置
Definition Pointer.h:258
bool isNull(void) const
檢查內部指標是否為空
Definition Pointer.h:387
E * pointer(int offset) const
模板方法,取得內部指標並轉換為指定型態(指定偏移)
Definition Pointer.h:410
virtual int copy(const void *source, int offset, int sourceOffset, int length)
將來源資料複製至內部記憶體區塊,可指定來源與目標的起始偏移
bool compairStrings(const char *str) const
比較內部資料與傳入字串是否相同(從起始位置開始比較)
Definition Pointer.h:209
E * pointer(uint32 offset) const
模板方法,取得內部指標並轉換為指定型態(指定偏移,使用 uint32 參數)
Definition Pointer.h:422
int indexOfStrings(const char *str, int limit) const
在內部資料中查找指定字串,回傳該字串的偏移位置(使用預設起始位置)
Definition Pointer.h:269
int copy(const void *source, int length)
複製來源資料至內部資料區塊,使用預設偏移參數
Definition Pointer.h:293
bool isAlignment32Bit(void)
檢查內部位址是否 32 位元對齊
Definition Pointer.h:367
static int getStringLength(const char *src)
取得C字串的長度
Definition Appendable.h:23