4d36082398
(everything described here lives in the namespace flightgear::addons) New classes: Author, Maintainer, and Contact. Author and Maintainer derive from Contact. For each contact, the following can be defined in addon-metadata.xml: name, email, and url. See [1] for details about the syntax and usage policy. Nasal bindings have been updated accordingly, there are three new ghosts: addons.Contact, addons.Author and addons.Maintainer. The enum class UrlType has two new members: author and maintainer. The Addon::getUrls() method has a new signature: std::multimap<UrlType, QualifiedUrl> getUrls() const; because non-empty 'url' fields for authors and maintainers contribute to the result, and there can be an arbitrary number of authors and an arbitrary number of maintainers defined for a given add-on---therefore, std::map can't be used anymore. Finally, QualifiedUrl has a new field (detail) which stores the author name (resp. maintainer name) when the QualifiedUrl type is UrlType::author (resp. UrlType::maintainer). Currently, this 'detail' field is not used for other URL types, but this could be changed if desired. [1] https://sourceforge.net/p/flightgear/fgdata/ci/next/tree/Docs/README.add-ons
127 lines
3.6 KiB
C++
127 lines
3.6 KiB
C++
// -*- coding: utf-8 -*-
|
|
//
|
|
// contacts.cxx --- FlightGear classes holding add-on contact metadata
|
|
// Copyright (C) 2018 Florent Rougon
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include <simgear/nasal/cppbind/Ghost.hxx>
|
|
#include <simgear/nasal/cppbind/NasalHash.hxx>
|
|
#include <simgear/sg_inlines.h>
|
|
#include <simgear/structure/exception.hxx>
|
|
|
|
#include "addon_fwd.hxx"
|
|
#include "contacts.hxx"
|
|
|
|
using std::string;
|
|
using simgear::enumValue;
|
|
|
|
namespace flightgear
|
|
{
|
|
|
|
namespace addons
|
|
{
|
|
|
|
// ***************************************************************************
|
|
// * Contact *
|
|
// ***************************************************************************
|
|
|
|
Contact::Contact(ContactType type, string name, string email, string url)
|
|
: _type(type),
|
|
_name(std::move(name)),
|
|
_email(std::move(email)),
|
|
_url(std::move(url))
|
|
{ }
|
|
|
|
ContactType Contact::getType() const
|
|
{ return _type; }
|
|
|
|
string Contact::getTypeString() const
|
|
{
|
|
switch (getType()) {
|
|
case ContactType::author:
|
|
return "author";
|
|
case ContactType::maintainer:
|
|
return "maintainer";
|
|
default:
|
|
throw sg_error("unexpected value for member of "
|
|
"flightgear::addons::ContactType: " +
|
|
std::to_string(enumValue(getType())));
|
|
}
|
|
}
|
|
|
|
string Contact::getName() const
|
|
{ return _name; }
|
|
|
|
void Contact::setName(const string& name)
|
|
{ _name = name; }
|
|
|
|
string Contact::getEmail() const
|
|
{ return _email; }
|
|
|
|
void Contact::setEmail(const string& email)
|
|
{ _email = email; }
|
|
|
|
string Contact::getUrl() const
|
|
{ return _url; }
|
|
|
|
void Contact::setUrl(const string& url)
|
|
{ _url = url; }
|
|
|
|
// Static method
|
|
void Contact::setupGhost(nasal::Hash& addonsModule)
|
|
{
|
|
nasal::Ghost<ContactRef>::init("addons.Contact")
|
|
.member("name", &Contact::getName)
|
|
.member("email", &Contact::getEmail)
|
|
.member("url", &Contact::getUrl);
|
|
}
|
|
|
|
// ***************************************************************************
|
|
// * Author *
|
|
// ***************************************************************************
|
|
|
|
Author::Author(string name, string email, string url)
|
|
: Contact(ContactType::author, name, email, url)
|
|
{ }
|
|
|
|
// Static method
|
|
void Author::setupGhost(nasal::Hash& addonsModule)
|
|
{
|
|
nasal::Ghost<AuthorRef>::init("addons.Author")
|
|
.bases<ContactRef>();
|
|
}
|
|
|
|
// ***************************************************************************
|
|
// * Maintainer *
|
|
// ***************************************************************************
|
|
|
|
Maintainer::Maintainer(string name, string email, string url)
|
|
: Contact(ContactType::maintainer, name, email, url)
|
|
{ }
|
|
|
|
// Static method
|
|
void Maintainer::setupGhost(nasal::Hash& addonsModule)
|
|
{
|
|
nasal::Ghost<MaintainerRef>::init("addons.Maintainer")
|
|
.bases<ContactRef>();
|
|
}
|
|
|
|
} // of namespace addons
|
|
|
|
} // of namespace flightgear
|