26 #include <QtCore/QDir>
27 #include <QtCore/QFile>
28 #include <QtCore/QStringList>
29 #include <QtCore/QRegularExpression>
30 #include <QtCore/QTextStream>
47 return "SgMasterRecord";
74 if (str.at(0) != QChar(
'|') ||
75 str.at(str.size()-1)!=QChar(
'|') ||
76 str.count(QChar(
'|')) != 16)
83 QStringList fields = str.split(
"|");
84 name_ = fields.at(1).simplified();
85 code_ = fields.at(2).simplified().toLower();
86 date_ = fields.at(3).simplified();
88 dbcCode_ = fields.at(12).simplified();
102 if (str.at(0) != QChar(
'|') ||
103 str.at(str.size()-1)!=QChar(
'|') ||
104 str.count(QChar(
'|')) != 14)
111 QStringList fields = str.split(
"|");
118 type_ = fields.at(1).simplified();
119 date_ = fields.at(2).simplified();
120 code_ = fields.at(3).simplified();
126 dbcCode_ = fields.at(11).simplified();
139 QRegularExpression reOldDbName(
"(\\d{2})([A-Z]{3})(\\d{2})([A-Z0-9]{1,2})");
140 QRegularExpression reNewDbName(
"(\\d{8})-([\\S]{2,12})");
141 QRegularExpressionMatch match;
147 "::lookupRecordByName(): the masterfile directory \"" + path +
148 "\" does not exist; master file records are unavailable");
155 if ((match=reOldDbName.match(dbName)).hasMatch())
157 sYear = match.captured(1);
158 sDate = match.captured(2) + match.captured(3);
159 sCode = match.captured(4);
162 else if ((match=reNewDbName.match(dbName)).hasMatch())
164 sYear = match.captured(1).left(4);
167 sCode = match.captured(2).toLower();
172 "::lookupRecordByName(): the database name, " + dbName +
", is of unknown pattern");
174 if (
findRecordByName(sDate, sCode, path +
"/" +
"master" + sYear +
"-loc.txt") ||
176 findRecordByName(sDate, sCode, path +
"/" +
"master" + sYear +
"-int.txt") ||
177 findRecordByName(sDate, sCode, path +
"/" +
"master" + sYear +
"-vgos.txt") )
186 const QString& fileName)
191 "::findRecordByName(): cannot guess masterfile version");
201 "::findRecordByName(): the masterfile \"" + fileName +
"\" does not exist");
205 if (f.open(QFile::ReadOnly))
251 if (sYear.size() == 2)
253 else if (sYear.size() == 4)
260 "::lookupRecordByCode(): the masterfile directory \"" + path +
261 "\" does not exist; master file records are unavailable");
264 if (
findRecordByCode(sessionCode.toLower(), path +
"/" +
"master" + sYear +
"-loc.txt") ||
265 findRecordByCode(sessionCode.toLower(), path +
"/" +
"master" + sYear +
".txt") ||
266 findRecordByCode(sessionCode.toLower(), path +
"/" +
"master" + sYear +
"-int.txt") ||
267 findRecordByCode(sessionCode.toLower(), path +
"/" +
"master" + sYear +
"-vgos.txt") )
280 "::findRecordByName(): cannot guess masterfile version");
290 "::findRecordByCode(): the masterfile \"" + fileName +
"\" does not exist");
294 if (f.open(QFile::ReadOnly))
297 "::findRecordByCode(): processing the masterfile \"" + fileName +
"\"");
308 if (mr.
getCode() == sessionCode)
virtual void write(LogLevel, quint32, const QString &, bool=false)
const QString & getDate() const
static const QString className()
bool lookupRecordByCode(const QString &sessionCode, const QString &sYear, const QString &path)
bool findRecordByCode(const QString &sessionCode, const QString &fileName)
void parseString_v1(const QString &)
void parseString_v2(const QString &)
const QString & getCode() const
SgMasterRecord & operator=(const SgMasterRecord &r)
bool findRecordByName(const QString &date, const QString &dbcCode, const QString &fileName)
const QString & getDbcCode() const
MasterFileVersion mfVersion_
bool lookupRecordByName(const QString &nickName, const QString &path)