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


C++ Bottle::fromString方法代码示例

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


在下文中一共展示了Bottle::fromString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {
    Network yarp;
    Carriers::addCarrierPrototype(new HumanCarrier);

    if (argc<2) {
        printf("Please run in two terminals as:\n");
        printf("  carrier_human --server\n");
        printf("  carrier_human --client\n");
        exit(1);
    }

    string mode = argv[1];

    if (mode == "--server") {
        Port out;
        out.open("/test/out");
        bool connected = false;
        while (!connected) {
            connected = Network::connect("/test/out","/test/in","human");
            if (!connected) Time::delay(1);
        }
        Bottle bot;
        bot.fromString("1 2 3");
        out.write(bot);
        out.close();
    }

    if (mode == "--client") {
        Port in;
        in.open("/test/in");
        Bottle bot;
        in.read(bot);
        printf("Got message %s\n", bot.toString().c_str());
        in.close();
    }

    return 0;
}
开发者ID:AbuMussabRaja,项目名称:yarp,代码行数:38,代码来源:carrier_human.cpp

示例2: blk

bool yarp::os::impl::HttpCarrier::expectSenderSpecifier(Protocol& proto) {
    proto.setRoute(proto.getRoute().addFromName("web"));
    String remainder = NetType::readLine(proto.is());
    if (!urlDone) {
        for (unsigned int i=0; i<remainder.length(); i++) {
            if (remainder[i]!=' ') {
                url += remainder[i];
            } else {
                break;
            }
        }
    }

    bool done = false;
    expectPost = false;
    contentLength = 0;
    while (!done) {
        String result = NetType::readLine(proto.is());
        if (result == "") {
            done = true;
        } else {
            //printf(">>> %s\n", result.c_str());
            Bottle b;
            b.fromString(result.c_str());
            if (b.get(0).asString()=="Content-Length:") {
                //printf("]]] got length %d\n", b.get(1).asInt());
                contentLength = b.get(1).asInt();
            }
            if (b.get(0).asString()=="Content-Type:") {
                //printf("]]] got type %s\n", b.get(1).asString());
                if (b.get(1).asString()=="application/x-www-form-urlencoded") {
                    expectPost = true;
                }
            }
        }
    }

    if (expectPost) {
        //printf("[[[this is a post message of length %d]]]\n", contentLength);
        ManagedBytes blk(contentLength+1);
        Bytes start(blk.get(),contentLength);
        NetType::readFull(proto.is(),start);
        blk.get()[contentLength] = '\0';
        //printf("message: %s\n", blk.get());
        input = blk.get();
    } else {
        //printf("message: %s\n", url.c_str());
        input = url;
    }
    prop.fromQuery(input.c_str());
    prop.put("REQUEST_URI",url.c_str());
    //printf("Property %s\n",prop.toString().c_str());

    Contact chome = NetworkBase::getNameServerContact();
    Address home = Address::fromContact(chome);
    Address me = proto.getStreams().getLocalAddress();

    String from = "<html><head><link href=\"http://";
    from += home.getName();
    from += ":";
    from += NetType::toString(home.getPort());
    from += "/web/main.css\" rel=\"stylesheet\" type=\"text/css\"/></head><body bgcolor='#ffffcc'><h1>yarp port ";
    from += proto.getRoute().getToName();
    from += "</h1>\n";

    from += "<p>(<a href=\"http://";
    from += home.getName();
    from += ":";
    from += NetType::toString(home.getPort());
    from += "/data=list\">All ports</a>)&nbsp;&nbsp;\n";

    from += "(<a href=\"http://";
    from += me.getName();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/\">connections</a>)&nbsp;&nbsp;\n";

    from += "(<a href=\"http://";
    from += me.getName();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/data=help\">help</a>)&nbsp;&nbsp;\n";

    from += "(<a href=\"http://";
    from += me.getName();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/r\">read</a>)&nbsp;&nbsp;\n";

    from += "</p>\n";
    from += "<p>\n";
    from += "<form method=\"post\" action=\"http://";
    from += me.getName();
    from += ":";
    from += NetType::toString(me.getPort());
    from += "/form\">";

    prefix = from;


//.........这里部分代码省略.........
开发者ID:paulfitz,项目名称:yarp,代码行数:101,代码来源:HttpCarrier.cpp

示例3: main

int main(int argc, char *argv[])
{
    if (argc<=1) {
        show_usage();
        return 0;
    }
    if (std::string("help")==argv[1] || std::string("--help")==argv[1]) {
        show_usage();
        return 0;
    }

    Property p;
    p.fromCommand(argc,argv);

    if (!(p.check("name")||p.check("cmd"))) {
        return generate_cpp(argc,argv);
    }
    if (!p.check("soft")) {
        p.put("soft",1);
    }
    if (!p.check("web")) {
        p.put("web",1);
    }

    bool has_cmd = p.check("cmd");
    bool verbose = p.check("verbose");

    RosTypeSearch env;
    configure_search(env,p);

    Network yarp;
    Port port;
    if (!has_cmd) {
        // Borrow an accidentally-available service type on ROS, in
        // order to avoid adding build dependencies for now.
        port.promiseType(Type::byNameOnWire("test_roscpp/TestStringString"));
        port.setRpcServer();
        if (!port.open(p.find("name").asString())) {
            return 1;
        }
    }
    while (true) {
        Bottle req;
        if (has_cmd) {
            req = p.findGroup("cmd").tail();
        } else {
            if (!port.read(req,true)) {
                continue;
            }
        }
        if (req.size()==1) {
            req.fromString(req.get(0).asString());
        }
        if (verbose) {
            printf("Request: %s\n", req.toString().c_str());
        }
        Bottle resp;
        ConstString tag = req.get(0).asString();
        string fname0 = req.get(1).asString().c_str();
        string fname = env.findFile(fname0.c_str());
        string txt = "";
        if (tag=="raw") {
            txt = env.readFile(fname.c_str());
            resp.addString(txt);
        } else if (tag=="twiddle") {
            RosTypeCodeGenYarp gen;
            RosType t;
            if (t.read(fname0.c_str(),env,gen)) {
                ConstString txt;
                generateTypeMap(t,txt);
                resp.addString(txt);
            } else {
                resp.addString("?");
            }
        } else {
            resp.addString("?");
        }
        if (!has_cmd) port.reply(resp);
        if (verbose||has_cmd) {
            printf("Response: %s\n", resp.toString().c_str());
        }
        if (has_cmd) break;
    }
    return 0;
}
开发者ID:BRKMYR,项目名称:yarp,代码行数:85,代码来源:main.cpp

示例4: main


//.........这里部分代码省略.........
    ok &= dd.view(iopenloop);
	ok &= dd.view(iimp);
    ok &= dd.view(posDir);
    ok &= dd.view(iMode2);
    ok &= dd.view(iInteract);

    if (!ok) {
        printf("Problems acquiring interfaces\n");
        return 1;
    }

    pos->getAxes(&jnts);
    printf("Working with %d axes\n", jnts);
    double *tmp = new double[jnts];

    printf("Device active...\n");
    while (dd.isValid()) {
        std::string s;
        s.resize(1024);
        
        printf("-> ");
        char c = 0;
        int i = 0;
        while (c != '\n') {
            c = (char)fgetc(stdin);
            s[i++] = c;
        }
        s[i-1] = s[i] = 0;

        Bottle p;
        Bottle response;
        bool ok=false;
        bool rec=false;
        p.fromString(s.c_str());
        printf("Bottle: %s\n", p.toString().c_str());

        switch(p.get(0).asVocab()) {      
        case VOCAB_HELP:
            printf("\n\n");
            printf("Available commands:\n");
			printf("-------------------\n\n");

            printf("IOpenLoop:\ntype [%s] and one of the following:\n", Vocab::decode(VOCAB_IOPENLOOP).c_str());
            printf("	[set] [%s] <int> <float>\n",
                    Vocab::decode(VOCAB_OUTPUT).c_str());
            printf("	[get] [%s] <int>\n",
                    Vocab::decode(VOCAB_OUTPUT).c_str());
            printf("	[get] [%s]\n\n",
                    Vocab::decode(VOCAB_OUTPUTS).c_str());

            printf("IControlMode:\ntype [%s] and one of the following:\n", Vocab::decode(VOCAB_ICONTROLMODE).c_str());
            printf("	[set] [%s]|[%s]|[%s]|[%s]|[%s]|[%s]|[%s]|[%s][%s]|[%s]\n",
                    Vocab::decode(VOCAB_CM_POSITION).c_str(),
                    Vocab::decode(VOCAB_CM_POSITION_DIRECT).c_str(),
                    Vocab::decode(VOCAB_CM_VELOCITY).c_str(),
                    Vocab::decode(VOCAB_CM_MIXED).c_str(),
                    Vocab::decode(VOCAB_CM_TORQUE).c_str(),
                    Vocab::decode(VOCAB_CM_OPENLOOP).c_str(),
                    Vocab::decode(VOCAB_CM_IDLE).c_str(),
                    Vocab::decode(VOCAB_CM_FORCE_IDLE).c_str(),
                    Vocab::decode(VOCAB_CM_IMPEDANCE_POS).c_str(),
                    Vocab::decode(VOCAB_CM_IMPEDANCE_VEL).c_str());
            
            printf("	[get] [%s] <int>\n\n",
                Vocab::decode(VOCAB_CM_CONTROL_MODE).c_str());
开发者ID:lorejam,项目名称:icub-main,代码行数:66,代码来源:main.cpp

示例5: main

int main(int argc, char *argv[]) 
{
    // just list the devices if no argument given
    if (argc <= 2) {
        printf("You can call %s like this:\n", argv[0]);
        printf("   %s --robot ROBOTNAME --OPTION VALUE ...\n", argv[0]);
        printf("For example:\n");
        printf("   %s --robot icub --part any --remote /controlboard\n", argv[0]);
        printf("Here are devices listed for your system:\n");
        printf("%s", Drivers::factory().toString().c_str());
        return 0;
    }

    // get command line options
    Property options;
    options.fromCommand(argc, argv);
    if (!options.check("robot") || !options.check("part")) {
        printf("Missing either --robot or --part options\n");
        return 0;
    }

    Network yarp;
	Time::turboBoost();
    
    char name[1024];
    Value& v = options.find("robot");
    Value& part = options.find("part");

    Value *val;
    if (!options.check("device", val)) {
        options.put("device", "remote_controlboard");
    }
    if (!options.check("local", val)) {
        sprintf(name, "/%s/%s/client", v.asString().c_str(), part.asString().c_str());
        options.put("local", name);
    }
    if (!options.check("remote", val)) {
        sprintf(name, "/%s/%s", v.asString().c_str(), part.asString().c_str());
        options.put("remote", name);
    }

	fprintf(stderr, "%s", options.toString().c_str());

    
    // create a device 
    PolyDriver dd(options);
    if (!dd.isValid()) {
        printf("Device not available.  Here are the known devices:\n");
        printf("%s", Drivers::factory().toString().c_str());
        return 1;
    }

    IPositionControl *pos;
    IVelocityControl *vel;
    IEncoders *enc;
    IPidControl *pid;
    IAmplifierControl *amp;
    IControlLimits *lim;

    bool ok;
    ok = dd.view(pos);
    ok &= dd.view(vel);
    ok &= dd.view(enc);
    ok &= dd.view(pid);
    ok &= dd.view(amp);
    ok &= dd.view(lim);

    if (!ok) {
        printf("Problems acquiring interfaces\n");
        return 1;
    }

    int jnts = 0;
    pos->getAxes(&jnts);
    printf("Working with %d axes\n", jnts);
    double *tmp = new double[jnts];
    assert (tmp != NULL);

    printf("Device active...\n");
    while (dd.isValid()) {
        char s[1024];
        
        printf("-> ");
        char c = 0;
        int i = 0;
        while (c != '\n') {
            c = (char)fgetc(stdin);
            s[i++] = c;
        }
        s[i-1] = s[i] = 0;

        Bottle p;
        p.fromString(s);
        printf("Bottle: %s\n", p.toString().c_str());

        switch(p.get(0).asVocab()) {        
        case VOCAB_HELP:
            printf("\n\n");
            printf("Available commands:\n\n");

//.........这里部分代码省略.........
开发者ID:AbuMussabRaja,项目名称:yarp,代码行数:101,代码来源:simple_motor_client.cpp

示例6: write

bool XmlRpcCarrier::write(Protocol& proto, SizedWriter& writer) {
    //XmlRpc::setVerbosity(10);
    StringOutputStream sos;
    StringInputStream sis;
    writer.write(sos);
    sis.reset(sos.toString());
    String header;
    if (sender) {
        header = NetType::readLine(sis);
    }
    String body = NetType::readLine(sis);
    //printf("Asked to write: hdr %s body %s\n",
    //     header.c_str(), body.c_str());
    Value v;
    //printf("HEADER %s\n", header.c_str());
    if (header[0]=='q') {
        body = "yarp.quit";
        // XMLRPC does not need a quit message, this should get stripped
        return false;
    }
    Bottle *bot = v.asList();
    //Bottle aux;
    bot->fromString(body.c_str());
    ConstString methodName;
    if (sender) {
        methodName = bot->get(0).toString();
        *bot = bot->tail();
    }
    XmlRpcValue args;
    if (bot->size()==1) {
        toXmlRpcValue(bot->get(0),args);
    } else {
        toXmlRpcValue(v,args);
    }
    //printf("xmlrpc block to write is %s\n", args.toXml().c_str());
    std::string req;
    if (sender) {
        const Address& addr = host.isValid()?host:proto.getStreams().getRemoteAddress();
        XmlRpcClient c(addr.getName().c_str(),(addr.getPort()>0)?addr.getPort():80);
        c.generateRequest(methodName.c_str(),args);
        req = c.getRequest();
    } else {
        XmlRpcServerConnection c(0,NULL);
        c.generateResponse(args.toXml());
        req = c.getResponse();
    }
    int start = 0;
    //printf("converts to %s\n", req.c_str());
    if (sender) {
        if (req.length()<8) {
            fprintf(stderr, "XmlRpcCarrier fail, %s:%d\n", __FILE__, __LINE__);
            return false;
        }
        for (int i=0; i<(int)req.length(); i++) {
            if (req[i] == '\n') {
                start++;
                break;
            }
            start++;
        }
        if (!firstRound) {
            Bytes b((char*)http.c_str(),http.length());
            proto.os().write(b);
        }
        firstRound = false;
    }
    Bytes b((char*)req.c_str()+start,req.length()-start);
    //printf("WRITING [%s]\n", req.c_str()+start);
    proto.os().write(b);

    return proto.os().isOk();
}
开发者ID:paulfitz,项目名称:yarp,代码行数:72,代码来源:XmlRpcCarrier.cpp

示例7: fromString

 void fromString(const ConstString& txt,bool wipe=true) {
     Bottle bot;
     bot.fromString(txt);
     fromBottle(bot,wipe);
 }
开发者ID:JoErNanO,项目名称:yarp,代码行数:5,代码来源:Property.cpp

示例8: fromConfig


//.........这里部分代码省略.........
                                            tag = "";
                                        }
                                        ConstString subName, fname;
                                        if (bot.size()==3) {
                                            // [include section "filename"]
                                            subName = bot.get(1).toString();
                                            fname = bot.get(2).toString();
                                        } else if (bot.size()==4) {
                                            // [include type section "filename"]
                                            ConstString key;
                                            key = bot.get(1).toString();
                                            subName = bot.get(2).toString();
                                            fname = bot.get(3).toString();
                                            Bottle *target =
                                                getBottle(key.c_str());
                                            if (target==NULL) {
                                                Bottle init;
                                                init.addString(key.c_str());
                                                init.addString(subName.c_str());
                                                putBottleCompat(key.c_str(),
                                                                init);
                                            } else {
                                                target->addString(subName.c_str());
                                            }
                                        } else {
                                            YARP_ERROR(Logger::get(),
                                                       String("bad include"));
                                            return;
                                        }


                                        Property p;
                                        if (getBottle(subName)!=NULL) {
                                            p.fromString(getBottle(subName)->tail().toString());
                                            //printf(">>> prior p %s\n",
                                            //     p.toString().c_str());
                                        }
                                        p.fromConfigFile(fname.c_str(),
                                                         env, false);
                                        accum.fromString(p.toString());
                                        tag = subName.c_str();
                                        //printf(">>> tag %s accum %s\n",
                                        //     tag.c_str(),
                                        //     accum.toString().c_str());
                                        if (tag!="") {
                                            if (accum.size()>=1) {
                                                Bottle b;
                                                b.addString(tag.c_str());
                                                //Bottle& subList = b.addList();
                                                //subList.copy(accum);
                                                b.append(accum);
                                                putBottleCompat(tag.c_str(),
                                                                b);
                                            }
                                            tag = "";
                                        }
                                    } else {
                                        tag = "";
                                        ConstString fname =
                                            bot.get(1).toString();
                                        //printf("Including %s\n", fname.c_str());
                                        fromConfigFile(fname.c_str(),
                                                       env, false);
                                    }
                                }
                            }
开发者ID:JoErNanO,项目名称:yarp,代码行数:67,代码来源:Property.cpp

示例9: main

int main(int ntargets, char *targets[]) {
    Network yarp;
    Port port;

    string hist_file(getenv("HOME") );
    hist_file += "/.yarp_write_history";

    read_history(hist_file.c_str());
    if (companion_active_port==NULL) {
        companion_install_handler();
    }
    ntargets--;
    targets++;
    
    if (!port.open(targets[0])) {
        printf("\nCould not open write port.\n");
        return 1;
    }
    ntargets--;
    targets++;

    if (adminMode) {
        port.setAdminMode();
    }

    bool raw = false;
    for (int i=0; i<ntargets; i++) {
        if (string(targets[i])=="verbatim") {
            raw = true;
        } else {
            if (!yarp.connect(port.getName().c_str(),targets[i])) {
			   printf("\nCould not connect ports\n");	
                     return 1; 
            }
        }
    }

	printf("\nTo stop: CTRL+C ENTER\n\n");
	rl_catch_signals = 1;
	rl_set_signals();
    while (!done) {
	    rl_on_new_line();
        string txt(rl_gets());
        if (!done) {
            if (txt[0]<32 && txt[0]!='\n' &&
                txt[0]!='\r' && txt[0]!='\0' && txt[0]!='\t') {
                break;  // for example, horrible windows ^D
            }
            Bottle bot;
            if (raw) {
                bot.addInt(0);
                bot.addString(txt.c_str());
            } else {
                bot.fromString(txt.c_str());
            }
            //core.send(bot);
            port.write(bot);
        }
    }

    write_history(hist_file.c_str());
    companion_active_port = NULL;

    if (raw) {
        Bottle bot;
        bot.addInt(1);
        bot.addString("<EOF>");
        //core.send(bot);
        port.write(bot);
    }

    port.close();

    return 0;
}
开发者ID:hauptmech,项目名称:stupid_yarp_tricks,代码行数:75,代码来源:main.cpp

示例10: if

ICubClient::ICubClient(const std::string &moduleName, const std::string &context, const std::string &clientConfigFile, bool isRFVerbose)
{
    yarp::os::ResourceFinder rfClient;
    rfClient.setVerbose(isRFVerbose);
    rfClient.setDefaultContext(context.c_str());
    rfClient.setDefaultConfigFile(clientConfigFile.c_str());
    rfClient.configure(0,NULL);

    yarp::os::ResourceFinder rfPostures;
    rfPostures.setVerbose(isRFVerbose);
    rfPostures.setDefaultContext(context.c_str());
    rfPostures.setDefaultConfigFile(rfClient.check("posturesFile",Value("postures.ini")).asString().c_str());
    rfPostures.configure(0,NULL);

    yarp::os::ResourceFinder rfChoregraphies;
    rfChoregraphies.setVerbose(isRFVerbose);
    rfChoregraphies.setDefaultContext(context.c_str());
    rfChoregraphies.setDefaultConfigFile(rfClient.check("choregraphiesFile",Value("choregraphies.ini")).asString().c_str());
    rfChoregraphies.configure(0,NULL);

    LoadPostures(rfPostures);
    LoadChoregraphies(rfChoregraphies);

    //Reaching range
    Bottle defaultRangeMin ;defaultRangeMin.fromString("-0.5 -0.3 -0.15");
    Bottle defaultRangeMax;defaultRangeMax.fromString("-0.1 0.3 0.5");
    Bottle *rangeMin = rfClient.find("reachingRangeMin").asList();
    Bottle *rangeMax = rfClient.find("reachingRangeMax").asList();
    if (rangeMin == NULL) rangeMin = new Bottle(defaultRangeMin);
    if (rangeMax == NULL) rangeMax = new Bottle(defaultRangeMax);
    xRangeMin = defaultRangeMin.get(0).asDouble(); xRangeMax =defaultRangeMax.get(0).asDouble();
    yRangeMin = defaultRangeMin.get(1).asDouble(); yRangeMax =defaultRangeMax.get(1).asDouble();
    zRangeMin = defaultRangeMin.get(2).asDouble(); zRangeMax =defaultRangeMax.get(2).asDouble();

    icubAgent = NULL;

    //OPC
    string fullName = moduleName + "/icubClient";
    opc = new OPCClient(fullName);
    opc->isVerbose = false;

    //Susbsystems
    if (Bottle* bSubsystems = rfClient.find("subsystems").asList())
    {
        for (int s=0; s<bSubsystems->size(); s++)
        {
            std::string currentSS = bSubsystems->get(s).asString();
            cout<<"Trying to open subsystem : "<<currentSS<<endl;
            if (currentSS == SUBSYSTEM_ATTENTION)
                subSystems[SUBSYSTEM_ATTENTION] = new SubSystem_Attention(fullName);
            else if (currentSS == SUBSYSTEM_EXPRESSION)
                subSystems[SUBSYSTEM_EXPRESSION] = new SubSystem_Expression(fullName);
            else if (currentSS == SUBSYSTEM_POSTURES)
                subSystems[SUBSYSTEM_POSTURES] = new SubSystem_Postures(fullName);
            else if (currentSS == SUBSYSTEM_REACTABLE)
                subSystems[SUBSYSTEM_REACTABLE] = new SubSystem_Reactable(fullName);
            else if (currentSS == SUBSYSTEM_IKART)
                subSystems[SUBSYSTEM_IKART] = new SubSystem_iKart(fullName);
            else if (currentSS == SUBSYSTEM_ABM)
                subSystems[SUBSYSTEM_ABM] = new SubSystem_ABM(fullName);
            else if (currentSS == SUBSYSTEM_SPEECH)
                subSystems[SUBSYSTEM_SPEECH] = new SubSystem_Speech(fullName);
            else if (currentSS == SUBSYSTEM_SLIDING_CONTROLLER)
                subSystems[SUBSYSTEM_SLIDING_CONTROLLER] = new SubSystem_SlidingController(fullName);
            else if (currentSS == SUBSYSTEM_ARE)
                subSystems[SUBSYSTEM_ARE] = new SubSystem_ARE(fullName);
        }
    }

    closed=false;
}
开发者ID:traversaro,项目名称:wysiwyd,代码行数:71,代码来源:icubClient.cpp

示例11: snapshot


//.........这里部分代码省略.........
        {
            bTemp = *(bInput.get(i).asList());
            if (bTemp.get(0) == "arguments" && bTemp.size() > 1)
            {
                for (int j = 1; j < bTemp.size(); j++)
                {
                    ostringstream osArg;
                    string cArgArgument, cArgType, cArgSubtype, cArgRole;

                    //check if the argument is an entity in OPC
                    Entity* currentEntity = opcWorld->getEntity(bTemp.get(j).asList()->get(0).toString().c_str());

                    if (currentEntity == NULL) {
                        cArgArgument = bTemp.get(j).asList()->get(0).asString();
                        cArgType = "external";
                        cArgSubtype = "default";
                    }
                    else {
                        cArgArgument = currentEntity->name();
                        cArgType = "entity";
                        cArgSubtype = currentEntity->entity_type();
                    }

                    if (bTemp.get(j).asList()->size() > 1) {
                        cArgRole = bTemp.get(j).asList()->get(1).asString();

                        //add sentence for single img label
                        if (cArgRole == "sentence"){
                            fullSentence = cArgArgument;
                        }
                        if (cArgRole == "semantic"){

                            yInfo() << " " << bTemp.get(j).asList()->get(0).toString();
                            bRecogSemantic.fromString(bTemp.get(j).asList()->get(0).toString());
                            yInfo() << " " << bRecogSemantic.toString();
                            yInfo() << "  bRecog size: " << bRecogSemantic.size();
                            bShouldSend = false;
                        }
                    }
                    else {
                        cArgRole = "unknown";
                    }

                    std::replace( cArgArgument.begin(), cArgArgument.end(), '\'', ' ');

                    if (bShouldSend){
                        osArg << "INSERT INTO contentarg(instance, argument, type, subtype, role) VALUES ( " << instance << ", '" << cArgArgument << "', " << "'" << cArgType << "', '" << cArgSubtype << "', '" << cArgRole << "') ; ";
                    }
                    else{
                        bShouldSend = true;
                    }
                    // one stringstream with all argments
                    osAllArg << osArg.str().c_str();
                }
            }
        }


        // add the snapshot of the OPC
        osAllArg << bSnapShot.get(0).asString();

        bRequest.clear();
        if(osAllArg.str() != "") {
            bRequest.addString("request");
            bRequest.addString(osAllArg.str().c_str());
            request(bRequest);
开发者ID:caomw,项目名称:wysiwyd,代码行数:67,代码来源:snapshots.cpp

示例12: main

int main(int argc, char *argv[]) {
    Network yarp;
    Port output;
	string from_port;
	string to_port;
    string fn;

	if (argc >=4) {
		from_port = string(argv[1]);
		to_port = string(argv[2]);
        fn = string(argv[3]);
	}
	else {
        if (argc < 2) {
            cout<<"usage: port_playback /thisPort /destPort filename"<<endl;
            return 0;
        }
        
	}
    
    //parse input file
    // ...
    
	output.open(from_port.c_str());

	yarp::os::Network::connect(from_port.c_str(),to_port.c_str());
	
    std::clock_t start;
	std::clock_t elapsed;

	ifstream file(fn.c_str());
	string line;
	if (file.is_open()) {
		start = std::clock();
		while (cont) {
			while (getline(file, line)) {
				cout<<"read line: "<<line<<endl;
				Bottle bot;
				bot.fromString(line.c_str());
				long t = bot.get(bot.size()-1).asInt(); //last value is timestamp
				cout<<"t="<<t<<endl;
				elapsed = std::clock() - start;
				while (elapsed <= t) {
					elapsed = std::clock() - start;
				};

				
				bot.pop(); //remove that timestamp!

				//wait, until we get past time.
				// of course, we should handle cases where there is nothing, in which case
				// it will hang!
				cout<<"sending! t="<<t<<endl;
				output.write(bot);
			}
			cont = false;
		}
    }
    output.close();
    return 0;
}
开发者ID:johnty,项目名称:timer,代码行数:61,代码来源:port_playback.cpp

示例13: write

bool XmlRpcCarrier::write(ConnectionState& proto, SizedWriter& writer) {
    StringOutputStream sos;
    StringInputStream sis;
    writer.write(sos);
    sis.reset(sos.toString());
    ConstString header;
    if (sender) {
        header = sis.readLine();
    }
    ConstString body = sis.readLine();
    Value v;
    if (header.length()>0 && header[0]=='q') {
        body = "yarp.quit";
        // XMLRPC does not need a quit message, this should get stripped
        return false;
    }
    Bottle *bot = v.asList();
    bot->fromString(body.c_str());
    ConstString methodName;
    if (sender) {
        methodName = bot->get(0).toString();
        *bot = bot->tail();
    }
    XmlRpcValue args;
    if (bot->size()==1) {
        toXmlRpcValue(bot->get(0),args);
    } else {
        toXmlRpcValue(v,args);
    }
    std::string req;
    if (sender) {
        const Contact& addr = host.isValid()?host:proto.getStreams().getRemoteAddress();
        XmlRpcClient c(addr.getHost().c_str(),(addr.getPort()>0)?addr.getPort():80);
        c.generateRequest(methodName.c_str(),args);
        req = c.getRequest();
    } else {
        XmlRpcServerConnection c(0,NULL);
        c.generateResponse(args.toXml());
        req = c.getResponse();
    }
    int start = 0;
    if (sender) {
        if (req.length()<8) {
            fprintf(stderr, "XmlRpcCarrier fail, %s:%d\n", __FILE__, __LINE__);
            return false;
        }
        for (int i=0; i<(int)req.length(); i++) {
            if (req[i] == '\n') {
                start++;
                break;
            }
            start++;
        }
        if (!firstRound) {
            Bytes b((char*)http.c_str(),http.length());
            proto.os().write(b);
        }
        firstRound = false;
    }
    Bytes b((char*)req.c_str()+start,req.length()-start);
    proto.os().write(b);

    return proto.os().isOk();
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:64,代码来源:XmlRpcCarrier.cpp


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