2019-03-28 15:35:23 +01:00
|
|
|
/* This file is part of mastodon-cpp.
|
|
|
|
* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
|
|
|
*
|
|
|
|
* 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, version 3.
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-02 11:20:35 +02:00
|
|
|
#ifndef MASTODON_CPP_EASY_RETURN_TYPES_EASY_HPP
|
|
|
|
#define MASTODON_CPP_EASY_RETURN_TYPES_EASY_HPP
|
2019-03-28 15:35:23 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <ostream>
|
2019-03-28 21:23:24 +01:00
|
|
|
#include <cstdint>
|
2019-03-28 15:35:23 +01:00
|
|
|
#include "mastodon-cpp.hpp"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2019-03-28 21:23:24 +01:00
|
|
|
using std::uint8_t;
|
2019-03-28 15:35:23 +01:00
|
|
|
|
|
|
|
namespace Mastodon
|
|
|
|
{
|
2019-03-28 21:23:24 +01:00
|
|
|
namespace Easy
|
2019-03-28 15:35:23 +01:00
|
|
|
{
|
2019-03-28 21:23:24 +01:00
|
|
|
template <typename T>
|
|
|
|
struct return_entity;
|
|
|
|
template <typename T> // https://stackoverflow.com/a/4661372/5965450
|
|
|
|
std::ostream &operator <<(std::ostream&, const return_entity<T>&);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Return types for calls that return a single `Easy::Entity`.
|
2019-03-29 14:44:39 +01:00
|
|
|
*
|
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
struct return_entity : return_base
|
|
|
|
{
|
2019-03-30 13:18:42 +01:00
|
|
|
/*!
|
|
|
|
* @brief Mastodon::Easy::Entity
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
T entity;
|
|
|
|
|
|
|
|
return_entity();
|
|
|
|
return_entity(const uint8_t ec, const string &em, const T &ent);
|
|
|
|
|
2019-03-30 13:18:42 +01:00
|
|
|
/*!
|
|
|
|
* @brief Same as return_entity::entity.
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
operator const T() const;
|
2019-03-30 13:18:42 +01:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Mastodon::Easy::Entity as string.
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
operator const string() const;
|
|
|
|
|
|
|
|
// FIXME: Can't get it to work, don't know why.
|
2019-03-30 13:18:42 +01:00
|
|
|
/*!
|
|
|
|
* @brief Mastodon::Easy::Entity as string.
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
friend std::ostream &operator <<<T>(std::ostream &out,
|
|
|
|
const return_entity<T> &ret);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief Return types for calls that return multiple `Easy::Entity`s.
|
2019-03-30 13:18:42 +01:00
|
|
|
*
|
|
|
|
* @since 0.100.0
|
2019-03-28 21:23:24 +01:00
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
struct return_entity_vector : return_base
|
|
|
|
{
|
2019-03-30 13:18:42 +01:00
|
|
|
/*!
|
|
|
|
* @brief std::vector of Mastodon::Easy::Entity.
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
vector<T> entities;
|
|
|
|
|
|
|
|
return_entity_vector();
|
|
|
|
return_entity_vector(const uint8_t ec, const string &em,
|
|
|
|
const vector<T> &vec);
|
|
|
|
|
2019-03-30 13:18:42 +01:00
|
|
|
/*!
|
|
|
|
* @brief Same es return_entity_vector::entities.
|
|
|
|
*
|
|
|
|
* @since 0.100.0
|
|
|
|
*/
|
2019-03-28 21:23:24 +01:00
|
|
|
operator const vector<T>() const;
|
|
|
|
};
|
2019-03-28 15:35:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:20:35 +02:00
|
|
|
#endif // MASTODON_CPP_EASY_RETURN_TYPES_EASY_HPP
|