2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp 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 of the License, or
9 (at your option) any later version.
11 libdcp 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.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
34 #ifndef LIBDCP_LANGUAGE_TAG_H
35 #define LIBDCP_LANGUAGE_TAG_H
38 #include <boost/filesystem.hpp>
39 #include <boost/optional.hpp>
50 std::string to_string () const;
51 std::string description () const;
57 SubtagData (std::string subtag_, std::string description_)
59 , description(description_)
63 std::string description;
65 bool operator== (SubtagData const& other) {
66 return subtag == other.subtag && description == other.description;
84 std::string subtag () const {
88 virtual SubtagType type () const = 0;
90 bool operator== (Subtag const& other) {
91 return _subtag == other._subtag;
95 Subtag (std::string subtag, SubtagType type);
101 class LanguageSubtag : public Subtag
104 LanguageSubtag (std::string subtag)
105 : Subtag(subtag, LANGUAGE) {}
106 LanguageSubtag (char const* subtag)
107 : Subtag(subtag, LANGUAGE) {}
109 SubtagType type () const {
114 class ScriptSubtag : public Subtag
117 ScriptSubtag (std::string subtag)
118 : Subtag(subtag, SCRIPT) {}
119 ScriptSubtag (char const* subtag)
120 : Subtag(subtag, SCRIPT) {}
122 SubtagType type () const {
127 class RegionSubtag : public Subtag
130 RegionSubtag (std::string subtag)
131 : Subtag(subtag, REGION) {}
132 RegionSubtag (char const* subtag)
133 : Subtag(subtag, REGION) {}
135 SubtagType type () const {
140 class VariantSubtag : public Subtag
143 VariantSubtag (std::string subtag)
144 : Subtag(subtag, VARIANT) {}
145 VariantSubtag (char const* subtag)
146 : Subtag(subtag, VARIANT) {}
148 SubtagType type () const {
152 bool operator== (VariantSubtag const& other) const;
153 bool operator< (VariantSubtag const& other) const;
157 class ExtlangSubtag : public Subtag
160 ExtlangSubtag (std::string subtag)
161 : Subtag(subtag, EXTLANG) {}
162 ExtlangSubtag (char const* subtag)
163 : Subtag(subtag, EXTLANG) {}
165 SubtagType type () const {
169 bool operator== (ExtlangSubtag const& other) const;
170 bool operator< (ExtlangSubtag const& other) const;
174 explicit LanguageTag (std::string tag);
176 boost::optional<LanguageSubtag> language() const {
180 void set_language (LanguageSubtag language);
182 boost::optional<ScriptSubtag> script() const {
186 void set_script (ScriptSubtag script);
188 boost::optional<RegionSubtag> region() const {
192 void set_region (RegionSubtag region);
194 std::vector<VariantSubtag> variants() const {
198 void set_variants (std::vector<VariantSubtag> variants);
199 void add_variant (VariantSubtag variant);
201 std::vector<ExtlangSubtag> extlangs() const {
205 void set_extlangs (std::vector<ExtlangSubtag> extlangs);
206 void add_extlang (ExtlangSubtag extlang);
208 std::vector<std::pair<SubtagType, SubtagData> > subtags () const;
210 static std::vector<SubtagData> const& get_all (SubtagType type);
211 static std::string subtag_type_name (SubtagType type);
213 static boost::optional<std::string> get_subtag_description (SubtagType, std::string subtag);
214 static boost::optional<SubtagData > get_subtag_data (SubtagType, std::string subtag);
217 static boost::optional<std::string> get_subtag_description (T s) {
218 return get_subtag_description (s.type(), s.subtag());
222 static boost::optional<SubtagData> get_subtag_data (T s) {
223 return get_subtag_data (s.type(), s.subtag());
228 boost::optional<LanguageSubtag> _language;
229 boost::optional<ScriptSubtag> _script;
230 boost::optional<RegionSubtag> _region;
231 std::vector<VariantSubtag> _variants;
232 std::vector<ExtlangSubtag> _extlangs;
235 extern bool operator==(dcp::LanguageTag const& a, dcp::LanguageTag const& b);
236 extern std::ostream& operator<<(std::ostream& os, dcp::LanguageTag const& tag);
239 extern void load_language_tag_lists (boost::filesystem::path tags_directory);