共用方式為


MatchEventStackInMemberFunction

C++ Build Insights SDK 與 Visual Studio 2017 和更新版本相容。 若要查看這些版本的檔,請將本文的 Visual Studio 版本 選取器控制項設定為 Visual Studio 2017 或更新版本。 其位於此頁面目錄頂端。

MatchEventStackInMemberFunction 式可用來比對事件堆疊與成員函式的參數清單所描述的特定事件階層。 相符階層會轉送至成員函式,以便進一步處理。 若要深入瞭解事件、事件堆疊和階層,請參閱 事件資料表

語法

template <
    typename     TInterface,
    typename     TReturn,
    typename     T1,
    typename...  TExtraParams,
    typename...  TExtraArgs>
bool MatchEventStackInMemberFunction(
    const EventStack&         eventStack,
    TInterface*               objectPtr,
    TReturn (TInterface::*    memberFunc)(T1, TExtraParams...),
    TExtraArgs&&...           extraArgs);

template <
    typename     TInterface,
    typename     TReturn,
    typename     T1,
    typename     T2,
    typename...  TExtraParams,
    typename...  TExtraArgs>
bool MatchEventStackInMemberFunction(
    const EventStack&         eventStack,
    TInterface*               objectPtr,
    TReturn (TInterface::*    memberFunc)(T1, T2, TExtraParams...),
    TExtraArgs&&...           extraArgs);

// Etc...

template <
    typename     TInterface,
    typename     TReturn,
    typename     T1,
    typename     T2,
    typename     T3,
    typename     T4,
    typename     T5,
    typename     T6,
    typename     T7,
    typename     T8,
    typename     T9,
    typename     T10,
    typename...  TExtraParams,
    typename...  TExtraArgs>
bool MatchEventStackInMemberFunction(
    const EventStack&         eventStack,
    TInterface*               objectPtr,
    TReturn (TInterface::*    memberFunc)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TExtraParams...),
    TExtraArgs&&...           extraArgs);

參數

TInterface
包含成員函式的類型。

TReturn
成員函式的傳回型別。

T1 、...、 T10
描述要比對之事件階層的類型。

TExtraParams
成員函式所接受之額外參數的類型,以及事件階層類型。

TExtraArgs
傳遞至 MatchEventStackInMemberFunction 的額外引數類型。

eventStack
要與 T1 至 T10 描述之事件種類階層相符的事件堆疊。

objectPtr
呼叫 memberFunc 之物件的 指標。

memberFunc
描述要比對之事件種類階層的成員函式。

extraArgs
取得完整轉送給 memberFunc 以及事件種類階層參數的引數。

傳回值

bool如果比對成功,則 false 為 , true 否則為 。

備註

eventStack 中的 最後一個事件一律會與事件種類階層中最後一個專案相符。 事件種類階層中的所有其他類型都可以比對 eventStack 中的任何 位置,但最後一個位置除外,前提是它們的順序相同。

從擷取類別清單中選取要用於 T1 到 T10 參數的事件 類型。 如需事件清單和可用來比對的事件擷取類別,請參閱 事件資料表

範例

void MyClass::Foo1(Compiler cl, BackEndPass bep, C2DLL c2,
    CodeGeneration cg, Thread t, Function f) { }

void MyClass::Foo2(Compiler cl, Function f) { }

void MyClass::Foo3(Thread t, Compiler cl, Function f) { }

void MyClass::Foo4(Compiler cl) { }

void MyClass::OnStartActivity(const EventStack& eventStack)
{
    // Let's assume eventStack contains:
    // [Compiler, BackEndPass, C2DLL, CodeGeneration, Thread, Function]

    bool b1 = MatchEventStackInMemberFunction(
        eventStack, this, &MyClass::Foo1);

    bool b2 = MatchEventStackInMemberFunction(
        eventStack, this, &MyClass::Foo2);

    bool b3 = MatchEventStackInMemberFunction(
        eventStack, this, &MyClass::Foo3);

    bool b4 = MatchEventStackInMemberFunction(
        eventStack, this, &MyClass::Foo4);

    // b1: true because the parameter types of Foo1 match the eventStack
    //     exactly.
    // b2: true because Function is the last entry in both the member
    //     function parameter list and 'eventStack', and also because
    //     Compiler comes before Function in 'eventStack' and in the
    //     parameter type list.
    // b3: false because, even though both Thread and Compiler come
    //     before Function in 'eventStack', the member function parameter
    //     list doesn't list them in the right order.
    // b4: false because the last entry in the member function parameter
    //     list is Compiler, which doesn't match the last entry in 'eventStack'
    //     (Function).
}