本文整理汇总了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 ¶m = 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();
}