diff options
author | Hiroshi Sumita <hsumita@chromium.org> | 2012-05-18 13:28:51 +0900 |
---|---|---|
committer | Hiroshi Sumita <hsumita@chromium.org> | 2012-05-18 13:28:51 +0900 |
commit | b4ab63adc086ec7e963ed2960f3b66e7a5782f46 (patch) | |
tree | 70e943d631c829fdf52d8eabd31b6c79ea01503d | |
parent | 9d37a22f7e337b0c191296afe24b324d7ff9766c (diff) | |
download | pyzy-b4ab63adc086ec7e963ed2960f3b66e7a5782f46.tar.gz |
Refactors Config.
BUG=None
TEST=Manual
Review URL: https://codereview.appspot.com/6202056
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/Makefile.am | 15 | ||||
-rw-r--r-- | src/PyZyBopomofoContext.cc | 50 | ||||
-rw-r--r-- | src/PyZyBopomofoContext.h | 13 | ||||
-rw-r--r-- | src/PyZyConfig.cc | 209 | ||||
-rw-r--r-- | src/PyZyConfig.h | 120 | ||||
-rw-r--r-- | src/PyZyConst.h | 79 | ||||
-rw-r--r-- | src/PyZyDoublePinyinContext.cc | 66 | ||||
-rw-r--r-- | src/PyZyDoublePinyinContext.h | 8 | ||||
-rw-r--r-- | src/PyZyFullPinyinContext.cc | 17 | ||||
-rw-r--r-- | src/PyZyFullPinyinContext.h | 4 | ||||
-rw-r--r-- | src/PyZyInputContext.cc | 8 | ||||
-rw-r--r-- | src/PyZyInputContext.h | 20 | ||||
-rw-r--r-- | src/PyZyPhoneticContext.cc | 55 | ||||
-rw-r--r-- | src/PyZyPhoneticContext.h | 51 | ||||
-rw-r--r-- | src/PyZyPhraseEditor.cc | 16 | ||||
-rw-r--r-- | src/PyZyPhraseEditor.h | 8 | ||||
-rw-r--r-- | src/PyZyPinyinContext.cc | 6 | ||||
-rw-r--r-- | src/PyZyPinyinContext.h | 2 | ||||
-rw-r--r-- | src/PyZyVariant.cc | 68 | ||||
-rw-r--r-- | src/PyZyVariant.h | 55 |
21 files changed, 462 insertions, 410 deletions
diff --git a/configure.ac b/configure.ac index fd8cda3..12a1f43 100644 --- a/configure.ac +++ b/configure.ac @@ -24,7 +24,7 @@ m4_define([pyzy_released], [1]) m4_define([pyzy_major_version], [0]) m4_define([pyzy_minor_version], [0]) -m4_define([pyzy_micro_version], [4]) +m4_define([pyzy_micro_version], [5]) m4_define([pyzy_interface_age], [0]) m4_define([pyzy_binary_age], [m4_eval(100 * pyzy_minor_version + pyzy_micro_version)]) diff --git a/src/Makefile.am b/src/Makefile.am index d3dda12..29d5860 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,8 +37,9 @@ libpyzy=libpyzy-1.0.la libpyzyincludedir = $(includedir)/pyzy-@PYZY_API_VERSION@ libpyzyinclude_HEADERS = \ + PyZyConst.h \ PyZyInputContext.h \ - PyZyConfig.h \ + PyZyVariant.h \ $(NULL) lib_LTLIBRARIES = $(libpyzy) @@ -51,30 +52,32 @@ libpyzy_built_h_sources = \ PyZySimpTradConverterTable.h \ $(NULL) libpyzy_c_sources = \ - PyZyInputContext.cc \ PyZyBopomofoContext.cc \ - PyZyConfig.cc \ PyZyDatabase.cc \ PyZyDoublePinyinContext.cc \ + PyZyDynamicSpecialPhrase.cc \ PyZyFullPinyinContext.cc \ + PyZyInputContext.cc \ PyZyPhoneticContext.cc \ PyZyPhraseEditor.cc \ PyZyPinyinContext.cc \ PyZyPinyinParser.cc \ PyZySimpTradConverter.cc \ - PyZyDynamicSpecialPhrase.cc \ PyZySpecialPhraseTable.cc \ + PyZyVariant.cc \ $(NULL) # PyZyTest.cc libpyzy_h_sources = \ - PyZyInputContext.h \ PyZyBopomofo.h \ PyZyBopomofoContext.h \ PyZyConfig.h \ + PyZyConst.h \ PyZyDatabase.h \ PyZyDoublePinyinContext.h \ PyZyDoublePinyinTable.h \ + PyZyDynamicSpecialPhrase.h \ PyZyFullPinyinContext.h \ + PyZyInputContext.h \ PyZyPhoneticContext.h \ PyZyPhrase.h \ PyZyPhraseArray.h \ @@ -84,11 +87,11 @@ libpyzy_h_sources = \ PyZyPinyinParser.h \ PyZySimpTradConverter.h \ PyZySpecialPhrase.h \ - PyZyDynamicSpecialPhrase.h \ PyZySpecialPhraseTable.h \ PyZyString.h \ PyZyTypes.h \ PyZyUtil.h \ + PyZyVariant.h \ $(NULL) libpyzy_1_0_la_SOURCES = \ diff --git a/src/PyZyBopomofoContext.cc b/src/PyZyBopomofoContext.cc index da456d0..e561a66 100644 --- a/src/PyZyBopomofoContext.cc +++ b/src/PyZyBopomofoContext.cc @@ -40,8 +40,9 @@ const static char * bopomofo_select_keys[] = { "qweasdzxcr" }; -BopomofoContext::BopomofoContext (Config & config, PhoneticContext::Observer *observer) - : PhoneticContext (config, observer) +BopomofoContext::BopomofoContext (PhoneticContext::Observer *observer) + : PhoneticContext (observer), + m_bopomofo_schema (BOPOMOFO_KEYBOARD_STANDARD) { } @@ -62,7 +63,7 @@ BopomofoContext::insert (char ch) m_text.insert (m_cursor++, ch); - if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) { + if (G_UNLIKELY (!(m_config.option & PINYIN_INCOMPLETE_PINYIN))) { updateSpecialPhrases (); updatePinyin (); } @@ -247,11 +248,12 @@ BopomofoContext::updatePinyin (void) bopomofo += bopomofo_char[keyvalToBopomofo (*i)]; } - m_pinyin_len = PinyinParser::parseBopomofo (bopomofo, // bopomofo - m_cursor, // text length - m_config.option (), // option - m_pinyin, // result - MAX_PHRASE_LEN); // max result length + m_pinyin_len = PinyinParser::parseBopomofo ( + bopomofo, // bopomofo + m_cursor, // text length + m_config.option, // option + m_pinyin, // result + MAX_PHRASE_LEN); // max result length } updatePhraseEditor (); @@ -396,7 +398,7 @@ BopomofoContext::updatePreeditText (void) const Phrase & candidate = m_phrase_editor.candidate (index - m_special_phrases.size ()); if (m_text.size () == m_cursor) { /* cursor at end */ - if (m_config.modeSimp ()) + if (m_config.modeSimp) m_buffer << candidate; else SimpTradConverter::simpToTrad (candidate, m_buffer); @@ -434,6 +436,34 @@ BopomofoContext::updatePreeditText (void) PhoneticContext::updatePreeditText (); } +Variant +BopomofoContext::getProperty (PropertyName name) const +{ + if (name == PROPERTY_BOPOMOFO_SCHEMA) { + return Variant::fromUnsignedInt(m_bopomofo_schema); + } + return PhoneticContext::getProperty (name); +} + +bool +BopomofoContext::setProperty (PropertyName name, const Variant &variant) +{ + if (name == PROPERTY_BOPOMOFO_SCHEMA) { + if (variant.getType () != Variant::TYPE_UNSIGNED_INT) { + return false; + } + const unsigned int schema = variant.getUnsignedInt (); + if (schema >= BOPOMOFO_KEYBOARD_LAST) { + return false; + } + + m_bopomofo_schema = schema; + return true; + } + + return PhoneticContext::setProperty (name, variant); +} + static int keyboard_cmp (const void * p1, const void * p2) { @@ -445,7 +475,7 @@ keyboard_cmp (const void * p1, const void * p2) int BopomofoContext::keyvalToBopomofo(int ch) { - const unsigned int keyboard = m_config.bopomofoKeyboardMapping (); + const unsigned int keyboard = m_bopomofo_schema; const unsigned char *brs; brs = (const unsigned char *) std::bsearch (GINT_TO_POINTER (ch), bopomofo_keyboard[keyboard], diff --git a/src/PyZyBopomofoContext.h b/src/PyZyBopomofoContext.h index 1394cae..e329375 100644 --- a/src/PyZyBopomofoContext.h +++ b/src/PyZyBopomofoContext.h @@ -27,12 +27,10 @@ namespace PyZy { -class Config; - class BopomofoContext : public PhoneticContext { public: - BopomofoContext (Config & config, PhoneticContext::Observer *observer); + explicit BopomofoContext (PhoneticContext::Observer *observer); virtual ~BopomofoContext (void); /* API of InputContext */ @@ -51,13 +49,20 @@ public: virtual bool moveCursorToBegin (void); virtual bool moveCursorToEnd (void); + virtual Variant getProperty (PropertyName name) const; + virtual bool setProperty (PropertyName name, const Variant &variant); + protected: virtual void updateAuxiliaryText (); virtual void updatePinyin (); virtual void updatePreeditText (); - bool processBopomofo (unsigned int keyval, unsigned int keycode, unsigned int modifiers); + bool processBopomofo ( + unsigned int keyval, unsigned int keycode, unsigned int modifiers); int keyvalToBopomofo(int ch); + +private: + unsigned int m_bopomofo_schema; }; }; diff --git a/src/PyZyConfig.cc b/src/PyZyConfig.cc deleted file mode 100644 index d0180bb..0000000 --- a/src/PyZyConfig.cc +++ /dev/null @@ -1,209 +0,0 @@ -/* vim:set et ts=4 sts=4: - * - * libpyzy - The Chinese PinYin and Bopomofo conversion library. - * - * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> - * - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#include "PyZyConfig.h" - -#include "PyZyUtil.h" -#include "PyZyDoublePinyinTable.h" - -namespace PyZy { - -const unsigned int PINYIN_DEFAULT_OPTION = - PINYIN_INCOMPLETE_PINYIN | - PINYIN_CORRECT_ALL | - PINYIN_FUZZY_C_CH | - // PINYIN_FUZZY_CH_C | - PINYIN_FUZZY_Z_ZH | - // PINYIN_FUZZY_ZH_Z | - PINYIN_FUZZY_S_SH | - // PINYIN_FUZZY_SH_S | - PINYIN_FUZZY_L_N | - // PINYIN_FUZZY_N_L | - PINYIN_FUZZY_F_H | - // PINYIN_FUZZY_H_F | - // PINYIN_FUZZY_L_R | - // PINYIN_FUZZY_R_L | - PINYIN_FUZZY_K_G | - PINYIN_FUZZY_G_K | - PINYIN_FUZZY_AN_ANG | - PINYIN_FUZZY_ANG_AN | - PINYIN_FUZZY_EN_ENG | - PINYIN_FUZZY_ENG_EN | - PINYIN_FUZZY_IN_ING | - PINYIN_FUZZY_ING_IN | - // PINYIN_FUZZY_IAN_IANG | - // PINYIN_FUZZY_IANG_IAN | - // PINYIN_FUZZY_UAN_UANG | - // PINYIN_FUZZY_UANG_UAN | - 0; - -struct Config::ConfigImpl { - bool m_special_phrases; - bool m_mode_simp; - unsigned int m_option; - unsigned int m_option_mask; - unsigned int m_double_pinyin_schema; - unsigned int m_bopomofo_keyboard_mapping; -}; - -Config::Config () - : m_impl (new Config::ConfigImpl) -{ - readDefaultValues (); -} - -Config::~Config () -{ - delete m_impl; -} - -/* Accessors */ -unsigned int -Config::option (void) const -{ - return m_impl->m_option; -} - -unsigned int -Config::doublePinyinSchema (void) const -{ - return m_impl->m_double_pinyin_schema; -} - -bool -Config::specialPhrases (void) const -{ - return m_impl->m_special_phrases; -} - -bool -Config::modeSimp (void) const -{ - return m_impl->m_mode_simp; -} - -unsigned int -Config::bopomofoKeyboardMapping (void) const -{ - return m_impl->m_bopomofo_keyboard_mapping; -} - -void -Config::setOption (unsigned int value) -{ - m_impl->m_option = value; -} - -void -Config::setDoublePinyinSchema (unsigned int value) -{ - m_impl->m_double_pinyin_schema = value; -} - -void -Config::setSpecialPhrases (bool value) -{ - m_impl->m_special_phrases = value; -} - -void -Config::setModeSimp (bool value) -{ - m_impl->m_mode_simp = value; -} - -void -Config::setBopomofoKeyboardMapping (unsigned int value) -{ - m_impl->m_bopomofo_keyboard_mapping = value; -} - -void -Config::readDefaultValues () -{ - m_impl->m_option = PINYIN_DEFAULT_OPTION; - m_impl->m_option_mask = PINYIN_INCOMPLETE_PINYIN | PINYIN_CORRECT_ALL; - m_impl->m_double_pinyin_schema = 0; - m_impl->m_mode_simp = true; - m_impl->m_special_phrases = true; - m_impl->m_bopomofo_keyboard_mapping = 0; -} - -/* Pinyin Config */ -struct PinyinConfig::PinyinConfigImpl { - static std::unique_ptr <PinyinConfig> m_instance; -}; - -std::unique_ptr<PinyinConfig> PinyinConfig::PinyinConfigImpl::m_instance; - -PinyinConfig::PinyinConfig () - : Config () -{ -} - -PinyinConfig & -PinyinConfig::instance () -{ - if (PinyinConfigImpl::m_instance == NULL) { - PinyinConfigImpl::m_instance.reset (new PinyinConfig ()); - PinyinConfigImpl::m_instance->readDefaultValues (); - } - return *PinyinConfigImpl::m_instance; -} - -void -PinyinConfig::readDefaultValues () -{ - Config::readDefaultValues (); -} - - -/* Bopomofo Config */ - -struct BopomofoConfig::BopomofoConfigImpl { - static std::unique_ptr <BopomofoConfig> m_instance; -}; - -std::unique_ptr<BopomofoConfig> BopomofoConfig::BopomofoConfigImpl::m_instance; - -BopomofoConfig::BopomofoConfig () - : Config () -{ -} - -BopomofoConfig & -BopomofoConfig::instance () -{ - if (BopomofoConfigImpl::m_instance == NULL) { - BopomofoConfigImpl::m_instance.reset (new BopomofoConfig ()); - BopomofoConfigImpl::m_instance->readDefaultValues (); - } - return *BopomofoConfigImpl::m_instance; -} - -void -BopomofoConfig::readDefaultValues (void) -{ - Config::readDefaultValues (); - m_impl->m_special_phrases = false; -} - -}; // namespace PyZy diff --git a/src/PyZyConfig.h b/src/PyZyConfig.h index 0b43a88..0104fd8 100644 --- a/src/PyZyConfig.h +++ b/src/PyZyConfig.h @@ -22,115 +22,21 @@ #ifndef __PYZY_CONFIG_H_ #define __PYZY_CONFIG_H_ -namespace PyZy { - -#define PINYIN_INCOMPLETE_PINYIN (1U << 0) - -#define PINYIN_CORRECT_GN_TO_NG (1U << 1) -#define PINYIN_CORRECT_MG_TO_NG (1U << 2) -#define PINYIN_CORRECT_IOU_TO_IU (1U << 3) -#define PINYIN_CORRECT_UEI_TO_UI (1U << 4) -#define PINYIN_CORRECT_UEN_TO_UN (1U << 5) -#define PINYIN_CORRECT_UE_TO_VE (1U << 6) -#define PINYIN_CORRECT_V_TO_U (1U << 7) -#define PINYIN_CORRECT_ON_TO_ONG (1U << 8) -#define PINYIN_CORRECT_ALL (0x000001fe) - -#define PINYIN_FUZZY_C_CH (1U << 9) -#define PINYIN_FUZZY_CH_C (1U << 10) -#define PINYIN_FUZZY_Z_ZH (1U << 11) -#define PINYIN_FUZZY_ZH_Z (1U << 12) -#define PINYIN_FUZZY_S_SH (1U << 13) -#define PINYIN_FUZZY_SH_S (1U << 14) -#define PINYIN_FUZZY_L_N (1U << 15) -#define PINYIN_FUZZY_N_L (1U << 16) -#define PINYIN_FUZZY_F_H (1U << 17) -#define PINYIN_FUZZY_H_F (1U << 18) -#define PINYIN_FUZZY_L_R (1U << 19) -#define PINYIN_FUZZY_R_L (1U << 20) -#define PINYIN_FUZZY_K_G (1U << 21) -#define PINYIN_FUZZY_G_K (1U << 22) - -#define PINYIN_FUZZY_AN_ANG (1U << 23) -#define PINYIN_FUZZY_ANG_AN (1U << 24) -#define PINYIN_FUZZY_EN_ENG (1U << 25) -#define PINYIN_FUZZY_ENG_EN (1U << 26) -#define PINYIN_FUZZY_IN_ING (1U << 27) -#define PINYIN_FUZZY_ING_IN (1U << 28) -#define PINYIN_FUZZY_IAN_IANG PINYIN_FUZZY_AN_ANG -#define PINYIN_FUZZY_IANG_IAN PINYIN_FUZZY_ANG_AN -#define PINYIN_FUZZY_UAN_UANG PINYIN_FUZZY_AN_ANG -#define PINYIN_FUZZY_UANG_UAN PINYIN_FUZZY_ANG_AN -#define PINYIN_FUZZY_ALL (0x1ffffe00) - -#define DOUBLE_PINYIN_KEYBOARD_MSPY (0) -#define DOUBLE_PINYIN_KEYBOARD_ZRM (1) -#define DOUBLE_PINYIN_KEYBOARD_ABC (2) -#define DOUBLE_PINYIN_KEYBOARD_ZGPY (3) -#define DOUBLE_PINYIN_KEYBOARD_PYJJ (4) -#define DOUBLE_PINYIN_KEYBOARD_XHE (5) -#define DOUBLE_PINYIN_KEYBOARD_LAST (5) - -#define BOPOMOFO_KEYBOARD_STANDARD (0) -#define BOPOMOFO_KEYBOARD_CHING_YEAH (1) -#define BOPOMOFO_KEYBOARD_ETAN (2) -#define BOPOMOFO_KEYBOARD_IBM (3) -#define BOPOMOFO_KEYBOARD_LAST (3) - -class Config { -protected: - Config (void); - virtual ~Config (void); - -private: - Config (const Config & obj) { } - -public: - virtual void readDefaultValues (void); +#include <PyZyConst.h> - unsigned int option (void) const; - unsigned int doublePinyinSchema (void) const; - bool specialPhrases (void) const; - bool modeSimp (void) const; - unsigned int bopomofoKeyboardMapping (void) const; - - void setOption (unsigned int value); - void setDoublePinyinSchema (unsigned int value); - void setSpecialPhrases (bool value); - void setModeSimp (bool value); - void setBopomofoKeyboardMapping (unsigned int value); - -protected: - struct ConfigImpl; - ConfigImpl *m_impl; -}; - -/* PinyinConfig */ -class PinyinConfig : public Config { -public: - static PinyinConfig & instance (void); - virtual void readDefaultValues (void); - -protected: - PinyinConfig (); - -private: - struct PinyinConfigImpl; - PinyinConfigImpl *m_pinyin_impl; -}; - -/* Bopomofo Config */ -class BopomofoConfig : public Config { -public: - static BopomofoConfig & instance (void); - virtual void readDefaultValues (void); - -protected: - BopomofoConfig (); +namespace PyZy { -private: - struct BopomofoConfigImpl; - BopomofoConfigImpl *m_bopomofo_impl; +struct Config { + Config (void) + : option (PINYIN_INCOMPLETE_PINYIN | + PINYIN_CORRECT_ALL | + PINYIN_FUZZY_ALL), + specialPhrases (true), + modeSimp (true) { } + + unsigned int option; + bool specialPhrases; + bool modeSimp; }; }; // namespace PyZy diff --git a/src/PyZyConst.h b/src/PyZyConst.h new file mode 100644 index 0000000..e698409 --- /dev/null +++ b/src/PyZyConst.h @@ -0,0 +1,79 @@ +/* vim:set et ts=4 sts=4: + * + * libpyzy - The Chinese PinYin and Bopomofo conversion library. + * + * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +#ifndef __PYZY_CONST_H_ +#define __PYZY_CONST_H_ + +/* constants for options */ +#define PINYIN_INCOMPLETE_PINYIN (1U << 0) + +#define PINYIN_CORRECT_GN_TO_NG (1U << 1) +#define PINYIN_CORRECT_MG_TO_NG (1U << 2) +#define PINYIN_CORRECT_IOU_TO_IU (1U << 3) +#define PINYIN_CORRECT_UEI_TO_UI (1U << 4) +#define PINYIN_CORRECT_UEN_TO_UN (1U << 5) +#define PINYIN_CORRECT_UE_TO_VE (1U << 6) +#define PINYIN_CORRECT_V_TO_U (1U << 7) +#define PINYIN_CORRECT_ON_TO_ONG (1U << 8) +#define PINYIN_CORRECT_ALL (0x000001fe) + +#define PINYIN_FUZZY_C_CH (1U << 9) +#define PINYIN_FUZZY_CH_C (1U << 10) +#define PINYIN_FUZZY_Z_ZH (1U << 11) +#define PINYIN_FUZZY_ZH_Z (1U << 12) +#define PINYIN_FUZZY_S_SH (1U << 13) +#define PINYIN_FUZZY_SH_S (1U << 14) +#define PINYIN_FUZZY_L_N (1U << 15) +#define PINYIN_FUZZY_N_L (1U << 16) +#define PINYIN_FUZZY_F_H (1U << 17) +#define PINYIN_FUZZY_H_F (1U << 18) +#define PINYIN_FUZZY_L_R (1U << 19) +#define PINYIN_FUZZY_R_L (1U << 20) +#define PINYIN_FUZZY_K_G (1U << 21) +#define PINYIN_FUZZY_G_K (1U << 22) + +#define PINYIN_FUZZY_AN_ANG (1U << 23) +#define PINYIN_FUZZY_ANG_AN (1U << 24) +#define PINYIN_FUZZY_EN_ENG (1U << 25) +#define PINYIN_FUZZY_ENG_EN (1U << 26) +#define PINYIN_FUZZY_IN_ING (1U << 27) +#define PINYIN_FUZZY_ING_IN (1U << 28) +#define PINYIN_FUZZY_IAN_IANG PINYIN_FUZZY_AN_ANG +#define PINYIN_FUZZY_IANG_IAN PINYIN_FUZZY_ANG_AN +#define PINYIN_FUZZY_UAN_UANG PINYIN_FUZZY_AN_ANG +#define PINYIN_FUZZY_UANG_UAN PINYIN_FUZZY_ANG_AN +#define PINYIN_FUZZY_ALL (0x1ffffe00) + +#define DOUBLE_PINYIN_KEYBOARD_MSPY (0) +#define DOUBLE_PINYIN_KEYBOARD_ZRM (1) +#define DOUBLE_PINYIN_KEYBOARD_ABC (2) +#define DOUBLE_PINYIN_KEYBOARD_ZGPY (3) +#define DOUBLE_PINYIN_KEYBOARD_PYJJ (4) +#define DOUBLE_PINYIN_KEYBOARD_XHE (5) +#define DOUBLE_PINYIN_KEYBOARD_LAST (6) /* Number of DoublePinyinSchema */ + +#define BOPOMOFO_KEYBOARD_STANDARD (0) +#define BOPOMOFO_KEYBOARD_CHING_YEAH (1) +#define BOPOMOFO_KEYBOARD_ETAN (2) +#define BOPOMOFO_KEYBOARD_IBM (3) +#define BOPOMOFO_KEYBOARD_LAST (4) /* Number of BopomofoSchema */ + +#endif // __PYZY_CONST_H_ diff --git a/src/PyZyDoublePinyinContext.cc b/src/PyZyDoublePinyinContext.cc index 63d76fe..8a68fee 100644 --- a/src/PyZyDoublePinyinContext.cc +++ b/src/PyZyDoublePinyinContext.cc @@ -37,15 +37,16 @@ namespace PyZy { ((c >= 'a' && c <= 'z') ? c - 'a' : (c == ';' ? 26 : -1)) #define ID_TO_SHENG(id) \ - (double_pinyin_map[m_config.doublePinyinSchema ()].sheng[id]) + (double_pinyin_map[m_double_pinyin_schema].sheng[id]) #define ID_TO_YUNS(id) \ - (double_pinyin_map[m_config.doublePinyinSchema ()].yun[id]) + (double_pinyin_map[m_double_pinyin_schema].yun[id]) #define IS_ALPHA(c) \ ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) -DoublePinyinContext::DoublePinyinContext (Config & config, PhoneticContext::Observer *observer) - : PinyinContext (config, observer) +DoublePinyinContext::DoublePinyinContext (PhoneticContext::Observer *observer) + : PinyinContext (observer), + m_double_pinyin_schema (DOUBLE_PINYIN_KEYBOARD_MSPY) { } @@ -325,7 +326,7 @@ DoublePinyinContext::moveCursorToEnd (void) inline const Pinyin * DoublePinyinContext::isPinyin (int i) { - if ((m_config.option () & PINYIN_INCOMPLETE_PINYIN) == 0) { + if ((m_config.option & PINYIN_INCOMPLETE_PINYIN) == 0) { return NULL; } @@ -352,20 +353,21 @@ DoublePinyinContext::isPinyin (int i, int j) return NULL; if (yun[1] == PINYIN_ID_VOID) { - return PinyinParser::isPinyin (sheng, yun[0], - m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); + return PinyinParser::isPinyin ( + sheng, yun[0], + m_config.option & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); } - pinyin = PinyinParser::isPinyin (sheng, yun[0], - m_config.option () & (PINYIN_FUZZY_ALL)); + pinyin = PinyinParser::isPinyin ( + sheng, yun[0], m_config.option & (PINYIN_FUZZY_ALL)); if (pinyin == NULL) - pinyin = PinyinParser::isPinyin (sheng, yun[1], - m_config.option () & (PINYIN_FUZZY_ALL)); + pinyin = PinyinParser::isPinyin ( + sheng, yun[1], m_config.option & (PINYIN_FUZZY_ALL)); if (pinyin != NULL) return pinyin; /* if sheng == j q x y and yun == v, try to correct v to u */ - if ((m_config.option () & PINYIN_CORRECT_V_TO_U) == 0) + if ((m_config.option & PINYIN_CORRECT_V_TO_U) == 0) return NULL; if (yun[0] != PINYIN_ID_V && yun[1] != PINYIN_ID_V) @@ -376,8 +378,9 @@ DoublePinyinContext::isPinyin (int i, int j) case PINYIN_ID_Q: case PINYIN_ID_X: case PINYIN_ID_Y: - return PinyinParser::isPinyin (sheng, PINYIN_ID_V, - m_config.option () & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); + return PinyinParser::isPinyin ( + sheng, PINYIN_ID_V, + m_config.option & (PINYIN_FUZZY_ALL | PINYIN_CORRECT_V_TO_U)); default: return NULL; } @@ -411,7 +414,8 @@ DoublePinyinContext::updatePinyin (bool all) size_t len = m_pinyin_len; if (m_pinyin.empty () == false && m_pinyin.back ()->flags & PINYIN_INCOMPLETE_PINYIN) { - const Pinyin *pinyin = isPinyin (ID (m_text[m_pinyin_len -1]),ID (m_text[m_pinyin_len])); + const Pinyin *pinyin = isPinyin ( + ID (m_text[m_pinyin_len -1]),ID (m_text[m_pinyin_len])); if (pinyin) { m_pinyin.pop_back (); m_pinyin.append (pinyin, m_pinyin_len - 1, 2); @@ -424,7 +428,8 @@ DoublePinyinContext::updatePinyin (bool all) pinyin = isPinyin (ID (m_text[m_pinyin_len])); } else { - pinyin = isPinyin (ID (m_text[m_pinyin_len]), ID (m_text[m_pinyin_len + 1])); + pinyin = isPinyin ( + ID (m_text[m_pinyin_len]), ID (m_text[m_pinyin_len + 1])); if (pinyin == NULL) pinyin = isPinyin (ID (m_text[m_pinyin_len])); } @@ -446,4 +451,33 @@ DoublePinyinContext::updatePinyin (bool all) return retval; } +Variant +DoublePinyinContext::getProperty (PropertyName name) const +{ + if (name == PROPERTY_DOUBLE_PINYIN_SCHEMA) { + return Variant::fromUnsignedInt (m_double_pinyin_schema); + } + + return PhoneticContext::getProperty (name); +} + +bool +DoublePinyinContext::setProperty (PropertyName name, const Variant &variant) +{ + if (name == PROPERTY_DOUBLE_PINYIN_SCHEMA) { + if (variant.getType () != Variant::TYPE_UNSIGNED_INT) { + return false; + } + const unsigned int schema = variant.getUnsignedInt (); + if (schema >= DOUBLE_PINYIN_KEYBOARD_LAST) { + return false; + } + + m_double_pinyin_schema = schema; + return true; + } + + return PhoneticContext::setProperty (name, variant); +} + }; // namespace PyZy diff --git a/src/PyZyDoublePinyinContext.h b/src/PyZyDoublePinyinContext.h index f8b18ce..b6871ad 100644 --- a/src/PyZyDoublePinyinContext.h +++ b/src/PyZyDoublePinyinContext.h @@ -26,12 +26,10 @@ namespace PyZy { -class Config; - class DoublePinyinContext : public PinyinContext { public: - DoublePinyinContext (Config & config, PhoneticContext::Observer *observer); + explicit DoublePinyinContext (PhoneticContext::Observer *observer); virtual ~DoublePinyinContext (); virtual bool insert (char ch); @@ -48,6 +46,9 @@ public: virtual bool moveCursorToBegin (void); virtual bool moveCursorToEnd (void); + virtual Variant getProperty (PropertyName name) const; + virtual bool setProperty (PropertyName name, const Variant &variant); + protected: virtual bool updatePinyin (bool all); @@ -55,6 +56,7 @@ private: const Pinyin *isPinyin (int i, int j); const Pinyin *isPinyin (int i); + unsigned int m_double_pinyin_schema; }; }; // namespace PyZy diff --git a/src/PyZyFullPinyinContext.cc b/src/PyZyFullPinyinContext.cc index 3636f4c..148478b 100644 --- a/src/PyZyFullPinyinContext.cc +++ b/src/PyZyFullPinyinContext.cc @@ -27,8 +27,8 @@ namespace PyZy { -FullPinyinContext::FullPinyinContext (Config & config, PhoneticContext::Observer *observer) - : PinyinContext (config, observer) +FullPinyinContext::FullPinyinContext (PhoneticContext::Observer *observer) + : PinyinContext (observer) { } @@ -50,7 +50,7 @@ FullPinyinContext::insert (char ch) m_text.insert (m_cursor++, ch); - if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) { + if (G_UNLIKELY (!(m_config.option & PINYIN_INCOMPLETE_PINYIN))) { updateSpecialPhrases (); updatePinyin (); } @@ -227,11 +227,12 @@ FullPinyinContext::updatePinyin (void) m_pinyin_len = 0; } else { - m_pinyin_len = PinyinParser::parse (m_text, // text - m_cursor, // text length - m_config.option (), // option - m_pinyin, // result - MAX_PHRASE_LEN); // max result length + m_pinyin_len = PinyinParser::parse ( + m_text, // text + m_cursor, // text length + m_config.option, // option + m_pinyin, // result + MAX_PHRASE_LEN); // max result length } updatePhraseEditor (); diff --git a/src/PyZyFullPinyinContext.h b/src/PyZyFullPinyinContext.h index 3739558..e2e9649 100644 --- a/src/PyZyFullPinyinContext.h +++ b/src/PyZyFullPinyinContext.h @@ -26,12 +26,10 @@ namespace PyZy { -class Config; - class FullPinyinContext : public PinyinContext { public: - FullPinyinContext (Config & config, PhoneticContext::Observer *observer); + explicit FullPinyinContext (PhoneticContext::Observer *observer); virtual ~FullPinyinContext (void); public: diff --git a/src/PyZyInputContext.cc b/src/PyZyInputContext.cc index 3fb383d..1795f9f 100644 --- a/src/PyZyInputContext.cc +++ b/src/PyZyInputContext.cc @@ -51,18 +51,16 @@ InputContext::finalize () Database::finalize (); } - InputContext * InputContext::create (InputContext::InputType type, - Config & config, InputContext::Observer * observer) { switch (type) { case FULL_PINYIN: - return new FullPinyinContext (config, observer); + return new FullPinyinContext (observer); case DOUBLE_PINYIN: - return new DoublePinyinContext (config, observer); + return new DoublePinyinContext (observer); case BOPOMOFO: - return new BopomofoContext (config, observer); + return new BopomofoContext (observer); default: g_warning ("unknown context type.\n"); return NULL; diff --git a/src/PyZyInputContext.h b/src/PyZyInputContext.h index 24382d6..72c947d 100644 --- a/src/PyZyInputContext.h +++ b/src/PyZyInputContext.h @@ -27,7 +27,7 @@ namespace PyZy { -class Config; +class Variant; enum CandidateType { NORMAL_PHRASE, @@ -63,7 +63,15 @@ public: enum CommitType { TYPE_RAW, TYPE_PHONETIC, - TYPE_CONVERTED + TYPE_CONVERTED, + }; + + enum PropertyName { + PROPERTY_CONVERSION_OPTION, + PROPERTY_DOUBLE_PINYIN_SCHEMA, + PROPERTY_BOPOMOFO_SCHEMA, + PROPERTY_SPECIAL_PHRASE, + PROPERTY_MODE_SIMP, }; /* member functions */ @@ -97,15 +105,12 @@ public: // TODO(hsumita): Parse pinyin after cursor. virtual bool removeWordAfter (void) = 0; - virtual void bopomofoSelectMode () = 0; - /* static functions */ static void init (); static void init (const std::string & user_data_dir); static void finalize (); static InputContext * create (InputContext::InputType type, - Config & config, - InputContext::Observer * observer); + InputContext::Observer * observer); /* accessors */ virtual const std::string & inputText () const = 0; @@ -115,6 +120,9 @@ public: virtual const std::string & auxiliaryText (void) const = 0; virtual unsigned int cursor () const = 0; virtual unsigned int focusedCandidate () const = 0; + + virtual Variant getProperty (PropertyName name) const = 0; + virtual bool setProperty (PropertyName name, const Variant &variant)= 0; }; }; // namespace PyZy diff --git a/src/PyZyPhoneticContext.cc b/src/PyZyPhoneticContext.cc index 55243d7..dca2bab 100644 --- a/src/PyZyPhoneticContext.cc +++ b/src/PyZyPhoneticContext.cc @@ -26,9 +26,8 @@ namespace PyZy { -PhoneticContext::PhoneticContext (Config & config, PhoneticContext::Observer *observer) - : m_config (config), - m_phrase_editor (config), +PhoneticContext::PhoneticContext (PhoneticContext::Observer *observer) + : m_phrase_editor (m_config), m_observer (observer) { resetContext (); @@ -44,7 +43,7 @@ PhoneticContext::updateSpecialPhrases (void) size_t size = m_special_phrases.size (); m_special_phrases.clear (); - if (!m_config.specialPhrases ()) + if (!m_config.specialPhrases) return false; if (!m_selected_special_phrase.empty ()) @@ -250,7 +249,7 @@ PhoneticContext::getCandidate (size_t i, Candidate & candidate) } i -= m_special_phrases.size (); - if (m_config.modeSimp ()) { + if (m_config.modeSimp) { candidate.text = m_phrase_editor.candidate (i).phrase; } else { String output; @@ -273,4 +272,50 @@ PhoneticContext::getPreparedCandidatesSize () const return m_special_phrases.size () + m_phrase_editor.candidates ().size (); } +Variant +PhoneticContext::getProperty (PropertyName name) const +{ + switch (name) { + case PROPERTY_CONVERSION_OPTION: + return Variant::fromUnsignedInt (m_config.option); + case PROPERTY_SPECIAL_PHRASE: + return Variant::fromBool (m_config.specialPhrases); + case PROPERTY_MODE_SIMP: + return Variant::fromBool (m_config.modeSimp); + default: + return Variant::nullVariant (); + } +} + +bool +PhoneticContext::setProperty (PropertyName name, const Variant &variant) +{ + if (variant.getType () == Variant::TYPE_UNSIGNED_INT) { + const unsigned int value = variant.getUnsignedInt (); + + switch (name) { + case PROPERTY_CONVERSION_OPTION: + m_config.option = value; + return true; + default: + return false; + } + } else if (variant.getType () == Variant::TYPE_BOOL) { + const bool value = variant.getBool (); + + switch (name) { + case PROPERTY_SPECIAL_PHRASE: + m_config.specialPhrases = value; + return true; + case PROPERTY_MODE_SIMP: + m_config.modeSimp = value; + return true; + default: + return false; + } + } + + return false; +} + }; // namespace PyZy diff --git a/src/PyZyPhoneticContext.h b/src/PyZyPhoneticContext.h index a299bd7..20ebfcd 100644 --- a/src/PyZyPhoneticContext.h +++ b/src/PyZyPhoneticContext.h @@ -26,9 +26,11 @@ #include <vector> #include "PyZyInputContext.h" #include "PyZyConfig.h" +#include "PyZyConst.h" #include "PyZyPinyinArray.h" #include "PyZyPhraseEditor.h" #include "PyZySpecialPhraseTable.h" +#include "PyZyVariant.h" namespace PyZy { @@ -48,7 +50,7 @@ struct Preedit { class PhoneticContext : public InputContext { public: - PhoneticContext (Config & config, PhoneticContext::Observer *observer); + explicit PhoneticContext (PhoneticContext::Observer *observer); virtual ~PhoneticContext (void); /* API of InputContext */ @@ -64,17 +66,44 @@ public: bool getCandidate (size_t i, Candidate & output); size_t getPreparedCandidatesSize () const; - /* inline functions */ - virtual void bopomofoSelectMode () { } + virtual Variant getProperty (PropertyName name) const; + virtual bool setProperty (PropertyName name, const Variant &variant); /* Accessors of InputContext. */ - virtual const std::string & inputText () const { return m_text; } - virtual const std::string & selectedText (void) const { return m_preedit_text.selected_text; } - virtual const std::string & conversionText (void) const { return m_preedit_text.candidate_text; } - virtual const std::string & restText (void) const { return m_preedit_text.rest_text; } - virtual const std::string & auxiliaryText (void) const { return m_auxiliary_text; } - virtual unsigned int cursor () const { return m_cursor; } - virtual unsigned int focusedCandidate () const { return m_focused_candidate; } + virtual const std::string & inputText () const + { + return m_text; + } + + virtual const std::string & selectedText (void) const + { + return m_preedit_text.selected_text; + } + + virtual const std::string & conversionText (void) const + { + return m_preedit_text.candidate_text; + } + + virtual const std::string & restText (void) const + { + return m_preedit_text.rest_text; + } + + virtual const std::string & auxiliaryText (void) const + { + return m_auxiliary_text; + } + + virtual unsigned int cursor () const + { + return m_cursor; + } + + virtual unsigned int focusedCandidate () const + { + return m_focused_candidate; + } protected: virtual void resetContext (void); @@ -111,7 +140,7 @@ protected: } /* variables */ - Config &m_config; + Config m_config; size_t m_cursor; size_t m_focused_candidate; PinyinArray m_pinyin; diff --git a/src/PyZyPhraseEditor.cc b/src/PyZyPhraseEditor.cc index 047fa79..2222441 100644 --- a/src/PyZyPhraseEditor.cc +++ b/src/PyZyPhraseEditor.cc @@ -26,14 +26,14 @@ namespace PyZy { -PhraseEditor::PhraseEditor (Config & config) - : m_candidates (32), +PhraseEditor::PhraseEditor (const Config & config) + : m_config(config), + m_candidates (32), m_selected_phrases (8), m_selected_string (32), m_candidate_0_phrases (8), m_pinyin (16), - m_cursor (0), - m_config (config) + m_cursor (0) { } @@ -83,7 +83,7 @@ PhraseEditor::selectCandidate (size_t i) m_selected_phrases.insert (m_selected_phrases.end (), m_candidate_0_phrases.begin (), m_candidate_0_phrases.end ()); - if (G_LIKELY (m_config.modeSimp ())) + if (G_LIKELY (m_config.modeSimp)) m_selected_string << m_candidates[0].phrase; else SimpTradConverter::simpToTrad (m_candidates[0].phrase, m_selected_string); @@ -91,7 +91,7 @@ PhraseEditor::selectCandidate (size_t i) } else { m_selected_phrases.push_back (m_candidates[i]); - if (G_LIKELY (m_config.modeSimp ())) + if (G_LIKELY (m_config.modeSimp)) m_selected_string << m_candidates[i].phrase; else SimpTradConverter::simpToTrad (m_candidates[i].phrase, m_selected_string); @@ -123,7 +123,7 @@ PhraseEditor::updateCandidates (void) m_query.reset (new Query (m_pinyin, m_cursor, m_pinyin.size () - m_cursor, - m_config.option ())); + m_config.option)); fillCandidates (); } @@ -146,7 +146,7 @@ PhraseEditor::updateTheFirstCandidate (void) Query query (m_pinyin, begin, end - begin, - m_config.option ()); + m_config.option); ret = query.fill (m_candidate_0_phrases, 1); g_assert (ret == 1); begin += m_candidate_0_phrases.back ().len; diff --git a/src/PyZyPhraseEditor.h b/src/PyZyPhraseEditor.h index 28923a9..10cc8ea 100644 --- a/src/PyZyPhraseEditor.h +++ b/src/PyZyPhraseEditor.h @@ -31,13 +31,13 @@ namespace PyZy { -class Query; -class Database; class Config; +class Database; +class Query; class PhraseEditor { public: - PhraseEditor (Config & config); + explicit PhraseEditor (const Config & config); ~PhraseEditor (void); const String & selectedString (void) const { return m_selected_string; } @@ -118,6 +118,7 @@ private: void updateTheFirstCandidate (void); private: + const Config &m_config; PhraseArray m_candidates; // candidates phrase array PhraseArray m_selected_phrases; // selected phrases, before cursor String m_selected_string; // selected phrases, in string format @@ -125,7 +126,6 @@ private: PinyinArray m_pinyin; size_t m_cursor; std::shared_ptr<Query> m_query; - Config & m_config; }; }; // namespace PyZy diff --git a/src/PyZyPinyinContext.cc b/src/PyZyPinyinContext.cc index 8bb8e62..bf17aff 100644 --- a/src/PyZyPinyinContext.cc +++ b/src/PyZyPinyinContext.cc @@ -24,8 +24,8 @@ namespace PyZy { -PinyinContext::PinyinContext (Config & config, PhoneticContext::Observer * observer) - : PhoneticContext (config, observer) +PinyinContext::PinyinContext (PhoneticContext::Observer * observer) + : PhoneticContext (observer) { } @@ -114,7 +114,7 @@ PinyinContext::updatePreeditText () const Phrase & candidate = m_phrase_editor.candidate (index - m_special_phrases.size ()); if (m_text.size () == m_cursor) { /* cursor at end */ - if (m_config.modeSimp ()) + if (m_config.modeSimp) m_buffer << candidate; else SimpTradConverter::simpToTrad (candidate, m_buffer); diff --git a/src/PyZyPinyinContext.h b/src/PyZyPinyinContext.h index 41a8fe8..7b4a16e 100644 --- a/src/PyZyPinyinContext.h +++ b/src/PyZyPinyinContext.h @@ -28,7 +28,7 @@ namespace PyZy { class PinyinContext : public PhoneticContext { public: - PinyinContext (Config &config, PhoneticContext::Observer *observer); + explicit PinyinContext (PhoneticContext::Observer *observer); virtual ~PinyinContext (void); virtual void commit (CommitType type); diff --git a/src/PyZyVariant.cc b/src/PyZyVariant.cc new file mode 100644 index 0000000..d077cda --- /dev/null +++ b/src/PyZyVariant.cc @@ -0,0 +1,68 @@ +/* vim:set et ts=4 sts=4: + * + * libpyzy - The Chinese PinYin and Bopomofo conversion library. + * + * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +#include "PyZyVariant.h" + +namespace PyZy { + +// static +Variant Variant::fromBool (bool value) +{ + Variant variant; + variant.m_type = TYPE_BOOL; + variant.m_value.bool_value = value; + return variant; +} + +// static +Variant Variant::fromUnsignedInt (unsigned int value) +{ + Variant variant; + variant.m_type = TYPE_UNSIGNED_INT; + variant.m_value.unsigned_int_value = value; + return variant; +} + +// static +Variant Variant::nullVariant (void) +{ + Variant variant; + variant.m_type = TYPE_NULL; + variant.m_value.unsigned_int_value = 0u; + return variant; +} + +Variant::Type Variant::getType (void) const +{ + return m_type; +} + +bool Variant::getBool (void) const +{ + return m_value.bool_value; +} + +unsigned int Variant::getUnsignedInt (void) const +{ + return m_value.unsigned_int_value; +} + +} // namespace PyZy diff --git a/src/PyZyVariant.h b/src/PyZyVariant.h new file mode 100644 index 0000000..7bea511 --- /dev/null +++ b/src/PyZyVariant.h @@ -0,0 +1,55 @@ +/* vim:set et ts=4 sts=4: + * + * libpyzy - The Chinese PinYin and Bopomofo conversion library. + * + * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com> + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + */ +#ifndef __PYZY_VARIANT_H_ +#define __PYZY_VARIANT_H_ + +namespace PyZy { + +class Variant { +public: + enum Type { + TYPE_NULL, + TYPE_BOOL, + TYPE_UNSIGNED_INT, + }; + + static Variant fromBool (bool value); + static Variant fromUnsignedInt (unsigned int value); + static Variant nullVariant (void); + + Type getType (void) const; + bool getBool (void) const; + unsigned int getUnsignedInt (void) const; + +private: + Variant(); + + Type m_type; + union { + bool bool_value; + unsigned int unsigned_int_value; + } m_value; +}; + +} // namespace PyZy + +#endif |