From 98f764e4acba396297a4776bb1d6293c5e3e5e9c Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 28 May 2015 15:23:41 +0800 Subject: update API --- src/include/novel_types.h | 5 --- src/libpinyin.ver | 2 ++ src/pinyin.cpp | 78 +++++++++++++++++++++++------------------------ src/pinyin.h | 28 ++++++++++++++--- src/storage/table_info.h | 5 +++ 5 files changed, 69 insertions(+), 49 deletions(-) diff --git a/src/include/novel_types.h b/src/include/novel_types.h index 8005ed0..7c545be 100644 --- a/src/include/novel_types.h +++ b/src/include/novel_types.h @@ -142,11 +142,6 @@ typedef GArray * CandidateConstraints; typedef guint32 pinyin_option_t; -typedef enum { - DEFAULT_TABLE, - ADDON_TABLE, -} TABLE_TARGET; - typedef enum { /* for default tables. */ RESERVED = 0, diff --git a/src/libpinyin.ver b/src/libpinyin.ver index a7b5073..40cd154 100644 --- a/src/libpinyin.ver +++ b/src/libpinyin.ver @@ -6,6 +6,8 @@ LIBPINYIN { pinyin_set_chewing_scheme; pinyin_load_phrase_library; pinyin_unload_phrase_library; + pinyin_load_addon_phrase_library; + pinyin_unload_addon_phrase_library; pinyin_begin_add_phrases; pinyin_iterator_add_phrase; pinyin_end_add_phrases; diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 1ddc9ce..e7da8db 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -474,62 +474,60 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir){ } bool pinyin_load_phrase_library(pinyin_context_t * context, - TABLE_TARGET target, guint8 index){ if (!(index < PHRASE_INDEX_LIBRARY_COUNT)) return false; - const pinyin_table_info_t * phrase_files = NULL; - FacadePhraseIndex * phrase_index = NULL; - const pinyin_table_info_t * table_info = NULL; - - if (DEFAULT_TABLE == target) { - phrase_files = context->m_system_table_info.get_default_tables(); - phrase_index = context->m_phrase_index; - table_info = phrase_files + index; - - /* Only SYSTEM_FILE or USER_FILE is allowed here. */ - assert(SYSTEM_FILE == table_info->m_file_type - || USER_FILE == table_info->m_file_type); - } - - if (ADDON_TABLE == target) { - phrase_files = context->m_system_table_info.get_addon_tables(); - phrase_index = context->m_addon_phrase_index; - table_info = phrase_files + index; - - /* Only DICTIONARY is allowed here. */ - assert(DICTIONARY == table_info->m_file_type); - } + const pinyin_table_info_t * phrase_files = + context->m_system_table_info.get_default_tables(); + FacadePhraseIndex * phrase_index = context->m_phrase_index; + const pinyin_table_info_t * table_info = phrase_files + index; - _load_phrase_library(context->m_system_dir, context->m_user_dir, - phrase_index, table_info); + /* Only SYSTEM_FILE or USER_FILE is allowed here. */ + assert(SYSTEM_FILE == table_info->m_file_type + || USER_FILE == table_info->m_file_type); - return false; + return _load_phrase_library(context->m_system_dir, context->m_user_dir, + phrase_index, table_info); } bool pinyin_unload_phrase_library(pinyin_context_t * context, - TABLE_TARGET target, guint8 index){ assert(index < PHRASE_INDEX_LIBRARY_COUNT); /* default table. */ - if (DEFAULT_TABLE == target) { - /* only GBK table can be unloaded. */ - if (GBK_DICTIONARY != index) - return false; + /* only GBK table can be unloaded. */ + if (GBK_DICTIONARY != index) + return false; - context->m_phrase_index->unload(index); - return true; - } + context->m_phrase_index->unload(index); + return true; +} - /* addon table. */ - if (ADDON_TABLE == target) { - context->m_addon_phrase_index->unload(index); - return true; - } +bool pinyin_load_addon_phrase_library(pinyin_context_t * context, + guint8 index){ + if (!(index < PHRASE_INDEX_LIBRARY_COUNT)) + return false; - return false; + const pinyin_table_info_t * phrase_files = + context->m_system_table_info.get_addon_tables(); + FacadePhraseIndex * phrase_index = context->m_addon_phrase_index; + const pinyin_table_info_t * table_info = phrase_files + index; + + /* Only DICTIONARY is allowed here. */ + assert(DICTIONARY == table_info->m_file_type); + + return _load_phrase_library(context->m_system_dir, context->m_user_dir, + phrase_index, table_info); +} + +bool pinyin_unload_addon_phrase_library(pinyin_context_t * context, + guint8 index){ + assert(index < PHRASE_INDEX_LIBRARY_COUNT); + + /* addon table. */ + context->m_addon_phrase_index->unload(index); + return true; } import_iterator_t * pinyin_begin_add_phrases(pinyin_context_t * context, diff --git a/src/pinyin.h b/src/pinyin.h index 12915ee..adb2bb8 100644 --- a/src/pinyin.h +++ b/src/pinyin.h @@ -64,7 +64,6 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir); /** * pinyin_load_phrase_library: * @context: the pinyin context. - * @target: the table target. * @index: the phrase index to be loaded. * @returns: whether the load succeeded. * @@ -72,13 +71,11 @@ pinyin_context_t * pinyin_init(const char * systemdir, const char * userdir); * */ bool pinyin_load_phrase_library(pinyin_context_t * context, - TABLE_TARGET target, guint8 index); /** * pinyin_unload_phrase_library: * @context: the pinyin context. - * @target: the table target. * @index: the phrase index to be unloaded. * @returns: whether the unload succeeded. * @@ -86,9 +83,32 @@ bool pinyin_load_phrase_library(pinyin_context_t * context, * */ bool pinyin_unload_phrase_library(pinyin_context_t * context, - TABLE_TARGET target, guint8 index); +/** + * pinyin_load_addon_phrase_library: + * @context: the pinyin context. + * @index: the addon phrase index to be loaded. + * @returns: whether the load succeeded. + * + * Load the addon sub phrase library of the index. + * + */ +bool pinyin_load_addon_phrase_library(pinyin_context_t * context, + guint8 index); + +/** + * pinyin_unload_addon_phrase_library: + * @context: the pinyin context. + * @index: the addon phrase index to be unloaded. + * @returns: whether the unload succeeded. + * + * Unload the addon sub phrase library of the index. + * + */ +bool pinyin_unload_addon_phrase_library(pinyin_context_t * context, + guint8 index); + /** * pinyin_begin_add_phrases: * @context: the pinyin context. diff --git a/src/storage/table_info.h b/src/storage/table_info.h index 02245f1..467e754 100644 --- a/src/storage/table_info.h +++ b/src/storage/table_info.h @@ -32,6 +32,11 @@ typedef enum { ZHUYIN_TABLE, /* use zhuyin. */ } TABLE_PHONETIC_TYPE; +typedef enum { + DEFAULT_TABLE, + ADDON_TABLE, +} TABLE_TARGET; + typedef enum { NOT_USED, /* not used. */ SYSTEM_FILE, /* system phrase file. */ -- cgit