本文整理汇总了C++中Signal类的典型用法代码示例。如果您正苦于以下问题:C++ Signal类的具体用法?C++ Signal怎么用?C++ Signal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Signal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Signal
bool SignalModifier::convertToTrigger(Signal &s)
{
// reference counted Signal ( string command, string origin )
Signal::SignalP midiSignal = new Signal("SEND_MIDI", "SIG_MOD");
midiSignal->addStringArg("CC");
// TODO: allow this to set the MIDI Channel
midiSignal->addIntArg(1);
midiSignal->addIntArg(s.getArgAsInt32(1));
midiSignal->addIntArg(s.getArgAsInt32(2) * 127);
_mCenter->handleSignal(*midiSignal);
// reference counted Signal ( string command, string origin )
Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "SIG_MOD");
ledStateSignal->addStringArg("/nomestate/grid/led/set");
// get the x position: LED bumber % 8
ledStateSignal->addIntArg(s.getArgAsInt32(1) % 8);
// get the y position: LED number / 8
ledStateSignal->addIntArg(s.getArgAsInt32(1) / 8);
// get the LED state: toggleState
ledStateSignal->addIntArg(s.getArgAsInt32(2));
_mCenter->handleSignal(*ledStateSignal);
return true;
}
示例2: tr
bool MainWindow::loadLearningSignals(Signal& referenceSignal, Signal& distortedSignal)
{
QString referenceFileName = QFileDialog::getOpenFileName(this, tr("Open Reference Physionet ECG File"),
"", tr("Physionet ECG File (*.dat)"));
if(referenceFileName.isEmpty())
return false;
if(!referenceSignal.ReadFile(referenceFileName.toStdWString().c_str()))
{
QMessageBox::warning(this, "Warning", "Failed to load file " + referenceFileName);
return false;
}
QString distortedFileName = QFileDialog::getOpenFileName(this, tr("Open Distorted Physionet ECG File"),
"", tr("Physionet ECG File (*.dat)"));
if(distortedFileName.isEmpty())
return false;
if(!distortedSignal.ReadFile(distortedFileName.toStdWString().c_str()))
{
QMessageBox::warning(this, "Warning", "Failed to load file " + distortedFileName);
return false;
}
return true;
}
示例3: 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;
}
示例4: fetch
unsigned int FlacDecoder::fetch(Signal& outleft, Signal& outright)
{
outleft.reset();
outright.reset();
if (_opened)
{
unsigned int request_size=Signal::size;
while (request_size > _bufferl.size() - _bufferpos)
{
if (!FLAC__stream_decoder_process_single(_streamdecoder) ||
(FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_READ_FRAME &&
FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_READ_METADATA ))
{
break;
}
}
const unsigned int to_read=request_size >_bufferl.size() - _bufferpos ? _bufferl.size() - _bufferpos : request_size;
for (unsigned int i=0; i < to_read; i++)
{
outleft.samples[i]=_bufferl.at(_bufferpos);
outright.samples[i]=_bufferr.at(_bufferpos++);
}
if (to_read == 0)
{
_ended=true;
}
return to_read;
}
_ended=true;
return 0;
}
示例5: error
/**
* Message AppConfig::getMessage(QVector<QString> messageBlock)
*
* Takes a block of strings corresponding to one CAN message definition as
* input and returns a Message struct with all applicable parameters set. This
* function will throw errors if the input data is missing or malformed.
*
* @param messageBlock - The block of strings corresponding to one CAN message
* defintion
* @returns A Message struct with all applicable parameters set, or an empty
* Message struct if an error occurred.
*/
Message AppConfig::getMessage(QVector<QString> messageBlock) {
QString msgDef = messageBlock[0];
QStringList sections = msgDef.split(" ", QString::SkipEmptyParts);
if (sections.size() != 5) {
emit error("Invalid message definition.");
return Message();
}
Message msg;
bool successful = true;
msg.id = sections[1].toUInt(&successful);
if (!successful) {
emit error(QString("Invalid message ID"));
return Message();
}
msg.dlc = sections[3].toUInt(&successful);
if (!successful) {
emit error(QString("Invalid DLC for message with ID: %1").arg(QString::number(msg.id, 16)));
return Message();
}
for (int i = 1; i < messageBlock.size(); i++) {
Signal sig = getSignal(messageBlock[i]);
if (!sig.valid()) {
return Message();
}
msg.sigs.push_back(sig);
}
return msg;
}
示例6: test1
void test1()
{
Signal<int> signal;
Test test1(1);
{
Test test2(2);
test1.connector.connect(signal);
signal.assert(100);
test2.connector.connect(signal);
signal.assert(200);
{
Test2 test3(3,&test2);
test3.connector.connect(signal);
signal.assert(2);
signal.assert(2);
}
}
signal.assert(300);
}
示例7: TestCase
// This method is cloned from Operator, just resetting sign and exception bits
// (because we don't have any exception support in this toy example)
TestCase* FPSumOf3Squares::buildRandomTestCase(int i){
TestCase *tc;
/* Generate test cases using random input numbers */
tc = new TestCase(this); // TODO free all this memory when exiting TestBench
/* Fill inputs */
for (unsigned int j = 0; j < ioList_.size(); j++) {
Signal* s = ioList_[j];
if (s->type() == Signal::in) {
// ****** Modification: positive normal numbers with small exponents
mpz_class m = getLargeRandom(wF);
mpz_class bias = (mpz_class(1)<<(wE-1)) - 1;
mpz_class e = getLargeRandom(wE-2) - (mpz_class(1)<<(wE-3)) + bias; // ensure no overflow
mpz_class a = (mpz_class(1)<<(wE+wF+1)) // 01 to denote a normal number
+ (e<<wF) + m;
tc->addInput(s->getName(), a);
}
}
/* Get correct outputs */
emulate(tc);
// cout << tc->getInputVHDL();
// cout << tc->getExpectedOutputVHDL();
return tc;
}
示例8: TEST
TEST(ConnectionList, MoveAssignmentOperator)
{
Signal<void(std::string)> nameChanged;
std::string name;
ConnectionList connections1;
{
ConnectionList connections2;
connections2 += nameChanged.Connect([&](std::string const& n) {
name = n;
});
nameChanged("alice");
EXPECT_EQ("alice", name);
connections1 = std::move(connections2);
nameChanged("bob");
EXPECT_EQ("bob", name);
connections2.Disconnect();
nameChanged("chuck");
EXPECT_EQ("chuck", name);
}
nameChanged("norris");
EXPECT_EQ("norris", name);
connections1.Disconnect();
nameChanged("gates");
EXPECT_EQ("norris", name);
}
示例9: getClkName
string Operator::buildVHDLRegisters() {
ostringstream o,l;
if (isSequential()){
if(getClkName().compare("") == 0) {
std::cerr << "-- Can't find clock port for sequential component" << std::endl;
return "";
}
std::string clk = getClkName();
o << "-- clkname = " << clk << endl;
o << tab << "process("<< clk <<") begin\n"
<< tab << tab << "if "<< clk << "'event and "<< clk <<"= '1' then\n";
for(unsigned int i=0; i<signalList_.size(); i++) {
Signal *s = signalList_[i];
if(s->getLifeSpan() >0) {
for(int j=1; j <= s->getLifeSpan(); j++)
l << tab <<tab << tab << s->delayedName(j) << " <= " << s->delayedName(j-1) <<";" << endl;
}
}
// when there are not registers then we don't need that process stmnt
if (l.str().compare("") == 0) return l.str();
o << l.str();
o << tab << tab << "end if;\n";
o << tab << "end process;\n";
}
return o.str();
}
示例10: throw
void Operator::syncCycleFromSignal(string name, bool report) throw(std::string) {
ostringstream e;
e << "ERROR in syncCycleFromSignal, "; // just in case
if(isSequential()) {
Signal* s;
try {
s=getSignalByName(name);
}
catch (string e2) {
e << endl << tab << e2;
throw e.str();
}
if( s->getCycle() < 0 ) {
ostringstream o;
o << "signal " << name << " doesn't have (yet?) a valid cycle";
throw o.str();
}
// advance cycle if needed
if (s->getCycle()>currentCycle_)
currentCycle_ = s->getCycle();
if(report)
vhdl << tab << "----------------Synchro barrier, entering cycle " << currentCycle_ << "----------------" << endl ;
// automatically update pipeline depth of the operator
if (currentCycle_ > pipelineDepth_)
pipelineDepth_ = currentCycle_;
}
}
示例11: DoSeek
bool Stream_File::DoSeek(Signal &sig, long offset, size_t offsetPrev, SeekMode seekMode)
{
if (_hFile == INVALID_HANDLE_VALUE) return true;
if (_map.hFileMappingObject == nullptr) {
DWORD dwMoveMethod =
(seekMode == SeekSet)? FILE_BEGIN :
(seekMode == SeekCur)? FILE_CURRENT : FILE_BEGIN;
DWORD dwPtr = ::SetFilePointer(_hFile, offset, nullptr, dwMoveMethod);
if (dwPtr == INVALID_SET_FILE_POINTER) {
sig.SetError(ERR_IOError, "seek error");
return false;
}
} else {
if (seekMode == SeekSet) {
_map.offset = static_cast<size_t>(offset);
} else if (seekMode == SeekCur) {
if (offset < 0 && _map.offset < static_cast<size_t>(-offset)) {
sig.SetError(ERR_IOError, "seek error");
return false;
}
_map.offset = static_cast<size_t>(_map.offset + offset);
}
if (_map.offset > _map.bytes) {
sig.SetError(ERR_IOError, "seek error");
return false;
}
}
return true;
}
示例12: TEST_F
TEST_F(SignalTest, DeferredSynchronousSignal) {
cout << "Instantiating signal object" << endl;
Signal<int, int> testSignal;
BasicTimer bt;
cout << "Connecting signal" << endl;
bt.start();
testSignal.connectSlot(ExecutorScheme::DEFERRED_SYNCHRONOUS, staticSumFunction);
bt.stop();
cout << "Time to connect: " << bt.getElapsedMilliseconds() << "ms" << endl;
cout << "Emitting signal" << endl;
bt.start();
testSignal(1, 2);
bt.stop();
cout << "Time to emit: " << bt.getElapsedMilliseconds() << "ms" << endl;
ASSERT_NE(globalStaticIntX, 3);
testSignal.invokeDeferred();
ASSERT_EQ(globalStaticIntX, 3);
testSignal.disconnectSlot(0);
}
示例13: main
int main()
{
Signal<int> sig;
sig.AddListener(argHandler);
sig.AddListener(noargHandler);
sig.Dispatch(22);
}
示例14: BuildSignal
void SegmentDescription::BuildSignal(Signal & signal) const
{
signal.Reset();
for (size_t i = 0; i < cores.size(); ++i)
{
cores[i].AddToArray(signal.GetData(), signal.GetDesc().N);
}
}
示例15: main
int main()
{
Signal<int, int> sig;
sig.AddListener(twoArgHandler);
sig.AddListener([](int a, int b) { oneArgHandler(a); });
sig.AddListener(noArgHandler);
sig.Dispatch(22, 12);
}