本文整理汇总了C++中Signal::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ Signal::connect方法的具体用法?C++ Signal::connect怎么用?C++ Signal::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Signal
的用法示例。
在下文中一共展示了Signal::connect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: benchSignalEmissionGroups
// profile time for emission with 4 slots, 2 in group 0 and 2 in group 1
static void benchSignalEmissionGroups()
{
Signal<void ( void*, uint64_t )> sigIncrement;
sigIncrement.connect( testCounterAdd2 );
sigIncrement.connect( testCounterAdd2 );
sigIncrement.connect( 1, testCounterAdd2 );
sigIncrement.connect( 1, testCounterAdd2 );
const uint64_t startCounter = TestCounter::get();
const uint64_t benchStart = timestampBenchmark();
uint64_t i;
for( i = 0; i < 1000000; i++ )
sigIncrement.emit( nullptr, 1 );
const uint64_t benchDone = timestampBenchmark();
const uint64_t endCounter = TestCounter::get();
assert( endCounter - startCounter == ( i * 4 ) );
cout << "OK" << endl;
cout << "\tper emission: " << double( benchDone - benchStart ) / double( i ) << "ns"
<< ", per slot: " << double( benchDone - benchStart ) / double( i * 4 ) << "ns"
<< endl;
}
示例2:
TEST(core_signal_test, empty_slot_is_not_same_as_no_slot) {
Signal signal;
signal.connect();
ASSERT_EQ(1u, signal.size());
signal.connect(Signal::Slot());
ASSERT_EQ(2u, signal.size());
}
示例3: signal
TEST(core_signal_test, executing_signal_actually_works_for_all_of_them) {
Signal signal;
int a = 0, b = 0;
signal.connect([&a](int _i) { a = _i; });
signal.connect([&b](int _i) { b = _i + 1; });
signal(5);
ASSERT_EQ(2u, signal.size());
ASSERT_EQ(5, a);
ASSERT_EQ(6, b);
}
示例4: main
int main()
{
Signal<void(int)> signal;
signal.connect(anyFunc);
signal.connect(
[] (int num) {
// TODO: Implement handler logic here.
}
);
signal.emit( 0 );
return 0;
}
示例5:
TEST(SignalTest, SignalBase) {
unsigned counter = 0;
auto f = [&counter]() { ++counter; };
Signal<> sig;
sig();
ASSERT_EQ(0, counter);
ConnectionRef c0 = sig.connect(f);
ASSERT_EQ(0, counter);
ASSERT_TRUE(c0.isValid());
ASSERT_TRUE(c0.isConnected());
sig();
ASSERT_EQ(1, counter);
ASSERT_TRUE(c0.isValid());
ASSERT_TRUE(c0.isConnected());
ConnectionRef c1 = sig.connect(f);
ASSERT_EQ(1, counter);
ASSERT_TRUE(c0.isValid());
ASSERT_TRUE(c0.isConnected());
ASSERT_TRUE(c1.isValid());
ASSERT_TRUE(c1.isConnected());
sig();
ASSERT_EQ(3, counter);
ASSERT_TRUE(c0.isValid());
ASSERT_TRUE(c0.isConnected());
ASSERT_TRUE(c1.isValid());
ASSERT_TRUE(c1.isConnected());
c1.disconnect();
ASSERT_EQ(3, counter);
ASSERT_TRUE(c0.isValid());
ASSERT_TRUE(c0.isConnected());
ASSERT_TRUE(c1.isValid());
ASSERT_FALSE(c1.isConnected());
sig();
ASSERT_EQ(4, counter);
ASSERT_TRUE(c0.isValid());
ASSERT_TRUE(c0.isConnected());
ASSERT_TRUE(c1.isValid());
ASSERT_FALSE(c1.isConnected());
}
示例6: main
int main() {
Signal<void()> sig;
HelloWorld hello;
sig.connect(hello);
sig();
return 0;
}
示例7: main
int main(int argc, char const *argv[])
{
Signal<void(int)> mySignal;
Foobar f;
int lol = 5;
Connection myConnection = mySignal.connect( std::bind(&Foobar::doSomething, &f , std::placeholders::_1) );
mySignal.connect( [](int stuff) { std::cout << "lambda did stuff " << stuff << std::endl; } );
mySignal.notify(1337);
std::cout << myConnection.getId() << std::endl;
myConnection.disconnect();
std::cout << myConnection.getId() << std::endl;
mySignal.notify(7331);
return 0;
}
示例8: connect
//________________________________________________________
void SignalHandler::connect( GObject* object, const std::string& signal, GCallback callback, gpointer data )
{
// check if object is already connected
if( _objects.find( object ) == _objects.end() )
{
// insert object
_objects.insert( object );
// insert destroy signal
Signal destroyId;
destroyId.connect( object, "destroy", (GCallback) destroyNotifyEvent, this );
_signals.push_back( destroyId );
}
// insert signal
Signal signalId;
signalId.connect( object, signal, callback, data );
_signals.push_back( signalId );
}
示例9: if
Handle<Value> Signal_Connect(const Arguments& args)
{
HandleScope handle_scope;
Signal* self = GetPtr(args.This());
assert(self);
if ((args.Length() == 2) && args[0]->IsObject() && args[1]->IsFunction())
{
self->connect(Persistent<Object>::New(args[0]->ToObject()),
Persistent<Object>::New(args[1]->ToObject()));
}
else if ((args.Length() == 1) && args[0]->IsFunction())
{
self->connect(Persistent<Object>::New(args[0]->ToObject()));
}
else
{
return ThrowException(String::New("Invalid parameters, valid syntax:\nconnect(object, function)\nconnect(function)"));
}
return Handle<Value>();
}
示例10: registerWidget
//____________________________________________________________________________________________
bool Animations::registerWidget( GtkWidget* widget )
{
if( _allWidgets.find( widget ) != _allWidgets.end() ) return false;
#if OXYGEN_DEBUG
std::cerr << "Oxygen::Animations::registerWidget - " << widget << " (" << (widget ? G_OBJECT_TYPE_NAME( widget ):"0x0") << ")" << std::endl;
#endif
Signal destroyId;
destroyId.connect( G_OBJECT( widget ), "destroy", G_CALLBACK( destroyNotifyEvent ), this );
_allWidgets.insert( std::make_pair( widget, destroyId ) );
return true;
}
示例11: benchmark_invocation
void benchmark_invocation(unsigned num_connections)
{
static const unsigned num_invocations = 1000000;
Signal signal;
std::cout << num_connections << " connections, invoking " << num_invocations << " times: ";
unsigned n;
for(n = 0; n < num_connections; ++n)
{
signal.connect(myslot());
}
{
boost::progress_timer timer;
unsigned i;
for(i = 0; i < num_invocations; ++i)
{
signal(0);
}
}
}
示例12: benchmark_connect_disconnect
void benchmark_connect_disconnect()
{
static const unsigned num_connections = 1000000;
std::vector<typename connection_type<Signal>::type> connections(num_connections);
Signal signal;
std::cout << "connecting " << num_connections << " connections then disconnecting: ";
unsigned n;
{
boost::progress_timer timer;
for(n = 0; n < num_connections; ++n)
{
connections.at(n) = signal.connect(myslot());
}
for(n = 0; n < num_connections; ++n)
{
connections.at(n).disconnect();
}
}
}
示例13: 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;
}