Diana Software
QGTextFileHandler.hh
Go to the documentation of this file.
1 #ifndef _QG_TEXT_FILE_HANDLER_HH_
2 #define _QG_TEXT_FILE_HANDLER_HH_
3 
11 #include <map>
12 #include <string>
13 #include <vector>
14 #include <utility>
15 #include "Rtypes.h"
16 
18 public:
21 
23  virtual ~QGTextFileHandler();
24 
26  void AppendLine(std::string key = "", std::string value = "");
27 
29  void AppendLine(std::string key, Double_t value);
30 
32  void AppendLine(std::string key, Int_t value);
33 
35  bool DoesKeyExist(std::string key);
36 
38  const std::vector<std::pair<std::string, std::string> >& GetLines() {return fFileLines;}
39 
41  std::string GetValue(std::string key);
42 
44  bool ReadFile(std::string filename);
45 
47  bool WriteFile(std::string filename);
48 
49 private:
51  std::pair<std::string, std::string> ParseLine(const std::string& line);
52 
54  std::string BuildLine(const std::pair<std::string, std::string>& parsedLine);
55 
57  std::map<std::string, std::string> fFileMap;
58 
60  std::vector<std::pair<std::string, std::string> > fFileLines;
61 
62  ClassDef(QGTextFileHandler, 0)
63 };
64 
65 #endif
Class to handle input and output for text files.
const std::vector< std::pair< std::string, std::string > > & GetLines()
Get the lines of the file as key, value pairs.
std::string GetValue(std::string key)
Retrieve value associated with a key.
void AppendLine(std::string key, Double_t value)
Append a key and (Double_t) value to the file.
std::pair< std::string, std::string > ParseLine(const std::string &line)
Parse a line of a text file, splitting at a delimiter.
bool ReadFile(std::string filename)
Read file, returns true if successful.
std::vector< std::pair< std::string, std::string > > fFileLines
Contents of text file, line by line.
std::string BuildLine(const std::pair< std::string, std::string > &parsedLine)
Build a line from a key and value, inserting a delimiter.
void AppendLine(std::string key, Int_t value)
Append a key and (Int_t) value to the file.
std::map< std::string, std::string > fFileMap
Contents of text file, useful for unique keys.
bool WriteFile(std::string filename)
Write file, returns true if successful.
bool DoesKeyExist(std::string key)
Return true if key exists.
void AppendLine(std::string key="", std::string value="")
Append a key and value to the file.
QGTextFileHandler()
Constructor.
virtual ~QGTextFileHandler()
Destructor.