本文整理汇总了C++中yaml::Node::GetScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::GetScalar方法的具体用法?C++ Node::GetScalar怎么用?C++ Node::GetScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml::Node
的用法示例。
在下文中一共展示了Node::GetScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseConfigItemFromYamlNode
static ConfigItem parseConfigItemFromYamlNode(const YAML::Node &n) {
ConfigItem item;
if(n.Type() == YAML::NodeType::Scalar) {
std::string s;
n.GetScalar(s);
item.setUnparsedString(s);
}
return item;
}
示例2: Exception
void
YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode *&node)
{
if (! node) {
node = new YamlConfigurationNode("root");
}
if (doc.Type() == YAML::NodeType::Map) {
#ifdef HAVE_YAMLCPP_0_5
for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
std::string key = it->first.as<std::string>();
#else
for (YAML::Iterator it = doc.begin(); it != doc.end(); ++it) {
std::string key;
it.first() >> key;
#endif
YamlConfigurationNode *in = node;
if (key.find("/") != std::string::npos) {
// we need to split and find the proper insertion node
std::vector<std::string> pel = str_split(key);
for (size_t i = 0; i < pel.size() - 1; ++i) {
YamlConfigurationNode *n = (*in)[pel[i]];
if (! n) {
n = new YamlConfigurationNode(pel[i]);
in->add_child(pel[i], n);
}
in = n;
}
key = pel.back();
}
YamlConfigurationNode *tmp = (*in)[key];
if (tmp) {
#ifdef HAVE_YAMLCPP_0_5
if (tmp->is_scalar() && it->second.Type() != YAML::NodeType::Scalar)
#else
if (tmp->is_scalar() && it.second().Type() != YAML::NodeType::Scalar)
#endif
{
throw Exception("YamlConfig: scalar %s cannot be overwritten by non-scalar",
tmp->name().c_str());
}
#ifdef HAVE_YAMLCPP_0_5
tmp->set_scalar(it->second.Scalar());
#else
std::string s;
if (it.second().GetScalar(s)) {
tmp->set_scalar(s);
}
#endif
} else {
#ifdef HAVE_YAMLCPP_0_5
YamlConfigurationNode *tmp = new YamlConfigurationNode(key, it->second);
in->add_child(key, tmp);
read_config_doc(it->second, tmp);
#else
YamlConfigurationNode *tmp = new YamlConfigurationNode(key, it.second());
in->add_child(key, tmp);
read_config_doc(it.second(), tmp);
#endif
}
}
} else if (doc.Type() == YAML::NodeType::Scalar) {
if (doc.Tag() == "tag:fawkesrobotics.org,cfg/tcp-port" ||
doc.Tag() == "tag:fawkesrobotics.org,cfg/udp-port")
{
unsigned int p = 0;
try {
p = node->get_uint();
} catch (Exception &e) {
e.prepend("YamlConfig: Invalid TCP/UDP port number (not an unsigned int)");
throw;
}
if (p <= 0 || p >= 65535) {
throw Exception("YamlConfig: Invalid TCP/UDP port number "
"(%u out of allowed range)", p);
}
} else if (doc.Tag() == "tag:fawkesrobotics.org,cfg/url") {
#ifdef HAVE_YAMLCPP_0_5
std::string scalar = doc.Scalar();
#else
std::string scalar;
doc.GetScalar(scalar);
#endif
#ifdef USE_REGEX_CPP
if (regex_search(scalar, __url_regex)) {
# if 0
// just for emacs auto-indentation
}
# endif
#else
if (regexec(&__url_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
throw Exception("YamlConfig: %s is not a valid URL", scalar.c_str());
}
#endif
} else if (doc.Tag() == "tag:fawkesrobotics.org,cfg/frame") {
#ifdef HAVE_YAMLCPP_0_5
std::string scalar = doc.Scalar();
//.........这里部分代码省略.........