本文整理汇总了C++中Signal::emit方法的典型用法代码示例。如果您正苦于以下问题:C++ Signal::emit方法的具体用法?C++ Signal::emit怎么用?C++ Signal::emit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Signal
的用法示例。
在下文中一共展示了Signal::emit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: poll_inserted
void poll_inserted() {
const auto card_present_now = sdcIsCardInserted(&SDCD1);
if( card_present_now != card_present ) {
card_present = card_present_now;
Status new_status { card_present ? Status::Present : Status::NotPresent };
if( card_present ) {
if( sdcConnect(&SDCD1) == CH_SUCCESS ) {
if( mount() == FR_OK ) {
new_status = Status::Mounted;
} else {
new_status = Status::MountError;
}
} else {
new_status = Status::ConnectError;
}
} else {
sdcDisconnect(&SDCD1);
}
status_ = new_status;
status_signal.emit(status_);
}
}
示例2: 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;
}
示例3: main
int main()
{
Signal<void(int)> signal;
signal.connect(anyFunc);
signal.connect(
[] (int num) {
// TODO: Implement handler logic here.
}
);
signal.emit( 0 );
return 0;
}
示例4: on_tick_second
void on_tick_second() {
signal_tick_second.emit();
}
示例5: 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;
}
示例6: main
//.........这里部分代码省略.........
action->m_slotMsgM.getStaticCastFunction()( mb, nullptr );
action->expectDynamicType( op, "MsgB" );
action->expectStaticType( op, "Message" );
//op = " Invoke action m_slotMsgA with mm";
//action->m_slotMsgA( mm ); is not a valid static cast
op = " Invoke action m_slotMsgA with ma";
action->m_slotMsgA.getStaticCastFunction()( ma, nullptr );
action->expectDynamicType( op, "MsgA" );
action->expectStaticType( op, "MsgA" );
op = " Invoke action m_slotMsgA with mb";
action->m_slotMsgA.getStaticCastFunction()( mb, nullptr );
action->expectDynamicType( op, "MsgB" );
action->expectStaticType( op, "MsgA" );
//op = " Invoke action m_slotMsgB with mm";
//action->m_slotMsgB( mm ); is not a valid static cast
//op = " Invoke action m_slotMsgB with ma";
//action->m_slotMsgB( ma ); is not a valid static cast
op = " Invoke action m_slotMsgB with mb";
action->m_slotMsgB.getStaticCastFunction()( mb, nullptr );
action->expectDynamicType( op, "MsgB" );
action->expectStaticType( op, "MsgB" );
cout << "Ok" << endl;
// Note: Without links emission has no effect
cout << "Test Signal type check : ";
action->m_signalMsgM.emit( mm );
action->m_signalMsgM.emit( ma );
action->m_signalMsgM.emit( mb );
// action->m_signalMsgA.emit( mm ); // Ok: static Error
action->m_signalMsgA.emit( ma );
action->m_signalMsgA.emit( mb );
// action->m_signalMsgB.emit( mm ); // Ok: static Error
// action->m_signalMsgB.emit( ma ); // Ok: static Error
action->m_signalMsgB.emit( mb );
cout << "Ok" << endl;
cout << "Test connecting links : ";
try
{
if( Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
{
cout << "Failed!" << endl;
cout << " Link myAction::signalMsgM -> myAction::slotMsgM exist." << endl;
exit(1);
}
Link::connect( "myAction::signalMsgM", "myAction::slotMsgM");
if( !Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
{
cout << "Failed!" << endl;
cout << " Link myAction::signalMsgM -> myAction::slotMsgM not created." << endl;
exit(1);
}