gem5  v21.1.0.2
inifile.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __INIFILE_HH__
30 #define __INIFILE_HH__
31 
32 #include <fstream>
33 #include <functional>
34 #include <list>
35 #include <string>
36 #include <unordered_map>
37 #include <vector>
38 
45 namespace gem5
46 {
47 
55 class IniFile
56 {
57  protected:
58 
62  class Entry
63  {
64  std::string value;
65  mutable bool referenced;
66 
67  public:
69  Entry(const std::string &v)
70  : value(v), referenced(false)
71  {
72  }
73 
75  bool isReferenced() { return referenced; }
76 
78  const std::string &getValue() const;
79 
81  void setValue(const std::string &v) { value = v; }
82 
88  void appendValue(const std::string &v) { value += " "; value += v; }
89  };
90 
94  class Section
95  {
97  typedef std::unordered_map<std::string, Entry *> EntryTable;
98 
100  mutable bool referenced;
101 
102  public:
105  : table(), referenced(false)
106  {
107  }
108 
110  bool isReferenced() { return referenced; }
111 
116  void addEntry(const std::string &entryName, const std::string &value,
117  bool append);
118 
124  bool add(const std::string &assignment);
125 
128  Entry *findEntry(const std::string &entryName) const;
129 
135  bool printUnreferenced(const std::string &sectionName);
136 
138  void dump(const std::string &sectionName);
139 
140  EntryTable::const_iterator begin() const;
141  EntryTable::const_iterator end() const;
142  };
143 
145  typedef std::unordered_map<std::string, Section *> SectionTable;
146 
147  protected:
150 
154  Section *addSection(const std::string &sectionName);
155 
158  Section *findSection(const std::string &sectionName) const;
159 
160  public:
162  IniFile();
163 
165  ~IniFile();
166 
171  bool load(std::istream &f);
172 
178  bool load(const std::string &file);
179 
183  bool add(const std::string &s);
184 
188  bool find(const std::string &section, const std::string &entry,
189  std::string &value) const;
190 
194  bool entryExists(const std::string &section,
195  const std::string &entry) const;
196 
202  bool sectionExists(const std::string &section) const;
203 
206 
209  bool printUnreferenced();
210 
212  void dump();
213 
215  using VisitSectionCallback = std::function<void(
216  const std::string&, const std::string&)>;
217 
219  void visitSection(const std::string &sectionName, VisitSectionCallback cb);
220 };
221 
222 } // namespace gem5
223 
224 #endif // __INIFILE_HH__
gem5::IniFile::entryExists
bool entryExists(const std::string &section, const std::string &entry) const
Determine whether the entry exists within named section exists in the .ini file.
Definition: inifile.cc:232
gem5::IniFile::findSection
Section * findSection(const std::string &sectionName) const
Look up section with the given name.
Definition: inifile.cc:151
gem5::ArmISA::f
Bitfield< 6 > f
Definition: misc_types.hh:67
gem5::IniFile::Entry::referenced
bool referenced
Has this entry been used?
Definition: inifile.hh:65
gem5::IniFile::Section::dump
void dump(const std::string &sectionName)
Print the contents of this section to cout (for debugging).
Definition: inifile.cc:333
gem5::IniFile::Section::findEntry
Entry * findEntry(const std::string &entryName) const
Find the entry with the given name.
Definition: inifile.cc:123
gem5::IniFile
This class represents the contents of a ".ini" file.
Definition: inifile.hh:55
gem5::IniFile::dump
void dump()
Dump contents to cout. For debugging.
Definition: inifile.cc:343
gem5::IniFile::Entry::isReferenced
bool isReferenced()
Has this entry been used?
Definition: inifile.hh:75
sc_dt::list
static scfx_rep_node * list
Definition: scfx_rep.cc:368
gem5::IniFile::getSectionNames
void getSectionNames(std::vector< std::string > &list) const
Push all section names into the given vector.
Definition: inifile.cc:295
gem5::IniFile::Section::begin
EntryTable::const_iterator begin() const
Definition: inifile.cc:352
std::vector< std::string >
gem5::IniFile::SectionTable
std::unordered_map< std::string, Section * > SectionTable
SectionTable type. Map of strings to Section object pointers.
Definition: inifile.hh:145
gem5::IniFile::Section
A section.
Definition: inifile.hh:94
gem5::IniFile::VisitSectionCallback
std::function< void(const std::string &, const std::string &)> VisitSectionCallback
Visitor callback that receives key/value pairs.
Definition: inifile.hh:216
gem5::IniFile::Entry::appendValue
void appendValue(const std::string &v)
Append the given string to the value.
Definition: inifile.hh:88
gem5::IniFile::Section::Section
Section()
Constructor.
Definition: inifile.hh:104
gem5::IniFile::Section::add
bool add(const std::string &assignment)
Add an entry to the table given a string assigment.
Definition: inifile.cc:99
gem5::IniFile::Section::addEntry
void addEntry(const std::string &entryName, const std::string &value, bool append)
Add an entry to the table.
Definition: inifile.cc:77
gem5::IniFile::Section::end
EntryTable::const_iterator end() const
Definition: inifile.cc:358
gem5::IniFile::Entry
A single key/value pair.
Definition: inifile.hh:62
gem5::IniFile::Section::table
EntryTable table
Table of entries.
Definition: inifile.hh:99
gem5::IniFile::sectionExists
bool sectionExists(const std::string &section) const
Determine whether the named section exists in the .ini file.
Definition: inifile.cc:244
gem5::IniFile::Entry::getValue
const std::string & getValue() const
Fetch the value.
Definition: inifile.cc:69
gem5::ArmISA::v
Bitfield< 28 > v
Definition: misc_types.hh:54
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
gem5::IniFile::Section::referenced
bool referenced
Has this section been used?
Definition: inifile.hh:100
gem5::IniFile::load
bool load(std::istream &f)
Load parameter settings from given istream.
Definition: inifile.cc:179
gem5::IniFile::Entry::setValue
void setValue(const std::string &v)
Set the value.
Definition: inifile.hh:81
gem5::IniFile::table
SectionTable table
Hash of section names to Section object pointers.
Definition: inifile.hh:149
gem5::IniFile::Section::EntryTable
std::unordered_map< std::string, Entry * > EntryTable
EntryTable type. Map of strings to Entry object pointers.
Definition: inifile.hh:97
gem5::IniFile::addSection
Section * addSection(const std::string &sectionName)
Look up section with the given name, creating a new section if not found.
Definition: inifile.cc:134
gem5::IniFile::visitSection
void visitSection(const std::string &sectionName, VisitSectionCallback cb)
Iterate over key/value pairs of the given section.
Definition: inifile.cc:364
gem5::IniFile::Section::printUnreferenced
bool printUnreferenced(const std::string &sectionName)
Print the unreferenced entries in this section to cerr.
Definition: inifile.cc:251
gem5::IniFile::Entry::Entry
Entry(const std::string &v)
Constructor.
Definition: inifile.hh:69
gem5::IniFile::~IniFile
~IniFile()
Destructor.
Definition: inifile.cc:45
gem5::IniFile::find
bool find(const std::string &section, const std::string &entry, std::string &value) const
Find value corresponding to given section and entry names.
Definition: inifile.cc:215
gem5::IniFile::add
bool add(const std::string &s)
Take string of the form "<section>:<parameter>=<value>" or "<section>:<parameter>+=<value>" and add t...
Definition: inifile.cc:162
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::IniFile::IniFile
IniFile()
Constructor.
Definition: inifile.cc:42
gem5::IniFile::Section::isReferenced
bool isReferenced()
Has this section been used?
Definition: inifile.hh:110
gem5::IniFile::printUnreferenced
bool printUnreferenced()
Print unreferenced entries in object.
Definition: inifile.cc:305
gem5::IniFile::Entry::value
std::string value
The entry value.
Definition: inifile.hh:64

Generated on Tue Sep 21 2021 12:24:57 for gem5 by doxygen 1.8.17