Cleanup: fix more comments/guards (and add check script).
[libdcp.git] / src / language_tag.h
index 74b4a8a77023a774ed2cc31234388d8dd0715bb1..3232dda9fd316faddfa2d356eac07b7c7e5c90e6 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
     files in the program, then also delete it here.
 */
 
+
+/** @file  src/language_tag.h
+ *  @brief LanguageTag class
+ */
+
+
 #ifndef LIBDCP_LANGUAGE_TAG_H
 #define LIBDCP_LANGUAGE_TAG_H
 
 
+#include <boost/filesystem.hpp>
 #include <boost/optional.hpp>
 #include <string>
 #include <vector>
@@ -61,12 +68,16 @@ public:
                std::string subtag;
                std::string description;
 
-               bool operator== (SubtagData const& other) {
+               bool operator== (SubtagData const& other) const {
                        return subtag == other.subtag && description == other.description;
                }
+
+               bool operator!=(SubtagData const& other) const {
+                       return subtag != other.subtag || description != other.description;
+               }
        };
 
-       enum SubtagType
+       enum class SubtagType
        {
                LANGUAGE,
                SCRIPT,
@@ -78,16 +89,26 @@ public:
        class Subtag
        {
        public:
+               virtual ~Subtag () {}
+
                std::string subtag () const {
                        return _subtag;
                }
 
                virtual SubtagType type () const = 0;
 
-               bool operator== (Subtag const& other) {
+               bool operator== (Subtag const& other) const {
                        return _subtag == other._subtag;
                }
 
+               bool operator!=(Subtag const& other) const {
+                       return _subtag != other._subtag;
+               }
+
+               bool operator<(Subtag const& other) const {
+                       return _subtag < other._subtag;
+               }
+
        protected:
                Subtag (std::string subtag, SubtagType type);
 
@@ -99,12 +120,12 @@ public:
        {
        public:
                LanguageSubtag (std::string subtag)
-                       : Subtag(subtag, LANGUAGE) {}
+                       : Subtag(subtag, SubtagType::LANGUAGE) {}
                LanguageSubtag (char const* subtag)
-                       : Subtag(subtag, LANGUAGE) {}
+                       : Subtag(subtag, SubtagType::LANGUAGE) {}
 
-               SubtagType type () const {
-                       return LANGUAGE;
+               SubtagType type () const override {
+                       return SubtagType::LANGUAGE;
                }
        };
 
@@ -112,12 +133,12 @@ public:
        {
        public:
                ScriptSubtag (std::string subtag)
-                       : Subtag(subtag, SCRIPT) {}
+                       : Subtag(subtag, SubtagType::SCRIPT) {}
                ScriptSubtag (char const* subtag)
-                       : Subtag(subtag, SCRIPT) {}
+                       : Subtag(subtag, SubtagType::SCRIPT) {}
 
-               SubtagType type () const {
-                       return SCRIPT;
+               SubtagType type () const override {
+                       return SubtagType::SCRIPT;
                }
        };
 
@@ -125,12 +146,12 @@ public:
        {
        public:
                RegionSubtag (std::string subtag)
-                       : Subtag(subtag, REGION) {}
+                       : Subtag(subtag, SubtagType::REGION) {}
                RegionSubtag (char const* subtag)
-                       : Subtag(subtag, REGION) {}
+                       : Subtag(subtag, SubtagType::REGION) {}
 
-               SubtagType type () const {
-                       return REGION;
+               SubtagType type () const override {
+                       return SubtagType::REGION;
                }
        };
 
@@ -138,16 +159,13 @@ public:
        {
        public:
                VariantSubtag (std::string subtag)
-                       : Subtag(subtag, VARIANT) {}
+                       : Subtag(subtag, SubtagType::VARIANT) {}
                VariantSubtag (char const* subtag)
-                       : Subtag(subtag, VARIANT) {}
+                       : Subtag(subtag, SubtagType::VARIANT) {}
 
-               SubtagType type () const {
-                       return VARIANT;
+               SubtagType type () const override {
+                       return SubtagType::VARIANT;
                }
-
-               bool operator== (VariantSubtag const& other) const;
-               bool operator< (VariantSubtag const& other) const;
        };
 
 
@@ -155,22 +173,19 @@ public:
        {
        public:
                ExtlangSubtag (std::string subtag)
-                       : Subtag(subtag, EXTLANG) {}
+                       : Subtag(subtag, SubtagType::EXTLANG) {}
                ExtlangSubtag (char const* subtag)
-                       : Subtag(subtag, EXTLANG) {}
+                       : Subtag(subtag, SubtagType::EXTLANG) {}
 
-               SubtagType type () const {
-                       return EXTLANG;
+               SubtagType type () const override {
+                       return SubtagType::EXTLANG;
                }
-
-               bool operator== (ExtlangSubtag const& other) const;
-               bool operator< (ExtlangSubtag const& other) const;
        };
 
        LanguageTag () {}
-       LanguageTag (std::string tag);
+       explicit LanguageTag (std::string tag);
 
-       boost::optional<LanguageSubtag> language() {
+       boost::optional<LanguageSubtag> language() const {
                return _language;
        }
 
@@ -202,13 +217,13 @@ public:
        void set_extlangs (std::vector<ExtlangSubtag> extlangs);
        void add_extlang (ExtlangSubtag extlang);
 
-       std::vector<std::pair<SubtagType, SubtagData> > subtags () const;
+       std::vector<std::pair<SubtagType, SubtagData>> subtags () const;
 
-       static std::vector<SubtagData> get_all (SubtagType type);
+       static std::vector<SubtagData> const& get_all (SubtagType type);
        static std::string subtag_type_name (SubtagType type);
 
        static boost::optional<std::string> get_subtag_description (SubtagType, std::string subtag);
-       static boost::optional<SubtagData > get_subtag_data (SubtagType, std::string subtag);
+       static boost::optional<SubtagData> get_subtag_data (SubtagType, std::string subtag);
 
        template <class T>
        static boost::optional<std::string> get_subtag_description (T s) {
@@ -229,9 +244,20 @@ private:
        std::vector<ExtlangSubtag> _extlangs;
 };
 
+
 extern bool operator==(dcp::LanguageTag const& a, dcp::LanguageTag const& b);
+extern bool operator!=(dcp::LanguageTag const& a, dcp::LanguageTag const& b);
+extern bool operator<(dcp::LanguageTag const& a, dcp::LanguageTag const& b);
 extern std::ostream& operator<<(std::ostream& os, dcp::LanguageTag const& tag);
 
+
+extern void load_language_tag_lists (boost::filesystem::path tags_directory);
+
+
+extern std::vector<std::pair<std::string, std::string>> dcnc_tags ();
+
+
 }
 
+
 #endif