FlightGear next
contacts.cxx
Go to the documentation of this file.
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
31using std::string;
32using simgear::enumValue;
33
34namespace flightgear
35{
36
37namespace addons
38{
39
40// ***************************************************************************
41// * Contact *
42// ***************************************************************************
43
44Contact::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
52{ return _type; }
53
55{
56 switch (getType()) {
58 return "author";
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
68string Contact::getName() const
69{ return _name; }
70
71void Contact::setName(const string& name)
72{ _name = name; }
73
74string Contact::getEmail() const
75{ return _email; }
76
77void Contact::setEmail(const string& email)
78{ _email = email; }
79
80string Contact::getUrl() const
81{ return _url; }
82
83void Contact::setUrl(const string& url)
84{ _url = url; }
85
86// Static method
87void 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
99Author::Author(string name, string email, string url)
100 : Contact(ContactType::author, name, email, url)
101{ }
102
103// Static method
104void Author::setupGhost(nasal::Hash& addonsModule)
105{
106 nasal::Ghost<AuthorRef>::init("addons.Author")
107 .bases<ContactRef>();
108}
109
110// ***************************************************************************
111// * Maintainer *
112// ***************************************************************************
113
114Maintainer::Maintainer(string name, string email, string url)
115 : Contact(ContactType::maintainer, name, email, url)
116{ }
117
118// Static method
119void 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
static void setupGhost(nasal::Hash &addonsModule)
Definition contacts.cxx:104
Author(std::string name, std::string email="", std::string url="")
Definition contacts.cxx:99
void setName(const std::string &name)
Definition contacts.cxx:71
std::string getName() const
Definition contacts.cxx:68
void setUrl(const std::string &url)
Definition contacts.cxx:83
std::string getEmail() const
Definition contacts.cxx:74
Contact(ContactType type, std::string name, std::string email="", std::string url="")
Definition contacts.cxx:44
std::string getTypeString() const
Definition contacts.cxx:54
void setEmail(const std::string &email)
Definition contacts.cxx:77
std::string getUrl() const
Definition contacts.cxx:80
static void setupGhost(nasal::Hash &addonsModule)
Definition contacts.cxx:87
ContactType getType() const
Definition contacts.cxx:51
static void setupGhost(nasal::Hash &addonsModule)
Definition contacts.cxx:119
Maintainer(std::string name, std::string email="", std::string url="")
Definition contacts.cxx:114
SGSharedPtr< Contact > ContactRef
Definition addon_fwd.hxx:48
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
const char * name