Tizen 2.1 base
[framework/uifw/ise-engine-anthy.git] / src / scim_anthy_style_file.h
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *  Copyright (C) 2005 Takuro Ashie
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __SCIM_ANTHY_STYLE_FILE_H__
21 #define __SCIM_ANTHY_STYLE_FILE_H__
22
23 #define Uses_SCIM_ICONV
24 #include <scim.h>
25
26 #include "scim_anthy_key2kana_table.h"
27
28 using namespace scim;
29
30 namespace scim_anthy {
31
32 class StyleLine;
33 class StyleSection;
34 class StyleFile;
35
36 typedef std::vector<StyleLine>  StyleLines;
37 typedef std::vector<StyleLines> StyleSections;
38 typedef std::vector<StyleFile>  StyleFiles;
39
40 typedef enum {
41     SCIM_ANTHY_STYLE_LINE_UNKNOWN,
42     SCIM_ANTHY_STYLE_LINE_SPACE,
43     SCIM_ANTHY_STYLE_LINE_COMMENT,
44     SCIM_ANTHY_STYLE_LINE_SECTION,
45     SCIM_ANTHY_STYLE_LINE_KEY,
46 } StyleLineType;
47
48 class StyleLine
49 {
50 public:
51     StyleLine (StyleFile  *style_file,
52                String      line);
53     StyleLine (StyleFile  *style_file,
54                String      key,
55                String      value);
56     StyleLine (StyleFile  *style_file,
57                String      key,
58                std::vector<String> &value);
59     ~StyleLine ();
60
61 public:
62     StyleLineType get_type        (void);
63     void          get_line        (String     &line) { line = m_line; }
64     bool          get_section     (String     &section);
65     bool          get_key         (String     &key);
66     bool          get_value       (String     &value);
67     void          set_value       (String      value);
68     bool          get_value_array (std::vector<String> &value);
69     void          set_value_array (std::vector<String> &value);
70
71 private:
72     StyleFile     *m_style_file;
73     String         m_line;
74     StyleLineType  m_type;
75 };
76
77 class StyleFile
78 {
79 public:
80     StyleFile ();
81     ~StyleFile ();
82
83 public:
84     bool   load                  (const char *filename);
85     bool   save                  (const char *filename);
86
87     String get_encoding          (void);
88     String get_title             (void);
89     String get_file_name         (void);
90
91     bool   get_section_list      (StyleSections &sections);
92     bool   get_entry_list        (StyleLines    &lines,
93                                   String         section);
94     bool   get_key_list          (std::vector<String> &keys,
95                                   String         section);
96     bool   get_string            (String        &value,
97                                   String         section,
98                                   String         key);
99     bool   get_string            (WideString    &value,
100                                   String         section,
101                                   String         key);
102     bool   get_string_array      (std::vector<String> &value,
103                                   String         section,
104                                   String         key);
105     bool   get_string_array      (std::vector<WideString> &value,
106                                   String         section,
107                                   String         key);
108
109     void   set_string            (String         section,
110                                   String         key,
111                                   String         value);
112     void   set_string            (String         section,
113                                   String         key,
114                                   WideString     value);
115     void   set_string_array      (String         section,
116                                   String         key,
117                                   std::vector<String> &value);
118     void   set_string_array      (String         section,
119                                   String         key,
120                                   std::vector<WideString> &value);
121
122     void   delete_key            (String         section,
123                                   String         key);
124     void   delete_section        (String         section);
125
126 public: // for getting specific data
127     Key2KanaTable *
128            get_key2kana_table    (String         section);
129
130 private:
131     void   clear                 (void);
132     void   setup_default_entries (void);
133     StyleLines *
134            find_section          (const String  &section);
135     StyleLines &
136            append_new_section    (const String  &section);
137
138 private:
139     IConvert      m_iconv;
140
141     String        m_filename;
142     String        m_format_version;
143     String        m_encoding;
144     String        m_title;
145     String        m_version;
146
147     StyleSections m_sections;
148 };
149
150 }
151
152 #endif /* __SCIM_ANTHY_STYLE_FILE_H__ */