Add language description -> enum.
[libsub.git] / src / stl_binary_tables.h
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <string>
21 #include <map>
22 #include <boost/optional.hpp>
23
24 namespace sub {
25
26 enum DisplayStandard {
27         DISPLAY_STANDARD_UNDEFINED,
28         DISPLAY_STANDARD_OPEN_SUBTITLING,
29         DISPLAY_STANDARD_LEVEL_1_TELETEXT,
30         DISPLAY_STANDARD_LEVEL_2_TELETEXT
31 };
32         
33 enum LanguageGroup {
34         LANGUAGE_GROUP_LATIN,
35         LANGUAGE_GROUP_LATIN_CYRILLIC,
36         LANGUAGE_GROUP_LATIN_ARABIC,
37         LANGUAGE_GROUP_LATIN_GREEK,
38         LANGUAGE_GROUP_LATIN_HEBREW
39 };
40
41 enum Language {
42         LANGUAGE_UNKNOWN,
43         LANGUAGE_ALBANIAN,
44         LANGUAGE_BRETON,
45         LANGUAGE_CATALAN,
46         LANGUAGE_CROATIAN,
47         LANGUAGE_WELSH,
48         LANGUAGE_CZECH,
49         LANGUAGE_DANISH,
50         LANGUAGE_GERMAN,
51         LANGUAGE_ENGLISH,
52         LANGUAGE_SPANISH,
53         LANGUAGE_ESPERANTO,
54         LANGUAGE_ESTONIAN,
55         LANGUAGE_BASQUE,
56         LANGUAGE_FAROESE,
57         LANGUAGE_FRENCH,
58         LANGUAGE_FRISIAN,
59         LANGUAGE_IRISH,
60         LANGUAGE_GAELIC,
61         LANGUAGE_GALACIAN,
62         LANGUAGE_ICELANDIC,
63         LANGUAGE_ITALIAN,
64         LANGUAGE_LAPPISH,
65         LANGUAGE_LATIN,
66         LANGUAGE_LATVIAN,
67         LANGUAGE_LUXEMBORGIAN,
68         LANGUAGE_LITHUANIAN,
69         LANGUAGE_HUNGARIAN,
70         LANGUAGE_MALTESE,
71         LANGUAGE_DUTCH,
72         LANGUAGE_NORWEGIAN,
73         LANGUAGE_OCCITAN,
74         LANGUAGE_POLISH,
75         LANGUAGE_PORTUGESE,
76         LANGUAGE_ROMANIAN,
77         LANGUAGE_ROMANSH,
78         LANGUAGE_SERBIAN,
79         LANGUAGE_SLOVAK,
80         LANGUAGE_SLOVENIAN,
81         LANGUAGE_FINNISH,
82         LANGUAGE_SWEDISH,
83         LANGUAGE_TURKISH,
84         LANGUAGE_FLEMISH,
85         LANGUAGE_WALLON,
86         LANGUAGE_AMHARIC,
87         LANGUAGE_ARABIC,
88         LANGUAGE_ARMENIAN,
89         LANGUAGE_ASSAMESE,
90         LANGUAGE_AZERBAIJANI,
91         LANGUAGE_BAMBORA,
92         LANGUAGE_BIELORUSSIAN,
93         LANGUAGE_BENGALI,
94         LANGUAGE_BULGARIAN,
95         LANGUAGE_BURMESE,
96         LANGUAGE_CHINESE,
97         LANGUAGE_CHURASH,
98         LANGUAGE_DARI,
99         LANGUAGE_FULANI,
100         LANGUAGE_GEORGIAN,
101         LANGUAGE_GREEK,
102         LANGUAGE_GUJURATI,
103         LANGUAGE_GURANI,
104         LANGUAGE_HAUSA,
105         LANGUAGE_HEBREW,
106         LANGUAGE_HINDI,
107         LANGUAGE_INDONESIAN,
108         LANGUAGE_JAPANESE,
109         LANGUAGE_KANNADA,
110         LANGUAGE_KAZAKH,
111         LANGUAGE_KHMER,
112         LANGUAGE_KOREAN,
113         LANGUAGE_LAOTIAN,
114         LANGUAGE_MACEDONIAN,
115         LANGUAGE_MALAGASAY,
116         LANGUAGE_MALAYSIAN,
117         LANGUAGE_MOLDAVIAN,
118         LANGUAGE_MARATHI,
119         LANGUAGE_NDEBELE,
120         LANGUAGE_NEPALI,
121         LANGUAGE_ORIYA,
122         LANGUAGE_PAPAMIENTO,
123         LANGUAGE_PERSIAN,
124         LANGUAGE_PUNJABI,
125         LANGUAGE_PUSHTU,
126         LANGUAGE_QUECHUA,
127         LANGUAGE_RUSSIAN,
128         LANGUAGE_RUTHENIAN,
129         LANGUAGE_SERBO_CROAT,
130         LANGUAGE_SHONA,
131         LANGUAGE_SINHALESE,
132         LANGUAGE_SOMALI,
133         LANGUAGE_SRANAN_TONGO,
134         LANGUAGE_SWAHILI,
135         LANGUAGE_TADZHIK,
136         LANGUAGE_TAMIL,
137         LANGUAGE_TATAR,
138         LANGUAGE_TELUGU,
139         LANGUAGE_THAI,
140         LANGUAGE_UKRANIAN,
141         LANGUAGE_URDU,
142         LANGUAGE_UZBEK,
143         LANGUAGE_VIETNAMESE,
144         LANGUAGE_ZULU
145 };
146
147 enum TimecodeStatus {
148         TIMECODE_STATUS_NOT_INTENDED_FOR_USE,
149         TIMECODE_STATUS_INTENDED_FOR_USE
150 };
151
152 enum CumulativeStatus {
153         CUMULATIVE_STATUS_NOT_CUMULATIVE,
154         CUMULATIVE_STATUS_FIRST,
155         CUMULATIVE_STATUS_INTERMEDIATE,
156         CUMULATIVE_STATUS_LAST
157 };
158
159 enum Justification {
160         JUSTIFICATION_NONE,
161         JUSTIFICATION_LEFT,
162         JUSTIFICATION_CENTRE,
163         JUSTIFICATION_RIGHT
164 };
165
166 enum Comment {
167         COMMENT_NO,
168         COMMENT_YES
169 };
170
171 /** @class STLBinaryCode
172  *  @brief A value of some STL parameter and a human-readable description of what it means.
173  */
174 template<class T>
175 class STLBinaryCode
176 {
177 public:
178         STLBinaryCode ()
179                 : value ((T) 0)
180         {}
181
182         STLBinaryCode (T v, std::string d)
183                 : value (v)
184                 , description (d)
185         {}
186         
187         T value;
188         std::string description;
189 };
190
191 /** @class STLBinaryTables
192  *  @brief A set of conversion tables for STL binary files.
193  */
194 class STLBinaryTables
195 {
196 public:
197         STLBinaryTables ();
198
199         DisplayStandard display_standard_file_to_enum (std::string) const;
200         LanguageGroup language_group_file_to_enum (std::string) const;
201         Language language_file_to_enum (std::string) const;
202         TimecodeStatus timecode_status_file_to_enum (std::string) const;
203         CumulativeStatus cumulative_status_file_to_enum (int) const;
204         Justification justification_file_to_enum (int) const;
205         Comment comment_file_to_enum (int) const;
206
207         std::string language_enum_to_file (Language) const;
208         int cumulative_status_enum_to_file (CumulativeStatus) const;
209         int justification_enum_to_file (Justification) const;
210         int comment_enum_to_file (Comment) const;
211
212         std::string display_standard_enum_to_description (DisplayStandard) const;
213         std::string language_group_enum_to_description (LanguageGroup) const;
214         std::string language_enum_to_description (Language) const;
215         std::string timecode_status_enum_to_description (TimecodeStatus) const;
216         std::string cumulative_status_enum_to_description (CumulativeStatus) const;
217         std::string justification_enum_to_description (Justification) const;
218         std::string comment_enum_to_description (Comment) const;
219
220         boost::optional<Language> language_description_to_enum (std::string) const;
221
222 private:        
223         std::map<std::string, STLBinaryCode<DisplayStandard> > _display_standard_map;
224         std::map<std::string, STLBinaryCode<LanguageGroup> > _language_group_map;
225         std::map<std::string, STLBinaryCode<Language> > _language_map;
226         std::map<std::string, STLBinaryCode<TimecodeStatus> > _timecode_status_map;
227         std::map<int, STLBinaryCode<CumulativeStatus> > _cumulative_status_map;
228         std::map<int, STLBinaryCode<Justification> > _justification_map;
229         std::map<int, STLBinaryCode<Comment> > _comment_map;
230 };
231
232 }