分享方式:


MatchEventStack

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

MatchEventStack 式可用來比對特定事件階層的事件堆疊。 相符的階層會轉送至處理常式以進行進一步處理。 若要深入瞭解事件、事件堆疊和階層,請參閱 事件資料表

語法

template <
    typename          TEvent,
    typename...       TEvents,
    typename          TCallable,
    typename...       TExtraArgs>
bool MatchEventStack(
    const EventStack& eventStack,
    TCallable&&       callable,
    TExtraArgs&&...   extraArgs);

參數

TEvent
要比對事件堆疊中最長父代的類型。

TEvents
您想要在事件堆疊中比對的其餘類型。

TCallable
支援 operator() 的類型。 如需哪些引數傳遞至此運算子的詳細資訊,請參閱 呼叫的參數描述。

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

eventStack
要與 TEvent TEvents 描述的事件種類階層相符的事件堆疊。

調用
成功比對事件堆疊與 TEvent TEvents 所描述 的事件種類階層時, MatchEventStack 會叫用 呼叫。 它會傳遞至 事件階層中每個類型可 呼叫的一個 r 值引數。 extraArgs 參數套件會在可 呼叫的 其餘參數中完美轉送。

extraArgs
取得完美轉送給 呼叫的引數,以及相符的事件種類。

傳回值

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

備註

eventStack 中的 最後一個事件一律會與串連 [ TEvent TEvents... ] 類型清單中的最後一個專案相符。 所有其他 TEvent 和 TEvents 專案都可以比對 eventStack 中的任何 位置,但前提是它們的順序相同。

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

範例

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

    bool b1 = MatchEventStack<Compiler, BackEndPass, C2DLL,
                CodeGeneration, Thread, Function>(
        eventStack, [](Compiler cl, BackEndPass bep, C2DLL c2,
            CodeGeneration cg, Thread t, Function f){ /* Do something ... */ });

    bool b2 = MatchEventStack<Compiler, Function>(
        eventStack, [](Compiler cl, Function f){ /* Do something... */ });

    bool b3 = MatchEventStack<Thread, Compiler, Function>(
        eventStack, [](Thread t, Compiler cl Function f){ /* Do something... */ });

    bool b4 = MatchEventStack<Compiler>(
        eventStack, [](Compiler cl){ /* Do something... */ });


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