本文整理汇总了C++中ConstString::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ ConstString::substr方法的具体用法?C++ ConstString::substr怎么用?C++ ConstString::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConstString
的用法示例。
在下文中一共展示了ConstString::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lookupCore
bool RosLookup::lookupCore(const ConstString& name) {
Bottle req, reply;
req.addString("lookupNode");
req.addString("dummy_id");
req.addString(name);
rpc(getRosCoreAddress(), "xmlrpc", req, reply, verbose);
if (reply.get(0).asInt()!=1) {
fprintf(stderr, "Failure: %s\n", reply.toString().c_str());
return false;
}
ConstString url = reply.get(2).asString();
ConstString::size_type break1 = url.find("://",0);
if (break1==ConstString::npos) {
fprintf(stderr, "url not understood: %s\n", url.c_str());
return false;
}
ConstString::size_type break2 = url.find(":",break1+3);
if (break2==ConstString::npos) {
fprintf(stderr, "url not understood: %s\n", url.c_str());
return false;
}
ConstString::size_type break3 = url.find("/",break2+1);
if (break3==ConstString::npos) {
fprintf(stderr, "url not understood: %s\n", url.c_str());
return false;
}
hostname = url.substr(break1+3,break2-break1-3);
Value vportnum;
vportnum.fromString(url.substr(break2+1,break3-break2-1).c_str());
portnum = vportnum.asInt();
if (verbose) printf("%s\n", reply.toString().c_str());
valid = (portnum!=0);
rpc(getRosCoreAddress(), "xmlrpc", req, reply, verbose);
return valid;
}
示例2: report
virtual void report(const SearchReport& report, const char *context) {
ConstString ctx = context;
ConstString key = report.key.c_str();
ConstString prefix = "";
prefix = ctx;
prefix += ".";
key = prefix + key;
if (key.substr(0,1)==".") {
key = key.substr(1,key.length());
}
if (!present.check(key.c_str())) {
present.put(key.c_str(),"present");
order.addString(key.c_str());
}
if (report.isFound) {
actual.put(key.c_str(),report.value);
return;
}
if (report.isComment==true) {
comment.put(key.c_str(),report.value);
return;
}
if (report.isDefault==true) {
fallback.put(key.c_str(),report.value);
return;
}
}
示例3: queryName
Contact NameServer::queryName(const ConstString& name) {
ConstString base = name;
ConstString pat = "";
if (name.find("/net=") == 0) {
size_t patStart = 5;
size_t patEnd = name.find('/',patStart);
if (patEnd>=patStart && patEnd!=ConstString::npos) {
pat = name.substr(patStart,patEnd-patStart);
base = name.substr(patEnd);
YARP_DEBUG(Logger::get(),ConstString("Special query form ") +
name + " (" + pat + "/" + base + ")");
}
}
NameRecord *rec = getNameRecord(base,false);
if (rec!=YARP_NULLPTR) {
if (pat!="") {
ConstString ip = rec->matchProp("ips",pat);
if (ip!="") {
SplitString sip(ip.c_str());
Contact c = rec->getAddress();
c.setHost(sip.get(0));
return c;
}
}
return rec->getAddress();
}
return Contact();
}
示例4: generateTypeMap
static void generateTypeMap(RosType& t, ConstString& txt) {
txt = "";
generateTypeMap1(t,txt);
if (txt.length()>0) {
txt = txt.substr(1,txt.length());
}
if (!t.reply) return;
txt += " ---";
generateTypeMap1(*(t.reply),txt);
}
示例5: getPath
ConstString context2path(Property& config, const ConstString& context ) {
ConstString cap =
config.check("capability_directory",Value("app")).asString();
ConstString path = getPath(root,cap,context,"");
if (path.length()>1) {
if (path[path.length()-1]=='/') {
path = path.substr(0,path.length()-1);
}
}
return path;
}
示例6: toString
/**
* Quick implementation, space for improvement.
*/
ConstString Matrix::toString(int precision, int width, const char* endRowStr) const
{
ConstString ret;
char tmp[350];
int c, r;
if(width>0) // if width is specified use a space as separator
{
for(r=0;r<nrows;r++)
{
for(c=0;c<ncols;c++)
{
sprintf(tmp, "% *.*lf ", width, precision, (*this)[r][c]);
ret+=tmp;
}
ret = ret.substr(0,ret.length()-1); // remove the last character (space)
if(r<nrows-1) // if it is not the last row
ret+= endRowStr;
}
}
else // if width is not specified use tab as separator
{
for(r=0;r<nrows;r++)
{
for(c=0;c<ncols;c++)
{
sprintf(tmp, "% .*lf\t", precision, (*this)[r][c]);
ret+=tmp;
}
ret = ret.substr(0,ret.length()-1); // remove the last character (tab)
if(r<nrows-1) // if it is not the last row
ret+= endRowStr;
}
}
return ret;
}
示例7: toString
/**
* Quick implementation, space for improvement.
*/
ConstString Vector::toString(int precision, int width) const
{
ConstString ret = "";
size_t c;
char tmp[350];
if(width<0){
for(c=0;c<length();c++){
sprintf(tmp, "% .*lf\t", precision, (*this)[c]);
ret+=tmp;
}
}else{
for(c=0;c<length();c++){
sprintf(tmp, "% *.*lf ", width, precision, (*this)[c]);
ret+=tmp;
}
}
if(length()>=1)
return ret.substr(0, ret.length()-1);
return ret;
}
示例8: readDir
bool readDir(const ConstString& dirname, ACE_DIR *&dir, String& result) {
bool ok = true;
struct YARP_DIRENT **namelist;
YARP_closedir(dir);
dir = NULL;
int n = YARP_scandir(dirname.c_str(),&namelist,NULL,YARP_alphasort);
if (n<0) {
return false;
}
for (int i=0; i<n; i++) {
ConstString name = namelist[i]->d_name;
free(namelist[i]);
int len = (int)name.length();
if (len<4) continue;
if (name.substr(len-4)!=".ini") continue;
ConstString fname = ConstString(dirname) + "/" + name;
ok = ok && readFile(fname,result,false);
result += "\n[]\n"; // reset any nested sections
}
free(namelist);
/*
struct YARP_DIRENT *ent = YARP_readdir(dir);
while (ent) {
ConstString name = ent->d_name;
ent = ACE_OS::readdir(dir);
int len = (int)name.length();
if (len<4) continue;
if (name.substr(len-4)!=".ini") continue;
ConstString fname = dirname + "/" + name;
ok = ok && readFile(fname,result,false);
result += "\n[]\n"; // reset any nested sections
}
YARP_closedir(dir);
dir = NULL;
*/
return ok;
}
示例9: toDox
static void toDox(PolyDriver& dd, FILE *os) {
fprintf(os, "<table>\n");
fprintf(os, "<tr><td>PROPERTY</td><td>DESCRIPTION</td><td>DEFAULT</td></tr>\n");
Bottle order = dd.getOptions();
for (int i=0; i<order.size(); i++) {
ConstString name = order.get(i).toString().c_str();
if (name=="wrapped"||name.substr(0,10)=="subdevice.") {
continue;
}
ConstString desc = dd.getComment(name.c_str());
ConstString def = dd.getDefaultValue(name.c_str()).toString();
ConstString out = "";
out += "<tr><td>";
out += name.c_str();
out += "</td><td>";
out += desc.c_str();
out += "</td><td>";
out += def.c_str();
out += "</td></tr>";
fprintf(os,"%s\n",out.c_str());
}
fprintf(os, "</table>\n");
}
示例10: registerAdvanced
//.........这里部分代码省略.........
cmd.addString(typ);
Contact c;
if (store) {
c = rosify(store->query(nc.getNodeName()));
} else {
Nodes& nodes = NameClient::getNameClient().getNodes();
c = rosify(nodes.getParent(contact.getName()));
}
//Contact c = rosify(contact);
cmd.addString(c.toURI());
bool ok = NetworkBase::write(getNameServerContact(),
cmd, reply);
if (!ok) {
fprintf(stderr, "ROS registration error: %s\n", reply.toString().c_str());
return Contact();
}
if (cat=="-") {
Bottle *publishers = reply.get(2).asList();
if (publishers && publishers->size()>=1) {
cmd.clear();
cmd.addString(contact.toURI());
cmd.addString("publisherUpdate");
cmd.addString("/yarp/RosNameSpace");
cmd.addString(toRosName(nc.getNestedName()));
cmd.addList() = *publishers;
mutex.wait();
bool need_start = false;
if (pending.size()==0) {
mutex.post();
stop();
need_start = true;
mutex.wait();
}
pending.addList() = cmd;
if (need_start) {
start();
}
mutex.post();
}
}
}
return contact;
}
// Remainder of method is supporting older /name+#/foo syntax
ConstString name = contact.getName();
size_t pub_idx = name.find("+#");
size_t sub_idx = name.find("-#");
ConstString node = "";
ConstString pub = "";
ConstString sub = "";
if (pub_idx!=ConstString::npos) {
node = name.substr(0, pub_idx);
pub = name.substr(pub_idx+2, name.length());
YARP_SPRINTF1(Logger::get(), debug, "Publish to %s", pub.c_str());
}
if (sub_idx!=ConstString::npos) {
node = name.substr(0, sub_idx);
sub = name.substr(sub_idx+2, name.length());
YARP_SPRINTF1(Logger::get(), debug, "Subscribe to %s", sub.c_str());
}
if (node=="") {
node = name;
}
YARP_SPRINTF4(Logger::get(), debug, "Name [%s] Node [%s] sub [%s] pub [%s]",
name.c_str(), node.c_str(), sub.c_str(), pub.c_str());
{
Bottle cmd, reply;
// for ROS, we fake port name registrations by
// registering them as nodes that publish to an arbitrary
// topic
cmd.clear();
cmd.addString("registerPublisher");
cmd.addString(toRosNodeName(node));
cmd.addString("/yarp/registration");
cmd.addString("*");
Contact c = rosify(contact);
cmd.addString(c.toString());
bool ok = NetworkBase::write(getNameServerContact(),
cmd, reply);
if (!ok) {
return Contact();
}
}
if (pub!="") {
NetworkBase::connect(node, ConstString("topic:/") + pub);
}
if (sub!="") {
NetworkBase::connect(ConstString("topic:/") + sub, node);
}
Contact c = contact;
c.setName(node);
return c;
}
示例11: unregisterAdvanced
Contact RosNameSpace::unregisterAdvanced(const ConstString& name, NameStore *store) {
NestedContact nc;
nc.fromString(name);
ConstString cat = nc.getCategory();
if (nc.getNestedName()!="") {
if (cat == "-1") {
Nodes& nodes = NameClient::getNameClient().getNodes();
Contact c = nodes.getURI(name);
c.setCarrier("rosrpc");
c = rosify(c);
Bottle cmd, reply;
cmd.clear();
cmd.addString("unregisterService");
cmd.addString(toRosNodeName(nc.getNodeName()));
cmd.addString(nc.getNestedName());
cmd.addString(c.toURI());
bool ok = NetworkBase::write(getNameServerContact(),
cmd, reply);
if (!ok) return Contact();
} else if (cat == "+" || cat== "-") {
Bottle cmd, reply;
cmd.clear();
cmd.addString((cat=="+")?"unregisterPublisher":"unregisterSubscriber");
cmd.addString(toRosNodeName(nc.getNodeName()));
cmd.addString(nc.getNestedName());
Contact c;
if (store) {
c = rosify(store->query(nc.getNodeName()));
} else {
Nodes& nodes = NameClient::getNameClient().getNodes();
c = rosify(nodes.getParent(name));
}
cmd.addString(c.toString());
bool ok = NetworkBase::write(getNameServerContact(),
cmd, reply);
if (!ok) return Contact();
}
return Contact();
}
// Remainder of method is supporting older /name+#/foo syntax
size_t pub_idx = name.find("+#");
size_t sub_idx = name.find("-#");
ConstString node = "";
ConstString pub = "";
ConstString sub = "";
if (pub_idx!=ConstString::npos) {
node = name.substr(0, pub_idx);
pub = name.substr(pub_idx+2, name.length());
}
if (sub_idx!=ConstString::npos) {
node = name.substr(0, sub_idx);
sub = name.substr(sub_idx+2, name.length());
}
if (node=="") {
node = name;
}
YARP_SPRINTF3(Logger::get(), debug, "Name [%s] sub [%s] pub [%s]\n",
name.c_str(), sub.c_str(), pub.c_str());
if (pub!="") {
NetworkBase::disconnect(name, ConstString("topic:/") + pub);
}
if (sub!="") {
NetworkBase::disconnect(ConstString("topic:/") + sub, name);
}
Contact contact = NetworkBase::queryName(name);
Bottle cmd, reply;
cmd.addString("unregisterPublisher");
cmd.addString(name);
cmd.addString("/yarp/registration");
Contact c("http", contact.getHost().c_str(), contact.getPort());
cmd.addString(c.toString());
bool ok = NetworkBase::write(getNameServerContact(),
cmd, reply);
if (!ok) return Contact();
return Contact();
}
示例12: open
bool Port::open(const Contact& contact, bool registerName,
const char *fakeName) {
Contact contact2 = contact;
if (!NetworkBase::initialized()) {
YARP_ERROR(Logger::get(), "YARP not initialized; create a yarp::os::Network object before using ports");
return false;
}
ConstString n = contact2.getName();
bool local = false;
if (n == "" && contact2.getPort()<=0) {
local = true;
registerName = false;
n = "...";
}
NestedContact nc(n);
if (nc.getNestedName()!="") {
if (nc.getNodeName() == "") {
Nodes& nodes = NameClient::getNameClient().getNodes();
nodes.requireActiveName();
ConstString node_name = nodes.getActiveName();
if (node_name!="") {
n = n + node_name;
}
}
}
if (n!="" && n[0]!='/' && n[0]!='=' && n!="..." && n.substr(0,3)!="...") {
if (fakeName==NULL) {
Nodes& nodes = NameClient::getNameClient().getNodes();
ConstString node_name = nodes.getActiveName();
if (node_name!="") {
// n = node_name + "=/" + n;
n = "/" + n + "@" + node_name;
}
}
}
if (n!="" && n[0]!='/' && n[0]!='=' && n!="..." && n.substr(0,3)!="...") {
if (fakeName==NULL) {
YARP_SPRINTF1(Logger::get(),error,
"Port name '%s' needs to start with a '/' character",
n.c_str());
return false;
}
}
if (n!="" && n!="..." && n[0]!='=' && n.substr(0,3)!="...") {
if (fakeName==NULL) {
ConstString prefix = NetworkBase::getEnvironment("YARP_PORT_PREFIX");
if (prefix!="") {
n = prefix + n;
contact2 = contact2.addName(n);
}
}
}
PortCoreAdapter *currentCore = &(HELPER(implementation));
if (currentCore!=NULL) {
NestedContact nc;
nc.fromString(n);
if (nc.getNestedName()!="") {
if (nc.getCategory()=="") {
// we need to add in a category
ConstString cat = "";
if (currentCore->commitToRead) {
cat = "-";
} else if (currentCore->commitToWrite) {
cat = "+";
}
if (cat!="") {
if (currentCore->commitToRpc) {
cat += "1";
}
contact2 = contact2.addName(nc.getNestedName() +
cat +
"@" +
nc.getNodeName());
} else {
YARP_SPRINTF1(Logger::get(),error,
"Error: Port '%s' is not committed to being either an input or output port.",
n.c_str());
YARP_SPRINTF0(Logger::get(),error,
"YARP does not mind, but we are trying to register with a name server that does.");
YARP_SPRINTF0(Logger::get(),error,
"You can call Port::setWriteOnly() or Port::setReadOnly(), OR rename the port.");
NestedContact nc2 = nc;
nc2.setCategoryWrite();
YARP_SPRINTF1(Logger::get(),error,
"For an output port, call it: %s (+ adds data)",
nc2.toString().c_str());
nc2.setCategoryRead();
YARP_SPRINTF1(Logger::get(),error,
"For an input port, call it: %s (- takes data)",
nc2.toString().c_str());
return false;
}
}
}
}
//.........这里部分代码省略.........
示例13: fromCommand
void fromCommand(int argc, char *argv[],bool wipe=true) {
String tag = "";
Bottle accum;
Bottle total;
bool qualified = false;
for (int i=0; i<argc; i++) {
String work = argv[i];
bool isTag = false;
if (work.length()>=2) {
if (work[0]=='-'&&work[1]=='-') {
work = work.substr(2,work.length()-2);
isTag = true;
if (work.find("::")!=String::npos) {
qualified = true;
}
}
}
if (isTag) {
if (tag!="") {
total.addList().copy(accum);
}
tag = work;
accum.clear();
} else {
if (work.find("\\")!=String::npos) {
// Specifically when reading from the command
// line, we will allow windows-style paths.
// Hence we have to break the "\" character
String buf = "";
for (unsigned int i=0; i<work.length(); i++) {
buf += work[i];
if (work[i]=='\\') {
buf += work[i];
}
}
work = buf;
}
}
accum.add(Value::makeValue(work.c_str()));
}
if (tag!="") {
total.addList().copy(accum);
}
if (!qualified) {
fromBottle(total,wipe);
return;
}
if (wipe) {
clear();
}
Bottle *cursor = NULL;
for (int i=0; i<total.size(); i++) {
cursor = NULL;
Bottle *term = total.get(i).asList();
if (!term) continue;
ConstString key = term->get(0).asString();
ConstString base = key;
while (key.length()>0) {
int at = key.find("::");
base = key;
if (at>=0) {
base = key.substr(0,at);
key = key.substr(at+2);
} else {
key = "";
}
Bottle& result = (cursor!=NULL)? (cursor->findGroup(base.c_str())) : owner.findGroup(base.c_str());
if (result.isNull()) {
if (!cursor) {
cursor = &putBottle((base).c_str());
} else {
cursor = &cursor->addList();
}
cursor->addString(base);
} else {
cursor = &result;
}
}
if (cursor) {
cursor->copy(*term);
cursor->get(0) = Value(base);
}
}
}
示例14: main
int main(int argc, char *argv[]) {
Property p;
p.fromCommand(argc,argv);
// To make sure that the dev test are able to find all the devices
// compile by YARP, also the one compiled as dynamic plugins
// we add the build directory to the YARP_DATA_DIRS enviromental variable
// CMAKE_CURRENT_DIR is the define by the CMakeLists.txt tests file
ConstString dirs = CMAKE_BINARY_DIR +
yarp::os::Network::getDirectorySeparator() +
"share" +
yarp::os::Network::getDirectorySeparator() +
"yarp";
// Add TEST_DATA_DIR to YARP_DATA_DIRS in order to find the contexts used
// by the tests
dirs += yarp::os::Network::getPathSeparator() +
TEST_DATA_DIR;
// If set, append user YARP_DATA_DIRS
// FIXME check if this can be removed
Network::getEnvironment("YARP_DATA_DIRS");
if (!Network::getEnvironment("YARP_DATA_DIRS").empty()) {
dirs += yarp::os::Network::getPathSeparator() +
Network::getEnvironment("YARP_DATA_DIRS");
}
Network::setEnvironment("YARP_DATA_DIRS", dirs);
printf("YARP_DATA_DIRS=\"%s\"\n", Network::getEnvironment("YARP_DATA_DIRS").c_str());
// check where to put description of device
ConstString dest = "";
dest = p.check("doc",Value("")).toString();
ConstString fileName = p.check("file",Value("default.ini")).asString();
if (p.check("file")) {
p.fromConfigFile(fileName);
}
ConstString deviceName = p.check("device",Value("")).asString();
// if no device given, we should be operating a completely
// standard test harness like for libYARP_OS and libYARP_sig
if (deviceName=="") {
return harness_main(argc,argv);
}
// device name given - use special device testing procedure
#ifdef CHECK_FOR_LEAKS
mtrace();
#endif
int result = 0;
Network::init();
Network::setLocalMode(true);
ConstString seek = fileName.c_str();
ConstString exampleName = "";
int pos = seek.rfind('/');
if (pos==-1) {
pos = seek.rfind('\\');
}
if (pos==-1) {
pos = 0;
} else {
pos++;
}
int len = seek.find('.',pos);
if (len==-1) {
len = seek.length();
} else {
len -= pos;
}
exampleName = seek.substr(pos,len).c_str();
ConstString shortFileName = seek.substr(pos,seek.length()).c_str();
PolyDriver dd;
YARP_DEBUG(Logger::get(), "harness opening...");
bool ok = dd.open(p);
YARP_DEBUG(Logger::get(), "harness opened.");
result = ok?0:1;
ConstString wrapperName = "";
ConstString codeName = "";
DriverCreator *creator =
Drivers::factory().find(deviceName.c_str());
if (creator!=nullptr) {
wrapperName = creator->getWrapper();
codeName = creator->getCode();
}
if (dest!="") {
ConstString dest2 = dest.c_str();
if (result!=0) {
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[]) {
Property p;
p.fromCommand(argc,argv);
// check where to put description of device
ConstString dest = "";
dest = p.check("doc",Value("")).toString();
ConstString fileName = p.check("file",Value("default.ini")).asString();
if (p.check("file")) {
p.fromConfigFile(fileName);
}
ConstString deviceName = p.check("device",Value("")).asString();
// if no device given, we should be operating a completely
// standard test harness like for libYARP_OS and libYARP_sig
if (deviceName=="") {
return harness_main(argc,argv);
}
// device name given - use special device testing procedure
#ifdef CHECK_FOR_LEAKS
mtrace();
#endif
int result = 0;
Network::init();
Network::setLocalMode(true);
ConstString seek = fileName.c_str();
ConstString exampleName = "";
int pos = seek.rfind('/');
if (pos==-1) {
pos = seek.rfind('\\');
}
if (pos==-1) {
pos = 0;
} else {
pos++;
}
int len = seek.find('.',pos);
if (len==-1) {
len = seek.length();
} else {
len -= pos;
}
exampleName = seek.substr(pos,len).c_str();
ConstString shortFileName = seek.substr(pos,seek.length()).c_str();
PolyDriver dd;
YARP_DEBUG(Logger::get(), "harness opening...");
bool ok = dd.open(p);
YARP_DEBUG(Logger::get(), "harness opened.");
result = ok?0:1;
ConstString wrapperName = "";
ConstString codeName = "";
DriverCreator *creator =
Drivers::factory().find(deviceName.c_str());
if (creator!=NULL) {
wrapperName = creator->getWrapper();
codeName = creator->getCode();
}
if (dest!="") {
ConstString dest2 = dest.c_str();
if (result!=0) {
dest2 += ".fail";
}
FILE *fout = fopen(dest2.c_str(),"w");
if (fout==NULL) {
printf("Problem writing to %s\n", dest2.c_str());
yarp::os::exit(1);
}
fprintf(fout,"/**\n");
fprintf(fout," * \\ingroup dev_examples\n");
fprintf(fout," *\n");
fprintf(fout," * \\defgroup %s Example for %s (%s)\n\n",
exampleName.c_str(),
deviceName.c_str(),
exampleName.c_str());
fprintf(fout, "Instantiates \\ref cmd_device_%s \"%s\" device implemented by %s.\n",
deviceName.c_str(), deviceName.c_str(), codeName.c_str());
fprintf(fout, "\\verbatim\n%s\\endverbatim\n",
getFile(fileName.c_str()).c_str());
fprintf(fout, "If this text is saved in a file called %s then the device can be created by doing:\n",
shortFileName.c_str());
fprintf(fout, "\\verbatim\nyarpdev --file %s\n\\endverbatim\n",
shortFileName.c_str());
fprintf(fout, "Of course, the configuration could be passed just as command line options, or as a yarp::os::Property object in a program:\n");
fprintf(fout, "\\code\n");
fprintf(fout, "Property p;\n");
fprintf(fout, "p.fromConfigFile(\"%s\");\n",
//.........这里部分代码省略.........