diff --git a/src/base/inifile.cc b/src/base/inifile.cc index 1fbebb46b3..b2eeafcbef 100644 --- a/src/base/inifile.cc +++ b/src/base/inifile.cc @@ -345,3 +345,25 @@ IniFile::dump() i->second->dump(i->first); } } + +IniFile::Section::EntryTable::const_iterator +IniFile::Section::begin() const +{ + return table.begin(); +} + +IniFile::Section::EntryTable::const_iterator +IniFile::Section::end() const +{ + return table.end(); +} + +void +IniFile::visitSection(const std::string §ionName, + IniFile::VisitSectionCallback cb) +{ + const auto& section = *table.at(sectionName); + for (const auto& pair : section) { + cb(pair.first, pair.second->getValue()); + } +} diff --git a/src/base/inifile.hh b/src/base/inifile.hh index 095d132665..ae6dc45015 100644 --- a/src/base/inifile.hh +++ b/src/base/inifile.hh @@ -30,6 +30,7 @@ #define __INIFILE_HH__ #include +#include #include #include #include @@ -132,6 +133,9 @@ class IniFile /// Print the contents of this section to cout (for debugging). void dump(const std::string §ionName); + + EntryTable::const_iterator begin() const; + EntryTable::const_iterator end() const; }; /// SectionTable type. Map of strings to Section object pointers. @@ -203,6 +207,13 @@ class IniFile /// Dump contents to cout. For debugging. void dump(); + + /// Visitor callback that receives key/value pairs. + using VisitSectionCallback = std::function; + + /// Iterate over key/value pairs of the given section. + void visitSection(const std::string §ionName, VisitSectionCallback cb); }; #endif // __INIFILE_HH__ diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc index e502d9aa77..a563332a17 100644 --- a/src/sim/serialize.cc +++ b/src/sim/serialize.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 ARM Limited + * Copyright (c) 2015, 2020 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -337,6 +337,13 @@ CheckpointIn::sectionExists(const string §ion) return db->sectionExists(section); } +void +CheckpointIn::visitSection(const std::string §ion, + IniFile::VisitSectionCallback cb) +{ + db->visitSection(section, cb); +} + void objParamIn(CheckpointIn &cp, const string &name, SimObject * ¶m) { diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh index 9e25d09879..80fac66617 100644 --- a/src/sim/serialize.hh +++ b/src/sim/serialize.hh @@ -55,6 +55,7 @@ #include #include +#include "base/inifile.hh" #include "base/logging.hh" #include "sim/serialize_handlers.hh" @@ -94,6 +95,8 @@ class CheckpointIn bool entryExists(const std::string §ion, const std::string &entry); bool sectionExists(const std::string §ion); + void visitSection(const std::string §ion, + IniFile::VisitSectionCallback cb); /** @}*/ //end of api_checkout group // The following static functions have to do with checkpoint @@ -555,6 +558,16 @@ mappingParamIn(CheckpointIn &cp, const char* sectionName, param[name_to_index[key]] = value; } } + cp.visitSection( + Serializable::currentSection(), + [name_to_index](const std::string& key, const std::string& val) + { + if (!name_to_index.count(key)) { + warn("unknown entry found in checkpoint: %s %s %s\n", + Serializable::currentSection(), key, val); + } + } + ); } //