消費者方法包裝類,將類別方法轉換為標準 Consumer 介面
更多...
#include <ConsumerMethod.h>
消費者方法包裝類,將類別方法轉換為標準 Consumer 介面
ConsumerMethod 類提供方法引用機制,將類別成員方法包裝為 Consumer 介面。 透過記錄物件實例與方法指針,允許以統一方式調用不同類別的方法。 實現了策略模式與命令模式,使物件方法能在函數式架構中靈活使用。
- 自
- 1.0.0
◆ ConsumerMethod() [1/2]
template<typename T = Interface, typename C = Interface>
ufm::func::ConsumerMethod::ConsumerMethod |
( |
Interface & | c, |
|
|
void(C::* | method )(T &) ) |
|
inline |
構造一個新的 ConsumerMethod 物件
將特定物件方法封裝為 Consumer 介面實現,建立方法引用。 透過型別轉換技術,實現跨類型方法的統一調用介面。 支援泛型編程,增強代碼的重用性與靈活性。
- 樣版參數
-
T | 方法參數型別,預設為 Interface |
C | 物件類型,預設為 Interface |
- 參數
-
c | 目標物件的引用 |
method | 要調用的成員方法指針 |
◆ ConsumerMethod() [2/2]
template<typename T = Interface>
ufm::func::ConsumerMethod::ConsumerMethod |
( |
Consumer< T > & | consumer | ) |
|
|
inline |
◆ ~ConsumerMethod()
virtual ufm::func::ConsumerMethod::~ConsumerMethod |
( |
void | | ) |
|
|
overridevirtual |
◆ accept()
virtual void ufm::func::ConsumerMethod::accept |
( |
Interface & | t | ) |
|
|
overridevirtual |
實現 Consumer 介面的 accept 方法
調用建構時指定的物件方法,實現委派模式。 此方法作為 Consumer 介面與實際物件方法之間的轉接層, 將標準化的消費操作轉發至特定物件的成員方法。
- 參數
-
◆ operator const Consumer< T > &()
template<typename T >
ufm::func::ConsumerMethod::operator const Consumer< T > & |
( |
void | | ) |
const |
|
inline |
Consumer 常量型轉換運算子
將當前物件轉換為常量型 Consumer<T> 引用, 實現了型別安全的向下轉換機制,使泛型消費者方法能作為特定型別消費者使用。 此運算子使物件能以唯讀方式被用作任何 Consumer<T> 型別的引用。
- 樣版參數
-
- 傳回值
- const Consumer<T>& 轉換後的常量 Consumer<T> 引用
◆ operator Consumer< T > &()
template<typename T >
ufm::func::ConsumerMethod::operator Consumer< T > & |
( |
void | | ) |
|
|
inline |
轉換為 Consumer<T> 引用的運算子
提供型別安全的向下轉換機制,使泛型消費者方法能作為特定型別消費者使用。 實現了多態性,同時提供完整操作權限。 支援泛型編程模式,增強類型系統的靈活性。
- 樣版參數
-
- 傳回值
- Consumer<T>& 轉換後的 Consumer<T> 引用
此類別(class) 文件是由下列檔案中產生: