|
| | Table (FunctionType default_handler=FunctionType{}) |
| | 构造 Table。
|
| void | add (const std::type_index &type1, const std::type_index &type2, FunctionType func) |
| | 注册一个类型对的处理函数(非对称)。
|
| void | add_symmetric (const std::type_info &type1, const std::type_info &type2, FunctionType func) |
| | 对称地注册一个类型对的处理函数。
|
| FunctionType | operator() (const std::type_index &type1, const std::type_index &type2) const |
| | 根据两个类型获取对应的处理函数。
|
| void | call (T &a, T &b) const |
| | 根据两个对象的运行时类型调用对应的处理函数。
|
| bool | has (const std::type_index &type1, const std::type_index &type2) const |
| | 检查是否为特定的类型对注册了处理函数。
|
| bool | has_default () const |
| | 检查是否设置了默认处理函数。
|
| bool | callable (const std::type_index &type1, const std::type_index &type2) const |
| | 检查是否为特定的类型对注册了处理函数,或者是否设置了默认处理函数。
|
| void | set_default (FunctionType func=FunctionType{}) |
| | 设置默认处理函数,当没有找到特定类型对的函数时调用。
|
| void | remove (const std::type_index &type1, const std::type_index &type2) |
| | 移除一个类型对的处理函数。
|
| void | clear () |
| | 清空所有注册的类型对和处理函数。
|
template<class T, class F = std::function<void(T &, T &)>>
class console::Table< T, F >
双重分派函数表,用于根据两个对象的运行时类型调用注册的函数。
- Template Parameters
-
| T | 所有操作的基类类型,函数表处理的对象都是 T 的派生类型。 |
该类维护一个从类型对到处理函数的映射。当需要处理两个对象时, 根据它们的实际类型(通过 typeid 获取)查找对应的处理函数并调用。 支持非对称和对称注册(自动注册两个方向)。
class Shape { ... };
collisionTable.
call(*
this, other);
class Circle :
public Shape { ... };
class Rect : public Shape { ... };
int register = []() -> int
{
onCircleRect);
return 0;
}();
Circle c;
Rect r;
c.collide(r);
void add_symmetric(const std::type_info &type1, const std::type_info &type2, FunctionType func)
对称地注册一个类型对的处理函数。
Definition collide.h:138
void call(T &a, T &b) const
根据两个对象的运行时类型调用对应的处理函数。
Definition collide.h:187
Table(FunctionType default_handler=FunctionType{})
构造 Table。
Definition collide.h:114