本文整理汇总了C++中Signal::disconnect方法的典型用法代码示例。如果您正苦于以下问题:C++ Signal::disconnect方法的具体用法?C++ Signal::disconnect怎么用?C++ Signal::disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Signal
的用法示例。
在下文中一共展示了Signal::disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
Handle<Value> Signal_Disconnect(const Arguments& args)
{
HandleScope handle_scope;
Signal* self = GetPtr(args.This());
assert(self);
if ((args.Length() == 2) && args[0]->IsObject() && args[1]->IsFunction())
{
self->disconnect(Persistent<Object>::New(args[0]->ToObject()),
Persistent<Object>::New(args[1]->ToObject()));
}
else if ((args.Length() == 1) && args[0]->IsFunction())
{
self->disconnect(Persistent<Object>::New(args[0]->ToObject()));
}
else
{
return ThrowException(String::New("Invalid parameters, valid syntax:\ndisconnect(object, function)\ndisconnect(function)"));
}
return Handle<Value>();
}
示例2: main
int main(int argc, char **argv) {
Signal<int(int)> sig;
Test("disconnect non existing");
{
bool res;
res = sig.disconnect(0);
ASSERT(!res);
}
Test("connect");
size_t id = sig.connect(Util::dummy);
Test("single connection: check result");
const int input = 100;
auto numVal = sig.emit(input);
auto val = sig.results();
ASSERT(numVal == val->size());
ASSERT(val->size() == 1);
ASSERT((*val)[0] == Util::dummy(input));
Test("multiple connections: check results");
size_t id2 = sig.connect(dummy2);
size_t id3 = sig.connect(Util::dummy);
size_t id4 = sig.connect(dummy2);
numVal = sig.emit(input);
val = sig.results();
ASSERT(numVal == val->size());
ASSERT(val->size() == 4);
ASSERT((*val)[0] == Util::dummy(input));
ASSERT((*val)[1] == dummy2(input));
ASSERT((*val)[2] == Util::dummy(input));
ASSERT((*val)[3] == dummy2(input));
Test("multiple connections: ask results again");
auto val2 = sig.results();
ASSERT(numVal == val2->size());
ASSERT(val2->size() == 4);
ASSERT((*val2)[0] == Util::dummy(input));
ASSERT((*val2)[1] == dummy2(input));
ASSERT((*val2)[2] == Util::dummy(input));
ASSERT((*val2)[3] == dummy2(input));
Test("disconnections");
{
bool res;
res = sig.disconnect(id2);
ASSERT(res);
res = sig.disconnect(id);
ASSERT(res);
//disconnect again
res = sig.disconnect(id);
ASSERT(!res);
//wrong id
res = sig.disconnect(id + 1);
ASSERT(!res);
}
return 0;
}