本文整理汇总了C++中TiXmlElement::Row方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlElement::Row方法的具体用法?C++ TiXmlElement::Row怎么用?C++ TiXmlElement::Row使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlElement
的用法示例。
在下文中一共展示了TiXmlElement::Row方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setFromXML
bool ProfileSelectorWeightedFactory::setFromXML(ProfileSelector* pSel, TiXmlElement* node,
const std::string& specFldr) const {
ProfileSelectorWeighted* sel = dynamic_cast<ProfileSelectorWeighted*>(pSel);
assert(sel != 0x0 &&
"Trying to set attributes of a weighted profile selector "
"element on an incompatible object");
if (!ProfileSelectorFactory::setFromXML(sel, node, specFldr)) return false;
// Parse each of the names.
for (TiXmlElement* child = node->FirstChildElement("Profile"); child;
child = child->NextSiblingElement()) {
const char* nameCStr = child->Attribute("name");
if (nameCStr == 0x0) {
logger << Logger::ERR_MSG << "The AgentProfile referred to on line " << child->Row()
<< " is missing the required \"name\" attribute.";
return false;
}
double weight;
if (!child->Attribute("weight", &weight)) {
logger << Logger::ERR_MSG << "The AgentProfile referred to on line " << child->Row()
<< " is missing the required \"weight\" attribute.";
return false;
}
sel->_profile_specs.emplace_back(nameCStr, static_cast<float>(weight));
}
return true;
}
示例2:
RobotInterface::ParamList RobotInterface::XMLReader::Private::readParamListTag(TiXmlElement* paramListElem)
{
if (paramListElem->ValueStr().compare("paramlist") != 0) {
SYNTAX_ERROR(paramListElem->Row()) << "Expected \"paramlist\". Found" << paramListElem->ValueStr();
}
ParamList params;
Param mainparam;
if (paramListElem->QueryStringAttribute("name", &mainparam.name()) != TIXML_SUCCESS) {
SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" element should contain the \"name\" attribute";
}
params.push_back(mainparam);
// yDebug() << "Found paramlist [" << params.at(0).name() << "]";
for (TiXmlElement* childElem = paramListElem->FirstChildElement(); childElem != 0; childElem = childElem->NextSiblingElement()) {
if (childElem->ValueStr().compare("elem") != 0) {
SYNTAX_ERROR(childElem->Row()) << "Expected \"elem\". Found" << childElem->ValueStr();
}
Param childParam;
if (childElem->QueryStringAttribute("name", &childParam.name()) != TIXML_SUCCESS) {
SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should contain the \"name\" attribute";
}
const char *valueText = childElem->GetText();
if (!valueText) {
SYNTAX_ERROR(childElem->Row()) << "\"elem\" element should have a value [ \"name\" = " << childParam.name() << "]";
}
childParam.value() = valueText;
params.push_back(childParam);
}
if (params.empty()) {
SYNTAX_ERROR(paramListElem->Row()) << "\"paramlist\" cannot be empty";
}
// +1 skips the first element, that is the main param
for (ParamList::iterator it = params.begin() + 1; it != params.end(); ++it) {
Param ¶m = *it;
params.at(0).value() += (params.at(0).value().empty() ? "(" : " ") + param.name();
}
params.at(0).value() += ")";
// yDebug() << params;
return params;
}
示例3: parseObstacle
ObstacleVertexList ExplicitObstacleSetFactory::parseObstacle( TiXmlElement * node) const {
int iVal;
// TODO: Simply eliminate the bounding box obstacle -- it is basically
// just ignored.
bool bb = false;
if ( node->Attribute( "boundingbox", &iVal ) ) {
// Skip bounding box obstacles, but treat it as normal
bb = (iVal != 0);
assert(!bb && "Bounding Boxes are depreciated!");
}
ObstacleVertexList vList;
vList.closed = false;
if ( node->Attribute( "closed", &iVal ) ) {
vList.closed = (iVal != 0);
}
double dVal;
bool valid = true;
for ( TiXmlElement * vert = node->FirstChildElement(); vert; vert = vert->NextSiblingElement() ) {
if ( vert->ValueStr() == "Vertex") {
float p_x = 0;
float p_y = 0;
if ( vert->Attribute( "p_x", &dVal) ) {
p_x = (float)dVal;
} else {
valid = false;
}
if ( vert->Attribute( "p_y", &dVal) ) {
p_y = (float)dVal;
} else {
valid = false;
}
if ( ! valid ) {
logger << Logger::ERR_MSG << "Obstacle vertex on line " << vert->Row() << " is missing the full x- and y-position specification.";
throw ObstacleSetFatalException("Obstacle vertex missing full specification");
}
vList.vertices.push_back( Vector2( p_x, p_y ) );
}
else {
logger << Logger::WARN_MSG << "Encountered unexpected tag inside an obstacle definition on line " << vert->Row() << ": " << vert->ValueStr() << ". It will be ignored.";
}
if ( ! valid ) {
logger << Logger::ERR_MSG << "Incomplete obstacle definition on line " << node->Row() << ".";
throw ObstacleSetFatalException("Incomplete obstacle definition");
}
}
return vList;
};
示例4: load
int SceneLoader::load(string scene_file, Scene** scene, int xRes, int yRes) {
TiXmlDocument doc(scene_file);
if ( !doc.LoadFile() ) {
Logger::log(LOG_ERROR) << "Scene loading failed : " << scene_file << endl;
Logger::log(LOG_ERROR) << "Error #" << doc.ErrorId() << " : " << doc.ErrorDesc() << endl;
return -1;
} else {
Logger::log(LOG_INFO) << "Start loading scene : " << scene_file << endl;
Uint32 initial_tick = SDL_GetTicks();
list<Object*> objects;
list<Light*> lights;
set<Material*> materials;
AmbientLight ambientLight;
Camera* camera=0;
TiXmlElement* tmp_node = 0;
TiXmlHandle hdl(&doc);
TiXmlElement* node = hdl.FirstChildElement().FirstChildElement().Element();
if (node == NULL) {
Logger::log(LOG_ERROR)<<"Error on top of the file"<<endl;
return -1;
}
while ( node ) {
string nodeName(node->Value());
if ( nodeName.compare("camera")==0 ) {
VEC3F position, target, normal;
float w = 8, d = 35;
tmp_node = node->FirstChildElement("position");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <position> near line "<<node->Row()<<endl;
} else {
position = readVec3Float(tmp_node);
}
tmp_node = node->FirstChildElement("target");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <target> near line "<<node->Row()<<endl;
} else {
target = readVec3Float(tmp_node);
}
tmp_node = node->FirstChildElement("normal");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <normal> near line "<<node->Row()<<endl;
} else {
normal = readVec3Float(tmp_node);
}
tmp_node = node->FirstChildElement("viewplane");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <viewplane> near line "<<node->Row()<<endl;
} else {
tmp_node->QueryFloatAttribute("w", &w);
tmp_node->QueryFloatAttribute("d", &d);
}
camera = new Camera(position,
target-position,
normal,
w, d,
xRes, yRes,
Settings::getAsFloat("camera_translation_factor"),
Settings::getAsFloat("camera_rotation_angle"));
} else if ( nodeName.compare("directionalLight")==0 ) {
Color color;
VEC3F direction;
tmp_node = node->FirstChildElement("color");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <color> near line "<<node->Row()<<endl;
} else {
color = readColor(tmp_node);
}
tmp_node = node->FirstChildElement("direction");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <direction> near line "<<node->Row()<<endl;
} else {
direction = readVec3Float(tmp_node);
}
DirectionalLight *dirLight = new DirectionalLight(color, direction.normalize()); // !!!!!!!!!! NEEDS TO BE DESTROYED
lights.push_back(dirLight);
} else if ( nodeName.compare("pointLight")==0 ) {
Color color;
VEC3F point;
tmp_node = node->FirstChildElement("color");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <color> near line "<<node->Row()<<endl;
} else {
color = readColor(tmp_node);
}
tmp_node = node->FirstChildElement("point");
if (tmp_node == NULL) {
Logger::log(LOG_ERROR)<<"Missing <point> near line "<<node->Row()<<endl;
} else {
//.........这里部分代码省略.........
示例5: LoadLoggerListenerDefs
bool LoggingSystem::LoadLoggerListenerDefs()
{
using namespace LogAppenders;
const TiXmlElement* config = Config::GetInstance().GetSection("LoggingSystem");
if (config == NULL) return false;
TiXmlHandle doc((TiXmlNode*)config);
TiXmlNode* node = doc.FirstChildElement("Appenders").Child(0).Node();
while (node && node->Type() != TiXmlNode::ELEMENT)
node = node->NextSibling();
if (node == NULL) return false;
TiXmlElement* loggerDef = node->ToElement();
for( loggerDef; loggerDef; loggerDef=loggerDef->NextSiblingElement())
{
const char* type = loggerDef->Value();
bool created = false;
bool error = false;
if (!XmlReadBool(loggerDef, "enabled", true)) continue;
for (uint i = 0; i < sizeof(gAppendersDefenitions) / sizeof(AppenderDefenition); i++)
{
if (strcmp(type, gAppendersDefenitions[i].Type) != 0) continue;
LogAppender* listener = NULL;
try
{
listener = gAppendersDefenitions[i].FactoryFunction(loggerDef);
if (listener == NULL)
{
std::wostringstream os;
os << L"Invalid log appender defenition <" << loggerDef->Value() << L" ... /> in config.xml at line " << loggerDef->Row();
Message(os.str().c_str(), LOG_WARN, L"System.LoggingSystem");
continue;
}
const char* thresholdAttr = loggerDef->Attribute("threshold");
LogLevel threshold = LOG_TRACE;
if (thresholdAttr)
{
if (strcmp(thresholdAttr, "trace") == 0)
threshold = LOG_TRACE;
else if (strcmp(thresholdAttr, "debug") == 0)
threshold = LOG_DEBUG;
else if (strcmp(thresholdAttr, "info") == 0)
threshold = LOG_INFO;
else if (strcmp(thresholdAttr, "warn") == 0)
threshold = LOG_WARN;
else if (strcmp(thresholdAttr, "error") == 0)
threshold = LOG_ERROR;
}
const char* source = loggerDef->Attribute("sources");
if (source == NULL)
AddAppender(listener);
else
AddAppender(listener, threshold, ToUTF16(source));
listener->Release();
created = true;
break;
}
catch (Exception& e)
{
if (listener != NULL) RemoveAppender(listener);
std::wostringstream os;
os << L"Failed to create log appender <" << loggerDef->Value() << L" ... /> in config.xml at line " << loggerDef->Row() << L": "
<< e.GetFullDescription();
Message(os.str().c_str(), LOG_WARN, L"System.LoggingSystem");
error = true;
break;
}
}
if (!created && !error)
{
std::wostringstream os;
os << L"Unrecognized log appender <" << loggerDef->Value() << L" ... /> in config.xml at line " << loggerDef->Row() << L".";
Message(os.str().c_str(), LOG_WARN, L"System.LoggingSystem");
}
}
return true;
}
示例6: VisitExit
/// Visit an element.
virtual bool VisitExit( const TiXmlElement& element )
{
std::string str = element.Value();
std::string top = mStack.top();
if(str != top)
{
OUTSTRING("... [%s]/[%s]: before element has not exit : %d\n", fileName.c_str(), element.Value(), element.Row());
}
mStack.pop();
return true;
}
示例7: readXml
bool Scene::readXml(TiXmlElement* e)
{
string objName;
TiXmlElement* child = e->FirstChildElement();
while(child != NULL)
{
if(child->ValueStr() == "pixel")
{
if((objName = Xml::getAttrString(child, "name")) != "")
{
Pixel* p = new Pixel(objName, getOscRootAddress());
p->loadXml(child);
addObject(p);
LOG_DEBUG << "Scene \"" << _name << "\": Loaded pixel \"" << objName << "\" \""
<< p->getOscRootAddress() << "\"" << std::endl;
}
else
{
LOG_WARN << "Scene \"" << _name << "\": cannot load pixel without name, line "
<< child->Row() << endl;
}
}
else if(child->ValueStr() == "line")
{
if((objName = Xml::getAttrString(child, "name")) != "")
{
Line* l = new Line(objName, getOscRootAddress());
l->loadXml(child);
addObject(l);
LOG_DEBUG << "Scene \"" << _name << "\": Loaded line \"" << objName << "\" \""
<< l->getOscRootAddress() << "\"" << std::endl;
}
else
{
LOG_WARN << "Scene \"" << _name << "\": cannot load line without name, line "
<< child->Row() << endl;
}
}
else if(child->ValueStr() == "rect")
{
if((objName = Xml::getAttrString(child, "name")) != "")
{
Rect* r = new Rect(objName, getOscRootAddress());
r->loadXml(child);
addObject(r);
LOG_DEBUG << "Scene \"" << _name << "\": Loaded rect \"" << objName << "\" \""
<< r->getOscRootAddress() << "\"" << std::endl;
}
else
{
LOG_WARN << "Scene \"" << _name << "\": cannot load rect without name, line "
<< child->Row() << endl;
}
}
else if(child->ValueStr() == "bitmap")
{
if((objName = Xml::getAttrString(child, "name")) != "")
{
Bitmap* b = new Bitmap(objName, getOscRootAddress());
b->loadXml(child);
addObject(b);
LOG_DEBUG << "Scene \"" << _name << "\": Loaded bitmap \"" << objName << "\" \""
<< b->getOscRootAddress() << "\"" << std::endl;
}
else
{
LOG_WARN << "Scene \"" << _name << "\": cannot load bitmap without name, line "
<< child->Row() << endl;
}
}
else if(child->ValueStr() == "sprite")
{
if((objName = Xml::getAttrString(child, "name")) != "")
{
Sprite* s = new Sprite(objName, getOscRootAddress());
s->loadXml(child);
addObject(s);
LOG_DEBUG << "Scene \"" << _name << "\": Loaded sprite \"" << objName << "\" \""
<< s->getOscRootAddress() << "\"" << std::endl;
}
else
{
LOG_WARN << "Scene \"" << _name << "\": cannot load sprite without name, line "
<< child->Row() << endl;
}
}
else if(child->ValueStr() == "image")
{
if((objName = Xml::getAttrString(child, "name")) != "")
//.........这里部分代码省略.........
示例8: parsXml
Application* XmlAppLoader::parsXml(const char* szFile)
{
app.clear();
ErrorLogger* logger = ErrorLogger::Instance();
TiXmlDocument doc(szFile);
if(!doc.LoadFile())
{
OSTRINGSTREAM err;
err<<"Syntax error while loading "<<szFile<<" at line "\
<<doc.ErrorRow()<<": ";
err<<doc.ErrorDesc();
logger->addError(err);
return NULL;
}
/* retrieving root element */
TiXmlElement *root = doc.RootElement();
if(!root)
{
OSTRINGSTREAM err;
err<<"Syntax error while loading "<<szFile<<" . ";
err<<"No root element.";
logger->addError(err);
return NULL;
}
if(!compareString(root->Value(), "application"))
{
//OSTRINGSTREAM err;
//err<<"File "<<szFile<<" has no tag <application>.";
//logger->addError(err);
return NULL;
}
/* retrieving name */
TiXmlElement* name = (TiXmlElement*) root->FirstChild("name");
if(!name || !name->GetText())
{
OSTRINGSTREAM err;
err<<"Module from "<<szFile<<" has no name.";
logger->addError(err);
//return NULL;
}
app.setXmlFile(szFile);
if(name)
{
string strname = name->GetText();
for(unsigned int i=0; i<strname.size(); i++)
if(strname[i] == ' ')
strname[i] = '_';
app.setName(strname.c_str());
}
/* retrieving description */
TiXmlElement* desc;
if((desc = (TiXmlElement*) root->FirstChild("description")))
app.setDescription(desc->GetText());
/* retrieving version */
TiXmlElement* ver;
if((ver = (TiXmlElement*) root->FirstChild("version")))
app.setVersion(ver->GetText());
/*
* TODO: setting prefix of the main application is inactivated.
* Check this should be supported in future or not!
*/
/*
//retrieving application prefix
TiXmlElement* pref;
if((pref = (TiXmlElement*) root->FirstChild("prefix")))
app.setPrefix(pref->GetText());
*/
/* retrieving authors information*/
TiXmlElement* authors;
if((authors = (TiXmlElement*) root->FirstChild("authors")))
for(TiXmlElement* ath = authors->FirstChildElement(); ath;
ath = ath->NextSiblingElement())
{
if(compareString(ath->Value(), "author"))
{
Author author;
if(ath->GetText())
author.setName(ath->GetText());
if(ath->Attribute("email"))
author.setEmail(ath->Attribute("email"));
app.addAuthor(author);
}
else
{
OSTRINGSTREAM war;
war<<"Unrecognized tag from "<<szFile<<" at line "\
<<ath->Row()<<".";
logger->addWarning(war);
}
//.........这里部分代码省略.........
示例9: parseAgentProfile
bool SimXMLLoader::parseAgentProfile( TiXmlElement * node, AgentInitializer * agentInit ) {
// Extract the name
const char * nameCStr = node->Attribute( "name" );
if ( nameCStr == 0x0 ) {
logger << Logger::ERR_MSG << "The AgentProfile defined on line " << node->Row() << " is missing the required \"name\" attribute.";
return false;
}
std::string name( nameCStr );
if ( _profiles.find( name ) != _profiles.end() ) {
logger << Logger::ERR_MSG << "The AgentProfile defined on line " << node->Row() << " has a name value (\"" << name << "\")that has previously been used.";
return false;
}
AgentInitializer * init;
// test inheritance
const char * parentCStr = node->Attribute( "inherits" );
if ( parentCStr ) {
std::string pName( parentCStr );
HASH_MAP< std::string, AgentInitializer * >::iterator itr = _profiles.find( pName );
if ( itr == _profiles.end() ) {
logger << Logger::ERR_MSG << "The AgentProfile on line " << node->Row() << " inherits from the undefined AgentProfile \"" << pName << "\". Make sure the parent profile is defined <i>before</i> the child profile.";
return false;
} else {
init = itr->second->copy();
}
} else {
init = agentInit->copy();
init->setDefaults();
}
_profiles[ name ] = init;
for( TiXmlElement * child = node->FirstChildElement(); child; child = child->NextSiblingElement()) {
if ( ! init->parseProperties( child, _sceneFldr) ) {
logger << Logger::ERR_MSG << "Error parsing AgentProfile properties from line " << child->Row() << ".";
return false;
}
}
return true;
}
示例10: parseAgentGroup
bool SimXMLLoader::parseAgentGroup( TiXmlElement * node, AgentInitializer * agentInit ) {
// 2-pass approach
// Pass 1 get the profile selector
// Pass 2 initialize AgentGenerator (Generator for short)
// Get the profile selector -
TiXmlElement* child;
ProfileSelector * profileSel = 0x0;
StateSelector * stateSel = 0x0;
// First pass, skip Agents
for( child = node->FirstChildElement(); child; child = child->NextSiblingElement()) {
if ( child->ValueStr() == "ProfileSelector" ) {
if ( profileSel != 0x0 ) {
// There should be only one. If there are multiple, only the first will have an effect.
logger << Logger::WARN_MSG << "Found multiple ProfileSelector tags in the AgentGroup on line " << node->Row() << ". Only the first will be used.";
continue;
}
profileSel = ProfileSelectorDB::getInstance( child, _sceneFldr );
if ( profileSel == 0x0 ) {
logger << Logger::ERR_MSG << "Unable to instantiate the profile selector specification line " << child->Row() << ".";
return false;
}
if ( ! profileSel->cacheProfiles( _profiles ) ) {
logger << Logger::ERR_MSG << "ProfileSelector on line " << child->Row() << " was unable to find a named profile.";
return false;
}
} else if ( child->ValueStr() == "StateSelector" ) {
if ( stateSel != 0x0 ) {
// There should be only one. If there are multiple, only the first will have an effect.
logger << Logger::WARN_MSG << "Found multiple StateSelector tags in the AgentGroup on line " << node->Row() << ". Only the first will be used.";
continue;
}
stateSel = StateSelectorDB::getInstance( child, _sceneFldr );
if ( stateSel == 0x0 ) {
logger << Logger::ERR_MSG << "Unable to instantiate the state selector specification line " << child->Row() << ".";
return false;
}
}
}
if ( profileSel == 0x0 ) {
logger << Logger::ERR_MSG << "No profile selector defined for the AgentGroup on line " << node->Row() << ".";
return false;
}
if ( stateSel == 0x0 ) {
logger << Logger::ERR_MSG << "No state selector defined for the AgentGroup on line " << node->Row() << ".";
return false;
}
// Second pass, parse Generators
for( child = node->FirstChildElement(); child; child = child->NextSiblingElement()) {
if ( child->ValueStr() == "Generator" ) {
AgentGenerator * generator = AgentGeneratorDB::getInstance( child, _sceneFldr );
if ( generator == 0x0 ) {
logger << Logger::ERR_MSG << "Unable to instantiate agent generator specifcation on line " << child->Row() << ".";
return false;
}
// Now instantiate the agents
const size_t AGT_COUNT = generator->agentCount();
for ( size_t i = 0; i < AGT_COUNT; ++i ) {
Vector2 p = generator->agentPos( i );
BaseAgent * agent = _sim->addAgent( p, profileSel->getProfile() );
_sim->getInitialState()->setAgentState( agent->_id, stateSel->getState() );
}
_agtCount += (unsigned int) AGT_COUNT;
generator->destroy();
}
}
return true;
}
示例11: loadFromXML
bool FSMDescrip::loadFromXML(const std::string& xmlName, bool verbose) {
logger << Logger::INFO_MSG << "Loading behavior from xml: " << xmlName;
TiXmlDocument xml(xmlName);
bool loadOkay = xml.LoadFile();
if (!loadOkay) {
logger << Logger::ERR_MSG << "Could not load behavior configuration xml (";
logger << xmlName << ") due to xml syntax errors.\n";
logger << "\t" << xml.ErrorDesc();
return false;
}
TiXmlElement* popNode = xml.RootElement();
if (!popNode) {
logger << Logger::ERR_MSG << "Root element does not exist.";
return false;
}
if (popNode->ValueStr() != "BFSM") {
logger << Logger::ERR_MSG << "Root element value should be \"BFSM\".";
return false;
}
std::string absPath;
os::path::absPath(xmlName, absPath);
std::string junk;
os::path::split(absPath, _behaviorFldr, junk);
logger << Logger::INFO_MSG << "Behavior root: " << _behaviorFldr;
TiXmlElement* child;
for (child = popNode->FirstChildElement(); child; child = child->NextSiblingElement()) {
if (child->ValueStr() == "GoalSet") {
int i;
if (!child->Attribute("id", &i)) {
logger << Logger::ERR_MSG << "GoalSet requires an \"id\" property.";
return false;
}
size_t setID = static_cast<size_t>(i);
// confirm that the id doesn't already exist
if (_goalSets.find(setID) != _goalSets.end()) {
logger << Logger::WARN_MSG << "Found multiple GoalSets with the same id: ";
logger << setID << ".\n\tGoal definitions will be merged!";
} else {
_goalSets[setID] = new GoalSet();
}
TiXmlElement* goalNode;
for (goalNode = child->FirstChildElement(); goalNode;
goalNode = goalNode->NextSiblingElement()) {
if (goalNode->ValueStr() == "Goal") {
Goal* goal = parseGoal(goalNode, _behaviorFldr);
if (goal == 0x0) {
logger << Logger::ERR_MSG << "Error parsing a goal description.";
return false;
}
// Make sure that this goal doesn't duplicate previous goal ids
if (!_goalSets[setID]->addGoal(goal->getID(), goal)) {
logger << Logger::ERR_MSG << "GoalSet " << setID;
logger << " has two goals with the identifier: " << goal->getID();
logger << " (second appears on line " << goalNode->Row() << ").";
return false;
}
} else {
logger << Logger::WARN_MSG
<< "Found a child tag of the GoalSet that "
"is not a \"Goal\" tag on line "
<< goalNode->Row()
<< ". "
"It will be ignored.";
}
}
} else if (child->ValueStr() == "State") {
if (!parseState(child, _behaviorFldr, _states)) {
return false;
}
} else if (child->ValueStr() == "Transition") {
std::string from;
Transition* trans = parseTransition(child, _behaviorFldr, from);
if (trans == 0x0) {
return false;
}
addTransition(from, trans);
} else if (child->ValueStr() == "VelModifier") {
VelModifier* vel = parseVelModifier(child, _behaviorFldr);
if (vel == 0x0) {
return false;
} else {
_velModifiers.push_back(vel);
}
} else if (child->ValueStr() == "Task") {
Task* task = parseTask(child, _behaviorFldr);
if (task == 0x0) {
logger << Logger::WARN_MSG << "User-specified Task on line ";
logger << child->Row()
<< " couldn't be instantiated. "
"It is being ignored.";
} else {
_tasks.push_back(task);
}
} else if (child->ValueStr() == "EventSystem") {
//.........这里部分代码省略.........
示例12: parsXml
bool XmlResLoader::parsXml(const char* szFile)
{
computers.clear();
ErrorLogger* logger = ErrorLogger::Instance();
TiXmlDocument doc(szFile);
if(!doc.LoadFile())
{
OSTRINGSTREAM err;
err<<"Syntax error while loading "<<szFile<<" at line "\
<<doc.ErrorRow()<<": ";
err<<doc.ErrorDesc();
logger->addError(err);
return false;
}
/* retrieving root module */
TiXmlElement *root = doc.RootElement();
if(!root)
{
OSTRINGSTREAM err;
err<<"Syntax error while loading "<<szFile<<" . ";
err<<"No root element.";
logger->addError(err);
return false;
}
if(!compareString(root->Value(), "resources"))
{
/*
OSTRINGSTREAM msg;
msg<<szFile<<" is not a resource descriptor file.";
logger->addWarning(msg);
*/
return false;
}
/* retrieving all computers descriptions */
for(TiXmlElement* restag = root->FirstChildElement();
restag; restag = restag->NextSiblingElement())
{
/* retrieving a computer resource */
if(compareString(restag->Value(), "computer"))
{
Computer computer;
computer.setXmlFile(szFile);
for(TiXmlElement* comptag = restag->FirstChildElement();
comptag; comptag = comptag->NextSiblingElement())
{
/* retrieving name */
if(compareString(comptag->Value(), "name"))
computer.setName(comptag->GetText());
/* retrieving description */
if(compareString(comptag->Value(), "description"))
computer.setDescription(comptag->GetText());
/* retrieving disablility */
if(compareString(comptag->Value(), "disable"))
{
if(compareString(comptag->GetText(), "yes"))
computer.setDisable(true);
}
// platform
if(compareString(comptag->Value(), "platform"))
{
Platform os;
TiXmlElement* element;
if((element = (TiXmlElement*) comptag->FirstChild("name")))
os.setName(element->GetText());
else
{
OSTRINGSTREAM war;
war<<"Platform from "<<szFile<<" at line "\
<<comptag->Row()<<" has no name.";
logger->addWarning(war);
}
if((element = (TiXmlElement*) comptag->FirstChild("distribution")))
os.setDistribution(element->GetText());
if((element = (TiXmlElement*) comptag->FirstChild("release")))
os.setRelease(element->GetText());
computer.setPlatform(os);
} // end of platform tag
// memory
if(compareString(comptag->Value(), "memory"))
{
Memory mem;
TiXmlElement* element;
if((element = (TiXmlElement*) comptag->FirstChild("total_space")))
mem.setTotalSpace((Capacity)atol(element->GetText()));
computer.setMemory(mem);
} // end of memory tag
// storage
//.........这里部分代码省略.........
示例13: FileLoadException
Island::Island(const std::string& filename, int pos_x, int pos_y, std::vector<bool>& waterTiles) : m_x(pos_x), m_y(pos_y), m_tiles(NULL), m_defaultTile(0)
{
m_defaultTile = Tile::getDefaultTile();
std::cout << "Trying to load island \"" << filename << "\"" << std::endl;
TiXmlDocument document;
if (!document.PHYSFS_LoadFile(filename))
{
throw FileLoadException(filename, document.ErrorDesc());
}
if(!document.RootElement() || document.RootElement()->ValueStr() != "island")
throw XMLException(filename, -1, "This is no valid island XML file (missing island root element)");
TiXmlElement *island = document.RootElement();
if (!island->Attribute("cols"))
throw XMLException(filename, island->Row(), "Missing attribute cols");
if (!island->Attribute("rows"))
throw XMLException(filename, island->Row(), "Missing attribute rows");
if (!island->Attribute("clime"))
throw XMLException(filename, island->Row(), "Missing attribute clime");
std::stringstream attr;
attr << island->Attribute("cols") << " " << island->Attribute("rows");
attr >> m_cols >> m_rows;
m_clime = island->Attribute("clime");
std::cout << "Creating " << (m_rows * m_cols) << " tiles" << std::endl;
m_tiles = new Tile* [m_rows * m_cols];
memset(m_tiles, 0, sizeof(Tile*) * m_rows * m_cols);
TiXmlElement *terrain = island->FirstChildElement("terrain");
if (!terrain)
throw XMLException(filename, island->Row(), "Missing toplevel element terrain");
TiXmlElement *row = terrain->FirstChildElement("row");
if (!terrain)
throw XMLException(filename, terrain->Row(), "Missing row subelements");
while (row)
{
if (!row->Attribute("value"))
throw XMLException(filename, row->Row(), "Missing attribute value");
std::stringstream rowStr(row->Attribute("value"));
int rowInt;
rowStr >> rowInt;
rowInt--;
TiXmlElement *col = row->FirstChildElement("col");
if (!col)
throw XMLException(filename, row->Row(), "Missing col subelements");
while (col)
{
if (!col->Attribute("value"))
throw XMLException(filename, col->Row(), "Missing attribute value");
std::stringstream colStr(col->Attribute("value"));
int colInt;
colStr >> colInt;
colInt--;
TiXmlElement *tile = col->FirstChildElement("tile");
if (!tile)
throw XMLException(filename, col->Row(), "Missing tile subelement");
if (((rowInt * m_cols) + colInt) >= m_cols * m_rows)
std::cout << "WARNING! Index out of bounds. Row: " << rowInt << ", column: " << colInt << std::endl;
else
{
m_tiles[(rowInt * m_cols) + colInt] = new Tile(tile);
if (m_tiles[(rowInt * m_cols) + colInt] == NULL) {
std::cout << "TILE CREATION FAILED" << std::endl;
}
waterTiles[(rowInt * m_cols) + colInt] = false;
}
col = col->NextSiblingElement("col");
}
row = row->NextSiblingElement("row");
}
std::cout << "Succesfully loaded island \"" << filename << "\"" << std::endl;
std::cout << "\tColums: " << m_cols << std::endl;
std::cout << "\tRows: " << m_rows << std::endl;
/* std::cout << "debug-listing 0,0 to 9,9" << std::endl;
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
std::cout << m_tiles[(y * m_cols) + x]->getName();
std::cout << ",";
}
std::cout << std::endl;
}*/
}
示例14: main
//.........这里部分代码省略.........
XmlTest( "'Item' children of the 'ToDo' element, using First/Next.", 3, count );
count = 0;
for( node = todoElement->LastChild( "Item" );
node;
node = node->PreviousSibling( "Item" ) )
{
count++;
}
XmlTest( "'Item' children of the 'ToDo' element, using Last/Previous.", 3, count );
#ifdef TIXML_USE_STL
{
cout << "\n** Parsing. **\n";
istringstream parse0( "<Element0 attribute0='foo0' attribute1= noquotes attribute2 = '>' />" );
TiXmlElement element0( "default" );
parse0 >> element0;
XmlTest ( "Element parsed, value is 'Element0'.", "Element0", element0.Value() );
XmlTest ( "Reads attribute 'attribute0=\"foo0\"'.", "foo0", element0.Attribute( "attribute0" ));
XmlTest ( "Reads incorrectly formatted 'attribute1=noquotes'.", "noquotes", element0.Attribute( "attribute1" ) );
XmlTest ( "Read attribute with entity value '>'.", ">", element0.Attribute( "attribute2" ) );
}
#endif
{
const char* error = "<?xml version=\"1.0\" standalone=\"no\" ?>\n"
"<passages count=\"006\" formatversion=\"20020620\">\n"
" <wrong error>\n"
"</passages>";
TiXmlDocument doc;
doc.Parse( error );
XmlTest( "Error row", doc.ErrorRow(), 3 );
XmlTest( "Error column", doc.ErrorCol(), 17 );
//printf( "error=%d id='%s' row %d col%d\n", (int) doc.Error(), doc.ErrorDesc(), doc.ErrorRow()+1, doc.ErrorCol() + 1 );
}
{
const char* str = "\t<?xml version=\"1.0\" standalone=\"no\" ?>\t<room doors='2'>\n"
" <!-- Silly example -->\n"
" <door wall='north'>A great door!</door>\n"
"\t<door wall='east'/>"
"</room>";
TiXmlDocument doc;
doc.Parse( str );
TiXmlHandle docHandle( &doc );
TiXmlHandle roomHandle = docHandle.FirstChildElement( "room" );
TiXmlHandle commentHandle = docHandle.FirstChildElement( "room" ).FirstChild();
TiXmlHandle textHandle = docHandle.FirstChildElement( "room" ).ChildElement( "door", 0 ).FirstChild();
TiXmlHandle door0Handle = docHandle.FirstChildElement( "room" ).ChildElement( 0 );
TiXmlHandle door1Handle = docHandle.FirstChildElement( "room" ).ChildElement( 1 );
assert( docHandle.Node() );
assert( roomHandle.Element() );
assert( commentHandle.Node() );
assert( textHandle.Text() );
assert( door0Handle.Element() );
assert( door1Handle.Element() );
TiXmlDeclaration* declaration = doc.FirstChild()->ToDeclaration();
assert( declaration );
TiXmlElement* room = roomHandle.Element();
assert( room );
示例15: loadFromXML
bool SimXMLLoader::loadFromXML( const std::string & filename, AgentInitializer * agentInit, bool verbose ) {
// COnfirms file is
// a) available for reading
// b) valid xml
// c) An "Experiment"
if ( verbose ) logger << Logger::INFO_MSG << "Loading from xml: " << filename << ".";
TiXmlDocument xml( filename );
bool loadOkay = xml.LoadFile();
if ( !loadOkay ) { // load xml file
logger << Logger::ERR_MSG << "Could not load simulation configuration xml (" << filename << ") due to xml syntax errors.\n";
logger << "\t" << xml.ErrorDesc();
return false;
}
TiXmlElement* experimentNode = xml.RootElement();
if( ! experimentNode ) {
logger << Logger::ERR_MSG << "Scene configuration (" << filename << ") does not contain a root element.";
return false;
}
if( experimentNode->ValueStr () != "Experiment" ) {
logger << Logger::ERR_MSG << "Scene configuration (" << filename << ")'s root element is not \"Experiment\".";
return false;
}
std::string absPath;
os::path::absPath( filename, absPath );
std::string junk;
os::path::split( absPath, _sceneFldr, junk );
logger << Logger::INFO_MSG << "Scene root: " << _sceneFldr << ".";
bool commonDone = false; // common experiment parameters parsed
bool targetDone = !_sim->hasExpTarget(); // target experiment parameters parsed
bool spatialQueryDone = false; // spatial query must be finished before obstacles and agents can be created
// Tags I'm not ready to parse - only parse agent sets and obstacles AFTER experiment
// parameters
std::list< TiXmlElement * > tagQueue;
TiXmlElement* child;
for( child = experimentNode->FirstChildElement(); child; child = child->NextSiblingElement()) {
if ( child->ValueStr() == "Common" ) {
// Currently the only "common" experiment parameter is the time step
TiXmlAttribute * attr;
for ( attr = child->FirstAttribute(); attr; attr = attr->Next() ) {
try {
if ( !_sim->setExpParam( attr->Name(), attr->ValueStr() ) ) {
logger << Logger::WARN_MSG << "Unrecognized parameter in the global \"Common\" parameters (" << attr->Name() << ") on line " << child->Row() << "\n";
}
} catch ( XMLParamException e ) {
logger << Logger::ERR_MSG << e.what();
return false;
}
}
commonDone = true;
} else if ( child->ValueStr() == "AgentProfile" ) {
if ( !parseAgentProfile( child, agentInit ) ) {
return false;
}
} else if ( child->ValueStr() == "AgentGroup" ) {
if ( ! ( commonDone || targetDone || spatialQueryDone ) ) {
tagQueue.push_back( child );
} else {
if ( !parseAgentGroup( child, agentInit ) ) {
return false;
}
}
} else if ( child->ValueStr() == "ObstacleSet" ) {
if ( ! ( commonDone || targetDone || spatialQueryDone) ) {
tagQueue.push_back( child );
} else {
if ( ! parseObstacleSet( child ) ) {
return false;
}
}
} else if ( child->ValueStr() == "Elevation" ) {
if ( _sim->hasElevation() ) {
logger << Logger::ERR_MSG << "More than one elevation has been specified. Found redundant elevation specification on line " << child->Row() << ".";
return false;
}
Elevation * elevation = ElevationDB::getInstance( child, _sceneFldr );
if ( elevation == 0x0 ) {
logger << Logger::ERR_MSG << "Unable to instantiate elevation specifcation on line " << child->Row() << ".";
return false;
} else {
_sim->setElevationInstance( elevation );
}
Menge::ELEVATION = elevation;
} else if ( child->ValueStr() == "SpatialQuery" ) {
if ( _sim->hasSpatialQuery() ) {
logger << Logger::ERR_MSG << "More than one spatial query implementation has been specified. Found redundant spatial query specification on line " << child->Row() << ".";
return false;
}
SpatialQuery * spQuery = SpatialQueryDB::getInstance( child, _sceneFldr );
if ( spQuery == 0x0 ) {
logger << Logger::ERR_MSG << "Unable to instantiate spatial query specifcation on line " << child->Row() << ".";
return false;
} else {
_sim->setSpatialQuery( spQuery );
//.........这里部分代码省略.........