gem5  v20.1.0.0
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 <list>
34 #include <string>
35 #include <unordered_map>
36 #include <vector>
37 
44 class IniFile
52 {
53  protected:
54 
58  class Entry
59  {
60  std::string value;
61  mutable bool referenced;
62 
63  public:
65  Entry(const std::string &v)
66  : value(v), referenced(false)
67  {
68  }
69 
71  bool isReferenced() { return referenced; }
72 
74  const std::string &getValue() const;
75 
77  void setValue(const std::string &v) { value = v; }
78 
84  void appendValue(const std::string &v) { value += " "; value += v; }
85  };
86 
90  class Section
91  {
93  typedef std::unordered_map<std::string, Entry *> EntryTable;
94 
96  mutable bool referenced;
97 
98  public:
101  : table(), referenced(false)
102  {
103  }
104 
106  bool isReferenced() { return referenced; }
107 
112  void addEntry(const std::string &entryName, const std::string &value,
113  bool append);
114 
120  bool add(const std::string &assignment);
121 
124  Entry *findEntry(const std::string &entryName) const;
125 
131  bool printUnreferenced(const std::string &sectionName);
132 
134  void dump(const std::string &sectionName);
135  };
136 
138  typedef std::unordered_map<std::string, Section *> SectionTable;
139 
140  protected:
143 
147  Section *addSection(const std::string &sectionName);
148 
151  Section *findSection(const std::string &sectionName) const;
152 
153  public:
155  IniFile();
156 
158  ~IniFile();
159 
164  bool load(std::istream &f);
165 
171  bool load(const std::string &file);
172 
176  bool add(const std::string &s);
177 
181  bool find(const std::string &section, const std::string &entry,
182  std::string &value) const;
183 
187  bool entryExists(const std::string &section,
188  const std::string &entry) const;
189 
195  bool sectionExists(const std::string &section) const;
196 
199 
202  bool printUnreferenced();
203 
205  void dump();
206 };
207 
208 #endif // __INIFILE_HH__
IniFile::Section::Section
Section()
Constructor.
Definition: inifile.hh:100
IniFile::printUnreferenced
bool printUnreferenced()
Print unreferenced entries in object.
Definition: inifile.cc:303
IniFile::SectionTable
std::unordered_map< std::string, Section * > SectionTable
SectionTable type. Map of strings to Section object pointers.
Definition: inifile.hh:138
IniFile::getSectionNames
void getSectionNames(std::vector< std::string > &list) const
Push all section names into the given vector.
Definition: inifile.cc:293
IniFile::~IniFile
~IniFile()
Destructor.
Definition: inifile.cc:44
IniFile::Section::addEntry
void addEntry(const std::string &entryName, const std::string &value, bool append)
Add an entry to the table.
Definition: inifile.cc:76
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:214
IniFile
This class represents the contents of a ".ini" file.
Definition: inifile.hh:51
sc_dt::list
static scfx_rep_node * list
Definition: scfx_rep.cc:368
std::vector< std::string >
IniFile::Entry::appendValue
void appendValue(const std::string &v)
Append the given string to the value.
Definition: inifile.hh:84
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:231
IniFile::Entry::Entry
Entry(const std::string &v)
Constructor.
Definition: inifile.hh:65
IniFile::Section::dump
void dump(const std::string &sectionName)
Print the contents of this section to cout (for debugging).
Definition: inifile.cc:331
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:161
IniFile::Entry::setValue
void setValue(const std::string &v)
Set the value.
Definition: inifile.hh:77
IniFile::Section::add
bool add(const std::string &assignment)
Add an entry to the table given a string assigment.
Definition: inifile.cc:98
IniFile::Section::findEntry
Entry * findEntry(const std::string &entryName) const
Find the entry with the given name.
Definition: inifile.cc:122
IniFile::Section::table
EntryTable table
Table of entries.
Definition: inifile.hh:95
IniFile::Section::referenced
bool referenced
Has this section been used?
Definition: inifile.hh:96
IniFile::Section::EntryTable
std::unordered_map< std::string, Entry * > EntryTable
EntryTable type. Map of strings to Entry object pointers.
Definition: inifile.hh:93
IniFile::Section::printUnreferenced
bool printUnreferenced(const std::string &sectionName)
Print the unreferenced entries in this section to cerr.
Definition: inifile.cc:249
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:133
IniFile::Section
A section.
Definition: inifile.hh:90
IniFile::Entry::value
std::string value
The entry value.
Definition: inifile.hh:60
IniFile::Entry
A single key/value pair.
Definition: inifile.hh:58
IniFile::table
SectionTable table
Hash of section names to Section object pointers.
Definition: inifile.hh:142
IniFile::Entry::referenced
bool referenced
Has this entry been used?
Definition: inifile.hh:61
IniFile::Entry::isReferenced
bool isReferenced()
Has this entry been used?
Definition: inifile.hh:71
IniFile::load
bool load(std::istream &f)
Load parameter settings from given istream.
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
IniFile::findSection
Section * findSection(const std::string &sectionName) const
Look up section with the given name.
Definition: inifile.cc:150
IniFile::Section::isReferenced
bool isReferenced()
Has this section been used?
Definition: inifile.hh:106
IniFile::sectionExists
bool sectionExists(const std::string &section) const
Determine whether the named section exists in the .ini file.
Definition: inifile.cc:242
ArmISA::v
Bitfield< 28 > v
Definition: miscregs_types.hh:51
IniFile::IniFile
IniFile()
Constructor.
Definition: inifile.cc:41
IniFile::Entry::getValue
const std::string & getValue() const
Fetch the value.
Definition: inifile.cc:68
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64
IniFile::dump
void dump()
Dump contents to cout. For debugging.
Definition: inifile.cc:341

Generated on Wed Sep 30 2020 14:02:07 for gem5 by doxygen 1.8.17