summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas.sandberg@arm.com>2016-10-04 11:22:16 +0100
committerAndreas Sandberg <andreas.sandberg@arm.com>2016-10-04 11:22:16 +0100
commit18135ce6abc0ee02e36aef424be183cd7238a558 (patch)
treed42079cc180d7f385e2efff5594964b6dfc5db39 /src
parentee7875885783d8b0945d27052bbf1e0a43aca18e (diff)
downloadgem5-18135ce6abc0ee02e36aef424be183cd7238a558.tar.xz
sim: Add a checkpoint function to test for entries
When loading a checkpoint, it's sometimes desirable to be able to test whether an entry within a secion exists. This is currently done automatically in the UNSERIALIZE_OPT_SCALAR macro, but it isn't possible to do for arrays, containers, or enums. Instead of adding even more macros, add a helper function (CheckpointIn::entryExists()) that tests for the presence of an entry. Change-Id: I4b4646b03276b889fd3916efefff3bd552317dbc Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src')
-rw-r--r--src/base/inifile.cc11
-rw-r--r--src/base/inifile.hh6
-rw-r--r--src/sim/serialize.cc6
-rw-r--r--src/sim/serialize.hh2
4 files changed, 25 insertions, 0 deletions
diff --git a/src/base/inifile.cc b/src/base/inifile.cc
index 402c6469f..80ed3eb06 100644
--- a/src/base/inifile.cc
+++ b/src/base/inifile.cc
@@ -230,6 +230,17 @@ IniFile::find(const string &sectionName, const string &entryName,
}
bool
+IniFile::entryExists(const string &sectionName, const string &entryName) const
+{
+ Section *section = findSection(sectionName);
+
+ if (!section)
+ return false;
+ else
+ return section->findEntry(entryName);
+}
+
+bool
IniFile::sectionExists(const string &sectionName) const
{
return findSection(sectionName) != NULL;
diff --git a/src/base/inifile.hh b/src/base/inifile.hh
index b4892d60a..447ec7c0f 100644
--- a/src/base/inifile.hh
+++ b/src/base/inifile.hh
@@ -184,6 +184,12 @@ class IniFile
bool find(const std::string &section, const std::string &entry,
std::string &value) const;
+ /// Determine whether the entry exists within named section exists
+ /// in the .ini file.
+ /// @return True if the section exists.
+ bool entryExists(const std::string &section,
+ const std::string &entry) const;
+
/// Determine whether the named section exists in the .ini file.
/// Note that the 'Section' class is (intentionally) not public,
/// so all clients can do is get a bool that says whether there
diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc
index e55107b79..d2e699c28 100644
--- a/src/sim/serialize.cc
+++ b/src/sim/serialize.cc
@@ -693,6 +693,12 @@ CheckpointIn::~CheckpointIn()
}
bool
+CheckpointIn::entryExists(const string &section, const string &entry)
+{
+ return db->entryExists(section, entry);
+}
+
+bool
CheckpointIn::find(const string &section, const string &entry, string &value)
{
return db->find(section, entry, value);
diff --git a/src/sim/serialize.hh b/src/sim/serialize.hh
index 2f0340e4b..4c5e9d79c 100644
--- a/src/sim/serialize.hh
+++ b/src/sim/serialize.hh
@@ -359,6 +359,8 @@ class CheckpointIn
bool findObj(const std::string &section, const std::string &entry,
SimObject *&value);
+
+ bool entryExists(const std::string &section, const std::string &entry);
bool sectionExists(const std::string &section);
// The following static functions have to do with checkpoint