本文整理汇总了C++中boost::property_tree::ptree::get_child_optional方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::get_child_optional方法的具体用法?C++ ptree::get_child_optional怎么用?C++ ptree::get_child_optional使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::property_tree::ptree
的用法示例。
在下文中一共展示了ptree::get_child_optional方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseConfig
void linear_population_growth_generator::parseConfig( boost::property_tree::ptree & config ) {
if( config.get_child_optional( "A" ) == boost::none ) {
config.put( "A", m_A);
} else {
m_A = config.get<double>( "A", m_A );
}
if( config.get_child_optional( "B" ) == boost::none ) {
config.put("B", m_B );
} else {
m_B = config.get<double>( "B", m_B );
}
}
示例2: ReadParticles
void ReadParticles(PartList &list,
const boost::property_tree::ptree &pt) {
auto particleTree = pt.get_child_optional("ParticleList");
if (!particleTree)
return;
for (auto const &v : particleTree.get()) {
auto tmp = ParticleProperties(v.second);
auto p = std::make_pair(tmp.name(), tmp);
auto last = list.insert(p);
if (!last.second) {
LOG(INFO) << "ReadParticles() | Particle " << last.first->first
<< " already exists in list. We overwrite its parameters!";
last.first->second = tmp;
}
tmp = last.first->second;
// cparity is optional
double cparity = 0.0;
try {
cparity = tmp.GetQuantumNumber("Cparity");
} catch (std::exception &ex) {
}
LOG(DEBUG) << "ReadParticles() | Particle " << tmp.name()
<< " (id=" << tmp.GetId() << ") "
<< " J(PC)=" << tmp.GetSpinQuantumNumber("Spin") << "("
<< tmp.GetQuantumNumber("Parity") << cparity << ") "
<< " mass=" << tmp.GetMass()
<< " decayType=" << tmp.GetDecayType();
}
return;
}
示例3: result
bool rai_daemon::daemon_config::upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a)
{
auto result (false);
switch (version_a)
{
case 1:
{
auto opencl_enable_l (tree_a.get_optional <bool> ("opencl_enable"));
if (!opencl_enable_l)
{
tree_a.put ("opencl_enable", "false");
}
auto opencl_l (tree_a.get_child_optional ("opencl"));
if (!opencl_l)
{
boost::property_tree::ptree opencl_l;
opencl.serialize_json (opencl_l);
tree_a.put_child ("opencl", opencl_l);
}
tree_a.put ("version", "2");
result = true;
}
case 2:
break;
default:
throw std::runtime_error ("Unknown daemon_config version");
}
return result;
}
示例4: unSerialize
void Key::unSerialize(boost::property_tree::ptree& node)
{
LOG(LogLevel::INFOS) << "Unserializing Key...";
if (node.get_child_optional("KeyDiversification"))
{
boost::property_tree::ptree keydivnode = node.get_child("KeyDiversification");
d_key_diversification = KeyDiversification::getKeyDiversificationFromType(keydivnode.get_child("<xmlattr>.keyDiversificationType").get_value<std::string>());
boost::property_tree::ptree kdnode = keydivnode.get_child(d_key_diversification->getDefaultXmlNodeName());
if (!kdnode.empty())
{
d_key_diversification->unSerialize(kdnode);
}
}
d_storeCipheredData = node.get_child("IsCiphered").get_value<bool>(false);
uncipherKeyData(node);
LOG(LogLevel::INFOS) << "Unserializing Key storage...";
d_key_storage = KeyStorage::getKeyStorageFromType(static_cast<KeyStorageType>(node.get_child("<xmlattr>.keyStorageType").get_value<unsigned int>()));
if (d_key_storage)
{
boost::property_tree::ptree ksnode = node.get_child(d_key_storage->getDefaultXmlNodeName());
if (!ksnode.empty())
{
d_key_storage->unSerialize(ksnode);
}
}
}
示例5: Exception
std::vector<STEMScannerGeometry*> TF_Datasource::parseProjectionStackProperties(const boost::property_tree::ptree& node, unsigned int imageCount)
{
if (!node.get_child_optional("convergent").is_initialized())
throw Exception("TF_Datasource can only read projection metadata of type TF_ProjectionMetaData");
std::string filename = node.get_child("image").get<std::string>("<xmlattr>.filename");
float tiltAngle = node.get_child("tiltAngle").get<float>("<xmlattr>.value");
float focalDistanceBase = node.get_child("focalDistanceBase").get<float>("<xmlattr>.value");
float focusAtImage = node.get_child("focusAtImage").get<float>("<xmlattr>.value");
float focalDistanceBetweenImages = node.get_child("focalDistanceBetweenImages").get<float>("<xmlattr>.value");
float beamOpeningAngle = node.get_child("beamOpeningAngle").get<float>("<xmlattr>.value");
boost::filesystem::path pathToImage( filename );
unsigned int imagesInStack = ImageDeserializer::getNumberOfImagesInStack( getAbsoluteImageLocation(pathToImage).string() );
std::vector<STEMScannerGeometry*> result;
for (unsigned int i = 0; i < imagesInStack; i++)
{
ScannerGeometry* rotatedGeometry = satRotator.createRotatedScannerGeometry(tiltAngle, 0.0f);
STEMScannerGeometry* stemGeometry = dynamic_cast<STEMScannerGeometry*>(rotatedGeometry);
stemGeometry->setFocalDifferenceBetweenImages(focalDistanceBetweenImages);
stemGeometry->setConfocalOpeningHalfAngle(beamOpeningAngle);
float focusPosition = focalDistanceBase + (focalDistanceBetweenImages * (float) (imagesInStack-i) );
stemGeometry->setFocalDepth(focusPosition);
stemGeometry->setTiltAngle(tiltAngle);
result.push_back(stemGeometry);
}
return result;
}
示例6: parseProjectionProperties
ImageStackDirectoryDatasource::MetaDataNode ImageStackDirectoryDatasource::parseProjectionProperties(const boost::property_tree::ptree& node) const
{
MetaDataNode props;
props.onLogarithmicScale = node.get_child_optional("logscale").is_initialized();
props.tiltAngle = node.get_child("tiltAngle").get<float>("<xmlattr>.value");
props.xmlNode = node;
return props;
}
示例7: ptree_entry_to_query
void ptree_entry_to_query(const boost::property_tree::ptree& ptree,
const std::string& entry_name,
LayerParameters* p_params) {
auto given_entry = ptree.get_child_optional(entry_name);
if (given_entry) {
(*p_params)[entry_name] = given_entry.get().data();
}
}
示例8: upgrade_json
bool upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a)
{
auto result (false);
switch (version_a)
{
case 1:
{
rai::account account;
account.decode_account (tree_a.get<std::string> ("account"));
tree_a.erase ("account");
tree_a.put ("account", account.to_account ());
tree_a.erase ("version");
tree_a.put ("version", "2");
result = true;
}
case 2:
{
boost::property_tree::ptree rpc_l;
rpc.serialize_json (rpc_l);
tree_a.put ("rpc_enable", "false");
tree_a.put_child ("rpc", rpc_l);
tree_a.erase ("version");
tree_a.put ("version", "3");
result = true;
}
case 3:
{
auto opencl_enable_l (tree_a.get_optional<bool> ("opencl_enable"));
if (!opencl_enable_l)
{
tree_a.put ("opencl_enable", "false");
}
auto opencl_l (tree_a.get_child_optional ("opencl"));
if (!opencl_l)
{
boost::property_tree::ptree opencl_l;
opencl.serialize_json (opencl_l);
tree_a.put_child ("opencl", opencl_l);
}
tree_a.put ("version", "4");
result = true;
}
case 4:
break;
default:
throw std::runtime_error ("Unknown qt_wallet_config version");
}
return result;
}
示例9: BadParameter
ParticleProperties::ParticleProperties(boost::property_tree::ptree pt)
: Properties(pt.get<std::string>("<xmlattr>.Name"), pt.get<pid>("Pid")) {
for (const auto &v : pt.get_child("")) {
if (v.first == "QuantumNumber") {
// QuantumNumbers which can be of type int or ComPWA::Spin
std::string type = v.second.get<std::string>("<xmlattr>.Type");
// We have to distinguish between spin and integer quantum numbers
if (v.second.get<std::string>("<xmlattr>.Class") == "Spin") {
auto value = v.second.get<double>("<xmlattr>.Value");
double valueZ = 0.0;
try { // Projection of spin is optional (e.g. (I,I3))
valueZ = v.second.get<double>("<xmlattr>.Projection");
} catch (std::exception &ex) {
}
spinQuantumNumbers_.insert(
std::make_pair(type, ComPWA::Spin(value, valueZ)));
} else if (v.second.get<std::string>("<xmlattr>.Class") == "Int") {
auto value = v.second.get<int>("<xmlattr>.Value");
intQuantumNumbers_.insert(std::make_pair(type, value));
} else {
throw BadParameter(
"ParticleProperties::ParticleProperties() | "
"QuantumNumber is neither of type 'Spin' nor of type "
"'Int'!");
}
} else if (v.first == "Parameter") {
// Parameter (e.g. Mass)
if (v.second.get<std::string>("<xmlattr>.Type") != "Mass")
continue;
Mass = FitParameter();
Mass.load(v.second);
} else {
}
}
// Info on the particle decay is stored as it is as property_tree and later
// used by AbstractDynamicalFunctions (e.g. RelativisticBreitWigner).
auto decayInfo = pt.get_child_optional("DecayInfo");
if (decayInfo) {
DecayInfo = decayInfo.get();
} else {
DecayInfo.put("<xmlattr>.Type", "Stable");
}
}
示例10: updateConfig
void ReprojectPCL::updateConfig(const boost::property_tree::ptree &pt) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " " << id();
using namespace boost::property_tree;
Filter::updateConfig(pt);
boost::optional<const boost::property_tree::ptree& > ocvo = pt.get_child_optional( "options.cameraMatrix" );
if (ocvo.is_initialized()) {
if( toffy::commons::checkOCVNone(*ocvo) ) {
boost::property_tree::ptree os;
os.put_child("cameraMatrix",*ocvo);
cv::FileStorage fs = commons::loadOCVnode(os);
//Mat val;
fs.getFirstTopLevelNode() >> _cameraMatrix;
cout << fs.getFirstTopLevelNode().name() << endl;
fs.release();
} else
示例11:
void
plugin_factory::load_settings(const boost::property_tree::ptree& settings)
{
using boost::property_tree::ptree;
BOOST_AUTO(path, settings.get_child_optional("path"));
if (path) {
BOOST_FOREACH(const ptree::value_type& v, *path) {
boost::filesystem::path plugin_path(v.second.get<std::string>(""));
if (plugin_path.is_absolute()) {
load_dir(plugin_path);
}
else {
load_dir(boost::filesystem::current_path() / plugin_path);
}
}
}
else {
示例12:
/* static */ bool Parser::parse_description( std::string & description, boost::property_tree::ptree const & root )
{
OptionalPTree values = root.get_child_optional( "values" );
if( !values )
{
return false;
}
boost::optional<std::string> desc = values->get_optional<std::string>( "statusmessage" );
if( !desc )
{
return false;
}
description = *desc;
return true;
}
示例13:
/* static */ bool Parser::parse_server_state(ServerState & server_state, GazeData & gaze_data, CalibResult & calib_result, Screen & screen, boost::property_tree::ptree const & root, bool& has_gaze_data, bool& has_calib_result)
{
OptionalPTree values = root.get_child_optional("values");
if (!values)
{
return false;
}
Parser::parse_calib_result(calib_result, root, has_calib_result);
OptionalPTree frame = values->get_child_optional("frame");
has_gaze_data = static_cast<bool>(frame);
if (has_gaze_data)
{
gaze_data.time = frame->get<int>("time");
gaze_data.fix = frame->get<bool>("fix");
gaze_data.state = frame->get<int>("state");
parse_point2d(gaze_data.raw, frame->get_child("raw"));
parse_point2d(gaze_data.raw, frame->get_child("avg"));
parse_eye(gaze_data.lefteye, frame->get_child("lefteye"));
parse_eye(gaze_data.righteye, frame->get_child("righteye"));
}
server_state.push = values->get<bool>("push", server_state.push);
server_state.heartbeatinterval = values->get<int>("heartbeatinterval", server_state.heartbeatinterval);
server_state.version = values->get<int>("version", server_state.version);
server_state.trackerstate = values->get<int>("trackerstate", server_state.trackerstate);
server_state.framerate = values->get<int>("framerate", server_state.framerate);
server_state.iscalibrated = values->get<bool>("iscalibrated", server_state.iscalibrated);
server_state.iscalibrating = values->get<bool>("iscalibrating", server_state.iscalibrating);
screen.screenindex = values->get<int>("screenindex", screen.screenindex);
screen.screenresw = values->get<int>("screenresw", screen.screenresw);
screen.screenresh = values->get<int>("screenresh", screen.screenresh);
screen.screenpsyw = values->get<float>("screenpsyw", screen.screenpsyw);
screen.screenpsyh = values->get<float>("screenpsyh", screen.screenpsyh);
return true;
}
示例14: parse
bool AstProvider::parse(const ::boost::property_tree::ptree& tree, MessageCallback callback)
{
boost::optional< const pt::ptree& > child = tree.get_child_optional("provider");
if (!child) {
CompileMessage error(CompileMessage::type_t::Error, CdefMessage::CDE101, callback, "Provider block not defined");
return false;
}
// get the name associated with this collection
_label = child.get().get_value<string>();
// Loop through all properties on this level
for (const pt::ptree::value_type &v : child.get())
{
if (boost::iequals(v.first.data(), "application"))
_application = child.get().get<string>("application");
else if (boost::iequals(v.first.data(), "uuid")) {
// read and Validate the uuid
string uuid = v.second.data();
if (!isValidUuid(uuid)) {
CompileMessage error(CompileMessage::type_t::Error, CdefMessage::CDE102, callback, "The provider '%s' contains an invalid uuid", _label.c_str());
return false;
}
_uuid = string_generator()(uuid);
}
else if (boost::iequals(v.first.data(), "counterset")) {
AstCounterSetPtr counterset = AstCounterSet::create();
if(!counterset->parse(v.second, callback))
return false;
counterset->setParent(shared_from_this());
// the contructor will throw an exception if a syntax error was detected.
this->push_back(counterset);
}
}
return isSane(callback);
}
示例15: unSerialize
void Key::unSerialize(boost::property_tree::ptree& node)
{
LOG(LogLevel::INFOS) << "Unserializing Key...";
if (node.get_child_optional("KeyDiversification"))
{
boost::property_tree::ptree keydivnode = node.get_child("KeyDiversification");
d_key_diversification = KeyDiversification::getKeyDiversificationFromType(keydivnode.get_child("<xmlattr>.keyDiversificationType").get_value<std::string>());
boost::property_tree::ptree kdnode = keydivnode.get_child(d_key_diversification->getDefaultXmlNodeName());
if (!kdnode.empty())
{
d_key_diversification->unSerialize(kdnode);
std::shared_ptr<ComputerMemoryKeyStorage> cmks = std::dynamic_pointer_cast<ComputerMemoryKeyStorage>(d_key_diversification);
if (cmks)
{
if (cmks->getRandom())
{
fromString(AccessInfo::generateSimpleKey(getLength()));
}
}
}
}
d_storeCipheredData = node.get_child("IsCiphered").get_value<bool>(false);
uncipherKeyData(node);
LOG(LogLevel::INFOS) << "Unserializing Key storage...";
d_key_storage = KeyStorage::getKeyStorageFromType(static_cast<KeyStorageType>(node.get_child("<xmlattr>.keyStorageType").get_value<unsigned int>()));
if (d_key_storage)
{
boost::property_tree::ptree ksnode = node.get_child(d_key_storage->getDefaultXmlNodeName());
if (!ksnode.empty())
{
d_key_storage->unSerialize(ksnode);
}
}
}