base: Add XOR and modulo operator to ChannelAddr
[gem5.git] / src / base / inifile.hh
index 3c68949780320d5b99a58334d80a7aee496af5b6..ae6dc45015b6ede73d797e95e6604c8e0e7060d1 100644 (file)
 #define __INIFILE_HH__
 
 #include <fstream>
+#include <functional>
 #include <list>
 #include <string>
+#include <unordered_map>
 #include <vector>
 
-#include "base/hashmap.hh"
-
 /**
  * @file
  * Declaration of IniFile object.
@@ -58,8 +58,8 @@ class IniFile
     ///
     class Entry
     {
-        std::string    value;          ///< The entry value.
-        mutable bool   referenced;     ///< Has this entry been used?
+        std::string     value;          ///< The entry value.
+        mutable bool    referenced;     ///< Has this entry been used?
 
       public:
         /// Constructor.
@@ -91,10 +91,10 @@ class IniFile
     class Section
     {
         /// EntryTable type.  Map of strings to Entry object pointers.
-        typedef m5::hash_map<std::string, Entry *> EntryTable;
+        typedef std::unordered_map<std::string, Entry *> EntryTable;
 
-        EntryTable     table;          ///< Table of entries.
-        mutable bool   referenced;     ///< Has this section been used?
+        EntryTable      table;          ///< Table of entries.
+        mutable bool    referenced;     ///< Has this section been used?
 
       public:
         /// Constructor.
@@ -133,10 +133,13 @@ class IniFile
 
         /// Print the contents of this section to cout (for debugging).
         void dump(const std::string &sectionName);
+
+        EntryTable::const_iterator begin() const;
+        EntryTable::const_iterator end() const;
     };
 
     /// SectionTable type.  Map of strings to Section object pointers.
-    typedef m5::hash_map<std::string, Section *> SectionTable;
+    typedef std::unordered_map<std::string, Section *> SectionTable;
 
   protected:
     /// Hash of section names to Section object pointers.
@@ -164,14 +167,6 @@ class IniFile
     /// @retval True if successful, false if errors were encountered.
     bool load(std::istream &f);
 
-    /// Load the specified file, passing it through the C preprocessor.
-    /// Parameter settings found in the file will be merged with any
-    /// already defined in this object.
-    /// @param file The path of the file to load.
-    /// @param cppFlags Vector of extra flags to pass to cpp.
-    /// @retval True if successful, false if errors were encountered.
-    bool loadCPP(const std::string &file, std::vector<char *> &cppFlags);
-
     /// Load the specified file.
     /// Parameter settings found in the file will be merged with any
     /// already defined in this object.
@@ -190,6 +185,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
@@ -197,12 +198,22 @@ class IniFile
     /// @return True if the section exists.
     bool sectionExists(const std::string &section) const;
 
+    /// Push all section names into the given vector
+    void getSectionNames(std::vector<std::string> &list) const;
+
     /// Print unreferenced entries in object.  Iteratively calls
     /// printUnreferend() on all the constituent sections.
     bool printUnreferenced();
 
     /// Dump contents to cout.  For debugging.
     void dump();
+
+    /// Visitor callback that receives key/value pairs.
+    using VisitSectionCallback = std::function<void(
+        const std::string&, const std::string&)>;
+
+    /// Iterate over key/value pairs of the given section.
+    void visitSection(const std::string &sectionName, VisitSectionCallback cb);
 };
 
 #endif // __INIFILE_HH__