From affe7b06a2867eb062afb9c922abd7d23a957be5 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 13 Oct 2016 09:01:23 +0200 Subject: [PATCH] Code clean-up --- ZRCola/zrcolaapp.cpp | 24 ++++++--------------- lib/libZRCola/include/zrcola/character.h | 21 ++++++++++++++++++ lib/libZRCola/include/zrcola/common.h | 11 ++++++++++ lib/libZRCola/include/zrcola/language.h | 21 ++++++++++++++++++ lib/libZRCola/include/zrcola/tag.h | 19 ++++++++++++++++ lib/libZRCola/include/zrcola/translate.h | 10 +++++++++ lib/libZRColaUI/include/zrcolaui/keyboard.h | 10 +++++++++ 7 files changed, 98 insertions(+), 18 deletions(-) diff --git a/ZRCola/zrcolaapp.cpp b/ZRCola/zrcolaapp.cpp index 9537272..5926849 100644 --- a/ZRCola/zrcolaapp.cpp +++ b/ZRCola/zrcolaapp.cpp @@ -99,49 +99,37 @@ bool ZRColaApp::OnInit() has_translation_data = true; } else { wxFAIL_MSG(wxT("Error reading translation data from ZRCola.zrcdb.")); - m_t_db.idxComp .clear(); - m_t_db.idxDecomp.clear(); - m_t_db.data .clear(); + m_t_db.clear(); } } else if (id == ZRCola::langchar_rec::id) { dat >> ZRCola::langchar_rec(m_lc_db); if (!dat.good()) { wxFAIL_MSG(wxT("Error reading language character data from ZRCola.zrcdb.")); - m_lc_db.idxChr.clear(); -#ifdef ZRCOLA_LANGCHAR_LANG_IDX - m_lc_db.idxLng.clear(); -#endif - m_lc_db.data .clear(); + m_lc_db.clear(); } } else if (id == ZRCola::language_rec::id) { dat >> ZRCola::language_rec(m_lang_db); if (!dat.good()) { wxFAIL_MSG(wxT("Error reading language character data from ZRCola.zrcdb.")); - m_lang_db.idxLng.clear(); - m_lang_db.data .clear(); + m_lang_db.clear(); } } else if (id == ZRCola::keyseq_rec::id) { dat >> ZRCola::keyseq_rec(m_ks_db); if (!dat.good()) { wxFAIL_MSG(wxT("Error reading key sequences data from ZRCola.zrcdb.")); - m_ks_db.idxChr.clear(); - m_ks_db.idxKey.clear(); - m_ks_db.data .clear(); + m_ks_db.clear(); } } else if (id == ZRCola::character_rec::id) { dat >> ZRCola::character_rec(m_chr_db); if (!dat.good()) { wxFAIL_MSG(wxT("Error reading character data from ZRCola.zrcdb.")); - m_chr_db.idxChr.clear(); - m_chr_db.data .clear(); + m_chr_db.clear(); } } else if (id == ZRCola::chrcat_rec::id) { dat >> ZRCola::chrcat_rec(m_cc_db); if (!dat.good()) { wxFAIL_MSG(wxT("Error reading character category data from ZRCola.zrcdb.")); - m_cc_db.idxChrCat.clear(); - m_cc_db.idxRnk .clear(); - m_cc_db.data .clear(); + m_cc_db.clear(); } } else stdex::idrec::ignore(dat); diff --git a/lib/libZRCola/include/zrcola/character.h b/lib/libZRCola/include/zrcola/character.h index 13ea23a..1c7fe75 100644 --- a/lib/libZRCola/include/zrcola/character.h +++ b/lib/libZRCola/include/zrcola/character.h @@ -231,6 +231,17 @@ namespace ZRCola { /// 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 /// @@ -379,6 +390,16 @@ namespace ZRCola { /// Constructs the database /// inline chrcat_db() : idxChrCat(data), idxRnk(data) {} + + /// + /// Clears the database + /// + inline void clear() + { + idxChrCat.clear(); + idxRnk .clear(); + data .clear(); + } }; diff --git a/lib/libZRCola/include/zrcola/common.h b/lib/libZRCola/include/zrcola/common.h index d2cc876..3816c1f 100644 --- a/lib/libZRCola/include/zrcola/common.h +++ b/lib/libZRCola/include/zrcola/common.h @@ -439,6 +439,17 @@ namespace ZRCola { textindex() {} + /// + /// Clears the index + /// + inline void clear() + { + std::vector< mappair_t >::clear(); + keys .clear(); + values.clear(); + } + + /// /// Finds data for given key /// diff --git a/lib/libZRCola/include/zrcola/language.h b/lib/libZRCola/include/zrcola/language.h index 22d7c84..5a15576 100644 --- a/lib/libZRCola/include/zrcola/language.h +++ b/lib/libZRCola/include/zrcola/language.h @@ -175,6 +175,18 @@ namespace ZRCola { #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 /// @@ -248,6 +260,15 @@ namespace ZRCola { /// Constructs the database /// inline language_db() : idxLng(data) {} + + /// + /// Clears the database + /// + inline void clear() + { + idxLng.clear(); + data .clear(); + } }; diff --git a/lib/libZRCola/include/zrcola/tag.h b/lib/libZRCola/include/zrcola/tag.h index ef46de4..b9d556d 100644 --- a/lib/libZRCola/include/zrcola/tag.h +++ b/lib/libZRCola/include/zrcola/tag.h @@ -170,6 +170,16 @@ namespace ZRCola { /// Constructs the database /// 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) {} + /// + /// Clears the database + /// + inline void clear() + { + idxName.clear(); + data .clear(); + } + /// /// Search for tags by names /// diff --git a/lib/libZRCola/include/zrcola/translate.h b/lib/libZRCola/include/zrcola/translate.h index 6824a5c..d7174b4 100644 --- a/lib/libZRCola/include/zrcola/translate.h +++ b/lib/libZRCola/include/zrcola/translate.h @@ -204,6 +204,16 @@ namespace ZRCola { /// inline translation_db() : idxComp(data), idxDecomp(data) {} + /// + /// Clears the database + /// + inline void clear() + { + idxComp .clear(); + idxDecomp.clear(); + data .clear(); + } + /// /// Composes string /// diff --git a/lib/libZRColaUI/include/zrcolaui/keyboard.h b/lib/libZRColaUI/include/zrcolaui/keyboard.h index 620bae3..428bb71 100644 --- a/lib/libZRColaUI/include/zrcolaui/keyboard.h +++ b/lib/libZRColaUI/include/zrcolaui/keyboard.h @@ -209,6 +209,16 @@ namespace ZRCola { /// 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 ///