~ubuntu-branches/ubuntu/quantal/sunpinyin/quantal

« back to all changes in this revision

Viewing changes to src/ime-core/imi_options.h

  • Committer: Package Import Robot
  • Author(s): YunQiang Su
  • Date: 2012-03-30 15:31:55 UTC
  • mfrom: (1.1.3) (1.2.7 sid)
  • Revision ID: package-import@ubuntu.com-20120330153155-qgls77sogzgtg9zp
Tags: 2.0.3+git20120222-1
* Team upload: git snapshot 20120222.
   - fix breaks if LDFLAGS in environment contains
       multiple words (Closese #646001).
   - rm patches merged to upstream:
       append-os-environ-toenv.patch
       fix-ftbfs-on-sh.patch
       remove-10-candidate-words-limitation.patch
   - refresh disable-lm-dict-compile.patch.
* Bump stardard version to 3.9.3: no modify needed.
* add libsunpinyin3-dbg and python-sunpinyin packages.
* debian/compat to 9, multiarch it.
* rewrite debian/rules with dh 7 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 
 * 
 
3
 *
4
4
 * Copyright (c) 2007 Sun Microsystems, Inc. All Rights Reserved.
5
 
 * 
 
5
 *
6
6
 * The contents of this file are subject to the terms of either the GNU Lesser
7
7
 * General Public License Version 2.1 only ("LGPL") or the Common Development and
8
8
 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
9
9
 * file except in compliance with the License. You can obtain a copy of the CDDL at
10
10
 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
11
 
 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the 
 
11
 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
12
12
 * specific language governing permissions and limitations under the License. When
13
13
 * distributing the software, include this License Header Notice in each file and
14
14
 * include the full text of the License in the License file as well as the
15
15
 * following notice:
16
 
 * 
 
16
 *
17
17
 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
18
18
 * (CDDL)
19
19
 * For Covered Software in this distribution, this License shall be governed by the
21
21
 * Any litigation relating to this License shall be subject to the jurisdiction of
22
22
 * the Federal Courts of the Northern District of California and the state courts
23
23
 * of the State of California, with venue lying in Santa Clara County, California.
24
 
 * 
 
24
 *
25
25
 * Contributor(s):
26
 
 * 
 
26
 *
27
27
 * If you wish your version of this file to be governed by only the CDDL or only
28
28
 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
29
29
 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
32
32
 * Version 2.1, or to extend the choice of license to its licensees as provided
33
33
 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
34
34
 * Version 2 license, then the option applies only if the new code is made subject
35
 
 * to such option by the copyright holder. 
 
35
 * to such option by the copyright holder.
36
36
 */
37
37
 
38
38
#ifndef _IMI_OPTIONS_H
54
54
#define SUNPINYIN_USERDATA_DIR_PREFIX ".sunpinyin"
55
55
#endif
56
56
 
57
 
struct CSimplifiedChinesePolicy : public IConfigurable
58
 
{
 
57
struct CSimplifiedChinesePolicy : public IConfigurable {
59
58
    CSimplifiedChinesePolicy ();
60
 
    
61
 
    bool loadResources ();
62
 
 
63
 
    CIMIContext* createContext ();
64
 
    void destroyContext (CIMIContext *context);
65
 
    
66
 
    void setPunctMapping (string_pairs punc_map)
67
 
        {m_getFullPunctOp.initPunctMap (punc_map);}
68
 
 
69
 
    string_pairs getDefaultPunctMapping () const;
70
 
    
71
 
    void enableFullSymbol (bool v=true) {m_bEnableFullSymbol = v;}
72
 
    void enableFullPunct  (bool v=true) {m_bEnableFullPunct = v;}
73
 
 
74
 
    void setDataDir (const std::string& data_dir)
75
 
        {m_data_dir = data_dir;}
76
 
 
77
 
    void setUserDataDir (const std::string& user_data_dir)
78
 
        {m_user_data_dir = user_data_dir;}
79
 
 
80
 
    virtual bool onConfigChanged (const COptionEvent& event);
81
 
    
 
59
 
 
60
    bool loadResources();
 
61
 
 
62
    CIMIContext* createContext();
 
63
    void destroyContext(CIMIContext *context);
 
64
 
 
65
    void setPunctMapping(string_pairs punc_map)
 
66
    { m_getFullPunctOp.initPunctMap(punc_map); }
 
67
 
 
68
    string_pairs getDefaultPunctMapping() const;
 
69
 
 
70
    void enableFullSymbol(bool v = true) { m_bEnableFullSymbol = v; }
 
71
    void enableFullPunct(bool v = true) { m_bEnableFullPunct = v; }
 
72
 
 
73
    void setDataDir(const std::string& data_dir)
 
74
    { m_data_dir = data_dir; }
 
75
 
 
76
    void setUserDataDir(const std::string& user_data_dir)
 
77
    { m_user_data_dir = user_data_dir; }
 
78
 
 
79
    virtual bool onConfigChanged(const COptionEvent& event);
 
80
 
82
81
    template<class> friend class SingletonHolder;
83
 
    
84
 
protected:
85
 
    ~CSimplifiedChinesePolicy () {}
86
 
 
87
 
    bool createDirectory (char *path);
88
 
    bool saveUserHistory ();
89
 
    
90
 
    CIMIData             m_coreData;
91
 
    CBigramHistory       m_historyCache;
92
 
    bool                 m_bLoaded;
93
 
    bool                 m_bTried;
94
 
    unsigned             m_csLevel;
95
 
    bool                 m_bEnableFullSymbol;
96
 
    CGetFullSymbolOp     m_getFullSymbolOp;
97
 
    bool                 m_bEnableFullPunct;
98
 
    CGetFullPunctOp      m_getFullPunctOp;
99
 
    std::string          m_data_dir;
100
 
    std::string          m_user_data_dir;
 
82
 
 
83
protected: ~CSimplifiedChinesePolicy () {}
 
84
 
 
85
    bool createDirectory(char *path);
 
86
    bool saveUserHistory();
 
87
 
 
88
    CIMIData m_coreData;
 
89
    CBigramHistory m_historyCache;
 
90
    bool m_bLoaded;
 
91
    bool m_bTried;
 
92
    unsigned m_csLevel;
 
93
    bool m_bEnableFullSymbol;
 
94
    CGetFullSymbolOp m_getFullSymbolOp;
 
95
    bool m_bEnableFullPunct;
 
96
    CGetFullPunctOp m_getFullPunctOp;
 
97
    std::string m_data_dir;
 
98
    std::string m_user_data_dir;
101
99
public:
102
 
    CUserDict            m_userDict;
 
100
    CUserDict m_userDict;
103
101
};
104
102
 
105
103
typedef SingletonHolder<CSimplifiedChinesePolicy> ASimplifiedChinesePolicy;
106
104
 
107
 
struct CQuanpinSchemePolicy : IConfigurable
108
 
{
 
105
struct CQuanpinSchemePolicy : IConfigurable {
109
106
public:
110
 
    
111
 
    IPySegmentor* createPySegmentor () 
112
 
    {
113
 
        CQuanpinSegmentor *pseg = new CQuanpinSegmentor ();
114
 
        pseg->setGetFuzzySyllablesOp (&m_getFuzzySyllablesOp);
115
 
        pseg->setGetCorrectionPairOp (&m_getCorrectionPairOp);
116
 
        pseg->setGetFuzzySegmentsOp  (&m_getFuzzySegmentsOp);
 
107
 
 
108
    IPySegmentor* createPySegmentor(){
 
109
        CQuanpinSegmentor *pseg = new CQuanpinSegmentor();
 
110
        pseg->setGetFuzzySyllablesOp(&m_getFuzzySyllablesOp);
 
111
        pseg->setGetCorrectionPairOp(&m_getCorrectionPairOp);
 
112
        pseg->setGetFuzzySegmentsOp(&m_getFuzzySegmentsOp);
117
113
        return pseg;
118
114
    }
119
115
 
120
 
    void setFuzzyForwarding (bool enable_fuzzies=true, bool enable_simpler_initials=true)
121
 
    {
122
 
        m_getFuzzySyllablesOp.setEnableFuzzies (enable_fuzzies);
123
 
        m_getFuzzySyllablesOp.setEnableSimplerInitials (enable_simpler_initials);
 
116
    void setFuzzyForwarding(bool enable_fuzzies = true,
 
117
                            bool enable_simpler_initials = true){
 
118
        m_getFuzzySyllablesOp.setEnableFuzzies(enable_fuzzies);
 
119
        m_getFuzzySyllablesOp.setEnableSimplerInitials(enable_simpler_initials);
124
120
    }
125
121
 
126
 
    void clearFuzzyPinyinPairs ()
127
 
        {m_getFuzzySyllablesOp.clearFuzzyMap();}
128
 
 
129
 
    void setFuzzyPinyinPairs (const string_pairs& pairs, bool duplex = true)
130
 
        {m_getFuzzySyllablesOp.initFuzzyMap (pairs, duplex);}
131
 
 
132
 
    void setAutoCorrecting (bool v=true)
133
 
        {m_getCorrectionPairOp.setEnable (v);}
134
 
 
135
 
    void setAutoCorrectionPairs (const string_pairs& pairs) 
136
 
        {m_getCorrectionPairOp.setCorrectionPairs (pairs);}
137
 
 
138
 
    void setFuzzySegmentation (bool v=true)
139
 
        {m_getFuzzySegmentsOp.setEnable (v);}
140
 
 
141
 
    void setInnerFuzzySegmentation (bool v=true)
142
 
        {m_getFuzzySegmentsOp.setInnerFuzzyEnable (v);}
 
122
    void clearFuzzyPinyinPairs()
 
123
    { m_getFuzzySyllablesOp.clearFuzzyMap(); }
 
124
 
 
125
    void setFuzzyPinyinPairs(const string_pairs& pairs, bool duplex = true)
 
126
    { m_getFuzzySyllablesOp.initFuzzyMap(pairs, duplex); }
 
127
 
 
128
    void setAutoCorrecting(bool v = true)
 
129
    { m_getCorrectionPairOp.setEnable(v); }
 
130
 
 
131
    void setAutoCorrectionPairs(const string_pairs& pairs)
 
132
    { m_getCorrectionPairOp.setCorrectionPairs(pairs); }
 
133
 
 
134
    void setFuzzySegmentation(bool v = true)
 
135
    { m_getFuzzySegmentsOp.setEnable(v); }
 
136
 
 
137
    void setInnerFuzzySegmentation(bool v = true)
 
138
    { m_getFuzzySegmentsOp.setInnerFuzzyEnable(v); }
143
139
 
144
140
    virtual bool onConfigChanged(const COptionEvent& event);
145
 
    
 
141
 
146
142
    template<class> friend class SingletonHolder;
147
 
    
148
 
protected:
149
 
    ~CQuanpinSchemePolicy () {}
 
143
 
 
144
protected: ~CQuanpinSchemePolicy () {}
150
145
 
151
146
    CGetFuzzySyllablesOp<CPinyinData>   m_getFuzzySyllablesOp;
152
 
    CGetCorrectionPairOp                m_getCorrectionPairOp;
153
 
    CGetFuzzySegmentsOp                 m_getFuzzySegmentsOp;
 
147
    CGetCorrectionPairOp m_getCorrectionPairOp;
 
148
    CGetFuzzySegmentsOp m_getFuzzySegmentsOp;
154
149
};
155
150
 
156
151
typedef SingletonHolder<CQuanpinSchemePolicy> AQuanpinSchemePolicy;
157
152
 
158
 
struct CShuangpinSchemePolicy : public IConfigurable
159
 
{
 
153
struct CShuangpinSchemePolicy : public IConfigurable {
160
154
public:
161
155
    CShuangpinSchemePolicy();
162
 
    
163
 
    IPySegmentor* createPySegmentor () 
164
 
    {
165
 
        CShuangpinSegmentor *pseg = new CShuangpinSegmentor (m_shuangpinType);
166
 
        pseg->setGetFuzzySyllablesOp (&m_getFuzzySyllablesOp);
 
156
 
 
157
    IPySegmentor* createPySegmentor(){
 
158
        CShuangpinSegmentor *pseg = new CShuangpinSegmentor(m_shuangpinType);
 
159
        pseg->setGetFuzzySyllablesOp(&m_getFuzzySyllablesOp);
167
160
        return pseg;
168
161
    }
169
162
 
170
 
    void setShuangpinType (EShuangpinType t) {m_shuangpinType = t;}
 
163
    void setShuangpinType(EShuangpinType t) { m_shuangpinType = t; }
171
164
 
172
 
    void setFuzzyForwarding (bool enable_fuzzies=true, bool enable_simpler_initials=true)
173
 
    {
174
 
        m_getFuzzySyllablesOp.setEnableFuzzies (enable_fuzzies);
175
 
        m_getFuzzySyllablesOp.setEnableSimplerInitials (enable_simpler_initials);
 
165
    void setFuzzyForwarding(bool enable_fuzzies = true,
 
166
                            bool enable_simpler_initials = true){
 
167
        m_getFuzzySyllablesOp.setEnableFuzzies(enable_fuzzies);
 
168
        m_getFuzzySyllablesOp.setEnableSimplerInitials(enable_simpler_initials);
176
169
    }
177
170
 
178
 
    void clearFuzzyPinyinPairs ()
179
 
        {m_getFuzzySyllablesOp.clearFuzzyMap();}
 
171
    void clearFuzzyPinyinPairs()
 
172
    { m_getFuzzySyllablesOp.clearFuzzyMap(); }
180
173
 
181
 
    void setFuzzyPinyinPairs (const string_pairs& pairs, bool duplex = true)
182
 
        {m_getFuzzySyllablesOp.initFuzzyMap (pairs, duplex);}
 
174
    void setFuzzyPinyinPairs(const string_pairs& pairs, bool duplex = true)
 
175
    { m_getFuzzySyllablesOp.initFuzzyMap(pairs, duplex); }
183
176
 
184
177
    virtual bool onConfigChanged(const COptionEvent& event);
185
 
    
 
178
 
186
179
    template<class> friend class SingletonHolder;
187
 
protected:
188
 
    ~CShuangpinSchemePolicy () {}
 
180
protected: ~CShuangpinSchemePolicy () {}
189
181
 
190
 
    EShuangpinType                      m_shuangpinType;
 
182
    EShuangpinType m_shuangpinType;
191
183
    CGetFuzzySyllablesOp<CPinyinData>   m_getFuzzySyllablesOp;
192
184
};
193
185
 
194
186
typedef SingletonHolder<CShuangpinSchemePolicy> AShuangpinSchemePolicy;
195
187
 
196
 
struct  CHunpinSchemePolicy: public IConfigurable
197
 
{
 
188
struct  CHunpinSchemePolicy : public IConfigurable {
198
189
public:
199
190
    CHunpinSchemePolicy();
200
 
    
201
 
    IPySegmentor* createPySegmentor () 
202
 
    {
203
 
        CHunpinSegmentor *pseg = new CHunpinSegmentor (m_shuangpinType);
204
 
        pseg->setGetFuzzySyllablesOp (&m_getFuzzySyllablesOp);
 
191
 
 
192
    IPySegmentor* createPySegmentor(){
 
193
        CHunpinSegmentor *pseg = new CHunpinSegmentor(m_shuangpinType);
 
194
        pseg->setGetFuzzySyllablesOp(&m_getFuzzySyllablesOp);
205
195
        return pseg;
206
196
    }
207
 
        
208
 
    void setShuangpinType (EShuangpinType t) {m_shuangpinType = t;}
209
 
        
210
 
    void setFuzzyForwarding (bool enable_fuzzies=true, bool enable_simpler_initials=true)
211
 
    {
212
 
        m_getFuzzySyllablesOp.setEnableFuzzies (enable_fuzzies);
213
 
        m_getFuzzySyllablesOp.setEnableSimplerInitials (enable_simpler_initials);
 
197
 
 
198
    void setShuangpinType(EShuangpinType t) { m_shuangpinType = t; }
 
199
 
 
200
    void setFuzzyForwarding(bool enable_fuzzies = true,
 
201
                            bool enable_simpler_initials = true){
 
202
        m_getFuzzySyllablesOp.setEnableFuzzies(enable_fuzzies);
 
203
        m_getFuzzySyllablesOp.setEnableSimplerInitials(enable_simpler_initials);
214
204
    }
215
 
        
216
 
    void clearFuzzyPinyinPairs ()
217
 
        {m_getFuzzySyllablesOp.clearFuzzyMap();}
218
 
        
219
 
    void setFuzzyPinyinPairs (const string_pairs& pairs, bool duplex = true)
220
 
        {m_getFuzzySyllablesOp.initFuzzyMap (pairs, duplex);}
221
 
        
 
205
 
 
206
    void clearFuzzyPinyinPairs()
 
207
    { m_getFuzzySyllablesOp.clearFuzzyMap(); }
 
208
 
 
209
    void setFuzzyPinyinPairs(const string_pairs& pairs, bool duplex = true)
 
210
    { m_getFuzzySyllablesOp.initFuzzyMap(pairs, duplex); }
 
211
 
222
212
    virtual bool onConfigChanged(const COptionEvent& event);
223
 
    
 
213
 
224
214
    template<class> friend class SingletonHolder;
225
 
protected:
226
 
    ~CHunpinSchemePolicy () {}
227
 
        
228
 
    EShuangpinType                      m_shuangpinType;
 
215
protected: ~CHunpinSchemePolicy () {}
 
216
 
 
217
    EShuangpinType m_shuangpinType;
229
218
    CGetFuzzySyllablesOp<CPinyinData>   m_getFuzzySyllablesOp;
230
219
};
231
220
 
232
221
typedef SingletonHolder<CHunpinSchemePolicy> AHunpinSchemePolicy;
233
222
 
234
 
struct CClassicStylePolicy : public IConfigurable
235
 
{
236
 
    CIMIView* createView () {return new CIMIClassicView ();}
 
223
struct CClassicStylePolicy : public IConfigurable {
 
224
    CIMIView* createView() { return new CIMIClassicView(); }
237
225
 
238
226
    template<class> friend class SingletonHolder;
239
 
protected:
240
 
    ~CClassicStylePolicy () {}
 
227
protected: ~CClassicStylePolicy () {}
241
228
};
242
229
 
243
230
typedef SingletonHolder<CClassicStylePolicy> AClassicStylePolicy;
244
231
 
245
 
struct ISunpinyinProfile
246
 
{
247
 
    virtual CIMIView* createProfile () = 0;
248
 
    virtual void destroyProfile (CIMIView *) = 0;
 
232
struct ISunpinyinProfile {
 
233
    virtual CIMIView* createProfile() = 0;
 
234
    virtual void destroyProfile(CIMIView *) = 0;
249
235
    virtual ~ISunpinyinProfile () {};
250
236
};
251
237
 
252
 
template <class LanguagePolicy, class PinyinSchemePolicy, class InputStylePolicy>
 
238
template <class LanguagePolicy, class PinyinSchemePolicy,
 
239
          class InputStylePolicy>
253
240
class CSunpinyinProfile : public ISunpinyinProfile
254
241
{
255
242
public:
256
 
    CSunpinyinProfile () : m_langPolicy(LanguagePolicy::instance()), 
 
243
    CSunpinyinProfile () : m_langPolicy(LanguagePolicy::instance()),
257
244
                           m_pySchemePolicy(PinyinSchemePolicy::instance()),
258
 
                           m_inputStylePolicy(InputStylePolicy::instance()) 
 
245
                           m_inputStylePolicy(InputStylePolicy::instance())
259
246
    {}
260
247
 
261
248
    /* profile by itself is a profile, so we are creating a session here? */
262
 
    virtual CIMIView* createProfile ()
263
 
    {
264
 
        if (!m_langPolicy.loadResources ())
 
249
    virtual CIMIView* createProfile(){
 
250
        if (!m_langPolicy.loadResources())
265
251
            return NULL;
266
252
 
267
 
        IPySegmentor* pseg = m_pySchemePolicy.createPySegmentor ();
 
253
        IPySegmentor* pseg = m_pySchemePolicy.createPySegmentor();
268
254
        if (pseg == NULL)
269
255
            return NULL;
270
 
        
271
 
        CIMIContext *pic = m_langPolicy.createContext ();
272
 
        CIMIView* pview = m_inputStylePolicy.createView ();
273
 
        pview->attachIC (pic);
274
 
        pview->setPySegmentor (pseg);
275
 
        
 
256
 
 
257
        CIMIContext *pic = m_langPolicy.createContext();
 
258
        CIMIView* pview = m_inputStylePolicy.createView();
 
259
        pview->attachIC(pic);
 
260
        pview->setPySegmentor(pseg);
 
261
 
276
262
        return pview;
277
263
    }
278
264
 
279
 
    virtual void destroyProfile(CIMIView* pview)
280
 
    {
 
265
    virtual void destroyProfile(CIMIView* pview){
281
266
        if (pview) {
282
267
            LanguagePolicy::instance().destroyContext(pview->getIC());
283
268
            delete pview->getPySegmentor();
285
270
        }
286
271
    }
287
272
private:
288
 
    typename LanguagePolicy::Type&      m_langPolicy;
289
 
    typename PinyinSchemePolicy::Type&  m_pySchemePolicy;
290
 
    typename InputStylePolicy::Type&    m_inputStylePolicy;
 
273
    typename LanguagePolicy::Type & m_langPolicy;
 
274
    typename PinyinSchemePolicy::Type & m_pySchemePolicy;
 
275
    typename InputStylePolicy::Type & m_inputStylePolicy;
291
276
};
292
277
 
293
278
class CSunpinyinSessionFactory : private CNonCopyable
298
283
        SHUANGPIN,
299
284
        YUEPIN,
300
285
        ZHUYIN,
301
 
                HUNPIN,
 
286
        HUNPIN,
302
287
    } EPyScheme;
303
 
    
 
288
 
304
289
    typedef enum {
305
290
        MSPY_STYLE,
306
291
        CLASSIC_STYLE,
312
297
    } ELanguage;
313
298
 
314
299
public:
315
 
    static CSunpinyinSessionFactory& getFactory ()
316
 
    {
 
300
    static CSunpinyinSessionFactory& getFactory(){
317
301
        static CSunpinyinSessionFactory inst;
318
302
        return inst;
319
303
    }
320
304
 
321
 
    void setLanguage (ELanguage lang) {m_lang = lang;}
322
 
    void setInputStyle (EInputStyle inputStyle) {m_inputStyle = inputStyle;}
323
 
    void setPinyinScheme (EPyScheme pyScheme) {m_pyScheme = pyScheme;}
324
 
    void setCandiWindowSize (unsigned size) {m_candiWindowSize = size;}
 
305
    void setLanguage(ELanguage lang) { m_lang = lang; }
 
306
    void setInputStyle(EInputStyle inputStyle) { m_inputStyle = inputStyle; }
 
307
    void setPinyinScheme(EPyScheme pyScheme) { m_pyScheme = pyScheme; }
 
308
    void setCandiWindowSize(unsigned size) { m_candiWindowSize = size; }
325
309
 
326
 
    CIMIView* createSession ()
327
 
    {
328
 
        unsigned key = _policiesToKey (m_lang, m_pyScheme, m_inputStyle);
 
310
    CIMIView* createSession(){
 
311
        unsigned key = _policiesToKey(m_lang, m_pyScheme, m_inputStyle);
329
312
        ISunpinyinProfile *profile = _getProfile(key);
330
313
        if (!profile)
331
314
            return NULL;
332
 
        
333
 
        CIMIView *pview = profile->createProfile ();
 
315
 
 
316
        CIMIView *pview = profile->createProfile();
334
317
        if (!pview)
335
318
            return NULL;
336
 
        
337
 
        pview->setHotkeyProfile (&m_hotkeyProfile);
338
 
        pview->setCandiWindowSize (m_candiWindowSize);
 
319
 
 
320
        pview->setHotkeyProfile(&m_hotkeyProfile);
 
321
        pview->setCandiWindowSize(m_candiWindowSize);
339
322
        return pview;
340
323
    }
341
324
 
342
 
    void destroySession (CIMIView* pview)
343
 
    {
344
 
        unsigned key = _policiesToKey (m_lang, m_pyScheme, m_inputStyle);
 
325
    void destroySession(CIMIView* pview){
 
326
        unsigned key = _policiesToKey(m_lang, m_pyScheme, m_inputStyle);
345
327
        ISunpinyinProfile *profile = _getProfile(key);
346
328
        if (!profile)
347
329
            return;
350
332
 
351
333
private:
352
334
    CSunpinyinSessionFactory ()
353
 
        : m_pyScheme (QUANPIN), m_inputStyle(CLASSIC_STYLE), m_lang(SIMPLIFIED_CHINESE),
354
 
          m_candiWindowSize(10)
355
 
    {
356
 
        m_profiles [_policiesToKey (SIMPLIFIED_CHINESE, QUANPIN, CLASSIC_STYLE)] = 
357
 
                new CSunpinyinProfile <ASimplifiedChinesePolicy, AQuanpinSchemePolicy, AClassicStylePolicy> ();
 
335
        : m_pyScheme(QUANPIN), m_inputStyle(CLASSIC_STYLE),
 
336
          m_lang(SIMPLIFIED_CHINESE),
 
337
          m_candiWindowSize(10){
 
338
        m_profiles [_policiesToKey(SIMPLIFIED_CHINESE, QUANPIN,
 
339
                                   CLASSIC_STYLE)] =
 
340
            new CSunpinyinProfile <ASimplifiedChinesePolicy,
 
341
                                   AQuanpinSchemePolicy, AClassicStylePolicy> ();
358
342
 
359
 
        m_profiles [_policiesToKey (SIMPLIFIED_CHINESE, SHUANGPIN, CLASSIC_STYLE)] = 
360
 
                new CSunpinyinProfile <ASimplifiedChinesePolicy, AShuangpinSchemePolicy, AClassicStylePolicy> ();
 
343
        m_profiles [_policiesToKey(SIMPLIFIED_CHINESE, SHUANGPIN,
 
344
                                   CLASSIC_STYLE)] =
 
345
            new CSunpinyinProfile <ASimplifiedChinesePolicy,
 
346
                                   AShuangpinSchemePolicy, AClassicStylePolicy> ();
361
347
    }
362
348
 
363
 
    ~CSunpinyinSessionFactory ()
364
 
    {
365
 
        std::map <unsigned, ISunpinyinProfile*>::iterator it  = m_profiles.begin ();
366
 
        std::map <unsigned, ISunpinyinProfile*>::iterator ite = m_profiles.end ();
367
 
        
 
349
    ~CSunpinyinSessionFactory (){
 
350
        std::map <unsigned, ISunpinyinProfile*>::iterator it = m_profiles.begin();
 
351
        std::map <unsigned, ISunpinyinProfile*>::iterator ite = m_profiles.end();
 
352
 
368
353
        for (; it != ite; ++it)
369
354
            delete it->second;
370
355
    }
371
356
 
372
 
    ISunpinyinProfile* _getProfile(unsigned key)
373
 
    {
374
 
        std::map <unsigned, ISunpinyinProfile*>::iterator it = m_profiles.find (key);
 
357
    ISunpinyinProfile* _getProfile(unsigned key){
 
358
        std::map <unsigned, ISunpinyinProfile*>::iterator it = m_profiles.find(
 
359
            key);
375
360
        if (it != m_profiles.end()) {
376
361
            return it->second;
377
362
        } else {
379
364
        }
380
365
    }
381
366
 
382
 
    unsigned _policiesToKey (ELanguage lang, EPyScheme pyScheme, EInputStyle inputStyle)
383
 
        {return (lang<<16) + (pyScheme<<8) + inputStyle;}
384
 
    
 
367
    unsigned _policiesToKey(ELanguage lang,
 
368
                            EPyScheme pyScheme,
 
369
                            EInputStyle inputStyle)
 
370
    { return (lang << 16) + (pyScheme << 8) + inputStyle; }
 
371
 
385
372
    std::map <unsigned, ISunpinyinProfile*> m_profiles;
386
373
 
387
 
    EPyScheme           m_pyScheme;
388
 
    EInputStyle         m_inputStyle;
389
 
    ELanguage           m_lang;
390
 
    unsigned            m_candiWindowSize;
391
 
    CHotkeyProfile      m_hotkeyProfile;
 
374
    EPyScheme m_pyScheme;
 
375
    EInputStyle m_inputStyle;
 
376
    ELanguage m_lang;
 
377
    unsigned m_candiWindowSize;
 
378
    CHotkeyProfile m_hotkeyProfile;
392
379
};
393
380
 
394
381
#endif