gem5  v21.1.0.2
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
gem5::IniFile Class Reference

This class represents the contents of a ".ini" file. More...

#include <inifile.hh>

Classes

class  Entry
 A single key/value pair. More...
 
class  Section
 A section. More...
 

Public Types

using VisitSectionCallback = std::function< void(const std::string &, const std::string &)>
 Visitor callback that receives key/value pairs. More...
 

Public Member Functions

 IniFile ()
 Constructor. More...
 
 ~IniFile ()
 Destructor. More...
 
bool load (std::istream &f)
 Load parameter settings from given istream. More...
 
bool load (const std::string &file)
 Load the specified file. More...
 
bool add (const std::string &s)
 Take string of the form "<section>:<parameter>=<value>" or "<section>:<parameter>+=<value>" and add to database. More...
 
bool find (const std::string &section, const std::string &entry, std::string &value) const
 Find value corresponding to given section and entry names. More...
 
bool entryExists (const std::string &section, const std::string &entry) const
 Determine whether the entry exists within named section exists in the .ini file. More...
 
bool sectionExists (const std::string &section) const
 Determine whether the named section exists in the .ini file. More...
 
void getSectionNames (std::vector< std::string > &list) const
 Push all section names into the given vector. More...
 
bool printUnreferenced ()
 Print unreferenced entries in object. More...
 
void dump ()
 Dump contents to cout. For debugging. More...
 
void visitSection (const std::string &sectionName, VisitSectionCallback cb)
 Iterate over key/value pairs of the given section. More...
 

Protected Types

typedef std::unordered_map< std::string, Section * > SectionTable
 SectionTable type. Map of strings to Section object pointers. More...
 

Protected Member Functions

SectionaddSection (const std::string &sectionName)
 Look up section with the given name, creating a new section if not found. More...
 
SectionfindSection (const std::string &sectionName) const
 Look up section with the given name. More...
 

Protected Attributes

SectionTable table
 Hash of section names to Section object pointers. More...
 

Detailed Description

This class represents the contents of a ".ini" file.

It's basically a two level lookup table: a set of named sections, where each section is a set of key/value pairs. Section names, keys, and values are all uninterpreted strings.

Definition at line 55 of file inifile.hh.

Member Typedef Documentation

◆ SectionTable

typedef std::unordered_map<std::string, Section *> gem5::IniFile::SectionTable
protected

SectionTable type. Map of strings to Section object pointers.

Definition at line 145 of file inifile.hh.

◆ VisitSectionCallback

using gem5::IniFile::VisitSectionCallback = std::function<void( const std::string&, const std::string&)>

Visitor callback that receives key/value pairs.

Definition at line 216 of file inifile.hh.

Constructor & Destructor Documentation

◆ IniFile()

gem5::IniFile::IniFile ( )

Constructor.

Definition at line 42 of file inifile.cc.

◆ ~IniFile()

gem5::IniFile::~IniFile ( )

Destructor.

Definition at line 45 of file inifile.cc.

References gem5::ArmISA::i, and table.

Member Function Documentation

◆ add()

bool gem5::IniFile::add ( const std::string &  s)

Take string of the form "<section>:<parameter>=<value>" or "<section>:<parameter>+=<value>" and add to database.

Return values
Trueif successful, false if parse error.

Definition at line 162 of file inifile.cc.

References addSection(), gem5::eat_white(), gem5::ArmISA::offset, and gem5::ArmISA::s.

◆ addSection()

IniFile::Section * gem5::IniFile::addSection ( const std::string &  sectionName)
protected

Look up section with the given name, creating a new section if not found.

Return values
Pointerto section object.

Definition at line 134 of file inifile.cc.

References gem5::ArmISA::i, and table.

Referenced by add(), and load().

◆ dump()

void gem5::IniFile::dump ( )

Dump contents to cout. For debugging.

Definition at line 343 of file inifile.cc.

References gem5::ArmISA::i, and table.

◆ entryExists()

bool gem5::IniFile::entryExists ( const std::string &  section,
const std::string &  entry 
) const

Determine whether the entry exists within named section exists in the .ini file.

Returns
True if the section exists.

Definition at line 232 of file inifile.cc.

References gem5::IniFile::Section::findEntry(), and findSection().

Referenced by gem5::CheckpointIn::entryExists().

◆ find()

bool gem5::IniFile::find ( const std::string &  section,
const std::string &  entry,
std::string &  value 
) const

Find value corresponding to given section and entry names.

Value is returned by reference in 'value' param.

Return values
Trueif found, false if not.

Definition at line 215 of file inifile.cc.

References gem5::IniFile::Section::findEntry(), findSection(), and gem5::IniFile::Entry::getValue().

Referenced by gem5::CheckpointIn::find(), gem5::CxxIniFile::getParam(), gem5::CxxIniFile::getParamVector(), and TEST().

◆ findSection()

IniFile::Section * gem5::IniFile::findSection ( const std::string &  sectionName) const
protected

Look up section with the given name.

Return values
Pointerto section object, or NULL if not found.

Definition at line 151 of file inifile.cc.

References gem5::ArmISA::i, and table.

Referenced by entryExists(), find(), and sectionExists().

◆ getSectionNames()

void gem5::IniFile::getSectionNames ( std::vector< std::string > &  list) const

Push all section names into the given vector.

Definition at line 295 of file inifile.cc.

References gem5::ArmISA::i, sc_dt::list, and table.

Referenced by gem5::CxxIniFile::getAllObjectNames().

◆ load() [1/2]

bool gem5::IniFile::load ( const std::string &  file)

Load the specified file.

Parameter settings found in the file will be merged with any already defined in this object.

Parameters
fileThe path of the file to load.
Return values
Trueif successful, false if errors were encountered.

Definition at line 57 of file inifile.cc.

References gem5::ArmISA::f, and load().

◆ load() [2/2]

bool gem5::IniFile::load ( std::istream &  f)

Load parameter settings from given istream.

This is a helper function for load(string) and loadCPP(), which open a file and then pass it here.

Return values
Trueif successful, false if errors were encountered.

Definition at line 179 of file inifile.cc.

References gem5::IniFile::Section::add(), addSection(), gem5::eat_end_white(), gem5::eat_white(), and gem5::ArmISA::f.

Referenced by gem5::CheckpointIn::CheckpointIn(), gem5::CxxIniFile::load(), load(), and TEST().

◆ printUnreferenced()

bool gem5::IniFile::printUnreferenced ( )

Print unreferenced entries in object.

Iteratively calls printUnreferend() on all the constituent sections.

Definition at line 305 of file inifile.cc.

References gem5::IniFile::Section::findEntry(), gem5::ArmISA::i, gem5::IniFile::Section::isReferenced(), gem5::IniFile::Section::printUnreferenced(), and table.

◆ sectionExists()

bool gem5::IniFile::sectionExists ( const std::string &  section) 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 are any values in that section or not.

Returns
True if the section exists.

Definition at line 244 of file inifile.cc.

References findSection().

Referenced by gem5::CxxIniFile::objectExists(), and gem5::CheckpointIn::sectionExists().

◆ visitSection()

void gem5::IniFile::visitSection ( const std::string &  sectionName,
IniFile::VisitSectionCallback  cb 
)

Iterate over key/value pairs of the given section.

Definition at line 364 of file inifile.cc.

References table.

Referenced by gem5::CheckpointIn::visitSection().

Member Data Documentation

◆ table

SectionTable gem5::IniFile::table
protected

The documentation for this class was generated from the following files:

Generated on Tue Sep 21 2021 12:27:43 for gem5 by doxygen 1.8.17