Various fixes to STL read/write.
[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
23 namespace sub {
24
25 enum DisplayStandard {
26         DISPLAY_STANDARD_UNDEFINED,
27         DISPLAY_STANDARD_OPEN_SUBTITLING,
28         DISPLAY_STANDARD_LEVEL_1_TELETEXT,
29         DISPLAY_STANDARD_LEVEL_2_TELETEXT
30 };
31         
32 enum LanguageGroup {
33         LANGUAGE_GROUP_LATIN,
34         LANGUAGE_GROUP_LATIN_CYRILLIC,
35         LANGUAGE_GROUP_LATIN_ARABIC,
36         LANGUAGE_GROUP_LATIN_GREEK,
37         LANGUAGE_GROUP_LATIN_HEBREW
38 };
39
40 enum Language {
41         LANGUAGE_UNKNOWN,
42         LANGUAGE_ALBANIAN,
43         LANGUAGE_BRETON,
44         LANGUAGE_CATALAN,
45         LANGUAGE_CROATIAN,
46         LANGUAGE_WELSH,
47         LANGUAGE_CZECH,
48         LANGUAGE_DANISH,
49         LANGUAGE_GERMAN,
50         LANGUAGE_ENGLISH,
51         LANGUAGE_SPANISH,
52         LANGUAGE_ESPERANTO,
53         LANGUAGE_ESTONIAN,
54         LANGUAGE_BASQUE,
55         LANGUAGE_FAROESE,
56         LANGUAGE_FRENCH,
57         LANGUAGE_FRISIAN,
58         LANGUAGE_IRISH,
59         LANGUAGE_GAELIC,
60         LANGUAGE_GALACIAN,
61         LANGUAGE_ICELANDIC,
62         LANGUAGE_ITALIAN,
63         LANGUAGE_LAPPISH,
64         LANGUAGE_LATIN,
65         LANGUAGE_LATVIAN,
66         LANGUAGE_LUXEMBORGIAN,
67         LANGUAGE_LITHUANIAN,
68         LANGUAGE_HUNGARIAN,
69         LANGUAGE_MALTESE,
70         LANGUAGE_DUTCH,
71         LANGUAGE_NORWEGIAN,
72         LANGUAGE_OCCITAN,
73         LANGUAGE_POLISH,
74         LANGUAGE_PORTUGESE,
75         LANGUAGE_ROMANIAN,
76         LANGUAGE_ROMANSH,
77         LANGUAGE_SERBIAN,
78         LANGUAGE_SLOVAK,
79         LANGUAGE_SLOVENIAN,
80         LANGUAGE_FINNISH,
81         LANGUAGE_SWEDISH,
82         LANGUAGE_TURKISH,
83         LANGUAGE_FLEMISH,
84         LANGUAGE_WALLON,
85         LANGUAGE_AMHARIC,
86         LANGUAGE_ARABIC,
87         LANGUAGE_ARMENIAN,
88         LANGUAGE_ASSAMESE,
89         LANGUAGE_AZERBAIJANI,
90         LANGUAGE_BAMBORA,
91         LANGUAGE_BIELORUSSIAN,
92         LANGUAGE_BENGALI,
93         LANGUAGE_BULGARIAN,
94         LANGUAGE_BURMESE,
95         LANGUAGE_CHINESE,
96         LANGUAGE_CHURASH,
97         LANGUAGE_DARI,
98         LANGUAGE_FULANI,
99         LANGUAGE_GEORGIAN,
100         LANGUAGE_GREEK,
101         LANGUAGE_GUJURATI,
102         LANGUAGE_GURANI,
103         LANGUAGE_HAUSA,
104         LANGUAGE_HEBREW,
105         LANGUAGE_HINDI,
106         LANGUAGE_INDONESIAN,
107         LANGUAGE_JAPANESE,
108         LANGUAGE_KANNADA,
109         LANGUAGE_KAZAKH,
110         LANGUAGE_KHMER,
111         LANGUAGE_KOREAN,
112         LANGUAGE_LAOTIAN,
113         LANGUAGE_MACEDONIAN,
114         LANGUAGE_MALAGASAY,
115         LANGUAGE_MALAYSIAN,
116         LANGUAGE_MOLDAVIAN,
117         LANGUAGE_MARATHI,
118         LANGUAGE_NDEBELE,
119         LANGUAGE_NEPALI,
120         LANGUAGE_ORIYA,
121         LANGUAGE_PAPAMIENTO,
122         LANGUAGE_PERSIAN,
123         LANGUAGE_PUNJABI,
124         LANGUAGE_PUSHTU,
125         LANGUAGE_QUECHUA,
126         LANGUAGE_RUSSIAN,
127         LANGUAGE_RUTHENIAN,
128         LANGUAGE_SERBO_CROAT,
129         LANGUAGE_SHONA,
130         LANGUAGE_SINHALESE,
131         LANGUAGE_SOMALI,
132         LANGUAGE_SRANAN_TONGO,
133         LANGUAGE_SWAHILI,
134         LANGUAGE_TADZHIK,
135         LANGUAGE_TAMIL,
136         LANGUAGE_TATAR,
137         LANGUAGE_TELUGU,
138         LANGUAGE_THAI,
139         LANGUAGE_UKRANIAN,
140         LANGUAGE_URDU,
141         LANGUAGE_UZBEK,
142         LANGUAGE_VIETNAMESE,
143         LANGUAGE_ZULU
144 };
145
146 enum TimecodeStatus {
147         TIMECODE_STATUS_NOT_INTENDED_FOR_USE,
148         TIMECODE_STATUS_INTENDED_FOR_USE
149 };
150
151 enum CumulativeStatus {
152         CUMULATIVE_STATUS_NOT_CUMULATIVE,
153         CUMULATIVE_STATUS_FIRST,
154         CUMULATIVE_STATUS_INTERMEDIATE,
155         CUMULATIVE_STATUS_LAST
156 };
157
158 enum Justification {
159         JUSTIFICATION_NONE,
160         JUSTIFICATION_LEFT,
161         JUSTIFICATION_CENTRE,
162         JUSTIFICATION_RIGHT
163 };
164
165 enum Comment {
166         COMMENT_NO,
167         COMMENT_YES
168 };
169
170 template<class T>
171 class STLBinaryCode
172 {
173 public:
174         STLBinaryCode ()
175                 : value ((T) 0)
176         {}
177
178         STLBinaryCode (T v, std::string d)
179                 : value (v)
180                 , description (d)
181         {}
182         
183         T value;
184         std::string description;
185 };
186
187 class STLBinaryTables
188 {
189 public:
190         STLBinaryTables ();
191
192         DisplayStandard display_standard_file_to_enum (std::string) const;
193         LanguageGroup language_group_file_to_enum (std::string) const;
194         Language language_file_to_enum (std::string) const;
195         TimecodeStatus timecode_status_file_to_enum (std::string) const;
196         CumulativeStatus cumulative_status_file_to_enum (int) const;
197         Justification justification_file_to_enum (int) const;
198         Comment comment_file_to_enum (int) const;
199
200         std::string language_enum_to_file (Language) const;
201         int cumulative_status_enum_to_file (CumulativeStatus) const;
202         int justification_enum_to_file (Justification) const;
203         int comment_enum_to_file (Comment) const;
204
205         std::string display_standard_enum_to_description (DisplayStandard) const;
206         std::string language_group_enum_to_description (LanguageGroup) const;
207         std::string language_enum_to_description (Language) const;
208         std::string timecode_status_enum_to_description (TimecodeStatus) const;
209         std::string cumulative_status_enum_to_description (CumulativeStatus) const;
210         std::string justification_enum_to_description (Justification) const;
211         std::string comment_enum_to_description (Comment) const;
212
213 private:        
214         std::map<std::string, STLBinaryCode<DisplayStandard> > _display_standard_map;
215         std::map<std::string, STLBinaryCode<LanguageGroup> > _language_group_map;
216         std::map<std::string, STLBinaryCode<Language> > _language_map;
217         std::map<std::string, STLBinaryCode<TimecodeStatus> > _timecode_status_map;
218         std::map<int, STLBinaryCode<CumulativeStatus> > _cumulative_status_map;
219         std::map<int, STLBinaryCode<Justification> > _justification_map;
220         std::map<int, STLBinaryCode<Comment> > _comment_map;
221 };
222
223 }