当前位置: 首页>>代码示例>>C++>>正文


C++ PortReaderBuffer类代码示例

本文整理汇总了C++中PortReaderBuffer的典型用法代码示例。如果您正苦于以下问题:C++ PortReaderBuffer类的具体用法?C++ PortReaderBuffer怎么用?C++ PortReaderBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PortReaderBuffer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
开发者ID:robotology,项目名称:yarp,代码行数:30,代码来源:PortablePairTest.cpp

示例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();
    }
开发者ID:JoErNanO,项目名称:yarp,代码行数:33,代码来源:PortTest.cpp

示例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();
    }
开发者ID:JoErNanO,项目名称:yarp,代码行数:31,代码来源:PortTest.cpp

示例4: testInt

    void testInt() {
        report(0,"checking binary read/write of native int");
        BinPortable<int> i;
        i.content() = 5;

        PortReaderBuffer<BinPortable<int> > buf;
        Port input, output;
        bool ok1 = input.open("/in");
        bool ok2 = output.open("/out");
        checkTrue(ok1&&ok2,"ports opened ok");
        if (!(ok1&&ok2)) {
            return;
        }
        //input.setReader(buf);
        buf.attach(input);
        output.addOutput(Contact("/in", "tcp"));
        report(0,"writing...");
        output.write(i);
        report(0,"reading...");
        BinPortable<int> *result = buf.read();
        checkTrue(result!=NULL,"got something check");
        if (result!=NULL) {
            checkEqual(result->content(),5,"value preserved");
        }
        output.close();
        input.close();
    }
开发者ID:apaikan,项目名称:yarp,代码行数:27,代码来源:BinPortableTest.cpp

示例5: 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();
    }
开发者ID:apaikan,项目名称:yarp,代码行数:59,代码来源:ImageTest.cpp

示例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();
    }
开发者ID:JoErNanO,项目名称:yarp,代码行数:46,代码来源:PortTest.cpp

示例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();
 }
开发者ID:JoErNanO,项目名称:yarp,代码行数:20,代码来源:PortTest.cpp

示例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();
    }
开发者ID:JoErNanO,项目名称:yarp,代码行数:41,代码来源:SoundTest.cpp

示例9: checkAccept

    void checkAccept() {
        report(0, "checking direct object accept...");

        PortReaderBuffer<Bottle> buffer;
        Bottle dummy;
        Bottle data("hello");
        Bottle data2("there");

        buffer.acceptObject(&data, &dummy);
        
        Bottle *bot = buffer.read();
        checkTrue(bot!=NULL,"Inserted message received");
        if (bot!=NULL) {
            checkEqual(bot->toString().c_str(),"hello","value ok");
        }

        buffer.acceptObject(&data2, NULL);

        bot = buffer.read();
        checkTrue(bot!=NULL,"Inserted message received");
        if (bot!=NULL) {
            checkEqual(bot->toString().c_str(),"there","value ok");
        }
        
        buffer.read(false);
    }
开发者ID:JoErNanO,项目名称:yarp,代码行数:26,代码来源:PortReaderBufferTest.cpp

示例10: 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();
    }
开发者ID:JoErNanO,项目名称:yarp,代码行数:43,代码来源:PortTest.cpp


注:本文中的PortReaderBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。