Class to read in a text file and allow easy retrieval of parameters.
More...
#include <TextFileDBReader.h>
Class to read in a text file and allow easy retrieval of parameters.
Definition at line 17 of file TextFileDBReader.h.
◆ TextFileDBReader() [1/2]
TextFileDBReader::TextFileDBReader |
( |
const std::string & |
filename | ) |
|
◆ TextFileDBReader() [2/2]
TextFileDBReader::TextFileDBReader |
( |
| ) |
|
◆ add() [1/2]
void TextFileDBReader::add |
( |
const std::string & |
key, |
|
|
const std::string & |
value |
|
) |
| |
|
private |
Definition at line 188 of file TextFileDBReader.cxx.
191 std::cout <<
"WARNING! Overwriting exist entry with key: " <<
key << std::endl;
◆ add() [2/2]
void TextFileDBReader::add |
( |
const std::string & |
key, |
|
|
int |
value |
|
) |
| |
|
private |
◆ find()
bool TextFileDBReader::find |
( |
const std::string & |
key, |
|
|
std::string & |
result |
|
) |
| const |
◆ formatKey()
std::string TextFileDBReader::formatKey |
( |
const std::string & |
key | ) |
const |
|
private |
Definition at line 121 of file TextFileDBReader.cxx.
126 std::string tableName;
128 std::string rowNumber;
129 bool foundRowNumber =
false;
130 std::string::size_type
pos =
key.find(
':');
131 if (
pos != std::string::npos) {
132 tableName =
key.substr(0,
pos);
138 std::string tmpRowNumber;
140 if (foundRowNumber) {
142 std::cout <<
"ERROR in format:" <<
key << std::endl;
144 rowNumber = tmpRowNumber;
148 std::string newKey =
key;
149 if ((tableName.empty() && !rowNumber.empty()) ||
fieldName.empty()) {
150 std::cout <<
"ERROR in format: " <<
key << std::endl;
152 if (rowNumber.empty()) rowNumber =
"0";
153 if (tableName.empty()) {
155 }
else if (tableName ==
"TableSize") {
158 newKey = tableName+
"#"+rowNumber+
":"+
fieldName;
◆ getRowNumber()
bool TextFileDBReader::getRowNumber |
( |
std::string & |
key, |
|
|
std::string & |
rowNumber |
|
) |
| const |
|
private |
◆ printNotUsed()
void TextFileDBReader::printNotUsed |
( |
const std::string & |
section = "" | ) |
const |
Definition at line 234 of file TextFileDBReader.cxx.
236 std::ios::fmtflags iosflags = std::cout.flags();
237 std::cout << std::left;
241 std::unordered_map<std::string,int>::const_iterator iterSect =
m_sections.find(
section);
242 if (iterSect !=
m_sections.end()) sectionNum = iterSect->second;
245 for (std::unordered_map<std::string,Data>::const_iterator iter =
m_table.begin();
248 if ((
section.empty() || iter->second.section == sectionNum) && (!(iter->second.flag))) {
249 std::cout << std::setw(35) << iter->first <<
" " << iter->second.value << std::endl;
254 std::cout <<
"All parameters used" << std::endl;
257 std::cout.flags(iosflags);
◆ printParameters()
void TextFileDBReader::printParameters |
( |
const std::string & |
section = "" | ) |
const |
Definition at line 211 of file TextFileDBReader.cxx.
213 std::ios::fmtflags iosflags = std::cout.flags();
214 std::cout << std::left;
217 std::unordered_map<std::string,int>::const_iterator iterSect =
m_sections.find(
section);
218 if (iterSect !=
m_sections.end()) sectionNum = iterSect->second;
221 for (std::unordered_map<std::string,Data>::const_iterator iter =
m_table.begin();
224 if (
section.empty() || iter->second.section == sectionNum) {
225 std::cout << std::setw(35) << iter->first <<
" " << iter->second.value << std::endl;
229 std::cout.flags(iosflags);
◆ readFile()
bool TextFileDBReader::readFile |
( |
const std::string & |
filename | ) |
|
Definition at line 26 of file TextFileDBReader.cxx.
35 bool tableMode =
false;
36 std::string currentTable;
37 int currentIndex = -1;
38 std::vector<std::string> currentFields;
46 if (
line.empty() ||
line[0] ==
'#' ||
line.substr(0,2) ==
"//" )
continue;
47 std::istringstream istr(
line);
53 if (
key.empty())
continue;
61 currentFields.clear();
62 }
else if (
key ==
"TableEnd") {
63 std::ostringstream ostr;
64 ostr <<
"TableSize:" << currentTable;
65 add(ostr.str(), currentIndex);
69 currentFields.clear();
70 }
else if (
key ==
"Section") {
79 }
else if (
key ==
"EndSection") {
90 std::istringstream istr2(
line);
92 if (currentIndex < 0) {
94 while (!istr2.eof()) {
97 if (!
value.empty()) currentFields.push_back(
value);
101 for (
unsigned int i=0;
i < currentFields.size();
i++) {
105 std::ostringstream ostr;
106 ostr << currentTable <<
"#" << currentIndex <<
":" << currentFields[
i];
◆ sectionPresent()
bool TextFileDBReader::sectionPresent |
( |
const std::string & |
section | ) |
const |
◆ m_currentSection
int TextFileDBReader::m_currentSection |
|
private |
◆ m_name
std::string TextFileDBReader::m_name |
|
private |
◆ m_numSections
int TextFileDBReader::m_numSections |
|
private |
◆ m_sections
std::unordered_map<std::string, int> TextFileDBReader::m_sections |
|
private |
◆ m_table
std::unordered_map<std::string, Data> TextFileDBReader::m_table |
|
private |
The documentation for this class was generated from the following files:
std::unordered_map< std::string, Data > m_table
bool getRowNumber(std::string &key, std::string &rowNumber) const
std::unordered_map< std::string, int > m_sections
void add(const std::string &key, const std::string &value)
bool readFile(const std::string &filename)
std::string formatKey(const std::string &key) const