Debian Codegraph @

src/conversion.h

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Copyright (C) 2005 Takuro Ashie
4 * Copyright (C) 2012 CSSlayer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef __FCITX_ANTHY_CONVERSION_H__
22 #define __FCITX_ANTHY_CONVERSION_H__
23
24 #include <anthy/anthy.h>
25 #include <fcitx/candidate.h>
26 #include "reading.h"
27
28 class AnthyInstance;
29
30 typedef enum {
31 FCITX_ANTHY_CANDIDATE_DEFAULT = 0,
32 FCITX_ANTHY_CANDIDATE_LATIN = -1,
33 FCITX_ANTHY_CANDIDATE_WIDE_LATIN = -2,
34 FCITX_ANTHY_CANDIDATE_HIRAGANA = -3,
35 FCITX_ANTHY_CANDIDATE_KATAKANA = -4,
36 FCITX_ANTHY_CANDIDATE_HALF_KATAKANA = -5,
37 FCITX_ANTHY_CANDIDATE_HALF = -6,
38 FCITX_ANTHY_LAST_SPECIAL_CANDIDATE = -7,
39 } CandidateType;
40
41 class ConversionSegment
42 {
43 public:
44 ConversionSegment (std::string str,
45 int cand_id,
46 unsigned int reading_len);
47 virtual ~ConversionSegment ();
48
49 std::string & get_string (void);
50 int get_candidate_id (void);
51 unsigned int get_reading_length (void);
52
53 void set (std::string str,
54 int cand_id);
55 void set_reading_length (unsigned int len);
56
57 private:
58 std::string m_string;
59 int m_cand_id;
60 unsigned int m_reading_len;
61 };
62 typedef std::vector<ConversionSegment> ConversionSegments;
63
64 class Conversion
65 {
66 public:
67 Conversion (AnthyInstance &anthy, Reading &reading);
68 virtual ~Conversion ();
69
70 // starting and finishing
71 void convert (std::string source,
72 CandidateType ctype,
73 bool single_segment);
74 void convert (CandidateType type
75 = FCITX_ANTHY_CANDIDATE_DEFAULT,
76 bool single_segment = false);
77 void convert (const std::string &source,
78 bool single_segment = false);
79 void predict (void);
80 void clear (int segment_id = -1);
81 void commit (int segment_id = -1,
82 bool learn = true);
83
84 // getting status
85 bool is_converting (void);
86 bool is_predicting (void);
87
88 std::string get (void);
89 unsigned int get_length (void);
90 unsigned int get_length_by_char (void);
91 void update_preedit (void);
92
93 // segments of the converted sentence
94 int get_nr_segments (void);
95 std::string get_segment_string (int segment_id = -1,
96 int candidate_id
97 = FCITX_ANTHY_LAST_SPECIAL_CANDIDATE);
98 int get_selected_segment (void);
99 void select_segment (int segment_id);
100 int get_segment_size (int segment_id = -1);
101 void resize_segment (int relative_size,
102 int segment_id = -1);
103 unsigned int get_segment_position (int segment_id = -1);
104
105 // candidates for a segment or prediction
106 void get_candidates (FcitxCandidateWordList* candList,
107 int segment_id = -1);
108 int get_selected_candidate (int segment_id = -1);
109 void select_candidate (int candidate_id,
110 int segment_id = -1);
111
112 private:
113 void get_reading_substr (std::string &string,
114 int segment_id,
115 int candidate_id,
116 int seg_start,
117 int seg_len);
118 std::string get_prediction_string (int candidate_id);
119 void join_all_segments (void);
120
121 private:
122 AnthyInstance &m_anthy;
123
124 // convertors
125 Reading &m_reading;
126 anthy_context_t m_anthy_context;
127
128 // status variables
129 ConversionSegments m_segments;
130 int m_start_id; // number of commited segments
131 int m_cur_segment; // relative position from m_start_id
132 bool m_predicting;
133 };
134
135
136 #endif /* __FCITX_ANTHY_READING_H__ */
137 /*
138 vi:ts=4:nowrap:ai:expandtab
139 */