~ubuntu-branches/ubuntu/saucy/ibus-pinyin/saucy-proposed

« back to all changes in this revision

Viewing changes to src/PYPhrase.h

  • Committer: Bazaar Package Importer
  • Author(s): LI Daobing, Asias He
  • Date: 2010-09-08 21:38:54 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100908213854-q4wlx8zlcyqxvelz
Tags: 1.3.11-1
[ Asias He ]
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim:set et ts=4 sts=4:
 
2
 *
 
3
 * ibus-pinyin - The Chinese PinYin engine for IBus
 
4
 *
 
5
 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2, or (at your option)
 
10
 * any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 */
 
21
#ifndef __PY_PHRASE_H_
 
22
#define __PY_PHRASE_H_
 
23
 
 
24
#include <cstring>
 
25
#include "PYTypes.h"
 
26
 
 
27
namespace PY {
 
28
 
 
29
#define PHRASE_LEN_IN_BYTE (MAX_UTF8_LEN * (MAX_PHRASE_LEN + 1))
 
30
 
 
31
struct Phrase {
 
32
    gchar phrase[PHRASE_LEN_IN_BYTE];
 
33
    guint freq;
 
34
    guint user_freq;
 
35
    struct {
 
36
        guint8 sheng;
 
37
        guint8 yun;
 
38
    } pinyin_id[MAX_PHRASE_LEN];
 
39
    guint len;
 
40
 
 
41
    void reset (void)
 
42
    {
 
43
        phrase[0] = 0;
 
44
        freq = 0;
 
45
        user_freq = 0;
 
46
        len = 0;
 
47
    }
 
48
 
 
49
    gboolean empty (void) const
 
50
    {
 
51
        return len == 0;
 
52
    }
 
53
 
 
54
    Phrase & operator += (const Phrase & a)
 
55
    {
 
56
        g_assert (len + a.len <= MAX_PHRASE_LEN);
 
57
        g_strlcat (phrase, a.phrase, sizeof (phrase));
 
58
        std::memcpy (pinyin_id + len, a.pinyin_id, a.len << 1);
 
59
        len += a.len;
 
60
        return *this;
 
61
    }
 
62
 
 
63
    operator const gchar * (void) const
 
64
    {
 
65
        return phrase;
 
66
    }
 
67
 
 
68
};
 
69
 
 
70
};
 
71
 
 
72
#endif