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/optional.hpp>
49 std::string to_string () const;
50 std::string description () const;
56 SubtagData (std::string subtag_, std::string description_)
58 , description(description_)
62 std::string description;
64 bool operator== (SubtagData const& other) {
65 return subtag == other.subtag && description == other.description;
81 std::string subtag () const {
86 Subtag (std::string subtag, SubtagType type);
92 class LanguageSubtag : public Subtag
95 LanguageSubtag (std::string subtag)
96 : Subtag(subtag, LANGUAGE) {}
97 LanguageSubtag (char const* subtag)
98 : Subtag(subtag, LANGUAGE) {}
101 class ScriptSubtag : public Subtag
104 ScriptSubtag (std::string subtag)
105 : Subtag(subtag, SCRIPT) {}
106 ScriptSubtag (char const* subtag)
107 : Subtag(subtag, SCRIPT) {}
110 class RegionSubtag : public Subtag
113 RegionSubtag (std::string subtag)
114 : Subtag(subtag, REGION) {}
115 RegionSubtag (char const* subtag)
116 : Subtag(subtag, REGION) {}
119 class VariantSubtag : public Subtag
122 VariantSubtag (std::string subtag)
123 : Subtag(subtag, VARIANT) {}
124 VariantSubtag (char const* subtag)
125 : Subtag(subtag, VARIANT) {}
127 bool operator== (VariantSubtag const& other) const;
128 bool operator< (VariantSubtag const& other) const;
132 class ExtlangSubtag : public Subtag
135 ExtlangSubtag (std::string subtag)
136 : Subtag(subtag, EXTLANG) {}
137 ExtlangSubtag (char const* subtag)
138 : Subtag(subtag, EXTLANG) {}
140 bool operator== (ExtlangSubtag const& other) const;
141 bool operator< (ExtlangSubtag const& other) const;
144 void set_language (LanguageSubtag language);
145 void set_script (ScriptSubtag script);
146 void set_region (RegionSubtag region);
147 void set_variants (std::vector<VariantSubtag> variants);
148 void add_variant (VariantSubtag variant);
149 void set_extlangs (std::vector<ExtlangSubtag> extlangs);
150 void add_extlang (ExtlangSubtag extlang);
152 static std::vector<SubtagData> get_all (SubtagType type);
153 static std::string subtag_type_name (SubtagType type);
156 boost::optional<LanguageSubtag> _language;
157 boost::optional<ScriptSubtag> _script;
158 boost::optional<RegionSubtag> _region;
159 std::vector<VariantSubtag> _variants;
160 std::vector<ExtlangSubtag> _extlangs;