Diana Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
QGTextFileHandler Class Reference

Class to handle input and output for text files. More...

Public Member Functions

 QGTextFileHandler ()
 Constructor. More...
 
virtual ~QGTextFileHandler ()
 Destructor. More...
 
void AppendLine (std::string key="", std::string value="")
 Append a key and value to the file. More...
 
void AppendLine (std::string key, Double_t value)
 Append a key and (Double_t) value to the file. More...
 
void AppendLine (std::string key, Int_t value)
 Append a key and (Int_t) value to the file. More...
 
bool DoesKeyExist (std::string key)
 Return true if key exists. More...
 
const std::vector< std::pair< std::string, std::string > > & GetLines ()
 Get the lines of the file as key, value pairs. More...
 
std::string GetValue (std::string key)
 Retrieve value associated with a key. More...
 
bool ReadFile (std::string filename)
 Read file, returns true if successful. More...
 
bool WriteFile (std::string filename)
 Write file, returns true if successful. More...
 

Private Member Functions

std::pair< std::string, std::string > ParseLine (const std::string &line)
 Parse a line of a text file, splitting at a delimiter. More...
 
std::string BuildLine (const std::pair< std::string, std::string > &parsedLine)
 Build a line from a key and value, inserting a delimiter. More...
 

Private Attributes

std::map< std::string, std::string > fFileMap
 Contents of text file, useful for unique keys. More...
 
std::vector< std::pair< std::string, std::string > > fFileLines
 Contents of text file, line by line. More...
 

Detailed Description

Class to handle input and output for text files.

Author
Adam Bryant (adam_.nosp@m.brya.nosp@m.nt@be.nosp@m.rkel.nosp@m.ey.ed.nosp@m.u)

Definition at line 17 of file QGTextFileHandler.hh.

Constructor & Destructor Documentation

◆ QGTextFileHandler()

QGTextFileHandler::QGTextFileHandler ( )

Constructor.

Definition at line 17 of file QGTextFileHandler.cc.

◆ ~QGTextFileHandler()

QGTextFileHandler::~QGTextFileHandler ( )
virtual

Destructor.

Definition at line 21 of file QGTextFileHandler.cc.

Member Function Documentation

◆ AppendLine() [1/3]

void QGTextFileHandler::AppendLine ( std::string  key,
Double_t  value 
)

Append a key and (Double_t) value to the file.

◆ AppendLine() [2/3]

void QGTextFileHandler::AppendLine ( std::string  key,
Int_t  value 
)

Append a key and (Int_t) value to the file.

◆ AppendLine() [3/3]

void QGTextFileHandler::AppendLine ( std::string  key = "",
std::string  value = "" 
)

Append a key and value to the file.

Referenced by QGCutsEditorWindow::Save(), and QGDefaultsHandler::SaveToFile().

◆ BuildLine()

string QGTextFileHandler::BuildLine ( const std::pair< std::string, std::string > &  parsedLine)
private

Build a line from a key and value, inserting a delimiter.

Definition at line 108 of file QGTextFileHandler.cc.

Referenced by WriteFile().

◆ DoesKeyExist()

bool QGTextFileHandler::DoesKeyExist ( std::string  key)

Return true if key exists.

Definition at line 59 of file QGTextFileHandler.cc.

References fFileMap.

Referenced by GetValue(), QGDefaultsHandler::LoadFromFile(), and QGFileHandler::ParseFileList().

◆ GetLines()

const std::vector<std::pair<std::string, std::string> >& QGTextFileHandler::GetLines ( )
inline

Get the lines of the file as key, value pairs.

Definition at line 38 of file QGTextFileHandler.hh.

References fFileLines.

Referenced by QGFileHandler::ParseFileList().

◆ GetValue()

string QGTextFileHandler::GetValue ( std::string  key)

Retrieve value associated with a key.

Definition at line 64 of file QGTextFileHandler.cc.

References DoesKeyExist(), and fFileMap.

Referenced by QGDefaultsHandler::LoadFromFile(), and QGFileHandler::ParseFileList().

◆ ParseLine()

pair< string, string > QGTextFileHandler::ParseLine ( const std::string &  line)
private

Parse a line of a text file, splitting at a delimiter.

Definition at line 94 of file QGTextFileHandler.cc.

Referenced by ReadFile().

◆ ReadFile()

bool QGTextFileHandler::ReadFile ( std::string  filename)

Read file, returns true if successful.

Definition at line 25 of file QGTextFileHandler.cc.

References fFileLines, fFileMap, ParseLine(), and success.

Referenced by QGDefaultsHandler::LoadFromFile(), and QGFileHandler::ParseFileList().

◆ WriteFile()

bool QGTextFileHandler::WriteFile ( std::string  filename)

Write file, returns true if successful.

Definition at line 44 of file QGTextFileHandler.cc.

References BuildLine(), fFileLines, and success.

Referenced by QGCutsEditorWindow::Save(), and QGDefaultsHandler::SaveToFile().

Member Data Documentation

◆ fFileLines

std::vector<std::pair<std::string, std::string> > QGTextFileHandler::fFileLines
private

Contents of text file, line by line.

Definition at line 60 of file QGTextFileHandler.hh.

Referenced by GetLines(), ReadFile(), and WriteFile().

◆ fFileMap

std::map<std::string, std::string> QGTextFileHandler::fFileMap
private

Contents of text file, useful for unique keys.

Definition at line 57 of file QGTextFileHandler.hh.

Referenced by DoesKeyExist(), GetValue(), and ReadFile().


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