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
值为 true
;否则,值为 false
。
备注
eventStack 中的最后一个事件始终与要匹配的事件类型层次结构中的最后一个条目进行匹配。 事件类型层次结构中的其他所有类型可以与 eventStack 中的任何位置进行匹配(最后一个除外),前提是它们的顺序相同。
用于 T1 到 T10 参数的事件类型是从 Capture 类的列表中选择的。 有关事件以及可用于匹配它们的 Capture 类的列表,请参阅事件表。
示例
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).
}