当前位置: 首页>>代码示例>>C++>>正文


C++ Iterator::GetScalar方法代码示例

本文整理汇总了C++中yaml::Iterator::GetScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ Iterator::GetScalar方法的具体用法?C++ Iterator::GetScalar怎么用?C++ Iterator::GetScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yaml::Iterator的用法示例。


在下文中一共展示了Iterator::GetScalar方法的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
  }
}
开发者ID:jmlich,项目名称:fawkes,代码行数:89,代码来源:yaml.cpp


注:本文中的yaml::Iterator::GetScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。