Skip to content
Snippets Groups Projects
Commit e2ba306b authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[BL] changed map key type

parent d5163998
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,7 @@ ConfigTreeNew::
getConfParamList(std::string const& param) const
{
checkUnique(param);
markVisited<T>(param, true);
markVisited<T>(param, false, true);
auto p = _tree->equal_range(param);
return Range<ValueIterator<T> >(
......@@ -144,7 +144,7 @@ ConfigTreeNew::
getAttribute(std::string const& attr) const
{
checkUniqueAttr(attr);
markVisited(attr, true);
markVisited<T>(attr, true);
if (auto attrs = _tree->get_child_optional("<xmlattr>")) {
if (auto a = attrs->get_child_optional(attr)) {
......@@ -166,11 +166,13 @@ getAttribute(std::string const& attr) const
template<typename T>
ConfigTreeNew::CountType&
ConfigTreeNew::
markVisited(std::string const& key, bool const peek_only) const
markVisited(std::string const& key, bool const is_attr,
bool const peek_only) const
{
auto const type = std::type_index(typeid(T));
auto p = _visited_params.emplace(key, CountType{peek_only ? 0 : 1, type});
auto p = _visited_params.emplace(std::make_pair(is_attr, key),
CountType{peek_only ? 0 : 1, type});
if (!p.second) { // no insertion happened
auto& v = p.first->second;
......
......@@ -211,7 +211,7 @@ void ConfigTreeNew::checkUnique(const std::string &key) const
{
checkKeyname(key);
if (_visited_params.find(key) != _visited_params.end()) {
if (_visited_params.find({false, key}) != _visited_params.end()) {
error("Key <" + key + "> has already been processed.");
}
}
......@@ -220,7 +220,7 @@ void ConfigTreeNew::checkUniqueAttr(const std::string &attr) const
{
checkKeyname(attr);
if (_visited_params.find("<xmlattr>." + attr) != _visited_params.end()) {
if (_visited_params.find({true, attr}) != _visited_params.end()) {
error("Attribute \"" + attr + "\" has already been processed.");
}
}
......@@ -229,16 +229,17 @@ ConfigTreeNew::CountType&
ConfigTreeNew::
markVisited(std::string const& key, bool const peek_only) const
{
return markVisited<ConfigTreeNew>(key, peek_only);
return markVisited<ConfigTreeNew>(key, false, peek_only);
}
void
ConfigTreeNew::
markVisitedDecrement(std::string const& key) const
markVisitedDecrement(bool const is_attr, std::string const& key) const
{
auto const type = std::type_index(typeid(nullptr));
auto p = _visited_params.emplace(key, CountType{-1, type});
auto p = _visited_params.emplace(std::make_pair(is_attr, key),
CountType{-1, type});
if (!p.second) { // no insertion happened
auto& v = p.first->second;
......@@ -276,24 +277,40 @@ ConfigTreeNew::checkAndInvalidate()
for (auto const& p : *_tree) {
DBUG("-- %s <%s> ", _path.c_str(), p.first.c_str());
if (p.first != "<xmlattr>") // attributes are handled below
markVisitedDecrement(p.first);
markVisitedDecrement(false, p.first);
DBUG("tag %s", p.first.c_str());
}
// iterate over attributes
if (auto attrs = _tree->get_child_optional("<xmlattr>")) {
DBUG("has attributes");
for (auto const& p : *attrs) {
markVisitedDecrement("<xmlattr>." + p.first);
// markVisitedDecrement("<xmlattr>");
markVisitedDecrement(true, p.first);
DBUG("attr %s", p.first.c_str());
}
}
for (auto const& p : _visited_params) {
if (p.second.count > 0) {
warning("Key <" + p.first + "> has been read " + std::to_string(p.second.count)
+ " time(s) more than it was present in the configuration tree.");
} else if (p.second.count < 0) {
warning("Key <" + p.first + "> has been read " + std::to_string(-p.second.count)
+ " time(s) less than it was present in the configuration tree.");
for (auto const& p : _visited_params)
{
auto const& tag = std::get<1>(p.first);
auto const& count = p.second.count;
if (std::get<0>(p.first)) { // tag
if (count > 0) {
warning("XML attribute \"" + tag + "\" has been read " + std::to_string(count)
+ " time(s) more than it was present in the configuration tree.");
} else if (count < 0) {
warning("XML attribute \"" + tag + "\" has been read " + std::to_string(-count)
+ " time(s) less than it was present in the configuration tree.");
}
} else { // XML attribute
if (count > 0) {
warning("Key <" + tag + "> has been read " + std::to_string(count)
+ " time(s) more than it was present in the configuration tree.");
} else if (count < 0) {
warning("Key <" + tag + "> has been read " + std::to_string(-count)
+ " time(s) less than it was present in the configuration tree.");
}
}
}
......
......@@ -396,7 +396,8 @@ private:
* \c param peek_only if true, do not change the read-count of the given key.
*/
template<typename T>
CountType& markVisited(std::string const& key, bool peek_only = false) const;
CountType& markVisited(std::string const& key, bool const is_attr,
bool peek_only = false) const;
/*! Keeps track of the key \c key and its value type ConfigTree.
*
......@@ -408,7 +409,7 @@ private:
//! Used in the destructor to compute the difference between number of reads of a parameter
//! and the number of times it exists in the ConfigTree
void markVisitedDecrement(std::string const& key) const;
void markVisitedDecrement(bool const is_attr, std::string const& key) const;
//! TODO doc
bool hasChildren(ConfigTreeNew const& ct) const;
......@@ -431,6 +432,8 @@ private:
//! \todo add file name
using KeyType = std::pair<bool, std::string>;
//! A map key -> (count, type) keeping track which parameters have been read how often
//! and which datatype they have.
//!
......@@ -438,7 +441,7 @@ private:
//! Therefore it has to be mutable in order to be able to read from
//! constant instances, e.g., those passed as constant references to
//! temporaries.
mutable std::map<std::string, CountType> _visited_params;
mutable std::map<KeyType, CountType> _visited_params;
//! \todo doc
mutable bool _have_read_data = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment