本文整理汇总了C++中yaml::Iterator::Tag方法的典型用法代码示例。如果您正苦于以下问题:C++ Iterator::Tag方法的具体用法?C++ Iterator::Tag怎么用?C++ Iterator::Tag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml::Iterator
的用法示例。
在下文中一共展示了Iterator::Tag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Exception
void
YamlConfiguration::read_meta_doc(YAML::Node &doc, std::queue<LoadQueueEntry> &load_queue,
std::string &host_file)
{
try {
const YAML::Node &includes = doc["include"];
#ifdef HAVE_YAMLCPP_0_5
for (YAML::const_iterator it = includes.begin(); it != includes.end(); ++it) {
std::string include = it->as<std::string>();
#else
for (YAML::Iterator it = includes.begin(); it != includes.end(); ++it) {
std::string include;
*it >> include;
#endif
bool ignore_missing = false;
if (it->Tag() == "tag:fawkesrobotics.org,cfg/ignore-missing") {
ignore_missing = true;
}
if (it->Tag() == "tag:fawkesrobotics.org,cfg/host-specific") {
if (host_file != "") {
throw Exception("YamlConfig: Only one host-specific file can be specified");
}
#ifdef HAVE_YAMLCPP_0_5
host_file = abs_cfg_path(it->Scalar());
#else
it->GetScalar(host_file);
host_file = abs_cfg_path(host_file);
#endif
continue;
}
if (include.empty()) {
throw Exception("YamlConfig: invalid empty include");
}
if (include[include.size() - 1] == '/') {
// this should be a directory
std::string dirname = abs_cfg_path(include);
struct stat dir_stat;
if ((stat(dirname.c_str(), &dir_stat) != 0)) {
if (ignore_missing) continue;
throw Exception(errno, "YamlConfig: Failed to stat directory %s", dirname.c_str());
}
if (! S_ISDIR(dir_stat.st_mode)) {
throw Exception("YamlConfig: %s is not a directory", dirname.c_str());
}
DIR *d = opendir(dirname.c_str());
if (! d) {
throw Exception(errno, "YamlConfig: failed to open directory %s",
dirname.c_str());
}
load_queue.push(LoadQueueEntry(dirname, ignore_missing, true));
std::list<std::string> files;
struct dirent *dent;
while ((dent = readdir(d)) != NULL) {
#ifdef USE_REGEX_CPP
if (regex_search(dent->d_name, __yaml_regex)) {
# if 0
// just for emacs auto-indentation
}
# endif
#else
if (regexec(&__yaml_regex, dent->d_name, 0, NULL, 0) != REG_NOMATCH) {
#endif
std::string dn = dent->d_name;
files.push_back(dirname + dn);
}
}
closedir(d);
files.sort();
for (std::list<std::string>::iterator f = files.begin(); f != files.end(); ++f) {
load_queue.push(LoadQueueEntry(*f, ignore_missing));
}
} else {
load_queue.push(LoadQueueEntry(abs_cfg_path(include), ignore_missing));
}
}
} catch (YAML::KeyNotFound &e) {
//ignored, no includes
}
}