本文整理汇总了C++中yaml::Node::Tag方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::Tag方法的具体用法?C++ Node::Tag怎么用?C++ Node::Tag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml::Node
的用法示例。
在下文中一共展示了Node::Tag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExpectedTagValue
bool ExpectedTagValue(YAML::Node& node, const char* tag)
{
if(node.Tag() == tag)
return true;
throw TagMismatch(node.Tag(), tag);
}
示例2: CloneScalar
TEST CloneScalar()
{
YAML::Node node = YAML::Load("!foo monkey");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(node.as<std::string>() == clone.as<std::string>());
YAML_ASSERT(node.Tag() == clone.Tag());
return true;
}
示例3: getFileType
IncludeResolver::FileType IncludeResolver::getFileType(const YAML::Node &yamlNode )
{
IncludeResolver::FileType fileType = IncludeResolver::FileType::NOTAG;
if (yamlNode.Tag() == "!include")
{
std::string value = yamlNode.as<std::string>();
std::size_t found = value.find_last_of(".");
if (found > value.length())
{
fileType = IncludeResolver::FileType::FILE;
return fileType;
}
std::string extension = value.substr(found + 1);
if (std::find(Keys::AllowedRamlYamlTypes.begin(), Keys::AllowedRamlYamlTypes.end(),
extension) != Keys::AllowedRamlYamlTypes.end())
fileType = IncludeResolver::FileType::NODE;
else if (extension == Keys::Json)
fileType = IncludeResolver::FileType::JSON;
else
fileType = IncludeResolver::FileType::FILE;
}
return fileType;
}
示例4: 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();
//.........这里部分代码省略.........
示例5: eMesh
//.........这里部分代码省略.........
YAML::Emitter out;
out << YAML::Anchor("NodeRegistry::map");
out << YAML::BeginMap;
out << YAML::Key << YAML::BeginSeq << 1 << 2 << YAML::EndSeq << YAML::Value << YAML::BeginSeq << -1 << -2 << YAML::EndSeq;
out << YAML::Key << 1;
out << YAML::Value << 2;
out << YAML::Key << 3;
out << YAML::Value << 4;
out << YAML::EndMap;
//std::cout << "out=\n" << out.c_str() << "\n=out" << std::endl;
std::string expected_result = "&NodeRegistry::map\n?\n - 1\n - 2\n:\n - -1\n - -2\n1: 2\n3: 4";
//std::cout << "out2=\n" << expected_result << std::endl;
STKUNIT_EXPECT_TRUE(expected_result == std::string(out.c_str()));
}
YAML::Emitter yaml;
std::cout << "\nnodeRegistry.serialize_write(yaml)" << std::endl;
SerializeNodeRegistry::serialize_write(nodeRegistry, yaml, 0);
//std::cout << yaml.c_str() << std::endl;
if (!yaml.good())
{
std::cout << "Emitter error: " << yaml.good() << " " <<yaml.GetLastError() << "\n";
STKUNIT_EXPECT_TRUE(false);
}
std::ofstream file1("out.yaml");
file1 << yaml.c_str();
file1.close();
std::ifstream file2("out.yaml");
YAML::Parser parser(file2);
YAML::Node doc;
try {
while(parser.GetNextDocument(doc)) {
std::cout << "\n read doc.Type() = " << doc.Type() << " doc.Tag()= " << doc.Tag() << " doc.size= " << doc.size() << std::endl;
if (doc.Type() == YAML::NodeType::Map)
{
for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
int key, value;
std::cout << "read it.first().Type() = " << it.first().Type() << " it.first().Tag()= " << it.first().Tag() << std::endl;
std::cout << "read it.second().Type() = " << it.second().Type() << " it.second().Tag()= " << it.second().Tag() << std::endl;
const YAML::Node& keySeq = it.first();
for(YAML::Iterator itk=keySeq.begin();itk!=keySeq.end();++itk) {
*itk >> key;
std::cout << "read key= " << key << std::endl;
}
const YAML::Node& valSeq = it.second();
for(YAML::Iterator itv=valSeq.begin();itv!=valSeq.end();++itv) {
*itv >> value;
std::cout << "read value= " << value << std::endl;
}
}
}
}
}
catch(YAML::ParserException& e) {
std::cout << e.what() << "\n";
STKUNIT_EXPECT_TRUE(false);
}
file2.close();
std::ifstream file3("out.yaml");
NodeRegistry nrNew(eMesh);
SerializeNodeRegistry::serialize_read(nrNew, file3);
YAML::Emitter yaml3;