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


C++ ParameterMap::size方法代码示例

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


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

示例1: string

/**
 * Output information that helps understanding the mismatch between two
 * parameter maps.
 * To loop through the difference between two very large parameter map can take
 * time, in which
 * you can a hit to what causes the difference faster setting firstDiffOnly to
 * true
 * @param rhs A reference to a ParameterMap object to compare it to
 * @param firstDiffOnly If true return only first difference found
 * @return diff as a string
 */
const std::string ParameterMap::diff(const ParameterMap &rhs,
                                     const bool &firstDiffOnly) const {
  if (this == &rhs)
    return std::string(""); // True for the same object

  // Quick size check
  if (this->size() != rhs.size()) {
    return std::string("Number of parameters does not match: ") +
           boost::lexical_cast<std::string>(this->size()) + " not equal to " +
           boost::lexical_cast<std::string>(rhs.size());
  }

  // Run this same loops as in operator==
  // The map is unordered and the key is only valid at runtime. The
  // asString method turns the ComponentIDs to full-qualified name identifiers
  // so we will use the same approach to compare them

  std::stringstream strOutput;
  pmap_cit thisEnd = this->m_map.end();
  pmap_cit rhsEnd = rhs.m_map.end();
  for (pmap_cit thisIt = this->m_map.begin(); thisIt != thisEnd; ++thisIt) {
    const IComponent *comp = static_cast<IComponent *>(thisIt->first);
    const std::string fullName = comp->getFullName();
    const auto &param = thisIt->second;
    bool match(false);
    for (pmap_cit rhsIt = rhs.m_map.begin(); rhsIt != rhsEnd; ++rhsIt) {
      const IComponent *rhsComp = static_cast<IComponent *>(rhsIt->first);
      const std::string rhsFullName = rhsComp->getFullName();
      if (fullName == rhsFullName && (*param) == (*rhsIt->second)) {
        match = true;
        break;
      }
    }

    if (!match) {
      // output some information that helps with understanding the mismatch
      strOutput << "Parameter mismatch LHS=RHS for LHS parameter in component "
                   "with name: " << fullName
                << ". Parameter name is: " << (*param).name()
                << " and value: " << (*param).asString() << std::endl;
      bool componentWithSameNameRHS = false;
      bool parameterWithSameNameRHS = false;
      for (pmap_cit rhsIt = rhs.m_map.begin(); rhsIt != rhsEnd; ++rhsIt) {
        const IComponent *rhsComp = static_cast<IComponent *>(rhsIt->first);
        const std::string rhsFullName = rhsComp->getFullName();
        if (fullName == rhsFullName) {
          componentWithSameNameRHS = true;
          if ((*param).name() == (*rhsIt->second).name()) {
            parameterWithSameNameRHS = true;
            strOutput << "RHS param with same name has value: "
                      << (*rhsIt->second).asString() << std::endl;
          }
        }
      }
      if (!componentWithSameNameRHS) {
        strOutput << "No matching RHS component name" << std::endl;
      }
      if (componentWithSameNameRHS && !parameterWithSameNameRHS) {
        strOutput << "Found matching RHS component name but not parameter name"
                  << std::endl;
      }
      if (firstDiffOnly)
        return strOutput.str();
    }
  }
  return strOutput.str();
}
开发者ID:spaceyatom,项目名称:mantid,代码行数:78,代码来源:ParameterMap.cpp


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