small prettification

This commit is contained in:
Jean-Francois Dockes 2018-05-31 16:45:40 +02:00
parent fbcbfbf7e5
commit be7b8379e1
2 changed files with 20 additions and 16 deletions

View File

@ -68,11 +68,11 @@ SynGroups::SynGroups()
bool SynGroups::setfile(const string& fn) bool SynGroups::setfile(const string& fn)
{ {
LOGDEB("SynGroups::setfile(" << (fn) << ")\n" ); LOGDEB("SynGroups::setfile(" << fn << ")\n");
if (!m) { if (!m) {
m = new Internal; m = new Internal;
if (!m) { if (!m) {
LOGERR("SynGroups:setfile:: new Internal failed: no mem ?\n" ); LOGERR("SynGroups:setfile:: new Internal failed: no mem ?\n");
return false; return false;
} }
} }
@ -86,7 +86,7 @@ bool SynGroups::setfile(const string& fn)
ifstream input; ifstream input;
input.open(fn.c_str(), ios::in); input.open(fn.c_str(), ios::in);
if (!input.is_open()) { if (!input.is_open()) {
LOGERR("SynGroups:setfile:: could not open " << (fn) << " errno " << (errno) << "\n" ); LOGSYSERR("SynGroups:setfile", "open", fn);
return false; return false;
} }
@ -101,7 +101,7 @@ bool SynGroups::setfile(const string& fn)
getline(input, cline); getline(input, cline);
if (!input.good()) { if (!input.good()) {
if (input.bad()) { if (input.bad()) {
LOGERR("Syngroup::setfile(" << (fn) << "):Parse: input.bad()\n" ); LOGERR("Syngroup::setfile(" << fn << "):Parse: input.bad()\n");
return false; return false;
} }
// Must be eof ? But maybe we have a partial line which // Must be eof ? But maybe we have a partial line which
@ -142,23 +142,25 @@ bool SynGroups::setfile(const string& fn)
vector<string> words; vector<string> words;
if (!stringToStrings(line, words)) { if (!stringToStrings(line, words)) {
LOGERR("SynGroups:setfile: " << (fn) << ": bad line " << (lnum) << ": " << (line) << "\n" ); LOGERR("SynGroups:setfile: " << fn << ": bad line " << lnum <<
": " << line << "\n");
continue; continue;
} }
if (words.empty()) if (words.empty())
continue; continue;
if (words.size() == 1) { if (words.size() == 1) {
LOGERR("Syngroup::setfile(" << (fn) << "):single term group at line " << (lnum) << " ??\n" ); LOGERR("Syngroup::setfile(" << fn << "):single term group at line "
<< lnum << " ??\n");
continue; continue;
} }
m->groups.push_back(words); m->groups.push_back(words);
for (vector<string>::const_iterator it = words.begin(); for (const auto& word : words) {
it != words.end(); it++) { m->terms[word] = m->groups.size()-1;
m->terms[*it] = m->groups.size()-1;
} }
LOGDEB1("SynGroups::setfile: group: [" << (stringsToString(m->groups.back())) << "]\n" ); LOGDEB1("SynGroups::setfile: group: [" <<
stringsToString(m->groups.back()) << "]\n");
} }
m->ok = true; m->ok = true;
return true; return true;
@ -170,16 +172,15 @@ vector<string> SynGroups::getgroup(const string& term)
if (!ok()) if (!ok())
return ret; return ret;
std::unordered_map<string, unsigned int>::const_iterator it1 = const auto it1 = m->terms.find(term);
m->terms.find(term);
if (it1 == m->terms.end()) { if (it1 == m->terms.end()) {
LOGDEB1("SynGroups::getgroup: [" << (term) << "] not found in direct map\n" ); LOGDEB1("SynGroups::getgroup: [" << term<<"] not found in direct map\n");
return ret; return ret;
} }
unsigned int idx = it1->second; unsigned int idx = it1->second;
if (idx >= m->groups.size()) { if (idx >= m->groups.size()) {
LOGERR("SynGroups::getgroup: line index higher than line count !\n" ); LOGERR("SynGroups::getgroup: line index higher than line count !\n");
return ret; return ret;
} }
return m->groups[idx]; return m->groups[idx];

View File

@ -28,14 +28,17 @@ class SynGroups {
public: public:
SynGroups(); SynGroups();
~SynGroups(); ~SynGroups();
SynGroups(const SynGroups&) = delete;
SynGroups& operator=(const SynGroups&) = delete;
SynGroups(const SynGroups&&) = delete;
SynGroups& operator=(const SynGroups&&) = delete;
bool setfile(const std::string& fname); bool setfile(const std::string& fname);
std::vector<std::string> getgroup(const std::string& term); std::vector<std::string> getgroup(const std::string& term);
bool ok(); bool ok();
private: private:
class Internal; class Internal;
Internal *m; Internal *m;
SynGroups(const SynGroups&);
SynGroups& operator=(const SynGroups&);
}; };
#endif /* _SYNGROUPS_H_INCLUDED_ */ #endif /* _SYNGROUPS_H_INCLUDED_ */