| 1 | // -*- coding: utf-8 -*- |
| 2 | // |
| 3 | // contacts.hxx --- FlightGear classes holding add-on contact metadata |
| 4 | // Copyright (C) 2018 Florent Rougon |
| 5 | // |
| 6 | // This program 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. |
| 10 | // |
| 11 | // This program 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. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | #ifndef FG_ADDON_CONTACTS_HXX |
| 21 | #define FG_ADDON_CONTACTS_HXX |
| 22 | |
| 23 | #include <string> |
| 24 | |
| 25 | #include <simgear/structure/SGReferenced.hxx> |
| 26 | |
| 27 | #include "addon_fwd.hxx" |
| 28 | |
| 29 | namespace nasal |
| 30 | { |
| 31 | class Hash; // forward declaration |
| 32 | }; |
| 33 | |
| 34 | namespace flightgear |
| 35 | { |
| 36 | |
| 37 | namespace addons |
| 38 | { |
| 39 | |
| 40 | enum class ContactType { |
| 41 | author, |
| 42 | maintainer |
| 43 | }; |
| 44 | |
| 45 | // Class used to store info about an author or maintainer (possibly also a |
| 46 | // mailing-list, things like that) |
| 47 | class Contact : public SGReferenced |
| 48 | { |
| 49 | public: |
| 50 | Contact(ContactType type, std::string name, std::string email = "", |
| 51 | std::string url = ""); |
| 52 | virtual ~Contact() = default; |
| 53 | |
| 54 | ContactType getType() const; |
| 55 | std::string getTypeString() const; |
| 56 | |
| 57 | std::string getName() const; |
| 58 | void setName(const std::string& name); |
| 59 | |
| 60 | std::string getEmail() const; |
| 61 | void setEmail(const std::string& email); |
| 62 | |
| 63 | std::string getUrl() const; |
| 64 | void setUrl(const std::string& url); |
| 65 | |
| 66 | static void setupGhost(nasal::Hash& addonsModule); |
| 67 | |
| 68 | private: |
| 69 | const ContactType _type; |
| 70 | std::string _name; |
| 71 | std::string _email; |
| 72 | std::string _url; |
| 73 | }; |
| 74 | |
| 75 | class Author : public Contact |
| 76 | { |
| 77 | public: |
| 78 | Author(std::string name, std::string email = "", std::string url = ""); |
| 79 | |
| 80 | static void setupGhost(nasal::Hash& addonsModule); |
| 81 | }; |
| 82 | |
| 83 | class Maintainer : public Contact |
| 84 | { |
| 85 | public: |
| 86 | Maintainer(std::string name, std::string email = "", std::string url = ""); |
| 87 | |
| 88 | static void setupGhost(nasal::Hash& addonsModule); |
| 89 | }; |
| 90 | |
| 91 | // *************************************************************************** |
| 92 | // * contact_traits * |
| 93 | // *************************************************************************** |
| 94 | |
| 95 | template <typename T> |
| 96 | struct contact_traits; |
| 97 | |
| 98 | template<> |
| 99 | struct contact_traits<Author> |
| 100 | { |
| 101 | using contact_type = Author; |
| 102 | using strong_ref = AuthorRef; |
| 103 | |
| 104 | static std::string xmlNodeName() |
| 105 | { |
| 106 | return "author"; |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | template<> |
| 111 | struct contact_traits<Maintainer> |
| 112 | { |
| 113 | using contact_type = Maintainer; |
| 114 | using strong_ref = MaintainerRef; |
| 115 | |
| 116 | static std::string xmlNodeName() |
| 117 | { |
| 118 | return "maintainer"; |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | } // of namespace addons |
| 123 | |
| 124 | } // of namespace flightgear |
| 125 | |
| 126 | #endif // of FG_ADDON_CONTACTS_HXX |