本文整理汇总了C++中ptree::get_child_optional方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::get_child_optional方法的具体用法?C++ ptree::get_child_optional怎么用?C++ ptree::get_child_optional使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ptree
的用法示例。
在下文中一共展示了ptree::get_child_optional方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//------------------------------------------------------------------------------
void
Image::set(ptree pt)
{
if(pt.get_child_optional("UV")) this->setUV(Box(pt.get_child("UV")), getBoolFromPT(pt, "UV.normalized", false));
if(pt.get_child_optional("NinePatch")) this->setNinePatchData(NinePatchData(pt.get_child("NinePatch")));
if(pt.get_child_optional("color")) this->color = Color(pt.get("color", "#FFF"));
};
示例2: if
//------------------------------------------------------------------------------
void
WText::_set(ptree n)
{
if(n.get_child_optional("text.content"))
this->setText(n.get("text.content", this->text));
if(n.get_child_optional("text.padding"))
this->padding = n.get<FNumber>("text.padding");
if(n.get_child_optional("text.font"))
{
if(n.get_child_optional("text.font.path") && n.get_child_optional("text.font.size"))
this->setFont(this->kernel->graphicsMgr->loadFont(
n.get<string>("text.font.path"),
n.get<int> ("text.font.size")));
else if(n.get_child_optional("text.font.size"))
this->setFontSize(n.get<int>("text.font.size"));
else if(n.get_child_optional("text.font.path"))
this->setFont(this->kernel->graphicsMgr->loadFont(
n.get<string>("text.font.path"),
this->font.getSize()));
if(n.get_child_optional("text.font.color"))
this->setColor(Color(n.get<string>("text.font.color")));
if(n.get_child_optional("text.font.background_color"))
this->setBG(Color(n.get<string>("text.font.background_color")));
/// TODO: transparent [bool]
/// TODO: alignment
}
};
示例3:
//------------------------------------------------------------------------------
void
WTextInput::_set(ptree n)
{
WText::_set(n);
if(n.get_child_optional("border_normal"))
this->setBorderNormal (kernel->graphicsMgr->loadImage(n.get_child("border_normal")));
if(n.get_child_optional("border_focused"))
this->setBorderFocused(kernel->graphicsMgr->loadImage(n.get_child("border_focused")));
};
示例4: gradient
radial_gradient::radial_gradient(element* doc, const ptree& pt)
: gradient(doc, pt)
{
auto attributes = pt.get_child_optional("<xmlattr>");
if(attributes) {
auto cx = attributes->get_child_optional("cx");
auto cy = attributes->get_child_optional("cy");
auto radius = attributes->get_child_optional("r");
auto fx = attributes->get_child_optional("fx");
auto fy = attributes->get_child_optional("fy");
if(cx) {
cx_.from_string(cx->data());
}
if(cy) {
cy_.from_string(cy->data());
}
if(radius) {
r_.from_string(radius->data());
}
if(fx) {
fx_.from_string(fx->data());
}
if(fy) {
fy_.from_string(fy->data());
}
}
}
示例5: load
// load
void configuration::load(const ptree& in_conf) {
try {
settings_ = in_conf.get_child(settings_path_);
LOG_INFO(settings_path_, "Loading settings");
auto model = settings_.get_optional<std::string>(model_key_);
if (!model) {
throw configuration_error("model descriptor '" + model_key_ +
"' has to be set in " + settings_path_);
}
defaults_path_ += "." + *model;
auto def = in_conf.get_child_optional(defaults_path_);
if (def) {
LOG_INFO(settings_path_, *model + " defaults found.");
defaults_ = *def;
} else {
LOG_INFO(settings_path_, "No default settings provided for this board.");
}
} catch (ptree_bad_path& e) {
throw path_error(e.path<std::string>());
} catch (ptree_error& e) {
// shouldn't happen
throw configuration_error("Processing error", e.what());
}
}
示例6: save
// save
void configuration::save(ptree& out_conf) const {
out_conf.put_child(settings_path_, settings_);
LOG_INFO(settings_path_, "Settings saved.");
if (!out_conf.get_child_optional(defaults_path_)) {
out_conf.put_child(defaults_path_, defaults_);
LOG_INFO(defaults_path_, "Settings saved.");
}
}
示例7: if
gradient::gradient(element* doc, const ptree& pt)
: core_attribs(pt),
coord_system_(GradientCoordSystem::OBJECT_BOUNDING_BOX),
spread_(GradientSpreadMethod::PAD)
{
// Process attributes
auto attributes = pt.get_child_optional("<xmlattr>");
if(attributes) {
auto xlink_href = attributes->get_child_optional("xlink:xref");
auto transforms = attributes->get_child_optional("gradientTransforms");
auto units = attributes->get_child_optional("gradientUnits");
auto spread = attributes->get_child_optional("spreadMethod");
if(transforms) {
transforms_ = transform::factory(transforms->data());
}
if(xlink_href) {
xlink_href_ = xlink_href->data();
}
if(units) {
std::string csystem = units->data();
if(csystem == "userSpaceOnUse") {
coord_system_ = GradientCoordSystem::USERSPACE_ON_USE;
} else if(csystem =="objectBoundingBox") {
coord_system_ = GradientCoordSystem::OBJECT_BOUNDING_BOX;
} else {
ASSERT_LOG(false, "Unrecognised 'gradientUnits' value: " << csystem);
}
}
if(spread) {
std::string spread_val = units->data();
if(spread_val == "pad") {
spread_ = GradientSpreadMethod::PAD;
} else if(spread_val =="reflect") {
spread_ = GradientSpreadMethod::REFLECT;
} else if(spread_val =="repeat") {
spread_ = GradientSpreadMethod::REPEAT;
} else {
ASSERT_LOG(false, "Unrecognised 'spreadMethod' value: " << spread_val);
}
}
// Process child elements
for(auto& v : pt) {
if(v.first == "stop") {
stops_.emplace_back(new gradient_stop(doc, v.second));
} else if(v.first == "<xmlattr>") {
// ignore
} else if(v.first == "<xmlcomment>") {
// ignore
} else {
ASSERT_LOG(false, "unexpected child element in gradient stop list: " << v.first);
}
}
}
}
示例8: add_to_data
void add_to_data(ptree& pt, const ptree& record)
{
if(!pt.get_child_optional("data")) {
ptree arrayPt;
arrayPt.push_back(make_pair("", record));
pt.push_back(make_pair("data", arrayPt));
} else {
auto& dataPt = pt.get_child("data");
dataPt.push_back(make_pair("", record));
}
}
示例9: vInit
/*
<scriptComponent>
<scriptObject constructor="addPlayer" destructor="removePlayer" />
<scriptData actorType="player"/>
</scriptComponent>
*/
bool ScriptComponent::vInit(const ptree componentNode) {
optional<const ptree&> optScriptObject = componentNode.get_child_optional(SCRIPT_OBJECT_NODE_NAME);
if (optScriptObject.is_initialized()) {
bool result = readScriptObjectNode(optScriptObject.get());
if (!result) {
return false;
}
}
optional<const ptree&> optScriptData = componentNode.get_child_optional(SCRIPT_DATA_NODE_NAME);
if (optScriptData.is_initialized()) {
bool result = readScriptDataNode(optScriptData.get());
if (!result) {
return false;
}
}
return true;
};
示例10: addToArray
void MsgPrinter::addToArray(ptree& root, string name, map<string, string>& object) {
static const string array_sufix = "..";
optional<ptree&> child = root.get_child_optional(name);
if (child.is_initialized()) {
child.get().push_front(
make_pair("", getItem(object))
);
} else {
put(root, name + array_sufix, object);
}
}
示例11: catch
gradient_stop::gradient_stop(element* doc, const ptree& pt)
: core_attribs(pt),
offset_(0.0),
opacity_(1.0),
opacity_set_(false)
{
auto attributes = pt.get_child_optional("<xmlattr>");
if(attributes) {
auto opacity = attributes->get_child_optional("stop-opacity");
auto color = attributes->get_child_optional("stop-color");
auto offset = attributes->get_child_optional("offset");
if(opacity) {
opacity_set_ = true;
const std::string alpha = opacity->data();
try {
opacity_ = boost::lexical_cast<double>(alpha);
} catch(const boost::bad_lexical_cast&) {
ASSERT_LOG(false, "Couldn't convert opacity value to number: " << alpha);
}
}
if(color) {
color_ = paint::from_string(color->data());
if(opacity) {
color_->set_opacity(opacity_);
}
}
ASSERT_LOG(!offset, "No offset field given in gradient color stop");
const std::string offs = offset->data();
try {
offset_ = boost::lexical_cast<double>(offs);
} catch(const boost::bad_lexical_cast&) {
ASSERT_LOG(false, "Couldn't convert opacity value to number: " << offs);
}
if(offs.find('%') != std::string::npos) {
offset_ /= 100.0;
}
offset_ = std::max(std::min(offset_, 1.0), 0.0);
}
}
示例12:
core_attribs::core_attribs(const ptree& pt)
{
auto attributes = pt.get_child_optional("<xmlattr>");
if(attributes) {
auto id = attributes->get_child_optional("id");
if(id) {
id_ = id->data();
}
auto xml_base = attributes->get_child_optional("xml:base");
if(xml_base) {
xml_base_ = xml_base->data();
}
auto xml_lang = attributes->get_child_optional("xml:lang");
if(xml_lang) {
xml_lang_ = xml_lang->data();
}
auto xml_space = attributes->get_child_optional("xml:space");
if(xml_space) {
xml_space_ = xml_space->data();
}
}
}
示例13: readPart
/**
* <Part>からパーツを構築する
*/
static shared_ptr<SsPart> readPart(const ptree& pt, textenc::Encoding encoding, int motionEndFrameNo)
{
do
{
shared_ptr<SsPart> part = shared_ptr<SsPart>(new SsPart());
// 必須パラメータ
optional<int> type = pt.get_optional<int>("Type");
if (!type) break;
// オプションパラメータ
optional<int> root = pt.get_optional<int>("<xmlattr>.Root");
optional<std::string> name = pt.get_optional<std::string>("Name");
optional<int> id = pt.get_optional<int>("ID");
optional<int> parentId = pt.get_optional<int>("ParentID");
optional<int> picId = pt.get_optional<int>("PicID");
optional<int> picAreaLeft = pt.get_optional<int>("PictArea.Left");
optional<int> picAreaTop = pt.get_optional<int>("PictArea.Top");
optional<int> picAreaRight = pt.get_optional<int>("PictArea.Right");
optional<int> picAreaBottom = pt.get_optional<int>("PictArea.Bottom");
optional<int> originX = pt.get_optional<int>("OriginX");
optional<int> originY = pt.get_optional<int>("OriginY");
optional<int> transBlendType = pt.get_optional<int>("TransBlendType"); // alpha blend
optional<int> inheritType = pt.get_optional<int>("InheritType");
// Rootアトリビュートが1のときはRootパーツとして扱う
if (root && root.get() == 1)
{
part->type = SsPart::TypeRoot;
}
else
{
part->type = static_cast<SsPart::Type>(type.get());
}
if (name)
{
std::string n = textenc::convert(name.get(), encoding, textenc::SHIFT_JIS);
part->name = n;
}
if (id) part->id = id.get();
if (parentId) part->parentId = parentId.get();
if (picId) part->picId = picId.get();
if (picAreaLeft && picAreaTop && picAreaRight && picAreaBottom)
{
part->picArea = SsRect(
picAreaLeft.get(),
picAreaTop.get(),
picAreaRight.get(),
picAreaBottom.get());
}
if (transBlendType)
{
int blendType = transBlendType.get();
if (blendType < 0 || blendType >= SsPart::NumAlphaBlend) blendType = 0;
part->alphaBlend = static_cast<SsPart::AlphaBlend>(blendType);
}
if (originX && originY)
{
part->origin = SsPoint(
originX.get(),
originY.get());
}
if (inheritType)
{
part->inheritEach = inheritType.get() != 0;
}
std::vector<SsAttribute::Ptr> attributes;
optional<const ptree&> attrs = pt.get_child_optional("Attributes");
if (attrs)
{
BOOST_FOREACH( const ptree::value_type& v2, pt.get_child("Attributes") )
{
if (v2.first == "Attribute")
{
const ptree& attr = v2.second;
shared_ptr<SsAttribute> attribute = readAttribute(attr, encoding);
if (!attribute) continue;
attributes.push_back(attribute);
}
}
}
part->attributes = SsAttributes(attributes, motionEndFrameNo);
return part;
} while (false);
return shared_ptr<SsPart>();
}
示例14: if
/**
* <Key>からキーフレームを構築する
*/
static shared_ptr<SsKeyframe> readKey(const ptree& pt, const SsAttributeTag::Tag& tag, textenc::Encoding encoding)
{
do
{
// 必須パラメータ
optional<int> time = pt.get_optional<int>("<xmlattr>.Time");
if (!time) break;
boost::shared_ptr<SsValue> ssValue;
if (tag == SsAttributeTag::VERT)
{
// 頂点変形
optional<int> topLeftX = pt.get_optional<int>("TopLeft.X");
optional<int> topLeftY = pt.get_optional<int>("TopLeft.Y");
optional<int> topRightX = pt.get_optional<int>("TopRight.X");
optional<int> topRightY = pt.get_optional<int>("TopRight.Y");
optional<int> bottomLeftX = pt.get_optional<int>("BottomLeft.X");
optional<int> bottomLeftY = pt.get_optional<int>("BottomLeft.Y");
optional<int> bottomRightX = pt.get_optional<int>("BottomRight.X");
optional<int> bottomRightY = pt.get_optional<int>("BottomRight.Y");
if (!topLeftX || !topLeftY) break;
if (!topRightX || !topRightY) break;
if (!bottomLeftX || !bottomLeftY) break;
if (!bottomRightX || !bottomRightY) break;
SsVertex4Value* value = new SsVertex4Value();
value->v[SS_VERTEX_TOP_LEFT].x = topLeftX.get();
value->v[SS_VERTEX_TOP_LEFT].y = topLeftY.get();
value->v[SS_VERTEX_TOP_RIGHT].x = topRightX.get();
value->v[SS_VERTEX_TOP_RIGHT].y = topRightY.get();
value->v[SS_VERTEX_BOTTOM_LEFT].x = bottomLeftX.get();
value->v[SS_VERTEX_BOTTOM_LEFT].y = bottomLeftY.get();
value->v[SS_VERTEX_BOTTOM_RIGHT].x = bottomRightX.get();
value->v[SS_VERTEX_BOTTOM_RIGHT].y = bottomRightY.get();
ssValue = boost::shared_ptr<SsValue>(value);
}
else if (tag == SsAttributeTag::PCOL)
{
// カラーブレンド
optional<int> type = pt.get_optional<int>("Type");
optional<int> blend = pt.get_optional<int>("Blend");
if (!type || !blend) break;
if (type.get() < 0 || type.get() >= SsColorBlendValue::END_OF_TYPE) break;
if (blend.get() < 0 || blend.get() >= SsColorBlendValue::END_OF_BLEND) break;
SsColorBlendValue value;
value.type = static_cast<SsColorBlendValue::Type>(type.get());
value.blend = static_cast<SsColorBlendValue::Blend>(SsColorBlendValue::BLEND_MIX + blend.get());
if (value.type == SsColorBlendValue::TYPE_COLORTYPE_PARTS)
{
// 単色
optional<const ptree&> v = pt.get_child_optional("Value");
if (!v) break;
bool result = readColors(value.colors[0], v.get());
if (!result) break;
// 後の処理で扱いやすいように他の頂点ワークにも同じ値を設定しておく
readColors(value.colors[1], v.get());
readColors(value.colors[2], v.get());
readColors(value.colors[3], v.get());
}
else if (value.type == SsColorBlendValue::TYPE_COLORTYPE_VERTEX)
{
// 頂点カラー
optional<const ptree&> tl = pt.get_child_optional("TopLeft");
optional<const ptree&> tr = pt.get_child_optional("TopRight");
optional<const ptree&> bl = pt.get_child_optional("BottomLeft");
optional<const ptree&> br = pt.get_child_optional("BottomRight");
if (!tl || !tr || !bl || !br) break;
bool result;
result = readColors(value.colors[SS_VERTEX_TOP_LEFT], tl.get());
if (!result) break;
result = readColors(value.colors[SS_VERTEX_TOP_RIGHT], tr.get());
if (!result) break;
result = readColors(value.colors[SS_VERTEX_BOTTOM_LEFT], bl.get());
if (!result) break;
result = readColors(value.colors[SS_VERTEX_BOTTOM_RIGHT], br.get());
if (!result) break;
}
else if (value.type == SsColorBlendValue::TYPE_COLORTYPE_NONE)
{
// カラー指定無し
value.colors[0] =
value.colors[1] =
value.colors[2] =
value.colors[3] = SsColor(0, 0, 0, 0);
}
else
{
throw std::logic_error("Not support color type");
}
ssValue = boost::shared_ptr<SsValue>(new SsColorBlendValue(value));
}
//.........这里部分代码省略.........
示例15:
//------------------------------------------------------------------------------
void
WImage::_set(ptree n)
{
if(n.get_child_optional("image"))
this->setImage(kernel->graphicsMgr->loadImage(n.get_child("image")));
};