本文整理汇总了C++中ArArgumentBuilder::setExtraString方法的典型用法代码示例。如果您正苦于以下问题:C++ ArArgumentBuilder::setExtraString方法的具体用法?C++ ArArgumentBuilder::setExtraString怎么用?C++ ArArgumentBuilder::setExtraString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArArgumentBuilder
的用法示例。
在下文中一共展示了ArArgumentBuilder::setExtraString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleGetConfigDefaults
AREXPORT void ArClientHandlerConfig::handleGetConfigDefaults(
ArNetPacket *packet)
{
ArLog::log(ArLog::Normal, "%sreceived default config %s",
myLogPrefix.c_str(),
((myHaveRequestedDefaultCopy) ? "(copy)" : "(reset)"));
char param[1024];
char argument[1024];
char errorBuffer[1024];
myDataMutex.lock();
ArConfig *config = NULL;
// If the config (or a section) is being reset to its default values,
// then we don't want to remove any parameters that are not set -- i.e.
// any parameters that are not contained in the default config.
bool isClearUnsetValues = false;
if (myHaveRequestedDefaults) {
config = &myConfig;
}
else if (myHaveRequestedDefaultCopy) {
// If we have requested a copy of the default configuration, then we
// will want to remove any parameters that haven't been explicitly set.
// (This is because of the next line, which copies the current config
// to the default config.)
isClearUnsetValues = true;
// The default config is transmitted in an "abbreviated" form -- just
// the section/param names and values. Copy the current config to the
// default before processing the packet so that the parameter types, etc.
// can be preserved.
if (myDefaultConfig == NULL) {
myDefaultConfig = new ArConfig(myConfig);
myDefaultConfig->setConfigName("Default", myRobotName.c_str());
myDefaultConfig->setQuiet(myIsQuiet);
}
else {
*myDefaultConfig = myConfig;
}
config = myDefaultConfig;
}
// if we didn't ask for any of these, then just return since the
// data is for someone else
else
{
myDataMutex.unlock();
return;
}
if (config == NULL) {
ArLog::log(ArLog::Normal,
"%serror determining config to populate with default values",
myLogPrefix.c_str());
myDataMutex.unlock();
return;
}
ArArgumentBuilder *builder = NULL;
ArLog::log(ArLog::Normal, "%sGot defaults", myLogPrefix.c_str());
errorBuffer[0] = '\0';
//myDataMutex.lock();
if (isClearUnsetValues) {
config->clearAllValueSet();
}
while (packet->getDataReadLength() < packet->getDataLength())
{
packet->bufToStr(param, sizeof(param));
packet->bufToStr(argument, sizeof(argument));
builder = new ArArgumentBuilder;
builder->setQuiet(myIsQuiet);
builder->setExtraString(param);
builder->add(argument);
if ((strcasecmp(param, "Section") == 0 &&
!config->parseSection(builder, errorBuffer, sizeof(errorBuffer))) ||
(strcasecmp(param, "Section") != 0 &&
!config->parseArgument(builder, errorBuffer, sizeof(errorBuffer))))
{
ArLog::log(ArLog::Terse, "%shandleGetConfigDefaults: Hideous problem getting defaults, couldn't parse '%s %s'",
myLogPrefix.c_str(), param, argument);
}
else {
IFDEBUG(if (strlen(param) > 0) {
ArLog::log(ArLog::Normal, "%shandleGetConfigDefaults: added default '%s %s'",
myLogPrefix.c_str(), param, argument); } );
}
delete builder;
builder = NULL;
}
示例2: main
//.........这里部分代码省略.........
}
printf("mapTest: Took %ld ms to write file mapTest.map\n", timer.mSecSince());
std::list<ArMapObject *>::iterator objIt;
ArMapObject *obj;
for (objIt = testMap.getMapObjects()->begin();
objIt != testMap.getMapObjects()->end();
objIt++)
{
obj = (*objIt);
printf("mapTest: Map object: %s named \"%s\". Pose: %0.2f,%0.2f,%0.2f. ", obj->getType(), obj->getName(), obj->getPose().getX(), obj->getPose().getY(), obj->getPose().getTh());
if(obj->hasFromTo())
printf("mapTest: Extents: From %0.2f,%0.2f to %0.2f,%0.2f.", obj->getFromPose().getX(), obj->getFromPose().getY(), obj->getToPose().getX(), obj->getToPose().getY());
printf("mapTest: \n");
/*
if (strcasecmp(obj->getType(), "Goal") == 0 ||
strcasecmp(obj->getType(), "GoalWithHeading") == 0)
{
printf("mapTest: Map object: Goal %s\n", obj->getName());
}
else if (strcasecmp(obj->getType(), "ForbiddenLine") == 0 &&
obj->hasFromTo())
{
printf("mapTest: Map object: Forbidden line from %.0f %.0f to %.0f %.0f\n",
obj->getFromPose().getX(), obj->getFromPose().getY(),
obj->getToPose().getX(), obj->getToPose().getY());
}
*/
}
std::list<ArArgumentBuilder*>* objInfo = testMap.getMapInfo();
for(std::list<ArArgumentBuilder*>::const_iterator i = objInfo->begin();
i != objInfo->end();
i++)
{
printf("mapTest: MapInfo object definition:\n----\n");
(*i)->log();
printf("mapTest: ----\n");
}
printf("mapTest: First 5 data points:\n");
std::vector<ArPose>::iterator pIt;
ArPose pose;
int n = 0;
for (pIt = testMap.getPoints()->begin();
pIt != testMap.getPoints()->end();
pIt++)
{
pose = (*pIt);
if (n > 5)
exit(0);
printf("mapTest: \t%.0f %.0f\n", pose.getX(), pose.getY());
n++;
// the points are gone through
}
if (argc >= 3)
{
timer.setToNow();
if (!testMap.readFile(argv[2]))
{
printf("mapTest: Could not read map '%s'\n", argv[2]);
}
printf("mapTest: Took %ld ms to read file2\n", timer.mSecSince());
/*
ArUtil::sleep(30);
printf("mapTest: ChangeTimes (in ms): mapObjects %ld points %ld mapInfo %ld\n",
testMap.getMapObjectsChanged().mSecSince(),
testMap.getPointsChanged().mSecSince(),
testMap.getMapInfoChanged().mSecSince());
*/
timer.setToNow();
testMap.writeFile("mapTest2.map");
printf("mapTest: Took %ld ms to write file2\n", timer.mSecSince());
}
// now test it with the config stuff
ArArgumentBuilder builder;
builder.setExtraString("Map");
builder.add(argv[1]);
printf("mapTest: Trying config with map (%s)\n", argv[1]);
Aria::getConfig()->parseArgument(&builder);
Aria::getConfig()->callProcessFileCallBacks(true, NULL, 0);
printf("mapTest: Trying config again with same map (%s)\n", argv[1]);
Aria::getConfig()->parseArgument(&builder);
Aria::getConfig()->callProcessFileCallBacks(true, NULL, 0);
if (argc >= 3)
{
ArArgumentBuilder builder2;
builder2.setExtraString("Map");
builder2.add(argv[2]);
printf("mapTest: Trying config with map2 (%s)\n", argv[2]);
Aria::getConfig()->parseArgument(&builder2);
Aria::getConfig()->callProcessFileCallBacks(true, NULL, 0);
}
}
示例3: internalSetConfig
bool ArServerHandlerConfig::internalSetConfig(ArServerClient *client,
ArNetPacket *packet)
{
char param[1024];
char argument[1024];
char errorBuffer[1024];
char firstError[1024];
ArNetPacket retPacket;
ArConfig *config;
bool ret = true;
if (client != NULL)
config = myConfig;
else
config = myDefault;
if (client != NULL)
lockConfig();
ArArgumentBuilder *builder = NULL;
if (client != NULL)
ArLog::log(ArLog::Normal, "Got new config from client %s", client->getIPString());
else
ArLog::log(ArLog::Verbose, "New default config");
errorBuffer[0] = '\0';
firstError[0] = '\0';
while (packet->getDataReadLength() < packet->getDataLength())
{
packet->bufToStr(param, sizeof(param));
packet->bufToStr(argument, sizeof(argument));
builder = new ArArgumentBuilder;
builder->setExtraString(param);
builder->add(argument);
ArLog::log(ArLog::Verbose, "Config: %s %s", param, argument);
// if the param name here is "Section" we need to parse sections,
// otherwise we parse the argument
if ((strcasecmp(param, "Section") == 0 &&
!config->parseSection(builder, errorBuffer, sizeof(errorBuffer))) ||
(strcasecmp(param, "Section") != 0 &&
!config->parseArgument(builder, errorBuffer, sizeof(errorBuffer))))
{
if (firstError[0] == '\0')
strcpy(firstError, errorBuffer);
}
delete builder;
builder = NULL;
}
if (firstError[0] == '\0')
{
if (config->callProcessFileCallBacks(true,
errorBuffer,
sizeof(errorBuffer)))
{
if (client != NULL)
ArLog::log(ArLog::Normal, "New config from client %s was fine.",
client->getIPString());
else
ArLog::log(ArLog::Verbose, "New default config was fine.");
retPacket.strToBuf("");
writeConfig();
}
else // error processing config callbacks
{
ret = false;
if (firstError[0] == '\0')
strcpy(firstError, errorBuffer);
// if its still empty it means we didn't have anything good in the errorBuffer
if (firstError[0] == '\0')
strcpy(firstError, "Error processing");
if (client != NULL)
ArLog::log(ArLog::Normal,
"New config from client %s had errors processing ('%s').",
client->getIPString(), firstError);
else
ArLog::log(ArLog::Normal,
"New default config had errors processing ('%s').",
firstError);
retPacket.strToBuf(firstError);
}
}
else
{
ret = false;
if (client != NULL)
ArLog::log(ArLog::Normal,
"New config from client %s had at least this problem: %s",
client->getIPString(), firstError);
else
ArLog::log(ArLog::Normal,
"New default config had at least this problem: %s",
firstError);
retPacket.strToBuf(firstError);
}
//printf("Sending ");
//retPacket.log();
if (client != NULL)
client->sendPacketTcp(&retPacket);
if (client != NULL)
//.........这里部分代码省略.........
示例4: parseLine
//.........这里部分代码省略.........
}
// if not its part of the keyword
else
keyword[i-textStart] = line[i];
}
keyword[i-textStart] = '\0';
//ArLog::log(ArLog::Verbose, "line %d: keyword %s", lineNumber, keyword);
// now find the start of the value (first non whitespace)
for (; i < len; i++)
{
// if its not a space we're done
if (!isspace(line[i]))
{
valueStart = &line[i];
break;
};
}
// lower that keyword
ArUtil::lower(keyword, keyword, 512);
// a variable for if we're using the remainder handler or not (don't
// do a test just because someone could set the remainder handler to
// some other handler they're using)
bool usingRemainder = false;
// see if we have a handler for the keyword
if ((it = myMap.find(keyword)) != myMap.end())
{
//printf("have handler for keyword %s\n", keyword);
// we have a handler, so pull that out
handler = (*it).second;
// valueStart was set above but make sure there's an argument
if (i == len)
noArgs = true;
}
// if we don't then check for a remainder handler
else
{
//printf("no handler for keyword %s\n", keyword);
// if we have one set it
if (myRemainderHandler != NULL)
{
usingRemainder = true;
handler = myRemainderHandler;
// reset the value to the start of the text
valueStart = &line[textStart];
}
// if we don't just keep going
else
{
ArLog::log(ArLog::Verbose,
"line %d: unknown keyword '%s' line '%s', continuing",
myLineNumber, keyword, &line[textStart]);
return true;
}
}
/*
if (noArgs)
ArLog::log(ArLog::Verbose, "line %d: firstword '%s' no argument",
myLineNumber, keyword);
else
ArLog::log(ArLog::Verbose, "line %d: firstword '%s' argument '%s'",
myLineNumber, keyword, valueStart);
*/
// now toss the rest of the argument into an argument builder then
// form it up to send to the functor
ArArgumentBuilder builder;
// if we have arguments add them
if (!noArgs)
builder.add(valueStart);
// if not we still set the name of whatever we parsed (unless we
// didn't have a param of course)
if (!usingRemainder)
builder.setExtraString(keyword);
// make sure we don't overwrite any errors
if (errorBuffer != NULL && errorBuffer[0] != '\0')
{
errorBuffer = NULL;
errorBufferLen = 0;
}
// call the functor and see if there are errors;
// if we had an error and aren't continuing on errors then we keep going
if (!handler->call(&builder, errorBuffer, errorBufferLen))
{
// put the line number in the error message (this won't overwrite
// anything because of the check above
if (errorBuffer != NULL)
{
std::string errorString = errorBuffer;
snprintf(errorBuffer, errorBufferLen, "Line %d: %s", myLineNumber,
errorString.c_str());
}
return false;
}
return true;
}