1 /******************************************************************************
4 Lantiq Deutschland GmbH
6 For licensing information, see the file 'LICENSE' in the root folder of
9 ******************************************************************************/
17 #define MAKE_ORGS_KEY(oid) ((uint8)oid)
18 #define MAKE_GRPS_KEY(oid, gid) ((((uint16)(uint8)(oid)) << 8) | ((uint16)(uint8)(gid)))
19 #define MAKE_FMTS_KEY(oid, gid, fid, lid) ((((uint64)(uint8)(oid)) << 40) | \
20 (((uint64)(uint8)(gid)) << 32) | \
21 (((uint64)(uint16)(fid)) << 16) | \
22 ((uint64)(uint16)(lid)))
25 replace_all(const string
&source
, const string
&victim
, const string
&replacement
)
27 string answer
= source
;
28 string::size_type j
= 0;
30 while ((j
= answer
.find(victim
, j
)) != std::string::npos
)
31 answer
.replace(j
, victim
.length(), replacement
);
36 CLogFmtDB::Read (string
&fname
)
40 ifs
.exceptions(ifstream::badbit
); /* An error happened. */
42 ifs
.open(fname
.c_str());
57 switch (record_type
) {
61 ifs
.getline(buf
, sizeof(buf
));
62 if (!ifs
.fail()) { /* if all the readings were OK */
63 if (!orgs
.insert(pair
<uint8
, string
> (MAKE_ORGS_KEY(oid
), buf
)).second
) {
64 throw bad_scd_file(oid
, buf
);
73 ifs
.getline(buf
, sizeof(buf
));
75 if (!ifs
.fail()) { /* if all the readings were OK */
76 if (!grps
.insert(pair
<uint16
, string
> (MAKE_GRPS_KEY(oid
, gid
), buf
)).second
) {
77 throw bad_scd_file(oid
, gid
, buf
);
91 /* read all strings before next record - we may have multiline format strings */
95 ifs
.getline(buf
, sizeof(buf
));
99 /* check if we are done: logprep inserts spaces for all multiline formats to align them */
102 if (record_type
!= '\"') {
108 fmt_str
= replace_all(fmt_str
, "\"\"", "");
109 if (!fmts
.insert(pair
<uint64
, string
> (MAKE_FMTS_KEY(oid
, gid
, fid
, lid
), fmt_str
.c_str())).second
) {
110 throw bad_scd_file(oid
, gid
, fid
, lid
, buf
);
115 throw bad_scd_file(record_type
);
122 CLogFmtDB::GetFormat (uint8 oid
, uint8 gid
, uint16 fid
, uint16 lid
, string
&res
) const
124 map
<uint64
, string
>::const_iterator it
= fmts
.find(MAKE_FMTS_KEY(oid
, gid
, fid
, lid
));
126 if (it
!= fmts
.end()) {
135 CLogFmtDB::GetOrgName (uint8 oid
, string
&res
) const
137 map
<uint8
, string
>::const_iterator it
= orgs
.find(MAKE_ORGS_KEY(oid
));
139 if (it
!= orgs
.end()) {
148 CLogFmtDB::GetGrpName (uint8 oid
, uint8 gid
, string
&res
) const
150 map
<uint16
, string
>::const_iterator it
= grps
.find(MAKE_GRPS_KEY(oid
, gid
));
152 if (it
!= grps
.end()) {