mFrame
載入中...
搜尋中...
無符合項目
ufm::lang::Pointer 類別 參考文件

提供記憶體位址存取與操作功能 更多...

#include <Pointer.h>

類別ufm::lang::Pointer的繼承圖:
ufm::lang::Object ufm::lang::Interface ufm::lang::Data ufm::io::SimpleReader ufm::io::SimpleWriter ufm::lang::Memory ufm::lang::Strings ufm::util::PArray

公開方法(Public Methods)

 Pointer (void)
 儲存指標的內部成員變數
 
 Pointer (const void *pointer)
 建立一個 Pointer 物件,並以 const void* 初始化內部指標
 
 Pointer (void *pointer)
 建立一個 Pointer 物件,並以 void* 初始化內部指標
 
 Pointer (uint32 pointer)
 建立一個 Pointer 物件,並以 32 位元整數表示的位址初始化
 
 Pointer (const Pointer &other)
 複製建構子,從另一個 Pointer 物件複製內部位址
 
 operator void * (void)
 隱式轉換為 void*,可直接取得內部指標
 
 operator const char * (void)
 隱式轉換為 const char*,適用於字串存取
 
bool operator== (const void *pointer)
 比較內部指標與外部指標是否相同
 
bool operator== (const Pointer &pointer)
 比較兩個 Pointer 物件的內部指標是否相同
 
template<typename E >
 operator E* (void)
 模板運算子,將內部指標轉換為指定型態的指標(非 const 版本)
 
template<typename E >
 operator E* (void) const
 模板運算子,將內部指標轉換為指定型態的指標(const 版本)
 
Pointeroperator= (const Pointer &other)=default
 賦值運算子,將另一個 Pointer 物件的內部指標複製到當前物件
 
int copyTo (void *destination, int length) const
 複製內部資料至目標記憶體區塊
 
int copyTo (void *destination, int start, int length) const
 複製內部資料至目標記憶體區塊,可指定來源起始位置
 
bool compairStrings (const char *str) const
 比較內部資料與傳入字串是否相同(從起始位置開始比較)
 
bool compairStrings (const char *str, int start) const
 比較內部資料與傳入字串是否相同,可指定來源資料起始位置
 
bool compair (const void *source, int length) const
 比較內部資料與來源資料是否相等(從起始位置開始比較)
 
bool compair (const void *source, int start, int length) const
 比較內部資料與來源資料是否相等,可指定來源資料的起始偏移
 
int indexOf (char ch, int start, int limit) const
 在內部資料中查找指定字元 ch,回傳該字元的偏移位置
 
int indexOfStrings (const char *str, int limit) const
 在內部資料中查找指定字串,回傳該字串的偏移位置(使用預設起始位置)
 
int indexOfStrings (const char *str, int start, int limit) const
 在內部資料中查找指定字串,回傳該字串的偏移位置
 
int copy (const void *source, int length)
 複製來源資料至內部資料區塊,使用預設偏移參數
 
int copy (const void *source, int offset, int length)
 複製來源資料至內部資料區塊,可指定目標位址偏移
 
char getByte (int shift) const
 取得指定偏移處的 byte 值
 
int getInteger (int shift) const
 取得指定偏移處的整數值
 
short getShort (int shift) const
 取得指定偏移處的 short 值
 
Pointer getPointer (int offset) const
 以指定偏移建立新的 Pointer 物件
 
uint32 getAddress (void) const
 取得內部記憶體位址的整數表示
 
bool isAlignment32Bit (void)
 檢查內部位址是否 32 位元對齊
 
bool isAlignment64Bit (void)
 檢查內部位址是否 64 位元對齊
 
bool isNull (void) const
 檢查內部指標是否為空
 
template<typename E = void*>
E * pointer (void) const
 模板方法,取得內部指標並轉換為指定型態(不指定偏移)
 
template<typename E = void*>
E * pointer (int offset) const
 模板方法,取得內部指標並轉換為指定型態(指定偏移)
 
template<typename E = void*>
E * pointer (uint32 offset) const
 模板方法,取得內部指標並轉換為指定型態(指定偏移,使用 uint32 參數)
 
virtual int copy (const void *source, int offset, int sourceOffset, int length)
 將來源資料複製至內部記憶體區塊,可指定來源與目標的起始偏移
 
virtual int copyTo (void *destination, int offset, int destinationOffset, int length) const
 將內部資料複製到目標記憶體區塊,可指定來源與目標的起始偏移
 
virtual bool compair (const void *source, int offset, int sourceOffset, int length) const
 比較內部資料與來源資料是否相等,可指定各自的起始偏移與比較長度
 
virtual int indexOfData (const void *destination, int destinationLen, int start=0, int limit=0) const
 尋找指定 pattern 是否存在於內部資料中,並返回第一個符合條件的偏移量
 
virtual void move (int head, int offset, int length)
 將來源位置的資料以中間緩衝區方式移動至新的位置
 
- 公開方法(Public Methods) 繼承自 ufm::lang::Object
void * operator new (size_t n)
 使用運算子 new 分配記憶體
 
void * operator new (size_t n, void *p)
 在指定記憶體上調用運算子 new
 
virtual ufm::lang::ObjectgetObject (void) override
 取得對應的 Object 物件
 
void delay (int milliseconds) const
 延遲指定的毫秒數進行執行緒等待
 
bool equals (Object *object) const
 判斷與另一物件是否為相同參照(指標型態比較)
 
bool equals (Object &object) const
 判斷與另一物件是否為相同參照(參照型態比較)
 
void wait (void) const
 使當前線程等待直到被通知
 
bool wait (int timeout) const
 等待通知或超時
 
bool yield (void) const
 讓執行緒讓渡控制權給同優先權的下一個執行緒
 
int lock (void) const
 核心鎖定,鎖定期間禁止線程切換
 
int unlock (void) const
 核心解鎖
 
ufm::sys::ThreadcurrentThread (void) const
 取得當前執行緒指標
 
virtual int hashcode (void) const
 返回對象的哈希碼值。支持這種方法是為了散列表,如HashMap提供的那樣。
 
- 公開方法(Public Methods) 繼承自 ufm::lang::Interface
virtual ~Interface (void)=default
 虛擬析構函式
 

詳細描述

提供記憶體位址存取與操作功能

此類別封裝一個記憶體位址,支援:

  • 資料複製
  • 比較
  • 搜尋
  • 移動 並提供多型轉換運算子與模板方法,以便將內部位址轉換為不同型態的指標。
vPointer 僅儲存記憶體位址,記憶體的分配與釋放需由使用者自行管理
參閱
ufm::lang::Memory
1.0.0

建構子與解構子說明文件

◆ Pointer() [1/5]

ufm::lang::Pointer::Pointer ( void )

儲存指標的內部成員變數

預設建構子,建立一個空的 Pointer 物件

使用此建構子會將內部指標初始化為 nullptr,使用者可之後透過其他方法或運算子賦予正確位址。

◆ Pointer() [2/5]

ufm::lang::Pointer::Pointer ( const void * pointer)

建立一個 Pointer 物件,並以 const void* 初始化內部指標

參數
pointer來源位址(不可修改內容)
此建構子接受 const 型態指標,但內部會儲存為 void*,使用時請留意 const 正確性。

◆ Pointer() [3/5]

ufm::lang::Pointer::Pointer ( void * pointer)

建立一個 Pointer 物件,並以 void* 初始化內部指標

參數
pointer原始記憶體位址

◆ Pointer() [4/5]

ufm::lang::Pointer::Pointer ( uint32 pointer)
explicit

建立一個 Pointer 物件,並以 32 位元整數表示的位址初始化

參數
pointer32 位元的記憶體位址,通常由系統或硬體取得

◆ Pointer() [5/5]

ufm::lang::Pointer::Pointer ( const Pointer & other)

複製建構子,從另一個 Pointer 物件複製內部位址

參數
other另一個 Pointer 物件

函式成員說明文件

◆ compair() [1/3]

bool ufm::lang::Pointer::compair ( const void * source,
int length ) const
inline

比較內部資料與來源資料是否相等(從起始位置開始比較)

參數
source來源資料位址
length比較的 byte 數
傳回值
true 當資料相等
false 當資料不相等

◆ compair() [2/3]

virtual bool ufm::lang::Pointer::compair ( const void * source,
int offset,
int sourceOffset,
int length ) const
virtual

比較內部資料與來源資料是否相等,可指定各自的起始偏移與比較長度

參數
source來源資料位址
offset內部資料比較起始偏移
sourceOffset來源資料比較起始偏移
length比較的 byte 數
傳回值
true 當指定區域資料完全相等
false 否則
此方法常用於記憶體驗證或資料完整性檢查。

◆ compair() [3/3]

bool ufm::lang::Pointer::compair ( const void * source,
int start,
int length ) const
inline

比較內部資料與來源資料是否相等,可指定來源資料的起始偏移

參數
source來源資料位址
start來源資料比較起始偏移
length比較的 byte 數
傳回值
true 當資料相等
false 當資料不相等

◆ compairStrings() [1/2]

bool ufm::lang::Pointer::compairStrings ( const char * str) const
inline

比較內部資料與傳入字串是否相同(從起始位置開始比較)

參數
str目標字串
傳回值
true 當內部資料與字串內容相等
false 不相等

◆ compairStrings() [2/2]

bool ufm::lang::Pointer::compairStrings ( const char * str,
int start ) const
inline

比較內部資料與傳入字串是否相同,可指定來源資料起始位置

參數
str目標字串
start來源資料比較起始偏移
傳回值
true 當內部資料與字串內容相等
false 不相等

◆ copy() [1/3]

int ufm::lang::Pointer::copy ( const void * source,
int length )
inline

複製來源資料至內部資料區塊,使用預設偏移參數

參數
source來源資料位址
length複製的 byte 數
傳回值
int 實際複製的 byte 數

◆ copy() [2/3]

int ufm::lang::Pointer::copy ( const void * source,
int offset,
int length )
inline

複製來源資料至內部資料區塊,可指定目標位址偏移

參數
source來源資料位址
offset內部資料儲存起始偏移
length複製的 byte 數
傳回值
int 實際複製的 byte 數

◆ copy() [3/3]

virtual int ufm::lang::Pointer::copy ( const void * source,
int offset,
int sourceOffset,
int length )
virtual

將來源資料複製至內部記憶體區塊,可指定來源與目標的起始偏移

參數
source來源資料位址
offset內部資料儲存起始偏移(目標偏移)
sourceOffset來源資料起始偏移
length複製的 byte 數
傳回值
int 實際複製的 byte 數
此方法可用於部分資料更新或資料重新排列,回傳值可能小於 length 表示未完整複製。

ufm::lang::Data重新實作.

◆ copyTo() [1/3]

int ufm::lang::Pointer::copyTo ( void * destination,
int length ) const
inline

複製內部資料至目標記憶體區塊

此方法會從內部資料的起始位置開始複製指定長度的資料到 destination, 並使用預設偏移(offset = 0)。

參數
destination目標記憶體區塊
length複製的資料長度(單位:byte)
傳回值
int 實際複製的 byte 數

◆ copyTo() [2/3]

virtual int ufm::lang::Pointer::copyTo ( void * destination,
int offset,
int destinationOffset,
int length ) const
virtual

將內部資料複製到目標記憶體區塊,可指定來源與目標的起始偏移

參數
destination目標記憶體位址
offset內部資料複製起始偏移(來源偏移)
destinationOffset目標資料儲存起始偏移
length複製的 byte 數
傳回值
int 實際複製的 byte 數
此方法適用於資料備份或傳輸操作,使用者應確保目標記憶體區塊足夠大。

◆ copyTo() [3/3]

int ufm::lang::Pointer::copyTo ( void * destination,
int start,
int length ) const
inline

複製內部資料至目標記憶體區塊,可指定來源起始位置

參數
destination目標記憶體區塊
start來源資料起始偏移
length複製的資料長度(單位:byte)
傳回值
int 實際複製的 byte 數

◆ getAddress()

uint32 ufm::lang::Pointer::getAddress ( void ) const
inline

取得內部記憶體位址的整數表示

傳回值
uint32 回傳 32 位元整數表示的位址

◆ getByte()

char ufm::lang::Pointer::getByte ( int shift) const
inline

取得指定偏移處的 byte 值

參數
shift欲讀取的位置偏移
傳回值
char 該位置的 byte 值

◆ getInteger()

int ufm::lang::Pointer::getInteger ( int shift) const
inline

取得指定偏移處的整數值

參數
shift欲讀取的位置偏移
傳回值
int 該位置的整數值

◆ getPointer()

Pointer ufm::lang::Pointer::getPointer ( int offset) const
inline

以指定偏移建立新的 Pointer 物件

參數
offset內部位址偏移量(單位:byte)
傳回值
Pointer 新的 Pointer 物件,其內部位址為原始位址 + offset

◆ getShort()

short ufm::lang::Pointer::getShort ( int shift) const
inline

取得指定偏移處的 short 值

參數
shift欲讀取的位置偏移
傳回值
short 該位置的 short 值

◆ indexOf()

int ufm::lang::Pointer::indexOf ( char ch,
int start,
int limit ) const
inline

在內部資料中查找指定字元 ch,回傳該字元的偏移位置

參數
ch目標字元
start查找起始偏移
limit最大搜尋範圍(<=0 表示無上限)
傳回值
int 若找到則回傳該字元在資料中的偏移,否則回傳 -1

◆ indexOfData()

virtual int ufm::lang::Pointer::indexOfData ( const void * destination,
int destinationLen,
int start = 0,
int limit = 0 ) const
virtual

尋找指定 pattern 是否存在於內部資料中,並返回第一個符合條件的偏移量

範例:

const char* pattern = "how";
const char* source = "hello peter, how are you?";
int index = pointer.indexOfData(pattern, 3, 0, 0);
// 若找到 pattern 則 index 為其在資料中的偏移,否則為 -1
提供記憶體位址存取與操作功能
Definition Pointer.h:44
Pointer(void)
儲存指標的內部成員變數
E * pointer(void) const
模板方法,取得內部指標並轉換為指定型態(不指定偏移)
Definition Pointer.h:398
參數
destination比較目標資料位址(pattern 位址)
destinationLenpattern 資料長度
  • [<= 0] 不指定資料搜尋起點。
  • [> 0] 指定 pattern 長度。
參數
start內部資料搜尋起始偏移
  • [<= 0] 從資料開始處搜尋。
  • [> 0] 從指定位置開始搜尋。
參數
limit最大搜尋範圍(<=0 表示搜尋到結束)
傳回值
int 若找到則回傳 pattern 的偏移位置,否則回傳 -1

◆ indexOfStrings() [1/2]

int ufm::lang::Pointer::indexOfStrings ( const char * str,
int limit ) const
inline

在內部資料中查找指定字串,回傳該字串的偏移位置(使用預設起始位置)

參數
str目標字串
limit最大搜尋範圍(<=0 表示無上限)
傳回值
int 若找到則回傳該字串在資料中的偏移,否則回傳 -1

◆ indexOfStrings() [2/2]

int ufm::lang::Pointer::indexOfStrings ( const char * str,
int start,
int limit ) const
inline

在內部資料中查找指定字串,回傳該字串的偏移位置

參數
str目標字串
start查找起始偏移
limit最大搜尋範圍(<=0 表示無上限)
傳回值
int 若找到則回傳該字串在資料中的偏移,否則回傳 -1

◆ isAlignment32Bit()

bool ufm::lang::Pointer::isAlignment32Bit ( void )
inline

檢查內部位址是否 32 位元對齊

傳回值
true 若位址符合 32 位元對齊要求
false 否則

◆ isAlignment64Bit()

bool ufm::lang::Pointer::isAlignment64Bit ( void )
inline

檢查內部位址是否 64 位元對齊

傳回值
true 若位址符合 64 位元對齊要求
false 否則

◆ isNull()

bool ufm::lang::Pointer::isNull ( void ) const
inline

檢查內部指標是否為空

傳回值
true 當 vPointer 為 nullptr
false 非 nullptr

◆ move()

virtual void ufm::lang::Pointer::move ( int head,
int offset,
int length )
virtual

將來源位置的資料以中間緩衝區方式移動至新的位置

此方法用於資料重組或資料塊移動,允許目標與來源記憶體區塊重疊操作。

範例:

// 例1:從索引 5 開始,向右位移 3 個 byte,移動 4 個 byte
this->move(5, 3, 4);
// 執行後:
// Index : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
// Raw : A B C D E F G H I J K L M N O
// - - - - > > >
// Result: A B C D E F G H F G H I M N O
// ^ ^ ^ ^
// 例2:從索引 2 開始,向左位移 2 個 byte,移動 3 個 byte
this->move(4, -2, 3);
// 執行後:
// Index : 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14
// Raw : A B C D E F G H I J K L M N O
// < < - - -
// Result: A B E F G F G H I J K L M N O
// ^ ^ ^
virtual void move(int head, int offset, int length)
將來源位置的資料以中間緩衝區方式移動至新的位置
參數
head起始位置(必須 >= 0)
offset以 head 為基準的相對位移(負值表示向左,正值表示向右)
length欲移動的 byte 數(必須 > 0)

◆ operator const char *()

ufm::lang::Pointer::operator const char * ( void )
inline

隱式轉換為 const char*,適用於字串存取

傳回值
const char* 回傳以字元陣列方式解讀的內部位址

◆ operator E*() [1/2]

template<typename E >
ufm::lang::Pointer::operator E* ( void )
inline

模板運算子,將內部指標轉換為指定型態的指標(非 const 版本)

樣版參數
E目標型態
傳回值
E* 指向轉換後型態的指標

◆ operator E*() [2/2]

template<typename E >
ufm::lang::Pointer::operator E* ( void ) const
inline

模板運算子,將內部指標轉換為指定型態的指標(const 版本)

樣版參數
E目標型態
傳回值
E* 指向轉換後型態的指標

◆ operator void *()

ufm::lang::Pointer::operator void * ( void )
inline

隱式轉換為 void*,可直接取得內部指標

傳回值
void* 回傳內部儲存的記憶體位址

◆ operator=()

Pointer & ufm::lang::Pointer::operator= ( const Pointer & other)
inlinedefault

賦值運算子,將另一個 Pointer 物件的內部指標複製到當前物件

參數
other另一個 Pointer 物件
傳回值
Pointer& 返回當前物件的參考,以支持鏈式賦值

◆ operator==() [1/2]

bool ufm::lang::Pointer::operator== ( const Pointer & pointer)
inline

比較兩個 Pointer 物件的內部指標是否相同

參數
pointer另一個 Pointer 物件
傳回值
true 當兩物件內部指標相等
false 不相等

◆ operator==() [2/2]

bool ufm::lang::Pointer::operator== ( const void * pointer)
inline

比較內部指標與外部指標是否相同

參數
pointer外部指標
傳回值
true 當內部指標與 pointer 相等
false 不相等

◆ pointer() [1/3]

template<typename E = void*>
E * ufm::lang::Pointer::pointer ( int offset) const
inline

模板方法,取得內部指標並轉換為指定型態(指定偏移)

樣版參數
E目標型態,預設為 void*
參數
offset內部位址偏移量(byte 為單位)
傳回值
E* 轉換後的指標

◆ pointer() [2/3]

template<typename E = void*>
E * ufm::lang::Pointer::pointer ( uint32 offset) const
inline

模板方法,取得內部指標並轉換為指定型態(指定偏移,使用 uint32 參數)

樣版參數
E目標型態,預設為 void*
參數
offset內部位址偏移量(byte 為單位)
傳回值
E* 轉換後的指標

◆ pointer() [3/3]

template<typename E = void*>
E * ufm::lang::Pointer::pointer ( void ) const
inline

模板方法,取得內部指標並轉換為指定型態(不指定偏移)

樣版參數
E目標型態,預設為 void*
傳回值
E* 轉換後的指標

此類別(class) 文件是由下列檔案中產生: