Code clean-up

This commit is contained in:
Simon Rozman 2016-10-13 09:01:23 +02:00
parent f51c4dbbec
commit affe7b06a2
7 changed files with 98 additions and 18 deletions

View File

@ -99,49 +99,37 @@ bool ZRColaApp::OnInit()
has_translation_data = true; has_translation_data = true;
} else { } else {
wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb."));
m_t_db.idxComp .clear(); m_t_db.clear();
m_t_db.idxDecomp.clear();
m_t_db.data .clear();
} }
} else if (id == ZRCola::langchar_rec::id) { } else if (id == ZRCola::langchar_rec::id) {
dat >> ZRCola::langchar_rec(m_lc_db); dat >> ZRCola::langchar_rec(m_lc_db);
if (!dat.good()) { if (!dat.good()) {
wxFAIL_MSG(wxT("Error reading language character data from ZRCola.zrcdb.")); wxFAIL_MSG(wxT("Error reading language character data from ZRCola.zrcdb."));
m_lc_db.idxChr.clear(); m_lc_db.clear();
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
m_lc_db.idxLng.clear();
#endif
m_lc_db.data .clear();
} }
} else if (id == ZRCola::language_rec::id) { } else if (id == ZRCola::language_rec::id) {
dat >> ZRCola::language_rec(m_lang_db); dat >> ZRCola::language_rec(m_lang_db);
if (!dat.good()) { if (!dat.good()) {
wxFAIL_MSG(wxT("Error reading language character data from ZRCola.zrcdb.")); wxFAIL_MSG(wxT("Error reading language character data from ZRCola.zrcdb."));
m_lang_db.idxLng.clear(); m_lang_db.clear();
m_lang_db.data .clear();
} }
} else if (id == ZRCola::keyseq_rec::id) { } else if (id == ZRCola::keyseq_rec::id) {
dat >> ZRCola::keyseq_rec(m_ks_db); dat >> ZRCola::keyseq_rec(m_ks_db);
if (!dat.good()) { if (!dat.good()) {
wxFAIL_MSG(wxT("Error reading key sequences data from ZRCola.zrcdb.")); wxFAIL_MSG(wxT("Error reading key sequences data from ZRCola.zrcdb."));
m_ks_db.idxChr.clear(); m_ks_db.clear();
m_ks_db.idxKey.clear();
m_ks_db.data .clear();
} }
} else if (id == ZRCola::character_rec::id) { } else if (id == ZRCola::character_rec::id) {
dat >> ZRCola::character_rec(m_chr_db); dat >> ZRCola::character_rec(m_chr_db);
if (!dat.good()) { if (!dat.good()) {
wxFAIL_MSG(wxT("Error reading character data from ZRCola.zrcdb.")); wxFAIL_MSG(wxT("Error reading character data from ZRCola.zrcdb."));
m_chr_db.idxChr.clear(); m_chr_db.clear();
m_chr_db.data .clear();
} }
} else if (id == ZRCola::chrcat_rec::id) { } else if (id == ZRCola::chrcat_rec::id) {
dat >> ZRCola::chrcat_rec(m_cc_db); dat >> ZRCola::chrcat_rec(m_cc_db);
if (!dat.good()) { if (!dat.good()) {
wxFAIL_MSG(wxT("Error reading character category data from ZRCola.zrcdb.")); wxFAIL_MSG(wxT("Error reading character category data from ZRCola.zrcdb."));
m_cc_db.idxChrCat.clear(); m_cc_db.clear();
m_cc_db.idxRnk .clear();
m_cc_db.data .clear();
} }
} else } else
stdex::idrec::ignore<ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dat); stdex::idrec::ignore<ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dat);

View File

@ -231,6 +231,17 @@ namespace ZRCola {
/// ///
inline character_db() : idxChr(data) {} inline character_db() : idxChr(data) {}
///
/// Clears the database
///
inline void clear()
{
idxChr .clear();
idxDsc .clear();
idxDscSub.clear();
data .clear();
}
/// ///
/// Search for characters by description in given categories /// Search for characters by description in given categories
/// ///
@ -379,6 +390,16 @@ namespace ZRCola {
/// Constructs the database /// Constructs the database
/// ///
inline chrcat_db() : idxChrCat(data), idxRnk(data) {} inline chrcat_db() : idxChrCat(data), idxRnk(data) {}
///
/// Clears the database
///
inline void clear()
{
idxChrCat.clear();
idxRnk .clear();
data .clear();
}
}; };

View File

@ -439,6 +439,17 @@ namespace ZRCola {
textindex() {} textindex() {}
///
/// Clears the index
///
inline void clear()
{
std::vector< mappair_t<T_idx> >::clear();
keys .clear();
values.clear();
}
/// ///
/// Finds data for given key /// Finds data for given key
/// ///

View File

@ -175,6 +175,18 @@ namespace ZRCola {
#endif #endif
{} {}
///
/// Clears the database
///
inline void clear()
{
idxChr.clear();
#ifdef ZRCOLA_LANGCHAR_LANG_IDX
idxLng.clear();
#endif
data .clear();
}
/// ///
/// Tests presence of character in the given language /// Tests presence of character in the given language
/// ///
@ -248,6 +260,15 @@ namespace ZRCola {
/// Constructs the database /// Constructs the database
/// ///
inline language_db() : idxLng(data) {} inline language_db() : idxLng(data) {}
///
/// Clears the database
///
inline void clear()
{
idxLng.clear();
data .clear();
}
}; };

View File

@ -170,6 +170,16 @@ namespace ZRCola {
/// Constructs the database /// Constructs the database
/// ///
inline chrtag_db() : idxChr(data), idxTag(data) {} inline chrtag_db() : idxChr(data), idxTag(data) {}
///
/// Clears the database
///
inline void clear()
{
idxChr.clear();
idxTag.clear();
data .clear();
}
}; };
@ -292,6 +302,15 @@ namespace ZRCola {
/// ///
inline tagname_db() : idxName(data) {} inline tagname_db() : idxName(data) {}
///
/// Clears the database
///
inline void clear()
{
idxName.clear();
data .clear();
}
/// ///
/// Search for tags by names /// Search for tags by names
/// ///

View File

@ -204,6 +204,16 @@ namespace ZRCola {
/// ///
inline translation_db() : idxComp(data), idxDecomp(data) {} inline translation_db() : idxComp(data), idxDecomp(data) {}
///
/// Clears the database
///
inline void clear()
{
idxComp .clear();
idxDecomp.clear();
data .clear();
}
/// ///
/// Composes string /// Composes string
/// ///

View File

@ -209,6 +209,16 @@ namespace ZRCola {
/// ///
inline keyseq_db() : idxChr(data), idxKey(data) {} inline keyseq_db() : idxChr(data), idxKey(data) {}
///
/// Clears the database
///
inline void clear()
{
idxChr.clear();
idxKey.clear();
data .clear();
}
/// ///
/// Get text representation of a given key sequence /// Get text representation of a given key sequence
/// ///