本文整理汇总了C++中PortReaderBuffer::setStrict方法的典型用法代码示例。如果您正苦于以下问题:C++ PortReaderBuffer::setStrict方法的具体用法?C++ PortReaderBuffer::setStrict怎么用?C++ PortReaderBuffer::setStrict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PortReaderBuffer
的用法示例。
在下文中一共展示了PortReaderBuffer::setStrict方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkTransmit
void checkTransmit() {
report(0,"testing pair transmission...");
PortablePair<Bottle,Bottle> pp;
pp.head.fromString("1 2 3");
pp.body.fromString("yes no");
PortReaderBuffer< PortablePair<Bottle,Bottle> > buf;
Port input, output;
input.open("/in");
output.open("/out");
buf.setStrict();
buf.attach(input);
Network::connect("/out","/in");
report(0,"writing...");
output.write(pp);
report(0,"reading...");
PortablePair<Bottle,Bottle> *result = buf.read();
checkTrue(result!=nullptr,"got something check");
if (result!=nullptr) {
checkEqual(result->head.size(),(size_t) 3,"head len is right");
checkEqual(result->body.size(),(size_t) 2,"body len is right");
}
output.close();
input.close();
}
示例2: testPair
void testPair() {
report(0,"checking paired send/receive");
PortReaderBuffer<PortablePair<Bottle,Bottle> > buf;
Port input, output;
input.open("/in");
output.open("/out");
buf.setStrict();
buf.attach(input);
output.addOutput(Contact::byName("/in").addCarrier("tcp"));
//Time::delay(0.2);
PortablePair<Bottle,Bottle> bot1;
bot1.head.fromString("1 2 3");
bot1.body.fromString("4 5 6 7");
report(0,"writing...");
output.write(bot1);
bool ok = output.write(bot1);
checkTrue(ok,"output proceeding");
report(0,"reading...");
PortablePair<Bottle,Bottle> *result = buf.read();
checkTrue(result!=NULL,"got something check");
checkEqual(bot1.head.size(),result->head.size(),"head size check");
checkEqual(bot1.body.size(),result->body.size(),"body size check");
output.close();
input.close();
}
示例3: testInterrupt
void testInterrupt() {
report(0,"checking interrupt...");
PortReaderBuffer<PortablePair<Bottle,Bottle> > buf;
Port input, output;
input.open("/in");
output.open("/out");
buf.setStrict();
buf.attach(input);
output.addOutput(Contact::byName("/in").addCarrier("tcp"));
//Time::delay(0.2);
PortablePair<Bottle,Bottle> bot1;
bot1.head.fromString("1 2 3");
bot1.body.fromString("4 5 6 7");
report(0,"interrupting...");
output.interrupt();
report(0,"writing...");
bool ok = output.write(bot1);
checkFalse(ok,"output rejected correctly");
output.resume();
ok = output.write(bot1);
checkTrue(ok,"output goes through after resume");
output.close();
input.close();
}
示例4: testTransmit
void testTransmit() {
report(0,"testing image transmission...");
ImageOf<PixelRgb> img1;
img1.resize(128,64);
for (int x=0; x<img1.width(); x++) {
for (int y=0; y<img1.height(); y++) {
PixelRgb& pixel = img1.pixel(x,y);
pixel.r = x;
pixel.g = y;
pixel.b = 42;
}
}
PortReaderBuffer< ImageOf<PixelRgb> > buf;
Port input, output;
buf.setStrict();
buf.attach(input);
input.open("/in");
output.open("/out");
output.addOutput(Contact("/in", "tcp"));
Time::delay(0.2);
report(0,"writing...");
output.write(img1);
output.write(img1);
output.write(img1);
report(0,"reading...");
ImageOf<PixelRgb> *result = buf.read();
checkTrue(result!=NULL,"got something check");
if (result!=NULL) {
checkEqual(img1.width(),result->width(),"width check");
checkEqual(img1.height(),result->height(),"height check");
if (img1.width()==result->width() &&
img1.height()==result->height()) {
int mismatch = 0;
for (int x=0; x<img1.width(); x++) {
for (int y=0; y<img1.height(); y++) {
PixelRgb& pix0 = img1.pixel(x,y);
PixelRgb& pix1 = result->pixel(x,y);
if (pix0.r!=pix1.r ||
pix0.g!=pix1.g ||
pix0.b!=pix1.b) {
mismatch++;
}
}
}
checkTrue(mismatch==0,"pixel match check");
}
}
output.close();
input.close();
}
示例5: testReadBuffer
void testReadBuffer() {
report(0,"checking read buffering");
Bottle bot1;
PortReaderBuffer<Bottle> buf;
buf.setStrict(true);
bot1.fromString("1 2 3");
for (int i=0; i<10000; i++) {
bot1.addInt(i);
}
Port input, output;
input.open("/in");
output.open("/out");
buf.setStrict();
buf.attach(input);
output.addOutput(Contact::byName("/in").addCarrier("udp"));
//Time::delay(0.2);
report(0,"writing...");
output.write(bot1);
output.write(bot1);
output.write(bot1);
report(0,"reading...");
Bottle *result = buf.read();
for (int j=0; j<3; j++) {
if (j!=0) {
result = buf.read();
}
checkTrue(result!=NULL,"got something check");
if (result!=NULL) {
checkEqual(bot1.size(),result->size(),"size check");
YARP_INFO(Logger::get(),String("size is in fact ") +
NetType::toString(result->size()));
}
}
output.close();
input.close();
}
示例6: testHeavy
void testHeavy() {
report(0,"checking heavy udp");
Bottle bot1;
PortReaderBuffer<Bottle> buf;
bot1.fromString("1 2 3");
for (int i=0; i<100000; i++) {
bot1.addInt(i);
}
Port input, output;
input.open("/in");
output.open("/out");
buf.setStrict();
buf.attach(input);
output.addOutput(Contact::byName("/in").addCarrier("udp"));
//Time::delay(0.2);
for (int j=0; j<3; j++) {
report(0,"writing/reading three times...");
output.write(bot1);
}
report(0,"checking for whatever got through...");
int ct = 0;
while (buf.check()) {
ct++;
Bottle *result = buf.read();
checkTrue(result!=NULL,"got something check");
if (result!=NULL) {
checkEqual(bot1.size(),result->size(),"size check");
YARP_INFO(Logger::get(),String("size is in fact ") +
NetType::toString(result->size()));
}
}
if (ct==0) {
report(0,"NOTHING got through - possible but sad");
}
output.close();
input.close();
}
示例7: testReaderHandler
virtual void testReaderHandler() {
report(0,"check reader handler...");
Port in;
Port out;
DelegatedCallback callback;
out.open("/out");
in.open("/in");
Network::connect("/out","/in");
PortReaderBuffer<Bottle> reader;
reader.setStrict();
reader.attach(in);
reader.useCallback(callback);
Bottle src("10 10 20");
out.write(src);
callback.produce.wait();
checkEqual(callback.saved.size(),3,"object came through");
reader.disableCallback();
out.close();
in.close();
}
示例8: checkTransmit
void checkTransmit() {
report(0,"checking sound transmission...");
Sound snd1;
snd1.resize(128);
snd1.setFrequency(50);
for (int i=0; i<snd1.getSamples(); i++) {
snd1.set(i-snd1.getSamples()/2,i);
}
PortReaderBuffer<Sound> buf;
Port input, output;
input.open("/in");
output.open("/out");
buf.setStrict();
buf.attach(input);
Network::connect("/out","/in");
report(0,"writing...");
output.write(snd1);
report(0,"reading...");
Sound *result = buf.read();
checkTrue(result!=NULL,"got something check");
if (result!=NULL) {
checkEqual(snd1.getSamples(),result->getSamples(),
"sample ct check");
checkEqual(snd1.getFrequency(),result->getFrequency(),
"freq check");
bool ok = true;
for (int i=0; i<result->getSamples(); i++) {
ok = ok && (result->get(i) == snd1.get(i));
}
checkTrue(ok,"sample values match");
}
output.close();
input.close();
}