本文整理汇总了C++中xml_node::child方法的典型用法代码示例。如果您正苦于以下问题:C++ xml_node::child方法的具体用法?C++ xml_node::child怎么用?C++ xml_node::child使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml_node
的用法示例。
在下文中一共展示了xml_node::child方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _configure
/**
* @brief Configures the block: defines the input file.
* @param n The configuration parameters
*/
virtual void _configure(const xml_node& n)
{
xml_node source = n.child("source");
xml_node gates_node = n.child("gates");
if( (!source) || (!gates_node) )
throw std::runtime_error("TweetReader: missing parameter");
std::string gates_s = gates_node.attribute("number").value();
std::string type = source.attribute("type").value();
std::string ip = source.attribute("ip").value();
file_name = source.attribute("name").value();
if(!type.length() || !file_name.length() || !gates_s.length())
throw std::runtime_error("TweetReader: missing attribute");
if(type.compare("offline") != 0)
throw std::runtime_error("TweetReader: invalid type parameter");
num_gates = atoi(gates_s.c_str());
file.open(file_name);
if(!file.is_open()) {
throw std::runtime_error("TweetReader: cannot open source file");
}
// Create and register the output gates
m_outgate_ids = new int[num_gates];
for(int i=0; i<num_gates; i++){
std::string ogate = outgate_basename + boost::lexical_cast<std::string>(i);
m_outgate_ids[i] = register_output_gate(ogate.c_str());
}
}
示例2: processInputVariable
bool XMLFPParser::processInputVariable(const xml_node& var_root,
MamdaniFuzzyObject* object) {
InputLinguisticVariable *variable = new InputLinguisticVariable(var_root.child(LINGUISTIC_VARIABLE_ID_TAG).first_child().value(),
parsing::extractFloat(var_root.child(LINGUISTIC_VARIABLE_LOW_BOUND_TAG).child(LINGUISTIC_VARIABLE_VALUE_TAG).first_child().value()),
parsing::extractFloat(var_root.child(LINGUISTIC_VARIABLE_UP_BOUND_TAG).child(LINGUISTIC_VARIABLE_VALUE_TAG).first_child().value()));
if(!loopFuzzySets(var_root.child(LINGUISTIC_VARIABLE_SETS_TAG),variable)){
LERROR << "Error in parsing the fuzzy set for the variable : " << std::string(var_root.child(LINGUISTIC_VARIABLE_ID_TAG).first_child().value());
return false;
}
return object->addInputVar(variable);
}
示例3: _configure
/**
* configures the filter
* @param n the xml subtree
*/
virtual void _configure(const xml_node& n )
{
xml_node config = n.child("config");
xml_node log = n.child("logdir");
if(!config or !log)
throw std::runtime_error("TstatAnalyzer: missing parameter");
std::string cname=config.attribute("name").value();
tstat_init((char*)cname.c_str());
std::string lname=config.attribute("name").value();
struct timeval cur_time;
gettimeofday(&cur_time,NULL);
tstat_new_logdir((char*)lname.c_str(), &cur_time);
}
示例4: parseRule
bool XMLFPParser::parseRule (const xml_node& rule, MamdaniFuzzyObject* object){
string rule_string = rule.child(RULE_CONSEQUENT_TAG).child(RULE_VALUE_TAG).first_child().value();
uniformRuleSintax(rule_string);
MamdaniRule* toAdd = new MamdaniRule(rule_string);
return object->addRule(toAdd);
}
示例5: domain_error
vector<Light> Scene::readLights(const xml_node &scene)
{
xml_node lightsNode = scene.child("lights");
if(!lightsNode)
throw domain_error("readLights: Couldn't found <lights> node");
vector<Light> res;
for (xml_node node = lightsNode.first_child(); node; node = node.next_sibling())
{
if(string(node.name()) != "light")
{
stringstream ss;
ss << "Encountered an invalid <" << node.name() << "> element in the lights element.";
throw domain_error(ss.str().c_str());
}
Light light(
vectorFromChild(node, "position"),
colorFromChild(node, "ambientColor"),
colorFromChild(node, "diffuseColor"),
floatFromChild(node, "linearAttenuation"),
floatFromChild(node, "quadAttenuation")
);
res.push_back(light);
}
if(res.empty()){
throw domain_error("No lights found. The scene must have at least one light.");
}
return res;
}
示例6: parseLinguisticVariable
bool XMLFPParser::parseLinguisticVariable(const xml_node& node,
MamdaniFuzzyObject* object, const string& outputName) {
string variable_name = node.child(LINGUISTIC_VARIABLE_ID_TAG).first_child().value();
if (variable_name == outputName) // it's the output variable
return processOutputVariable(node, object);
else
return processInputVariable(node, object);
}
示例7: intFromChild
int Scene::intFromChild(const xml_node &node, const string &child)
{
xml_node childNode = node.child(child.c_str());
if(!childNode){
stringstream ss;
ss << "node <"<< node.name() << "> has no child named '" << child << "'";
throw invalid_argument(ss.str().c_str());
}
return childNode.text().as_int();
}
示例8:
static void
get_channelnames (const xml_node &n, std::vector<std::string> &channelnames)
{
xml_node channel_node = n.child ("channelnames");
for (xml_node n = channel_node.child ("channelname"); n;
n = n.next_sibling ("channelname")) {
channelnames.push_back (n.child_value ());
}
}
示例9: add_layer
void Tilemap::add_layer(std::map<unsigned, Surface>& tiles, xml_node node,
int tilewidth, int tileheight)
{
Layer layer;
int width = node.attribute("width").as_int();
int height = node.attribute("height").as_int();
if (!width || !height)
throw std::logic_error("Layer is empty.");
#if 0
std::cerr << "Adding layer:" <<
" Name: " << node.attribute("name").value() <<
" Width: " << width <<
" Height: " << height << std::endl;
#endif
Utils::xml_node_walker walk{node.child("data"), "tile", "gid"};
int index = 0;
for (auto& gid_str : walk)
{
Pos pos = Pos(index % width, index / width);
unsigned gid = Utils::stoi(gid_str);
if (gid)
{
Blit::Surface surf = tiles[gid];
surf.rect().pos = pos * Pos(tilewidth, tileheight);
layer.cluster.vec().push_back({surf, Pos()});
if (Utils::find_or_default(surf.attr(), "collision", "") == "true")
collisions.insert(pos);
}
index++;
}
layer.attr = get_attributes(node.child("properties"), "property");
layer.name = node.attribute("name").value();
m_layers.push_back(std::move(layer));
}
示例10: Load
bool BoneTimelineKey::Load(const xml_node& node)
{
if (!SpatialTimelineKey::Load(node))
return false;
xml_node boneNode = node.child("bone");
length_ = boneNode.attribute("length").as_float(200.0f);
width_ = boneNode.attribute("width").as_float(10.0f);
return true;
}
示例11: loopRules
bool XMLFPParser::loopRules(const xml_node& rules_root,
MamdaniFuzzyObject* object) {
for (xml_node rule = rules_root.child(RULE_TAG); rule; rule = rule.next_sibling(RULE_TAG)){
if(!parseRule(rule, object)){
LERROR << "Error during parse rule for object: " << object->getName();
return false;
}
}
return true;
}
示例12: EnemyWeaponSystem
FrogShip::FrogShip(xml_node mirrorNode) {
xml_node shipNode = mirrorNode.parent().parent();
xml_node startNode = mirrorNode.child("start");
xml_node controlNode = mirrorNode.child("controlPoint");
xml_node climaxNode = mirrorNode.child("climax");
xml_node endNode = mirrorNode.child("end");
startPos = Vector2(
getFloatFrom(startNode.attribute("x")) + camera.viewportPosition.x,
getFloatFrom(startNode.attribute("y")));
controlPoint = Vector2(
getFloatFrom(controlNode.attribute("x")) + camera.viewportPosition.x,
getFloatFrom(controlNode.attribute("y")));
climaxPos = Vector2(
getFloatFrom(climaxNode.attribute("x")) + camera.viewportPosition.x,
getFloatFrom(climaxNode.attribute("y")));;
endPos = Vector2(
getFloatFrom(endNode.attribute("x")) + camera.viewportPosition.x,
getFloatFrom(endNode.attribute("y")));
xml_node weaponPointsNode = shipNode.child("weaponPoints");
xml_node weaponSystemsNode = shipNode.parent().child("weaponSystems");
for (xml_node weaponNode = weaponPointsNode.child("weapon");
weaponNode; weaponNode = weaponNode.next_sibling()) {
weaponSystems.push_back(unique_ptr<EnemyWeaponSystem>(
new EnemyWeaponSystem(weaponNode, weaponSystemsNode)));
}
maxHealth = shipNode.child("health").text().as_int();
health = maxHealth;
position = Globals::SHIP_STORE_POSITION;
}
示例13: readSceneResolution
void Scene::readSceneResolution(const xml_node &scene, int& outWidth, int& outHeight)
{
xml_node node = scene.child("resolution");
if(!node)
throw domain_error("readSceneResolution: Couldn't found <resolution> node");
stringstream ss;
ss << node.text().as_string();
ss >> outWidth >> outHeight;
if(ss.fail())
throw domain_error("Bad resolution format. Couldn't read resolution x & y");
}
示例14:
ConfigManager::ConfigManager( xml_node n)
{
activeLineIndicator=n.child("LineIndicator").attribute("active").value();
lineIndicator=n.child("LineIndicator").attribute("default").value();
int l= activeLineIndicator.length() - lineIndicator.length();
if( l>0 ){ //active is longer
for( int i=0;i<l;i++)
lineIndicator+=" ";
}else{
for( int i=0;i<l;i++)
lineIndicator+=" ";
}
maxLines=n.child("maxLines").text().as_int();
maxChar=n.child("maxChar").text().as_int();
if( activeLineIndicator.length() > lineIndicator.length() ){
maxLineIndicatorLength=activeLineIndicator.length();
}else{
maxLineIndicatorLength=lineIndicator.length();
}
}
示例15: loopLinguisticVariables
bool XMLFPParser::loopLinguisticVariables(const xml_node& node,
MamdaniFuzzyObject* object, const string& outputName) {
for (xml_node lang_var_root = node.child(LINGUISTIC_VARIABLE_TAG) ; lang_var_root ; lang_var_root = lang_var_root.next_sibling(LINGUISTIC_VARIABLE_TAG)){
if(!parseLinguisticVariable(lang_var_root, object, outputName)){
LERROR << "Error parsing the object " + outputName;
return false;
}
}
return true;
}