Moved easy types to easy/types.hpp.
the build was successful Details

This commit is contained in:
tastytea 2019-03-31 22:24:14 +02:00
parent 86dccaf2d7
commit c35b7f56fa
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 219 additions and 178 deletions

View File

@ -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<const string>(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)

View File

@ -19,9 +19,7 @@
#include <string>
#include <cstdint>
#include <chrono>
#include <vector>
#include <utility>
#include <functional>
#include <ostream>
#include <jsoncpp/json/json.h>
@ -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 <mastodon-cpp/mastodon-cpp.hpp>
#include <mastodon-cpp/easy/return_types_easy.hpp>
#include <mastodon-cpp/easy/types.hpp>
#include <mastodon-cpp/easy/entities/notification.hpp>
#include <mastodon-cpp/easy/entities/status.hpp>
#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<event_type, string> stream_event;
/*!
* @brief Map of 'notification type' and 'push is requested or not'
*
* Used in PushSubscription::alerts().
*
* @since 0.13.3
*/
typedef std::map<Easy::notification_type, bool> 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.
*

View File

@ -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 <mastodon-cpp/easy/easy.hpp>
#include <mastodon-cpp/easy/types.hpp>
#endif
using std::string;

56
src/easy/types.cpp Normal file
View File

@ -0,0 +1,56 @@
/* 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 "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<const string>(buffer);
}
std::ostream &Mastodon::Easy::operator <<(std::ostream &out,
const Easy::time &t)
{
out << t.strtime("%FT%T%z", true);
return out;
}

155
src/easy/types.hpp Normal file
View File

@ -0,0 +1,155 @@
/* 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/>.
*/
#ifndef MASTODON_CPP_TYPES_HPP
#define MASTODON_CPP_TYPES_HPP
#include <string>
#include <utility>
#include <chrono>
#include <map>
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<event_type, string> stream_event;
/*!
* @brief Map of 'notification type' and 'push is requested or not'.
*
* Used in PushSubscription::alerts().
*
* @since 0.13.3
*/
typedef std::map<Easy::notification_type, bool> 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