diff options
author | Peng Wu <alexepico@gmail.com> | 2016-03-14 13:48:07 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2016-03-14 13:48:07 +0800 |
commit | c8068ec8520d3ab1f34b7e55c9238827d8d56a68 (patch) | |
tree | eef9153298aa2278ba7e18532f5c095483c4fd50 /src/storage | |
parent | 312eb6bb3212ed3aceef1daaadfe3e7d5554c95a (diff) | |
download | libpinyin-c8068ec8520d3ab1f34b7e55c9238827d8d56a68.tar.gz libpinyin-c8068ec8520d3ab1f34b7e55c9238827d8d56a68.tar.xz libpinyin-c8068ec8520d3ab1f34b7e55c9238827d8d56a68.zip |
re-factor code
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/chewing_large_table2.cpp | 84 | ||||
-rw-r--r-- | src/storage/chewing_large_table2_bdb.cpp | 84 | ||||
-rw-r--r-- | src/storage/chewing_large_table2_kyotodb.h | 4 |
3 files changed, 88 insertions, 84 deletions
diff --git a/src/storage/chewing_large_table2.cpp b/src/storage/chewing_large_table2.cpp index 2376a5c..7f49772 100644 --- a/src/storage/chewing_large_table2.cpp +++ b/src/storage/chewing_large_table2.cpp @@ -23,6 +23,90 @@ #include "pinyin_parser2.h" +void ChewingLargeTable2::init_entries() { + assert(NULL == m_entries); + + m_entries = g_ptr_array_new(); + /* NULL for the first pointer. */ + g_ptr_array_set_size(m_entries, MAX_PHRASE_LENGTH + 1); + +#define CASE(len) case len: \ + { \ + ChewingTableEntry<len> * entry = \ + new ChewingTableEntry<len>; \ + g_ptr_array_index(m_entries, len) = entry; \ + } + + for (size_t i = 1; i < m_entries->len; i++) { + switch(i) { + CASE(1); + CASE(2); + CASE(3); + CASE(4); + CASE(5); + CASE(6); + CASE(7); + CASE(8); + CASE(9); + CASE(10); + CASE(11); + CASE(12); + CASE(13); + CASE(14); + CASE(15); + CASE(16); + default: + assert(false); + } + } + +#undef CASE +} + +void ChewingLargeTable2::fini_entries() { + assert(NULL != m_entries); + + assert(MAX_PHRASE_LENGTH + 1 == m_entries->len); + + for (size_t i = 1; i < m_entries->len; i++) { + +#define CASE(len) case len: \ + { \ + ChewingTableEntry<len> * entry = \ + (ChewingTableEntry<len> *) \ + g_ptr_array_index(m_entries, len); \ + delete entry; \ + } + + switch(i) { + CASE(1); + CASE(2); + CASE(3); + CASE(4); + CASE(5); + CASE(6); + CASE(7); + CASE(8); + CASE(9); + CASE(10); + CASE(11); + CASE(12); + CASE(13); + CASE(14); + CASE(15); + CASE(16); + default: + assert(false); + } + +#undef CASE + + } + + g_ptr_array_free(m_entries, TRUE); + m_entries = NULL; +} + /* load text method */ bool ChewingLargeTable2::load_text(FILE * infile) { char pinyin[256]; diff --git a/src/storage/chewing_large_table2_bdb.cpp b/src/storage/chewing_large_table2_bdb.cpp index 8bd47f3..2ecfced 100644 --- a/src/storage/chewing_large_table2_bdb.cpp +++ b/src/storage/chewing_large_table2_bdb.cpp @@ -39,90 +39,6 @@ ChewingLargeTable2::ChewingLargeTable2() { init_entries(); } -void ChewingLargeTable2::init_entries() { - assert(NULL == m_entries); - - m_entries = g_ptr_array_new(); - /* NULL for the first pointer. */ - g_ptr_array_set_size(m_entries, MAX_PHRASE_LENGTH + 1); - -#define CASE(len) case len: \ - { \ - ChewingTableEntry<len> * entry = \ - new ChewingTableEntry<len>; \ - g_ptr_array_index(m_entries, len) = entry; \ - } - - for (size_t i = 1; i < m_entries->len; i++) { - switch(i) { - CASE(1); - CASE(2); - CASE(3); - CASE(4); - CASE(5); - CASE(6); - CASE(7); - CASE(8); - CASE(9); - CASE(10); - CASE(11); - CASE(12); - CASE(13); - CASE(14); - CASE(15); - CASE(16); - default: - assert(false); - } - } - -#undef CASE -} - -void ChewingLargeTable2::fini_entries() { - assert(NULL != m_entries); - - assert(MAX_PHRASE_LENGTH + 1 == m_entries->len); - - for (size_t i = 1; i < m_entries->len; i++) { - -#define CASE(len) case len: \ - { \ - ChewingTableEntry<len> * entry = \ - (ChewingTableEntry<len> *) \ - g_ptr_array_index(m_entries, len); \ - delete entry; \ - } - - switch(i) { - CASE(1); - CASE(2); - CASE(3); - CASE(4); - CASE(5); - CASE(6); - CASE(7); - CASE(8); - CASE(9); - CASE(10); - CASE(11); - CASE(12); - CASE(13); - CASE(14); - CASE(15); - CASE(16); - default: - assert(false); - } - -#undef CASE - - } - - g_ptr_array_free(m_entries, TRUE); - m_entries = NULL; -} - void ChewingLargeTable2::reset() { if (m_db) { m_db->sync(m_db, 0); diff --git a/src/storage/chewing_large_table2_kyotodb.h b/src/storage/chewing_large_table2_kyotodb.h index 49b5dbe..fbc7b2f 100644 --- a/src/storage/chewing_large_table2_kyotodb.h +++ b/src/storage/chewing_large_table2_kyotodb.h @@ -41,6 +41,10 @@ protected: /* Array of ChewingTableEntry. */ GPtrArray * m_entries; + void init_entries(); + + void fini_entries(); + void reset(); public: |