Cleaned up, fixed formatting and so on.
All checks were successful
the build was successful

This commit is contained in:
tastytea 2019-03-28 21:23:24 +01:00
parent 76dc6a623c
commit dff3b11c00
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
8 changed files with 419 additions and 371 deletions

View File

@ -23,7 +23,6 @@
#include "debug.hpp"
using namespace Mastodon;
using namespace Mastodon::Easy;
using std::string;
Easy::API::API(const string &instance, const string &access_token)
@ -51,8 +50,8 @@ const std::vector<string> Easy::json_array_to_vector(const string &json)
return {};
}
const std::vector<Easy::stream_event>
Easy::parse_stream(const std::string &streamdata)
const vector<Easy::stream_event> Easy::parse_stream(
const std::string &streamdata)
{
string stream = streamdata;
std::regex reevent("event: (update|notification|delete)\ndata: (.*)\n");

View File

@ -134,6 +134,7 @@ namespace Easy
*/
typedef std::map<Easy::notification_type, bool> alertmap;
// TODO: Get rid of forward declarations.
class Account;
class Application;
class Attachment;
@ -222,17 +223,21 @@ namespace Easy
*
* @since before 0.11.0
*/
const std::vector<stream_event>
parse_stream(const std::string &streamdata);
const std::vector<stream_event> parse_stream(const std::string &streamdata);
/*!
* @brief Interface to the Mastodon API, easy version.
*
* Provides convenient functions to deal with the responses you get.
*/
class API : public Mastodon::API
{
public:
/*!
* @brief Constructs a new Easy object.
*
* To register your application, leave access_token blank and call
* register_app1() and register_app2().
* To register your application, leave access_token blank and
* call register_app1() and register_app2().
*
* @param instance The hostname of your instance
* @param access_token The access token
@ -254,7 +259,8 @@ namespace Easy
* The return value can not exceed 1023 chars.
*
* @param timepoint The timepoint
* @param format The format of the string, same as with `strftime`.
* @param format The format of the string, same as with
* `strftime`.
*
* Example:
* @code
@ -281,9 +287,10 @@ namespace Easy
const string &format);
// #### simple calls ####
// TODO: Own file.
/*!
* @brief Sends a toot.
* @brief Sends a post.
*
* @param status The status to send
* @param error @ref error "Error code"

View File

@ -0,0 +1,88 @@
/* 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/>.
*/
#include "return_types_easy.hpp"
#include "easy/entities/status.hpp"
#include "easy/entities/notification.hpp"
using namespace Mastodon;
template<typename T>
Easy::return_entity<T>::return_entity()
: entity()
{}
template<typename T>
Easy::return_entity<T>::return_entity(const uint8_t ec, const string &em,
const T &ent)
: entity(ent)
{
error_code = ec;
error_message = em;
}
template<typename T>
Easy::return_entity<T>::return_entity::operator const T() const
{
return entity;
}
template<typename T>
Easy::return_entity<T>::return_entity::operator const string() const
{
return entity.to_string();
}
template<typename T>
std::ostream &Easy::operator <<(std::ostream &out,
const Easy::return_entity<T> &ret)
{
out << ret.entity.to_string();
return out;
}
// Explicit instantiations, so it can be used from outside.
// TODO: Complete this.
template struct Easy::return_entity<Easy::Status>;
template struct Easy::return_entity<Easy::Notification>;
template<typename T>
Easy::return_entity_vector<T>::
return_entity_vector::return_entity_vector()
: entities()
{}
template<typename T>
Easy::return_entity_vector<T>::return_entity_vector::return_entity_vector(
const uint8_t ec, const string &em, const vector<T> &vec)
: entities(vec)
{
error_code = ec;
error_message = em;
}
template<typename T>
Easy::return_entity_vector<T>::return_entity_vector::operator const vector<T>()
const
{
return entities;
}
// Explicit instantiations, so it can be used from outside.
// TODO: Complete this.
template struct Easy::return_entity_vector<Easy::Status>;
template struct Easy::return_entity_vector<Easy::Notification>;

View File

@ -20,19 +20,25 @@
#include <string>
#include <vector>
#include <ostream>
#include <cstdint>
#include "mastodon-cpp.hpp"
using std::string;
using std::vector;
using std::uint8_t;
namespace Mastodon
{
namespace Easy
{
template <typename T>
struct return_entity;
// https://stackoverflow.com/a/4661372/5965450
template <typename T>
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`.
*/
template <typename T>
struct return_entity : return_base
{
@ -44,10 +50,14 @@ struct return_entity : return_base
operator const T() const;
operator const string() const;
// FIXME: Can't get it to work, don't know why.
friend std::ostream &operator <<<T>(std::ostream &out,
const return_entity<T> &ret);
};
/*!
* @brief Return types for calls that return multiple `Easy::Entity`s.
*/
template <typename T>
struct return_entity_vector : return_base
{
@ -59,62 +69,6 @@ struct return_entity_vector : return_base
operator const vector<T>() const;
};
template<typename T>
return_entity<T>::return_entity()
: entity()
{}
template<typename T>
return_entity<T>::return_entity(const uint8_t ec, const string &em,
const T &ent)
: entity(ent)
{
error_code = ec;
error_message = em;
}
template<typename T>
return_entity<T>::return_entity::operator const T() const
{
return entity;
}
template<typename T>
return_entity<T>::return_entity::operator const string() const
{
return entity.to_string();
}
template<typename T>
std::ostream &operator <<(std::ostream &out, const return_entity<T> &ret)
{
out << ret.entity.to_string();
return out;
}
// Explicit instantiation
// template struct Mastodon::return_entity<Easy::Status>;
template<typename T>
return_entity_vector<T>::return_entity_vector::return_entity_vector()
: entities()
{}
template<typename T>
return_entity_vector<T>::return_entity_vector::return_entity_vector(
const uint8_t ec, const string &em, const vector<T> &vec)
: entities(vec)
{
error_code = ec;
error_message = em;
}
template<typename T>
return_entity_vector<T>::return_entity_vector::operator const vector<T>() const
{
return entities;
}
}

View File

@ -21,14 +21,14 @@
#include "easy/entities/attachment.hpp"
#include "easy/entities/notification.hpp"
using namespace Mastodon;
using namespace Mastodon::Easy;
const return_entity<Easy::Status> Easy::API::send_toot(const Status &status)
const return_entity<Status> API::send_toot(const Status &status)
{
return send_post(status);
}
const return_entity<Easy::Status> Easy::API::send_post(const Status &status)
const return_entity<Status> API::send_post(const Status &status)
{
API::parametermap parameters;
@ -129,7 +129,7 @@ const return_entity<Easy::Status> Easy::API::send_post(const Status &status)
return { ret.error_code, ret.error_message, Status(ret.answer) };
}
const return_entity_vector<Easy::Notification> Easy::API::get_notifications(
const return_entity_vector<Notification> API::get_notifications(
const uint16_t limit, const string since_id, const string max_id)
{
API::parametermap parameters;

View File

@ -70,7 +70,7 @@ namespace Mastodon
} return_call;
/*!
* @brief Class for the Mastodon API.
* @brief Interface to the Mastodon API.
*
* All input is expected to be UTF-8. Binary data must be
* base64-encoded or a filename.