diff options
| author | Peng Wu <alexepico@gmail.com> | 2016-05-09 15:57:29 +0800 |
|---|---|---|
| committer | Peng Wu <alexepico@gmail.com> | 2016-05-09 15:57:29 +0800 |
| commit | 1b6ef8cab2bf04c1e29c212f31af8781cf3eb38e (patch) | |
| tree | 6a1fe12b33ddc4895271811d0f8f5d3199edce6b /src | |
| parent | bb539e9cbdc4d5fe951c3ee5c7dc1d8c71f00f77 (diff) | |
write class PhoneticTable
Diffstat (limited to 'src')
| -rw-r--r-- | src/storage/phonetic_key_matrix.h | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/storage/phonetic_key_matrix.h b/src/storage/phonetic_key_matrix.h index f2ff3d2..559c5d4 100644 --- a/src/storage/phonetic_key_matrix.h +++ b/src/storage/phonetic_key_matrix.h @@ -31,16 +31,49 @@ protected: GPtrArray * m_table_content; public: - bool clear_all(); + bool clear_all() { + for (size_t i = 0; i < m_table_content->len; ++i) { + GArray * column = g_ptr_array_index(m_table_content, i); + g_array_free(column, TRUE); + } + + g_ptr_array_set_size(m_table_content, 0); + return true; + } /* when call this function, reserve one extra slot for the end slot. */ - bool set_size(size_t size); + bool set_size(size_t size) { + clear_all(); + + g_ptr_array_set_size(m_table_content, size); + for (size_t i = 0; i < m_table_content->len; ++i) { + g_ptr_array_index(m_table_content, i) = + g_array_new(TRUE, TRUE, sizeof(Item)); + } + + return true; + } /* Array of Item. */ - bool get_items(size_t index, GArray * items); + bool get_items(size_t index, GArray * items) { + g_array_set_size(items, 0); + + if (index >= m_table_content->len) + return false; + + GArray * column = g_ptr_array_index(m_table_content, index); + g_array_append_vals(items, column->data, column->len); + return true; + } + + bool append(size_t index, Item item) { + if (index >= m_table_content->len) + return false; - bool append(size_t index, Item item); + GArray * column = g_ptr_array_index(m_table_content, index); + g_array_append_val(column, item); + } }; @@ -56,7 +89,7 @@ public: bool set_size(size_t size); /* Array of keys and key rests. */ - bool get_column(size_t index, GArray * keys, GArray * key_rests); + bool get_items(size_t index, GArray * keys, GArray * key_rests); bool append(size_t index, ChewingKey & key, ChewingKeyRest & key_rest); |
