diff --git a/ZRColaCompile/dbsource.cpp b/ZRColaCompile/dbsource.cpp index 4583077..cae3a52 100644 --- a/ZRColaCompile/dbsource.cpp +++ b/ZRColaCompile/dbsource.cpp @@ -709,7 +709,7 @@ bool ZRCola::DBSource::GetTranslationSet(const com_obj& rs, ZRCola { com_obj f; wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"entCode"), &f))); - wxCHECK(GetValue(f, ts.id), false); + wxCHECK(GetValue(f, ts.set), false); } { @@ -847,7 +847,7 @@ bool ZRCola::DBSource::GetLanguage(const com_obj& rs, ZRCola::DBSo { com_obj f; wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"entCode"), &f))); - wxCHECK(GetLanguage(f, lang.id), false); + wxCHECK(GetLanguage(f, lang.lang), false); } { @@ -931,18 +931,18 @@ bool ZRCola::DBSource::GetCharacterGroup(const com_obj& rs, chrgrp com_obj flds; wxVERIFY(SUCCEEDED(rs->get_Fields(&flds))); - wstring id; + wstring grp; { com_obj f; wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"id"), &f))); - wxCHECK(GetValue(f, cg.id), false); + wxCHECK(GetValue(f, cg.grp), false); } { com_obj f; wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"Skupina"), &f))); - wxCHECK(GetValue(f, id), false); + wxCHECK(GetValue(f, grp), false); } { @@ -958,7 +958,7 @@ bool ZRCola::DBSource::GetCharacterGroup(const com_obj& rs, chrgrp } // Read character list from database. - wxVERIFY(SUCCEEDED(m_pCharacterGroup1->put_Value(variant(id.c_str())))); + wxVERIFY(SUCCEEDED(m_pCharacterGroup1->put_Value(variant(grp.c_str())))); com_obj rs_chars; wxVERIFY(SUCCEEDED(::CoCreateInstance(CLSID_CADORecordset, NULL, CLSCTX_ALL, IID_IADORecordset, (LPVOID*)&rs_chars))); wxVERIFY(SUCCEEDED(rs_chars->put_CursorLocation(adUseClient))); @@ -1103,12 +1103,11 @@ bool ZRCola::DBSource::GetCharacterCategory(const com_obj& rs, chr com_obj flds; wxVERIFY(SUCCEEDED(rs->get_Fields(&flds))); - wstring id; { com_obj f; wxVERIFY(SUCCEEDED(flds->get_Item(variant(L"kat"), &f))); - wxCHECK(GetChrCat(f, cc.id), false); + wxCHECK(GetChrCat(f, cc.cat), false); } { @@ -1154,7 +1153,6 @@ bool ZRCola::DBSource::GetCharacterTag(const winstd::com_obj& rs, com_obj flds; wxVERIFY(SUCCEEDED(rs->get_Fields(&flds))); - wstring id; { com_obj f; @@ -1199,7 +1197,6 @@ bool ZRCola::DBSource::GetTagName(const winstd::com_obj& rs, tagna com_obj flds; wxVERIFY(SUCCEEDED(rs->get_Fields(&flds))); - wstring id; tn.names.clear(); { diff --git a/ZRColaCompile/dbsource.h b/ZRColaCompile/dbsource.h index ed62364..aeef161 100644 --- a/ZRColaCompile/dbsource.h +++ b/ZRColaCompile/dbsource.h @@ -21,11 +21,18 @@ #include #include +#include +#include #include +#include +#include + #include #include +#include + #include #include #include @@ -67,6 +74,7 @@ namespace ZRCola { /// class translation { public: + int set; ///< Translation set ID charseq src; ///< Source sequence charseq dst; ///< Destination sequence }; @@ -77,7 +85,7 @@ namespace ZRCola { /// class transet { public: - int id; ///< ID + int set; ///< ID std::wstring src; ///< Source name std::wstring dst; ///< Destination name }; @@ -123,8 +131,8 @@ namespace ZRCola { /// class language { public: - ZRCola::langid_t id; ///< Language ID - std::wstring name; ///< Language name + ZRCola::langid_t lang; ///< Language ID + std::wstring name; ///< Name }; @@ -143,11 +151,11 @@ namespace ZRCola { /// class chrgrp { public: - int id; ///< Character group ID - int rank; ///< Character group rank - std::wstring name; ///< Character group name - std::vector chars; ///< Character group characters - std::vector show; ///< Bit vector if particular character is displayed initially + int grp; ///< Character group ID + int rank; ///< Rank + std::wstring name; ///< Name + std::vector chars; ///< Characters (zero-delimited) + std::vector show; ///< Bit vector if particular character from \c chars is displayed initially }; @@ -175,7 +183,7 @@ namespace ZRCola { std::wstring desc; ///< Character description std::set terms; ///< Search terms std::set terms_rel; ///< Relevant terms for relating characters - std::vector rel; ///< Related characters + std::vector rel; ///< Related characters (zero-delimited) }; @@ -291,9 +299,9 @@ namespace ZRCola { /// class chrcat { public: - ZRCola::chrcatid_t id; ///> Category ID - int rank; ///< Character category rank - std::wstring name; ///< Character category name + ZRCola::chrcatid_t cat; ///> Category ID + int rank; ///< Rank + std::wstring name; ///< Name }; @@ -729,3 +737,200 @@ namespace ZRCola { std::set m_terms_ignore; ///< Terms to ignore when comparing characters }; }; + + +inline ZRCola::translation_db& operator<<(_Inout_ ZRCola::translation_db &db, _In_ const ZRCola::DBSource::translation &rec) +{ + unsigned __int32 idx = db.data.size(); + wxASSERT_MSG((int)0xffff8000 <= rec.set && rec.set <= (int)0x00007fff, wxT("translation set index out of bounds")); + db.data.push_back((unsigned __int16)rec.set); + wxASSERT_MSG((int)0xffff8000 <= rec.dst.rank && rec.dst.rank <= (int)0x00007fff, wxT("destination character rank out of bounds")); + db.data.push_back((unsigned __int16)rec.dst.rank); + wxASSERT_MSG((int)0xffff8000 <= rec.src.rank && rec.src.rank <= (int)0x00007fff, wxT("source character rank out of bounds")); + db.data.push_back((unsigned __int16)rec.src.rank); + std::wstring::size_type n = rec.dst.str.length(); + wxASSERT_MSG(n <= 0xffff, wxT("destination overflow")); + db.data.push_back((unsigned __int16)n); + n += rec.src.str.length(); + wxASSERT_MSG(n <= 0xffff, wxT("source overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.dst.str.cbegin(), rec.dst.str.cend()); + db.data.insert(db.data.end(), rec.src.str.cbegin(), rec.src.str.cend()); + db.idxSrc.push_back(idx); + db.idxDst.push_back(idx); + + return db; +} + + +inline ZRCola::transet_db& operator<<(_Inout_ ZRCola::transet_db &db, _In_ const ZRCola::DBSource::transet &rec) +{ + unsigned __int32 idx = db.data.size(); + wxASSERT_MSG((int)0xffff8000 <= rec.set && rec.set <= (int)0x00007fff, wxT("translation set index out of bounds")); + db.data.push_back((unsigned __int16)rec.set); + std::wstring::size_type n = rec.src.length(); + wxASSERT_MSG(n <= 0xffff, wxT("translation set source name overflow")); + db.data.push_back((unsigned __int16)n); + n += rec.dst.length(); + wxASSERT_MSG(n <= 0xffff, wxT("translation set destination name overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.src.cbegin(), rec.src.cend()); + db.data.insert(db.data.end(), rec.dst.cbegin(), rec.dst.cend()); + db.idxTranSet.push_back(idx); + + return db; +} + + +inline ZRCola::keyseq_db& operator<<(_Inout_ ZRCola::keyseq_db &db, _In_ const ZRCola::DBSource::keyseq &rec) +{ + unsigned __int32 idx = db.data.size(); + std::wstring::size_type n = rec.chr.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); + db.data.push_back((unsigned __int16)n); + n += rec.seq.size() * sizeof(ZRCola::keyseq_db::keyseq::key_t) / sizeof(wchar_t); + wxASSERT_MSG(n <= 0xffff, wxT("key sequence overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.chr.cbegin(), rec.chr.cend()); + for (auto kc = rec.seq.cbegin(), kc_end = rec.seq.cend(); kc != kc_end; ++kc) { + db.data.push_back(kc->key); + db.data.push_back( + (kc->shift ? ZRCola::keyseq_db::keyseq::SHIFT : 0) | + (kc->ctrl ? ZRCola::keyseq_db::keyseq::CTRL : 0) | + (kc->alt ? ZRCola::keyseq_db::keyseq::ALT : 0)); + } + db.idxChr.push_back(idx); + db.idxKey.push_back(idx); + + return db; +} + + +inline ZRCola::language_db& operator<<(_Inout_ ZRCola::language_db &db, _In_ const ZRCola::DBSource::language &rec) +{ + unsigned __int32 idx = db.data.size(); + db.data.insert(db.data.end(), reinterpret_cast(&rec.lang), reinterpret_cast(&rec.lang + 1)); + std::wstring::size_type n = rec.name.length(); + wxASSERT_MSG(n <= 0xffff, wxT("language name overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.name.cbegin(), rec.name.cend()); + db.idxLang.push_back(idx); + + return db; +} + + +inline ZRCola::langchar_db& operator<<(_Inout_ ZRCola::langchar_db &db, _In_ const ZRCola::DBSource::langchar &rec) +{ + unsigned __int32 idx = db.data.size(); + db.data.insert(db.data.end(), reinterpret_cast(&rec.lang), reinterpret_cast(&rec.lang + 1)); + std::wstring::size_type n = rec.chr.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.chr.cbegin(), rec.chr.cend()); + db.idxChr .push_back(idx); +#ifdef ZRCOLA_LANGCHAR_LANG_IDX + db.idxLang.push_back(idx); +#endif + + return db; +} + + +inline ZRCola::chrgrp_db& operator<<(_Inout_ ZRCola::chrgrp_db &db, _In_ const ZRCola::DBSource::chrgrp &rec) +{ + unsigned __int32 idx = db.data.size(); + wxASSERT_MSG((int)0xffff8000 <= rec.grp && rec.grp <= (int)0x00007fff, wxT("character group ID out of bounds")); + db.data.push_back((unsigned __int16)rec.grp); + wxASSERT_MSG((int)0xffff8000 <= rec.rank && rec.rank <= (int)0x00007fff, wxT("character group rank out of bounds")); + db.data.push_back((unsigned __int16)rec.rank); + std::wstring::size_type n = rec.name.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character group name overflow")); + db.data.push_back((unsigned __int16)n); + n += rec.chars.size(); + wxASSERT_MSG(n <= 0xffff, wxT("character group characters overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.name .cbegin(), rec.name .cend()); + db.data.insert(db.data.end(), rec.chars.cbegin(), rec.chars.cend()); + db.data.insert(db.data.end(), rec.show .cbegin(), rec.show .cend()); + db.idxRank.push_back(idx); + + return db; +} + + +inline ZRCola::character_db& operator<<(_Inout_ ZRCola::character_db &db, _In_ const ZRCola::DBSource::character &rec) +{ + unsigned __int32 idx = db.data.size(); + db.data.insert(db.data.end(), reinterpret_cast(&rec.second.cat), reinterpret_cast(&rec.second.cat + 1)); + std::wstring::size_type n = rec.first.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); + db.data.push_back((unsigned __int16)n); + n += rec.second.desc.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character description overflow")); + db.data.push_back((unsigned __int16)n); + n += rec.second.rel.size(); + wxASSERT_MSG(n <= 0xffff, wxT("related characters overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.first .cbegin(), rec.first .cend()); + db.data.insert(db.data.end(), rec.second.desc.cbegin(), rec.second.desc.cend()); + db.data.insert(db.data.end(), rec.second.rel .cbegin(), rec.second.rel .cend()); + db.idxChr.push_back(idx); + + return db; +} + + +inline ZRCola::chrcat_db& operator<<(_Inout_ ZRCola::chrcat_db &db, _In_ const ZRCola::DBSource::chrcat &rec) +{ + unsigned __int32 idx = db.data.size(); + db.data.insert(db.data.end(), reinterpret_cast(&rec.cat), reinterpret_cast(&rec.cat + 1)); + wxASSERT_MSG((int)0xffff8000 <= rec.rank && rec.rank <= (int)0x00007fff, wxT("character category rank out of bounds")); + db.data.push_back((unsigned __int16)rec.rank); + std::wstring::size_type n = rec.name.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character category name overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.name.cbegin(), rec.name.cend()); + db.idxChrCat.push_back(idx); + db.idxRank .push_back(idx); + + return db; +} + + +inline ZRCola::chrtag_db& operator<<(_Inout_ ZRCola::chrtag_db &db, _In_ const ZRCola::DBSource::chrtag &rec) +{ + unsigned __int32 idx = db.data.size(); + wxASSERT_MSG((int)0xffff8000 <= rec.tag && rec.tag <= (int)0x00007fff, wxT("tag out of bounds")); + db.data.push_back((unsigned __int16)rec.tag); + std::wstring::size_type n = rec.chr.length(); + wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), rec.chr.cbegin(), rec.chr.cend()); + db.idxChr.push_back(idx); + db.idxTag.push_back(idx); + + return db; +} + + +inline ZRCola::tagname_db& operator<<(_Inout_ ZRCola::tagname_db &db, _In_ const ZRCola::DBSource::tagname &rec) +{ + for (auto ln = rec.names.cbegin(), ln_end = rec.names.cend(); ln != ln_end; ++ln) { + for (auto nm = ln->second.cbegin(), nm_end = ln->second.cend(); nm != nm_end; ++nm) { + unsigned __int32 idx = db.data.size(); + wxASSERT_MSG((int)0xffff8000 <= rec.tag && rec.tag <= (int)0x00007fff, wxT("tag out of bounds")); + db.data.push_back((unsigned __int16)rec.tag); + db.data.push_back(LOWORD(ln->first)); + db.data.push_back(HIWORD(ln->first)); + std::wstring::size_type n = nm->length(); + wxASSERT_MSG(n <= 0xffff, wxT("tag name overflow")); + db.data.push_back((unsigned __int16)n); + db.data.insert(db.data.end(), nm->cbegin(), nm->cend()); + db.idxName.push_back(idx); + db.idxTag .push_back(idx); + } + } + + return db; +} diff --git a/ZRColaCompile/main.cpp b/ZRColaCompile/main.cpp index 10a9e9f..eaa9948 100644 --- a/ZRColaCompile/main.cpp +++ b/ZRColaCompile/main.cpp @@ -230,25 +230,16 @@ int _tmain(int argc, _TCHAR *argv[]) db_trans.data .reserve(count*5); // Parse translations and build index and data. + ZRCola::DBSource::translation trans; + trans.set = 0; for (auto t = db_temp2.cbegin(), t_end = db_temp2.cend(); t != t_end; ++t) { // Add translation to index and data. + trans.dst.str = std::move(t->first); for (auto d = t->second.cbegin(), d_end = t->second.cend(); d != d_end; ++d) { - unsigned __int32 idx = db_trans.data.size(); - db_trans.data.push_back((unsigned __int16)0); - wxASSERT_MSG((int)0xffff8000 <= d->first && d->first <= (int)0x00007fff, wxT("destination character rank out of bounds")); - db_trans.data.push_back((unsigned __int16)d->first); - wxASSERT_MSG((int)0xffff8000 <= d->second.rank && d->second.rank <= (int)0x00007fff, wxT("source character rank out of bounds")); - db_trans.data.push_back((unsigned __int16)d->second.rank); - wstring::size_type n = t->first.length(); - wxASSERT_MSG(n <= 0xffff, wxT("destination overflow")); - db_trans.data.push_back((unsigned __int16)n); - n += d->second.str.length(); - wxASSERT_MSG(n <= 0xffff, wxT("source overflow")); - db_trans.data.push_back((unsigned __int16)n); - db_trans.data.insert(db_trans.data.end(), t->first .cbegin(), t->first .cend()); - db_trans.data.insert(db_trans.data.end(), d->second.str.cbegin(), d->second.str.cend()); - db_trans.idxSrc.push_back(idx); - db_trans.idxDst.push_back(idx); + trans.dst.rank = d->first; + trans.src.rank = d->second.rank; + trans.src.str = std::move(d->second.str); + db_trans << trans; } } } else { @@ -275,21 +266,10 @@ int _tmain(int argc, _TCHAR *argv[]) db.data .reserve(count*4); // Add (de)composing translation set to index and data. - ts.id = 0; + ts.set = 0; ts.src = L"ZRCola Decomposed"; ts.dst = L"ZRCola Composed"; - unsigned __int32 idx = db.data.size(); - wxASSERT_MSG((int)0xffff8000 <= ts.id && ts.id <= (int)0x00007fff, wxT("translation set index out of bounds")); - db.data.push_back((unsigned __int16)ts.id); - wstring::size_type n = ts.src.length(); - wxASSERT_MSG(n <= 0xffff, wxT("translation set source name overflow")); - db.data.push_back((unsigned __int16)n); - n += ts.dst.length(); - wxASSERT_MSG(n <= 0xffff, wxT("translation set destination name overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), ts.src.cbegin(), ts.src.cend()); - db.data.insert(db.data.end(), ts.dst.cbegin(), ts.dst.cend()); - db.idxTranSet.push_back(idx); + db << ts; // Parse translation sets and build index and data. for (; !ZRCola::DBSource::IsEOF(rs); rs->MoveNext()) { @@ -301,47 +281,21 @@ int _tmain(int argc, _TCHAR *argv[]) } // Add translation set to index and data. - unsigned __int32 idx = db.data.size(); - wxASSERT_MSG((int)0xffff8000 <= ts.id && ts.id <= (int)0x00007fff, wxT("translation set index out of bounds")); - db.data.push_back((unsigned __int16)ts.id); - wstring::size_type n = ts.src.length(); - wxASSERT_MSG(n <= 0xffff, wxT("translation set source name overflow")); - db.data.push_back((unsigned __int16)n); - n += ts.dst.length(); - wxASSERT_MSG(n <= 0xffff, wxT("translation set destination name overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), ts.src.cbegin(), ts.src.cend()); - db.data.insert(db.data.end(), ts.dst.cbegin(), ts.dst.cend()); - db.idxTranSet.push_back(idx); + db << ts; // Get translations. com_obj rs_tran; - if (src.SelectTranslations(ts.id, rs_tran)) { + if (src.SelectTranslations(ts.set, rs_tran)) { size_t count = src.GetRecordsetCount(rs_tran); if (count < 0xffffffff) { // 4G check (-1 is reserved for error condition) // Parse translations and build temporary database. + ZRCola::DBSource::translation trans; + trans.set = ts.set; for (; !ZRCola::DBSource::IsEOF(rs_tran); rs_tran->MoveNext()) { // Read translation from the database. - ZRCola::DBSource::translation trans; if (src.GetTranslation(rs_tran, trans)) { // Add translation to index and data. - unsigned __int32 idx = db_trans.data.size(); - wxASSERT_MSG((int)0xffff8000 <= ts.id && ts.id <= (int)0x00007fff, wxT("translation set index out of bounds")); - db_trans.data.push_back((unsigned __int16)ts.id); - wxASSERT_MSG((int)0xffff8000 <= trans.dst.rank && trans.dst.rank <= (int)0x00007fff, wxT("destination character rank out of bounds")); - db_trans.data.push_back((unsigned __int16)trans.dst.rank); - wxASSERT_MSG((int)0xffff8000 <= trans.src.rank && trans.src.rank <= (int)0x00007fff, wxT("source character rank out of bounds")); - db_trans.data.push_back((unsigned __int16)trans.src.rank); - wstring::size_type n = trans.dst.str.length(); - wxASSERT_MSG(n <= 0xffff, wxT("destination overflow")); - db_trans.data.push_back((unsigned __int16)n); - n += trans.src.str.length(); - wxASSERT_MSG(n <= 0xffff, wxT("source overflow")); - db_trans.data.push_back((unsigned __int16)n); - db_trans.data.insert(db_trans.data.end(), trans.dst.str.cbegin(), trans.dst.str.cend()); - db_trans.data.insert(db_trans.data.end(), trans.src.str.cbegin(), trans.src.str.cend()); - db_trans.idxSrc.push_back(idx); - db_trans.idxDst.push_back(idx); + db_trans << trans; } else has_errors = true; } @@ -398,23 +352,7 @@ int _tmain(int argc, _TCHAR *argv[]) // Read key sequence from the database. if (src.GetKeySequence(rs, ks)) { // Add key sequence to index and data. - unsigned __int32 idx = db.data.size(); - wstring::size_type n = ks.chr.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); - db.data.push_back((unsigned __int16)n); - n += ks.seq.size() * sizeof(ZRCola::keyseq_db::keyseq::key_t) / sizeof(wchar_t); - wxASSERT_MSG(n <= 0xffff, wxT("key sequence overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), ks.chr.cbegin(), ks.chr.cend()); - for (auto kc = ks.seq.cbegin(), kc_end = ks.seq.cend(); kc != kc_end; ++kc) { - db.data.push_back(kc->key); - db.data.push_back( - (kc->shift ? ZRCola::keyseq_db::keyseq::SHIFT : 0) | - (kc->ctrl ? ZRCola::keyseq_db::keyseq::CTRL : 0) | - (kc->alt ? ZRCola::keyseq_db::keyseq::ALT : 0)); - } - db.idxChr.push_back(idx); - db.idxKey.push_back(idx); + db << ks; } else has_errors = true; } @@ -473,13 +411,7 @@ int _tmain(int argc, _TCHAR *argv[]) pot.insert(lang.name); // Add language to index and data. - unsigned __int32 idx = db.data.size(); - db.data.insert(db.data.end(), reinterpret_cast(&lang.id), reinterpret_cast(&lang.id + 1)); - wstring::size_type n = lang.name.length(); - wxASSERT_MSG(n <= 0xffff, wxT("language name overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), lang.name.cbegin(), lang.name.cend()); - db.idxLang.push_back(idx); + db << lang; } else has_errors = true; } @@ -520,16 +452,7 @@ int _tmain(int argc, _TCHAR *argv[]) // Read language characters from the database. if (src.GetLanguageCharacter(rs, lc)) { // Add language characters to index and data. - unsigned __int32 idx = db.data.size(); - db.data.insert(db.data.end(), reinterpret_cast(&lc.lang), reinterpret_cast(&lc.lang + 1)); - wstring::size_type n = lc.chr.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), lc.chr.cbegin(), lc.chr.cend()); - db.idxChr .push_back(idx); -#ifdef ZRCOLA_LANGCHAR_LANG_IDX - db.idxLang.push_back(idx); -#endif + db << lc; } else has_errors = true; } @@ -578,21 +501,7 @@ int _tmain(int argc, _TCHAR *argv[]) } // Add character group to index and data. - unsigned __int32 idx = db.data.size(); - wxASSERT_MSG((int)0xffff8000 <= cg.id && cg.id <= (int)0x00007fff, wxT("character group ID out of bounds")); - db.data.push_back((unsigned __int16)cg.id); - wxASSERT_MSG((int)0xffff8000 <= cg.rank && cg.rank <= (int)0x00007fff, wxT("character group rank out of bounds")); - db.data.push_back((unsigned __int16)cg.rank); - wstring::size_type n = cg.name.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character group name overflow")); - db.data.push_back((unsigned __int16)n); - n += cg.chars.size(); - wxASSERT_MSG(n <= 0xffff, wxT("character group characters overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), cg.name .cbegin(), cg.name .cend()); - db.data.insert(db.data.end(), cg.chars.cbegin(), cg.chars.cend()); - db.data.insert(db.data.end(), cg.show .cbegin(), cg.show .cend()); - db.idxRank.push_back(idx); + db << cg; } else has_errors = true; } @@ -646,21 +555,7 @@ int _tmain(int argc, _TCHAR *argv[]) // Phase 3: Parse characters and build index and data. for (auto chr = chrs.cbegin(), chr_end = chrs.cend(); chr != chr_end; ++chr) { // Add character to index and data. - unsigned __int32 idx = db.data.size(); - db.data.insert(db.data.end(), reinterpret_cast(&chr->second.cat), reinterpret_cast(&chr->second.cat + 1)); - wstring::size_type n = chr->first.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); - db.data.push_back((unsigned __int16)n); - n += chr->second.desc.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character description overflow")); - db.data.push_back((unsigned __int16)n); - n += chr->second.rel.size(); - wxASSERT_MSG(n <= 0xffff, wxT("related characters overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), chr->first .cbegin(), chr->first .cend()); - db.data.insert(db.data.end(), chr->second.desc.cbegin(), chr->second.desc.cend()); - db.data.insert(db.data.end(), chr->second.rel .cbegin(), chr->second.rel .cend()); - db.idxChr.push_back(idx); + db << *chr; // Add description (and keywords) to index. idxChrDsc .add_keywords(chr->second.terms, chr->first, 0); @@ -710,22 +605,13 @@ int _tmain(int argc, _TCHAR *argv[]) if (build_pot) pot.insert(cc.name); - if (categories_used.find(cc.id) == categories_used.end()) { + if (categories_used.find(cc.cat) == categories_used.end()) { // Skip empty character categories. continue; } // Add character category to index and data. - unsigned __int32 idx = db.data.size(); - db.data.insert(db.data.end(), reinterpret_cast(&cc.id), reinterpret_cast(&cc.id + 1)); - wxASSERT_MSG((int)0xffff8000 <= cc.rank && cc.rank <= (int)0x00007fff, wxT("character category rank out of bounds")); - db.data.push_back((unsigned __int16)cc.rank); - wstring::size_type n = cc.name.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character category name overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), cc.name.cbegin(), cc.name.cend()); - db.idxChrCat.push_back(idx); - db.idxRank .push_back(idx); + db << cc; } else has_errors = true; } @@ -765,15 +651,7 @@ int _tmain(int argc, _TCHAR *argv[]) // Read characters tags from the database. if (src.GetCharacterTag(rs, ct)) { // Add characters tags to index and data. - unsigned __int32 idx = db.data.size(); - wxASSERT_MSG((int)0xffff8000 <= ct.tag && ct.tag <= (int)0x00007fff, wxT("tag out of bounds")); - db.data.push_back((unsigned __int16)ct.tag); - wstring::size_type n = ct.chr.length(); - wxASSERT_MSG(n <= 0xffff, wxT("character overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), ct.chr.cbegin(), ct.chr.cend()); - db.idxChr.push_back(idx); - db.idxTag.push_back(idx); + db << ct; } else has_errors = true; } @@ -813,21 +691,7 @@ int _tmain(int argc, _TCHAR *argv[]) // Read tag name from the database. if (src.GetTagName(rs, tn)) { // Add tag name to index and data. - for (auto ln = tn.names.cbegin(), ln_end = tn.names.cend(); ln != ln_end; ++ln) { - for (auto nm = ln->second.cbegin(), nm_end = ln->second.cend(); nm != nm_end; ++nm) { - unsigned __int32 idx = db.data.size(); - wxASSERT_MSG((int)0xffff8000 <= tn.tag && tn.tag <= (int)0x00007fff, wxT("tag out of bounds")); - db.data.push_back((unsigned __int16)tn.tag); - db.data.push_back(LOWORD(ln->first)); - db.data.push_back(HIWORD(ln->first)); - wstring::size_type n = nm->length(); - wxASSERT_MSG(n <= 0xffff, wxT("tag name overflow")); - db.data.push_back((unsigned __int16)n); - db.data.insert(db.data.end(), nm->cbegin(), nm->cend()); - db.idxName.push_back(idx); - db.idxTag .push_back(idx); - } - } + db << tn; } else has_errors = true; } diff --git a/ZRColaCompile/stdafx.h b/ZRColaCompile/stdafx.h index 773ac08..5403c87 100644 --- a/ZRColaCompile/stdafx.h +++ b/ZRColaCompile/stdafx.h @@ -22,12 +22,6 @@ #include "../include/version.h" #include "dbsource.h" -#include -#include -#include -#include -#include - #include #include #include