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


C++ ConfigNode::IsSequence方法代码示例

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


在下文中一共展示了ConfigNode::IsSequence方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: validate

bool KeyedConfigList::validate(ConfigNode node)
{
	if(!node.IsSequence())
	{
		config_log.error() << "Section '" << m_path
		                   << "' expects a list of values.\n";
		return false;
	}

	int n = -1;
	bool ok = true;
	for(auto it = node.begin(); it != node.end(); ++it)
	{
		n += 1;

		if(!it->IsMap())
		{
			config_log.error() << "The " << n << "th item of section '" << m_path
			                   << "' does not have key/value config variables.\n";
			ok = false;
			continue;
		}

		ConfigNode element = *it;
		if(!element[m_key])
		{
			config_log.error() << "The " << n << "th item of section '" << m_path
			                   << "' did not specify the attribute '" << m_key << "'.\n";
			ok = false;
			continue;
		}

		string key = element[m_key].as<std::string>();
		auto found_grp = m_children.find(key);
		if(found_grp == m_children.end())
		{
			config_log.error() << "The value '" << key << "' is not valid for attribute '"
			                   << m_key << "' of section '" << m_path << "'.\n";
			print_keys();
			ok = false;
			continue;
		}

		if(!found_grp->second->validate(element))
		{
			ok = false;
		}
	}

	return ok;
}
开发者ID:Unkn0wn-0nes,项目名称:Astron,代码行数:51,代码来源:ConfigGroup.cpp

示例2: print

void print(const ConfigNode& in, const std::string& indent, std::ostream& os, bool longMap, bool newlines,
           unsigned maxDepth) {
  if (maxDepth == 0) {
    os << "...";
    return;
  }
  if (in.IsScalar()) {
    os << indent << in.as<std::string>();
    return;
  }
  std::string deeperIndent;
  if (newlines) {
    deeperIndent = indent;
    deeperIndent.push_back(' ');
    deeperIndent.push_back(' ');
  }
  bool const sequence = in.IsSequence();
  bool const map = in.IsMap();
  if (!(sequence || map)) return;
  YAML::const_iterator i = in.begin(), end = in.end();
  if (sequence) {
    if (newlines && !sequenceAllScalar(in.begin(), in.end())) {
      for (; i != end; ++i) {
        os << indent << "- ";
        ConfigNode node = *i;
        if (node.IsScalar())
          os << node.as<std::string>();
        else
          print(*i, deeperIndent, os, longMap, newlines, --maxDepth);
        os << '\n';
      }
    } else {
      os << indent << "[ ";
      bool first = true;
      for (; i != end; ++i) {
        ConfigNode node = *i;
        if (!first) os << ", ";
        if (node.IsScalar())
          os << node.as<std::string>();
        else if (node.IsMap())
          print(node, "", os, longMap, newlines, --maxDepth);
        else if (node.IsSequence())
          print(node, "", os, longMap, newlines, --maxDepth);
        first = false;
      }
      os << " ]";
    }
  } else {
    assert(map);
    if (!longMap && !newlines) longMap = true;
    if (longMap) {
      os << " { ";
    }
    if (newlines) os << '\n';
    bool first = true;
    for (; i != end; ++i) {
      std::string const& key = i->first.as<std::string>();
      ConfigNode val = i->second;
      if (!val.IsNull()) {
        if (!first) {
          if (longMap) os << ", ";
          if (newlines) os << '\n';
        }
        os << (newlines && longMap ? deeperIndent : indent) << key << ": ";
        if (val.IsScalar())
          os << val.as<std::string>();
        else
          print(val, deeperIndent, os, longMap, newlines, --maxDepth);
      }
      first = false;
    }
    if (longMap) {
      if (newlines) {
        os << '\n';
        os << indent << "}";
      } else
        os << indent << " }";
    }
  }
}
开发者ID:graehl,项目名称:hyp,代码行数:80,代码来源:Config.cpp


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