Debian Codegraph @

src/Add-ons/contacts.cxx

raw symbols SCIP
1 // -*- coding: utf-8 -*-
2 //
3 // contacts.cxx --- 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 #include <string>
21 #include <utility>
22
23 #include <simgear/nasal/cppbind/Ghost.hxx>
24 #include <simgear/nasal/cppbind/NasalHash.hxx>
25 #include <simgear/sg_inlines.h>
26 #include <simgear/structure/exception.hxx>
27
28 #include "addon_fwd.hxx"
29 #include "contacts.hxx"
30
31 using std::string;
32 using simgear::enumValue;
33
34 namespace flightgear
35 {
36
37 namespace addons
38 {
39
40 // ***************************************************************************
41 // * Contact *
42 // ***************************************************************************
43
44 Contact::Contact(ContactType type, string name, string email, string url)
45 : _type(type),
46 _name(std::move(name)),
47 _email(std::move(email)),
48 _url(std::move(url))
49 { }
50
51 ContactType Contact::getType() const
52 { return _type; }
53
54 string Contact::getTypeString() const
55 {
56 switch (getType()) {
57 case ContactType::author:
58 return "author";
59 case ContactType::maintainer:
60 return "maintainer";
61 default:
62 throw sg_error("unexpected value for member of "
63 "flightgear::addons::ContactType: " +
64 std::to_string(enumValue(getType())));
65 }
66 }
67
68 string Contact::getName() const
69 { return _name; }
70
71 void Contact::setName(const string& name)
72 { _name = name; }
73
74 string Contact::getEmail() const
75 { return _email; }
76
77 void Contact::setEmail(const string& email)
78 { _email = email; }
79
80 string Contact::getUrl() const
81 { return _url; }
82
83 void Contact::setUrl(const string& url)
84 { _url = url; }
85
86 // Static method
87 void Contact::setupGhost(nasal::Hash& addonsModule)
88 {
89 nasal::Ghost<ContactRef>::init("addons.Contact")
90 .member("name", &Contact::getName)
91 .member("email", &Contact::getEmail)
92 .member("url", &Contact::getUrl);
93 }
94
95 // ***************************************************************************
96 // * Author *
97 // ***************************************************************************
98
99 Author::Author(string name, string email, string url)
100 : Contact(ContactType::author, name, email, url)
101 { }
102
103 // Static method
104 void Author::setupGhost(nasal::Hash& addonsModule)
105 {
106 nasal::Ghost<AuthorRef>::init("addons.Author")
107 .bases<ContactRef>();
108 }
109
110 // ***************************************************************************
111 // * Maintainer *
112 // ***************************************************************************
113
114 Maintainer::Maintainer(string name, string email, string url)
115 : Contact(ContactType::maintainer, name, email, url)
116 { }
117
118 // Static method
119 void Maintainer::setupGhost(nasal::Hash& addonsModule)
120 {
121 nasal::Ghost<MaintainerRef>::init("addons.Maintainer")
122 .bases<ContactRef>();
123 }
124
125 } // of namespace addons
126
127 } // of namespace flightgear