diff --git a/src/easy/easy.cpp b/src/easy/easy.cpp index ef20bff..828115c 100644 --- a/src/easy/easy.cpp +++ b/src/easy/easy.cpp @@ -23,44 +23,6 @@ #include "debug.hpp" using namespace Mastodon; -using std::string; - -Easy::time::operator const system_clock::time_point() -{ - return timepoint; -} - -Easy::time::operator const string() -{ - return strtime("%FT%T%z", true); -} - -const string Easy::time::strtime(const string &format, const bool &local) const -{ - constexpr std::uint16_t bufsize = 1024; - std::time_t time = system_clock::to_time_t(timepoint); - std::tm *timeinfo; - if (local) - { - timeinfo = std::localtime(&time); - } - else - { - timeinfo = std::gmtime(&time); - } - - char buffer[bufsize]; - std::strftime(buffer, bufsize, format.c_str(), timeinfo); - - return static_cast(buffer); -} - -std::ostream &Mastodon::Easy::operator <<(std::ostream &out, - const Easy::time &t) -{ - out << t.strtime("%FT%T%z", true); - return out; -} Easy::API::API(const string &instance, const string &access_token) : Mastodon::API(instance, access_token) diff --git a/src/easy/easy.hpp b/src/easy/easy.hpp index 86eb988..e6c3b2c 100644 --- a/src/easy/easy.hpp +++ b/src/easy/easy.hpp @@ -19,9 +19,7 @@ #include #include -#include #include -#include #include #include #include @@ -30,16 +28,21 @@ #ifdef MASTODON_CPP #include "mastodon-cpp.hpp" #include "easy/return_types_easy.hpp" + #include "easy/types.hpp" + #include "easy/entities/notification.hpp" + #include "easy/entities/status.hpp" #else #include #include + #include + #include + #include #endif using std::string; using std::vector; using std::uint64_t; using std::uint16_t; -using std::chrono::system_clock; namespace Mastodon { @@ -50,141 +53,6 @@ namespace Mastodon */ namespace Easy { - /*! - * @brief Describes the event type - * - * @since before 0.11.0 - */ - enum class event_type - { - Update, - Notification, - Delete, - Undefined - }; - - /*! - * @brief Describes visibility of toots. - * - * @since before 0.11.0 - */ - enum class visibility_type - { - Direct, - Private, - Unlisted, - Public, - Undefined - }; - - /*! - * @brief Describes the attachment type - * - * @since before 0.11.0 - */ - enum class attachment_type - { - Image, - Video, - Gifv, - Unknown, - Undefined - }; - - /*! - * @brief Describes the card type - * - * @since before 0.11.0 - */ - enum class card_type - { - Link, - Photo, - Video, - Rich, - Undefined - }; - - /*! - * @brief Describes the notification type - * - * @since before 0.11.0 - */ - enum class notification_type - { - Mention, - Reblog, - Favourite, - Follow, - Undefined - }; - - /*! - * @brief Used for stream events. - * - * @since before 0.11.0 - */ - typedef std::pair stream_event; - - /*! - * @brief Map of 'notification type' and 'push is requested or not' - * - * Used in PushSubscription::alerts(). - * - * @since 0.13.3 - */ - typedef std::map alertmap; - - struct time - { - system_clock::time_point timepoint = system_clock::time_point(); - - operator const system_clock::time_point(); - operator const string(); - friend std::ostream &operator <<(std::ostream &out, - const Easy::time &t); - - /*! - * @brief Converts time to a string. - * - * The return value can not exceed 1023 chars. - * - * @param format The format of the string, same as with - * `strftime`. - * @param local Use local time (default). - * - * Example: - * @code - * Mastodon::Easy::time timepoint = status.created_at(); - * std::cout << timepoint.strtime("%F, %T UTC", false) << '\n'; - * @endcode - * - * @return The time as string. - * - * @since 0.100.0 - */ - const string strtime (const string &format, - const bool &local = true) const; - }; - - // TODO: Get rid of forward declarations. - class Account; - class Application; - class Attachment; - class Card; - class Context; - class Emoji; - class Instance; - class List; - class Mention; - class Notification; - class Relationship; - class Report; - class Results; - class Status; - class Tag; - class PushSubscription; - /*! * @brief Class to hold the `Link`-header. * diff --git a/src/easy/entity.hpp b/src/easy/entity.hpp index 4f46925..5cfd8f0 100644 --- a/src/easy/entity.hpp +++ b/src/easy/entity.hpp @@ -22,9 +22,9 @@ // If we are compiling mastodon-cpp, use another include path #ifdef MASTODON_CPP - #include "easy/easy.hpp" + #include "easy/types.hpp" #else - #include + #include #endif using std::string; diff --git a/src/easy/types.cpp b/src/easy/types.cpp new file mode 100644 index 0000000..8ced2c1 --- /dev/null +++ b/src/easy/types.cpp @@ -0,0 +1,56 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#include "types.hpp" + +using namespace Mastodon; + +Easy::time::operator const system_clock::time_point() +{ + return timepoint; +} + +Easy::time::operator const string() +{ + return strtime("%FT%T%z", true); +} + +const string Easy::time::strtime(const string &format, const bool &local) const +{ + constexpr std::uint16_t bufsize = 1024; + std::time_t time = system_clock::to_time_t(timepoint); + std::tm *timeinfo; + if (local) + { + timeinfo = std::localtime(&time); + } + else + { + timeinfo = std::gmtime(&time); + } + + char buffer[bufsize]; + std::strftime(buffer, bufsize, format.c_str(), timeinfo); + + return static_cast(buffer); +} + +std::ostream &Mastodon::Easy::operator <<(std::ostream &out, + const Easy::time &t) +{ + out << t.strtime("%FT%T%z", true); + return out; +} diff --git a/src/easy/types.hpp b/src/easy/types.hpp new file mode 100644 index 0000000..5605a9f --- /dev/null +++ b/src/easy/types.hpp @@ -0,0 +1,155 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2019 tastytea + * + * 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 . + */ + +#ifndef MASTODON_CPP_TYPES_HPP +#define MASTODON_CPP_TYPES_HPP + +#include +#include +#include +#include + +using std::string; +using std::chrono::system_clock; + +namespace Mastodon +{ +namespace Easy +{ + /*! + * @brief Describes the event type + * + * @since before 0.11.0 + */ + enum class event_type + { + Update, + Notification, + Delete, + Undefined + }; + + /*! + * @brief Describes visibility of toots. + * + * @since before 0.11.0 + */ + enum class visibility_type + { + Direct, + Private, + Unlisted, + Public, + Undefined + }; + + /*! + * @brief Describes the attachment type + * + * @since before 0.11.0 + */ + enum class attachment_type + { + Image, + Video, + Gifv, + Unknown, + Undefined + }; + + /*! + * @brief Describes the card type + * + * @since before 0.11.0 + */ + enum class card_type + { + Link, + Photo, + Video, + Rich, + Undefined + }; + + /*! + * @brief Describes the notification type + * + * @since before 0.11.0 + */ + enum class notification_type + { + Mention, + Reblog, + Favourite, + Follow, + Undefined + }; + + /*! + * @brief Used for stream events. + * + * @since before 0.11.0 + */ + typedef std::pair stream_event; + + /*! + * @brief Map of 'notification type' and 'push is requested or not'. + * + * Used in PushSubscription::alerts(). + * + * @since 0.13.3 + */ + typedef std::map alertmap; + + /*! + * @brief Type for time. Converts to time_point and string. + * + * @since 0.100.0 + */ + struct time + { + system_clock::time_point timepoint = system_clock::time_point(); + + operator const system_clock::time_point(); + operator const string(); + friend std::ostream &operator <<(std::ostream &out, + const Easy::time &t); + + /*! + * @brief Converts time to a string. + * + * The return value can not exceed 1023 chars. + * + * @param format The format of the string, same as with + * `strftime`. + * @param local Use local time (default). + * + * Example: + * @code + * Mastodon::Easy::time timepoint = status.created_at(); + * std::cout << timepoint.strtime("%F, %T UTC", false) << '\n'; + * @endcode + * + * @return The time as string. + * + * @since 0.100.0 + */ + const string strtime (const string &format, + const bool &local = true) const; + }; +} +} +#endif // MASTODON_CPP_TYPES_HPP