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 186 of file TextFileDBReader.cxx.
189 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 119 of file TextFileDBReader.cxx.
124 std::string tableName;
126 std::string rowNumber;
127 bool foundRowNumber =
false;
128 std::string::size_type
pos =
key.find(
':');
129 if (
pos != std::string::npos) {
130 tableName =
key.substr(0,
pos);
136 std::string tmpRowNumber;
138 if (foundRowNumber) {
140 std::cout <<
"ERROR in format:" <<
key << std::endl;
142 rowNumber = std::move(tmpRowNumber);
146 std::string newKey =
key;
147 if ((tableName.empty() && !rowNumber.empty()) ||
fieldName.empty()) {
148 std::cout <<
"ERROR in format: " <<
key << std::endl;
150 if (rowNumber.empty()) rowNumber =
"0";
151 if (tableName.empty()) {
153 }
else if (tableName ==
"TableSize") {
156 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 232 of file TextFileDBReader.cxx.
234 std::ios::fmtflags iosflags = std::cout.flags();
235 std::cout << std::left;
239 std::unordered_map<std::string,int>::const_iterator iterSect =
m_sections.find(
section);
240 if (iterSect !=
m_sections.end()) sectionNum = iterSect->second;
243 for (std::unordered_map<std::string,Data>::const_iterator
iter =
m_table.begin();
246 if ((
section.empty() ||
iter->second.section == sectionNum) && (!(
iter->second.flag))) {
247 std::cout << std::setw(35) <<
iter->first <<
" " <<
iter->second.value << std::endl;
252 std::cout <<
"All parameters used" << std::endl;
255 std::cout.flags(iosflags);
◆ printParameters()
void TextFileDBReader::printParameters |
( |
const std::string & |
section = "" | ) |
const |
Definition at line 209 of file TextFileDBReader.cxx.
211 std::ios::fmtflags iosflags = std::cout.flags();
212 std::cout << std::left;
215 std::unordered_map<std::string,int>::const_iterator iterSect =
m_sections.find(
section);
216 if (iterSect !=
m_sections.end()) sectionNum = iterSect->second;
219 for (std::unordered_map<std::string,Data>::const_iterator
iter =
m_table.begin();
222 if (
section.empty() ||
iter->second.section == sectionNum) {
223 std::cout << std::setw(35) <<
iter->first <<
" " <<
iter->second.value << std::endl;
227 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;
59 currentFields.clear();
60 }
else if (
key ==
"TableEnd") {
61 std::ostringstream ostr;
62 ostr <<
"TableSize:" << currentTable;
63 add(ostr.str(), currentIndex);
67 currentFields.clear();
68 }
else if (
key ==
"Section") {
77 }
else if (
key ==
"EndSection") {
88 std::istringstream istr2(
line);
90 if (currentIndex < 0) {
92 while (!istr2.eof()) {
95 if (!
value.empty()) currentFields.push_back(std::move(
value));
99 for (
unsigned int i=0;
i < currentFields.size();
i++) {
103 std::ostringstream ostr;
104 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