Source code reformated.

This commit is contained in:
Kirill Kirilenko 2017-02-15 20:22:18 +03:00
parent 81bb25f4fe
commit 592751a50c
23 changed files with 1118 additions and 1069 deletions

View file

@ -6,11 +6,11 @@
#include <memory>
#include <vector>
namespace telebotxx
namespace telebotxx {
class Attachment
{
class Attachment
{
public:
public:
enum class Type
{
Audio,
@ -34,15 +34,15 @@ namespace telebotxx
void swap(Attachment& other) noexcept;
private:
private:
Type attachmentType_;
};
};
using AttachmentPtr = std::shared_ptr<Attachment>;
using AttachmentPtr = std::shared_ptr<Attachment>;
class PhotoSize
{
public:
class PhotoSize
{
public:
PhotoSize();
PhotoSize(const PhotoSize&);
PhotoSize(PhotoSize&&);
@ -64,18 +64,18 @@ namespace telebotxx
const PhotoSize& operator=(PhotoSize other) noexcept;
private:
private:
std::string fileId_;
int width_;
int height_;
int fileSize_;
};
};
using PhotoSizePtr = std::shared_ptr<PhotoSize>;
using PhotoSizePtr = std::shared_ptr<PhotoSize>;
class PhotoSizeArray : public Attachment
{
public:
class PhotoSizeArray : public Attachment
{
public:
PhotoSizeArray();
PhotoSizeArray(const PhotoSizeArray&);
PhotoSizeArray(PhotoSizeArray&&);
@ -88,15 +88,15 @@ namespace telebotxx
const PhotoSizeArray& operator=(PhotoSizeArray other) noexcept;
private:
private:
std::vector<PhotoSize> array_;
};
};
using PhotoSizeArrayPtr = std::shared_ptr<PhotoSizeArray>;
using PhotoSizeArrayPtr = std::shared_ptr<PhotoSizeArray>;
class Audio : public Attachment
{
public:
class Audio : public Attachment
{
public:
Audio();
Audio(const Audio&);
Audio(Audio&&);
@ -124,18 +124,18 @@ namespace telebotxx
const Audio& operator=(Audio other) noexcept;
private:
private:
std::string fileId_;
int duration_;
std::string performer_;
std::string title_;
std::string mimeType_;
int fileSize_;
};
};
class Document : public Attachment
{
public:
class Document : public Attachment
{
public:
Document();
Document(const Document&);
Document(Document&&);
@ -160,17 +160,17 @@ namespace telebotxx
const Document& operator=(Document other) noexcept;
private:
private:
std::string fileId_;
PhotoSizePtr thumb_;
std::string fileName_;
std::string mimeType_;
int fileSize_;
};
};
class Sticker : public Attachment
{
public:
class Sticker : public Attachment
{
public:
Sticker();
Sticker(const Sticker&);
Sticker(Sticker&&);
@ -198,20 +198,21 @@ namespace telebotxx
const Sticker& operator=(Sticker other) noexcept;
private:
private:
std::string fileId_;
int width_;
int height_;
PhotoSizePtr thumb_;
std::string emoji_;
int fileSize_;
};
};
void swap(PhotoSize& lhs, PhotoSize& rhs);
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs);
void swap(Audio& lhs, Audio& rhs);
void swap(Document& lhs, Document& rhs);
void swap(Sticker& lhs, Sticker& rhs);
void swap(PhotoSize& lhs, PhotoSize& rhs);
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs);
void swap(Audio& lhs, Audio& rhs);
void swap(Document& lhs, Document& rhs);
void swap(Sticker& lhs, Sticker& rhs);
}
#endif // TELEBOTXX_ATTACHMENT_HPP

View file

@ -1,5 +1,5 @@
#ifndef TELEBOTXX_BOTAPI_H
#define TELEBOTXX_BOTAPI_H
#ifndef TELEBOTXX_BOTAPI_HPP
#define TELEBOTXX_BOTAPI_HPP
#include "User.hpp"
#include "Message.hpp"
@ -10,24 +10,24 @@
#include <string>
#include <memory>
namespace telebotxx
{
template <typename RequestType, typename T>
void setRequestOption(RequestType& request, T t)
{
request.setOption(t);
}
namespace telebotxx {
template <typename RequestType, typename T, typename... Ts>
void setRequestOption(RequestType& request, T&& t, Ts&&... ts)
{
template <typename RequestType, typename T>
void setRequestOption(RequestType& request, T t)
{
request.setOption(t);
}
template <typename RequestType, typename T, typename... Ts>
void setRequestOption(RequestType& request, T&& t, Ts&&... ts)
{
setRequestOption(request, std::forward<T>(t));
setRequestOption(request, std::forward<Ts>(ts)...);
};
};
class BotApi
{
public:
class BotApi
{
public:
/// \param [in] token bot's secret token
BotApi(const std::string& token);
@ -49,7 +49,7 @@ namespace telebotxx
/// \param text text
/// \param args parameters
/// \return Message object, recieved from the server
template<typename... Ts>
template <typename... Ts>
Message sendMessage(ChatId&& chatId, Text&& text, Ts&&... args)
{
SendMessageRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Text>(text));
@ -68,7 +68,7 @@ namespace telebotxx
/// \param [in] photo photo
/// \param [in] args parameters
/// \return Message object, recieved from the server
template<typename... Ts>
template <typename... Ts>
Message sendPhoto(ChatId&& chatId, Photo&& photo, Ts&&... args)
{
SendPhotoRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Photo>(photo));
@ -83,12 +83,13 @@ namespace telebotxx
/// \return Updates (vector of Update)
Updates getUpdates(int offset = 0, unsigned short limit = 0, unsigned timeout = 0);
private:
private:
std::string getTelegramMainUrl() const;
class Impl;
std::unique_ptr<Impl> impl_;
};
};
}
#endif // TELEBOTXX_BOTAPI_H
#endif // TELEBOTXX_BOTAPI_HPP

View file

@ -5,11 +5,11 @@
#include <memory>
#include <cstdint>
namespace telebotxx
namespace telebotxx {
class Chat
{
class Chat
{
public:
public:
enum class Type
{
Private,
@ -48,7 +48,7 @@ namespace telebotxx
const Chat& operator=(Chat other) noexcept;
private:
private:
std::int64_t id_;
Type type_;
std::string title_;
@ -56,13 +56,14 @@ namespace telebotxx
std::string firstName_;
std::string lastName_;
bool allAdmins_;
};
};
using ChatPtr = std::shared_ptr<Chat>;
using ChatPtr = std::shared_ptr<Chat>;
void swap(Chat& lhs, Chat& rhs);
void swap(Chat& lhs, Chat& rhs);
Chat::Type chatTypeFromString(const std::string& str);
Chat::Type chatTypeFromString(const std::string& str);
}
#endif // TELEBOTXX_CHAT_HPP

View file

@ -3,20 +3,20 @@
#include <stdexcept>
namespace telebotxx
namespace telebotxx {
class ParseError : public std::invalid_argument
{
class ParseError : public std::invalid_argument
{
public:
public:
ParseError(const std::string& message)
: std::invalid_argument(message)
{
}
};
};
class ApiError : public std::runtime_error
{
public:
class ApiError : public std::runtime_error
{
public:
ApiError(int code, const std::string& message)
: std::runtime_error(message), code_(code)
{
@ -27,9 +27,9 @@ namespace telebotxx
return code_;
}
protected:
protected:
int code_;
};
};
}

View file

@ -1,12 +1,13 @@
#ifndef TELEBOTXX_LOGGING_HPP
#define TELEBOTXX_LOGGING_HPP
namespace telebotxx
{
extern bool debugMode;
namespace telebotxx {
extern bool debugMode;
/// \brief Enable/disable debug output
void setDebugMode(bool enabled);
/// \brief Enable/disable debug output
void setDebugMode(bool enabled);
}
#endif // TELEBOTXX_LOGGING_HPP

View file

@ -9,11 +9,11 @@
#include <ctime>
#include <memory>
namespace telebotxx
namespace telebotxx {
class MessageEntity
{
class MessageEntity
{
public:
public:
enum class Type
{
Mention,
@ -53,24 +53,24 @@ namespace telebotxx
const MessageEntity& operator=(MessageEntity other);
private:
private:
Type type_;
int offset_;
std::size_t length_;
std::string url_;
User user_;
};
};
MessageEntity::Type messageEntityTypeFromString(const std::string& str);
MessageEntity::Type messageEntityTypeFromString(const std::string& str);
using MessageEntities = std::vector<MessageEntity>;
using MessageEntities = std::vector<MessageEntity>;
class Message;
using MessagePtr = std::shared_ptr<Message>;
class Message;
using MessagePtr = std::shared_ptr<Message>;
class Message
{
public:
class Message
{
public:
Message();
Message(const Message&);
Message(Message&&);
@ -152,7 +152,7 @@ namespace telebotxx
const Message& operator=(Message other) noexcept;
private:
private:
int id_;
UserPtr from_;
std::time_t date_;
@ -177,9 +177,10 @@ namespace telebotxx
std::int64_t migrateToChatId_;
std::int64_t migrateFromChatId_;
MessagePtr pinnedMessage_;
};
};
void swap(Message& lhs, Message& rhs);
void swap(Message& lhs, Message& rhs);
}
#endif // TELEBOTXX_MESSAGE_HPP

View file

@ -4,11 +4,11 @@
#include <string>
#include <vector>
namespace telebotxx
namespace telebotxx {
class ChatId
{
class ChatId
{
public:
public:
ChatId(int);
ChatId(const std::string&);
ChatId(const ChatId&);
@ -19,87 +19,87 @@ namespace telebotxx
Type getType() const;
const int getId() const;
const std::string getUsername() const;
private:
private:
Type type_;
union
{
int id_;
std::string username_;
};
};
};
using Text = std::string;
using Caption = std::string;
using Text = std::string;
using Caption = std::string;
enum class ParseMode
{
enum class ParseMode
{
Plain,
Markdown,
Html
};
};
class DisableWebPagePreview
{
public:
class DisableWebPagePreview
{
public:
DisableWebPagePreview(bool disabled = true);
bool value() const;
private:
private:
bool disable_;
};
};
class DisableNotification
{
public:
class DisableNotification
{
public:
DisableNotification(bool disabled = true);
bool value() const;
private:
private:
bool disable_;
};
};
class ReplyTo
{
public:
class ReplyTo
{
public:
explicit ReplyTo(int id);
int value() const;
private:
private:
int id_;
};
};
class Buffer
{
public:
Buffer(const char* buffer, std::size_t size, const std::string& filename);
class Buffer
{
public:
Buffer(const char *buffer, std::size_t size, const std::string& filename);
explicit Buffer(const std::vector<char>& data, const std::string& filename);
const char* data() const;
const char *data() const;
const std::size_t size() const;
const std::string filename() const;
private:
const char* data_;
private:
const char *data_;
std::size_t size_;
std::string filename_;
};
};
class File
{
public:
class File
{
public:
explicit File(const std::string& filename);
const std::string& getFilename() const;
private:
private:
std::string filename_;
};
};
class Url
{
public:
class Url
{
public:
explicit Url(const std::string& url);
const std::string& getUrl() const;
private:
private:
std::string url_;
};
};
class Photo
{
public:
class Photo
{
public:
explicit Photo(int id);
explicit Photo(const Buffer&);
explicit Photo(const File&);
@ -108,7 +108,7 @@ namespace telebotxx
Photo(Photo&&);
~Photo();
enum class Type { Id, Buffer, File, Url};
enum class Type { Id, Buffer, File, Url };
Type getType() const;
int getId() const;
@ -116,7 +116,7 @@ namespace telebotxx
const File& getFile() const;
const Url& getUrl() const;
private:
private:
Type type_;
union
{
@ -125,7 +125,8 @@ namespace telebotxx
File file_;
Url url_;
};
};
};
}
#endif // TELEBOTXX_REQUEST_OPTIONS_HPP

View file

@ -4,16 +4,14 @@
#include <telebotxx/RequestOptions.hpp>
#include <telebotxx/Message.hpp>
#include <boost/optional.hpp>
#include <string>
#include <memory>
namespace telebotxx
namespace telebotxx {
class SendMessageRequest
{
class SendMessageRequest
{
public:
public:
SendMessageRequest(const std::string& telegramMainUrl, const ChatId& chat, const Text& text);
~SendMessageRequest();
@ -29,10 +27,11 @@ namespace telebotxx
Message execute();
private:
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
};
}
#endif // TELEBOTXX_SEND_MESSAGE_REQUEST_HPP

View file

@ -4,32 +4,32 @@
#include <telebotxx/RequestOptions.hpp>
#include <telebotxx/Message.hpp>
#include <boost/optional.hpp>
#include <string>
#include <memory>
namespace telebotxx
namespace telebotxx {
class SendPhotoRequest
{
class SendPhotoRequest
{
public:
public:
SendPhotoRequest(const std::string& telegramMainUrl, const ChatId& chat, const Photo& photo);
~SendPhotoRequest();
void setCaption(const Caption& caption);
void setDisableNotification(const DisableNotification& disableNotification);
void setReplyToMessageId(const ReplyTo& replyToMessageId);
void setOption(const Caption& caption);
void setOption(const DisableNotification& disableNotification);
void setOption(const ReplyTo& replyToMessageId);
Message execute();
private:
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
};
}
#endif // TELEBOTXX_SEND_PHOTO_REQUEST_HPP

View file

@ -6,11 +6,11 @@
#include <vector>
#include <memory>
namespace telebotxx
namespace telebotxx {
class Update
{
class Update
{
public:
public:
enum class Type
{
Message,
@ -30,17 +30,17 @@ namespace telebotxx
void swap(Update& other) noexcept;
private:
private:
int id_;
Type updateType_;
};
};
using UpdatePtr = std::shared_ptr<Update>;
using Updates = std::vector<UpdatePtr>;
using UpdatePtr = std::shared_ptr<Update>;
using Updates = std::vector<UpdatePtr>;
class MessageUpdate : public Update
{
public:
class MessageUpdate : public Update
{
public:
MessageUpdate(int id, const Message& message);
MessageUpdate(const MessageUpdate&);
MessageUpdate(MessageUpdate&&);
@ -52,13 +52,13 @@ namespace telebotxx
const MessageUpdate& operator=(MessageUpdate other);
private:
private:
Message message_;
};
};
class EditedMessageUpdate: public MessageUpdate
{
public:
class EditedMessageUpdate : public MessageUpdate
{
public:
EditedMessageUpdate(int id, const Message& message);
EditedMessageUpdate(const EditedMessageUpdate&);
EditedMessageUpdate(EditedMessageUpdate&&);
@ -67,7 +67,7 @@ namespace telebotxx
void swap(EditedMessageUpdate& other) noexcept;
const EditedMessageUpdate& operator=(EditedMessageUpdate other);
};
};
}

View file

@ -4,11 +4,11 @@
#include <string>
#include <memory>
namespace telebotxx
namespace telebotxx {
class User
{
class User
{
public:
public:
User();
User(const User&);
User(User&&);
@ -45,16 +45,17 @@ namespace telebotxx
const User& operator=(User other);
private:
private:
int id_;
std::string firstName_;
std::string lastName_;
std::string username_;
};
};
using UserPtr = std::shared_ptr<User>;
using UserPtr = std::shared_ptr<User>;
std::ostream& operator<<(std::ostream& os, const User& user);
std::ostream& operator<<(std::ostream& os, const User& user);
}
#endif // TELEBOTXX_USER_H

View file

@ -1,6 +1,6 @@
#include <telebotxx/Attachment.hpp>
using namespace telebotxx;
namespace telebotxx {
Attachment::Attachment(Type type)
: attachmentType_(type)
@ -8,7 +8,9 @@ Attachment::Attachment(Type type)
}
Attachment::Attachment(const Attachment&) = default;
Attachment::Attachment(Attachment&&) = default;
Attachment::~Attachment() = default;
Attachment::Type Attachment::getType() const
@ -31,7 +33,9 @@ PhotoSize::PhotoSize()
}
PhotoSize::PhotoSize(const PhotoSize&) = default;
PhotoSize::PhotoSize(PhotoSize&&) = default;
PhotoSize::~PhotoSize() = default;
const std::string& PhotoSize::getFileId() const
@ -97,7 +101,9 @@ PhotoSizeArray::PhotoSizeArray()
}
PhotoSizeArray::PhotoSizeArray(const PhotoSizeArray&) = default;
PhotoSizeArray::PhotoSizeArray(PhotoSizeArray&&) = default;
PhotoSizeArray::~PhotoSizeArray() = default;
const std::vector<PhotoSize>& PhotoSizeArray::getArray() const
@ -132,7 +138,9 @@ Audio::Audio()
}
Audio::Audio(const Audio&) = default;
Audio::Audio(Audio&&) = default;
Audio::~Audio() = default;
const std::string& Audio::getFileId() const
@ -222,7 +230,9 @@ Document::Document()
}
Document::Document(const Document&) = default;
Document::Document(Document&&) = default;
Document::~Document() = default;
const std::string& Document::getFileId() const
@ -301,7 +311,9 @@ Sticker::Sticker()
}
Sticker::Sticker(const Sticker&) = default;
Sticker::Sticker(Sticker&&) = default;
Sticker::~Sticker() = default;
const std::string& Sticker::getFileId() const
@ -384,27 +396,29 @@ const Sticker& Sticker::operator=(Sticker other) noexcept
////////////////////////////////////////////////////////////////
void telebotxx::swap(PhotoSize& lhs, PhotoSize& rhs)
void swap(PhotoSize& lhs, PhotoSize& rhs)
{
lhs.swap(rhs);
}
void telebotxx::swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs)
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs)
{
lhs.swap(rhs);
}
void telebotxx::swap(Audio& lhs, Audio& rhs)
void swap(Audio& lhs, Audio& rhs)
{
lhs.swap(rhs);
}
void telebotxx::swap(Document& lhs, Document& rhs)
void swap(Document& lhs, Document& rhs)
{
lhs.swap(rhs);
}
void telebotxx::swap(Sticker& lhs, Sticker& rhs)
void swap(Sticker& lhs, Sticker& rhs)
{
lhs.swap(rhs);
}
}

View file

@ -10,7 +10,7 @@
#include <cpr/cpr.h>
using namespace telebotxx;
namespace telebotxx {
class BotApi::Impl
{
@ -181,3 +181,5 @@ std::string BotApi::getTelegramMainUrl() const
{
return impl_->getTelegramMainUrl();
}
}

View file

@ -1,7 +1,7 @@
#include <telebotxx/Chat.hpp>
#include <stdexcept>
using namespace telebotxx;
namespace telebotxx {
Chat::Chat()
: id_(-1),
@ -11,7 +11,9 @@ Chat::Chat()
}
Chat::Chat(const Chat&) = default;
Chat::Chat(Chat&&) = default;
Chat::~Chat() = default;
std::int64_t Chat::getId() const
@ -102,12 +104,12 @@ const Chat& Chat::operator=(Chat other) noexcept
return *this;
}
void telebotxx::swap(Chat& lhs, Chat& rhs)
void swap(Chat& lhs, Chat& rhs)
{
lhs.swap(rhs);
}
Chat::Type telebotxx::chatTypeFromString(const std::string& str)
Chat::Type chatTypeFromString(const std::string& str)
{
if (str == "private")
return Chat::Type::Private;
@ -120,3 +122,5 @@ Chat::Type telebotxx::chatTypeFromString(const std::string& str)
else
throw std::invalid_argument("Unknown chat type");
}
}

View file

@ -3,47 +3,47 @@
#include <cstdint>
namespace telebotxx
namespace telebotxx {
namespace impl {
template<typename T> bool is(const rapidjson::Value& obj);
template<> bool is<int>(const rapidjson::Value& obj) { return obj.IsInt(); }
template<> bool is<std::int64_t>(const rapidjson::Value& obj) { return obj.IsInt64(); }
template<> bool is<bool>(const rapidjson::Value& obj) { return obj.IsBool(); }
template<> bool is<std::string>(const rapidjson::Value& obj) { return obj.IsString(); }
template<typename T> const T get(const rapidjson::Value& obj);
template<> const int get(const rapidjson::Value& obj) { return obj.GetInt(); }
template<> const std::int64_t get(const rapidjson::Value& obj) { return obj.GetInt64(); }
template<> const bool get(const rapidjson::Value& obj) { return obj.GetBool(); }
template<> const std::string get(const rapidjson::Value& obj) { return obj.GetString(); }
template<typename T> const T null();
template<> const int null() { return 0; }
template<> const std::int64_t null() { return 0; }
template<> const bool null() { return false; }
template<> const std::string null() { return ""; }
}
template<typename T>
const T parse(const rapidjson::Value& obj, const char* name, bool required)
{
namespace impl
{
template<typename T> bool is(const rapidjson::Value& obj);
template<> bool is<int>(const rapidjson::Value& obj) { return obj.IsInt(); }
template<> bool is<std::int64_t>(const rapidjson::Value& obj) { return obj.IsInt64(); }
template<> bool is<bool>(const rapidjson::Value& obj) { return obj.IsBool(); }
template<> bool is<std::string>(const rapidjson::Value& obj) { return obj.IsString(); }
template<typename T> const T get(const rapidjson::Value& obj);
template<> const int get(const rapidjson::Value& obj) { return obj.GetInt(); }
template<> const std::int64_t get(const rapidjson::Value& obj) { return obj.GetInt64(); }
template<> const bool get(const rapidjson::Value& obj) { return obj.GetBool(); }
template<> const std::string get(const rapidjson::Value& obj) { return obj.GetString(); }
template<typename T> const T null();
template<> const int null() { return 0; }
template<> const std::int64_t null() { return 0; }
template<> const bool null() { return false; }
template<> const std::string null() { return ""; }
}
template <typename T>
const T parse(const rapidjson::Value& obj, const char* name, bool required)
{
if (obj.HasMember(name))
{
if (impl::is<T>(obj[name]))
return impl::get<T>(obj[name]);
else
throw ParseError(std::string("Field '")+ name + "' has invalid type");
throw ParseError(std::string("Field '") + name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '")+ name + "' not found");
throw ParseError(std::string("Field '") + name + "' not found");
else
return impl::null<T>();
}
}
const rapidjson::Value& parseObject(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
const rapidjson::Value& parseObject(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
if (parent.HasMember(name))
{
if (parent[name].IsObject())
@ -52,19 +52,19 @@ namespace telebotxx
return parent[name];
}
else
throw ParseError(std::string("Field '")+ name + "' has invalid type");
throw ParseError(std::string("Field '") + name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '")+ name + "' not found");
throw ParseError(std::string("Field '") + name + "' not found");
else
{
found = false;
return parent;
}
}
}
const rapidjson::Value& parseArray(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
const rapidjson::Value& parseArray(const rapidjson::Value& parent, const char* name, bool required, bool& found)
{
if (parent.HasMember(name))
{
if (parent[name].IsArray())
@ -73,29 +73,29 @@ namespace telebotxx
return parent[name];
}
else
throw ParseError(std::string("Field '")+ name + "' has invalid type");
throw ParseError(std::string("Field '") + name + "' has invalid type");
}
else if (required)
throw ParseError(std::string("Field '")+ name + "' not found");
throw ParseError(std::string("Field '") + name + "' not found");
else
{
found = false;
return parent;
}
}
}
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& obj)
{
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& obj)
{
auto photo = std::make_unique<PhotoSize>();
photo->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
photo->setWidth(parse<int>(obj, "width", REQUIRED));
photo->setHeight(parse<int>(obj, "height", REQUIRED));
photo->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
return photo;
}
}
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -104,10 +104,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<PhotoSizeArray> parsePhotoSizeArray(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<PhotoSizeArray> parsePhotoSizeArray(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseArray(parent, name, required, found);
if (found)
@ -124,10 +124,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<Audio> parseAudio(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<Audio> parseAudio(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -143,10 +143,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<Document> parseDocument(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<Document> parseDocument(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -161,10 +161,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<Sticker> parseSticker(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<Sticker> parseSticker(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -180,10 +180,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -227,10 +227,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -247,10 +247,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<Update> parseUpdate(const rapidjson::Value& obj)
{
std::unique_ptr<Update> parseUpdate(const rapidjson::Value& obj)
{
int id = parse<int>(obj, "update_id", REQUIRED);
std::unique_ptr<Message> message;
@ -261,10 +261,10 @@ namespace telebotxx
/// \todo: other updates
else
throw ParseError("Unknown update type");
}
}
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseArray(parent, name, required, found);
if (found)
@ -279,10 +279,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required)
{
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required)
{
bool found;
auto& obj = parseObject(parent, name, required, found);
if (found)
@ -296,10 +296,10 @@ namespace telebotxx
}
else
return nullptr;
}
}
void checkResponse(const rapidjson::Document& doc)
{
void checkResponse(const rapidjson::Document& doc)
{
if (!doc.IsObject())
throw ParseError("Object expected");
@ -311,5 +311,6 @@ namespace telebotxx
std::string description(parse<std::string>(doc, "description", REQUIRED));
throw ApiError(code, description);
}
}
}
}

View file

@ -10,44 +10,45 @@
#include <rapidjson/document.h>
namespace telebotxx
{
const bool REQUIRED = true;
const bool OPTIONAL = false;
namespace telebotxx {
/// \brief Parse JSON object to Chat
/// \param parent reference to parent JSON object
/// \param name field with Chat object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to Chat
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required);
const bool REQUIRED = true;
const bool OPTIONAL = false;
/// \brief Parse JSON object to User
/// \param parent reference to parent JSON object
/// \param name field with Document object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to User
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON object to Chat
/// \param parent reference to parent JSON object
/// \param name field with Chat object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to Chat
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON object to Message
/// \param parent reference to parent JSON object
/// \param name field with Message object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to Message
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON object to User
/// \param parent reference to parent JSON object
/// \param name field with Document object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to User
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON array of Update
/// \param parent reference to parent JSON object
/// \param name field with array of Update objects
/// \param required REQUIRED or OPTIONAL
/// \return Updates (vector of UpdatePtr>
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON object to Message
/// \param parent reference to parent JSON object
/// \param name field with Message object
/// \param required REQUIRED or OPTIONAL
/// \return pointer to Message
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Parse JSON array of Update
/// \param parent reference to parent JSON object
/// \param name field with array of Update objects
/// \param required REQUIRED or OPTIONAL
/// \return Updates (vector of UpdatePtr>
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required);
/// \brief Check JSON response
///
/// Throws an exception if error code recieved.
/// \param doc reference to JSON document
void checkResponse(const rapidjson::Document& doc);
/// \brief Check JSON response
///
/// Throws an exception if error code recieved.
/// \param doc reference to JSON document
void checkResponse(const rapidjson::Document& doc);
}
#endif // TELEBOTXX_JSON_OBJECTS_HPP

View file

@ -1,11 +1,12 @@
#include <telebotxx/Logging.hpp>
namespace telebotxx
{
bool debugMode = false;
namespace telebotxx {
void setDebugMode(bool enabled)
{
bool debugMode = false;
void setDebugMode(bool enabled)
{
debugMode = enabled;
}
}
}

View file

@ -1,6 +1,6 @@
#include <telebotxx/Message.hpp>
using namespace telebotxx;
namespace telebotxx {
MessageEntity::MessageEntity()
: type_(Type::Mention),
@ -10,7 +10,9 @@ MessageEntity::MessageEntity()
}
MessageEntity::MessageEntity(const MessageEntity&) = default;
MessageEntity::MessageEntity(MessageEntity&&) = default;
MessageEntity::~MessageEntity() = default;
MessageEntity::Type MessageEntity::getType() const
@ -79,7 +81,7 @@ const MessageEntity& MessageEntity::operator=(MessageEntity other)
return *this;
}
MessageEntity::Type telebotxx::messageEntityTypeFromString(const std::string& str)
MessageEntity::Type messageEntityTypeFromString(const std::string& str)
{
if (str == "mention")
return MessageEntity::Type::Mention;
@ -113,7 +115,9 @@ Message::Message()
}
Message::Message(const Message&) = default;
Message::Message(Message&&) = default;
Message::~Message() = default;
int Message::getId() const
@ -391,7 +395,9 @@ const Message& Message::operator=(Message other) noexcept
return *this;
}
void telebotxx::swap(Message& lhs, Message& rhs)
void swap(Message& lhs, Message& rhs)
{
lhs.swap(rhs);
}
}

View file

@ -1,6 +1,6 @@
#include <telebotxx/RequestOptions.hpp>
using namespace telebotxx;
namespace telebotxx {
ChatId::ChatId(int id)
: type_(Type::Id), id_(id)
@ -95,7 +95,7 @@ int ReplyTo::value() const
////////////////////////////////////////////////////////////////
Buffer::Buffer(const char *buffer, std::size_t size, const std::string& filename)
Buffer::Buffer(const char* buffer, std::size_t size, const std::string& filename)
: data_(buffer), size_(size), filename_(filename)
{
}
@ -207,7 +207,7 @@ Photo::~Photo()
{
if (type_ == Type::File)
file_.~File();
else if(type_ == Type::Url)
else if (type_ == Type::Url)
url_.~Url();
}
@ -235,3 +235,5 @@ const Url& Photo::getUrl() const
{
return url_;
}
}

View file

@ -7,8 +7,9 @@
#include <rapidjson/writer.h>
#include <iostream>
#include <boost/optional.hpp>
using namespace telebotxx;
namespace telebotxx {
class SendMessageRequest::Impl
{
@ -61,7 +62,8 @@ public:
if (parseMode_)
{
writer.String("parse_mode");
writer.String((parseMode_ == ParseMode::Markdown) ? "Markdown" : (parseMode_ == ParseMode::Html) ? "HTML" : "Plain");
writer.String(
(parseMode_ == ParseMode::Markdown) ? "Markdown" : (parseMode_ == ParseMode::Html) ? "HTML" : "Plain");
}
// Add disable_web_page_preview
@ -173,3 +175,5 @@ Message SendMessageRequest::execute()
{
return impl_->execute();
}
}

View file

@ -1,5 +1,4 @@
#include <telebotxx/SendPhotoRequest.hpp>
#include <telebotxx/Logging.hpp>
#include "JsonObjects.hpp"
@ -8,8 +7,9 @@
#include <rapidjson/writer.h>
#include <iostream>
#include <boost/optional.hpp>
using namespace telebotxx;
namespace telebotxx {
class SendPhotoRequest::Impl
{
@ -137,3 +137,5 @@ Message SendPhotoRequest::execute()
{
return impl_->execute();
}
}

View file

@ -1,6 +1,6 @@
#include <telebotxx/Update.hpp>
using namespace telebotxx;
namespace telebotxx {
Update::Update(int id, Type type)
: id_(id),
@ -80,3 +80,5 @@ const EditedMessageUpdate& EditedMessageUpdate::operator=(EditedMessageUpdate ot
swap(other);
return *this;
}
}

View file

@ -1,7 +1,7 @@
#include <telebotxx/User.hpp>
#include <sstream>
using namespace telebotxx;
namespace telebotxx {
User::User()
: id_(-1)
@ -9,7 +9,9 @@ User::User()
}
User::User(const User&) = default;
User::User(User&&) = default;
User::~User() = default;
int User::getId() const
@ -73,8 +75,10 @@ const User& User::operator=(User other)
return *this;
}
std::ostream& telebotxx::operator<<(std::ostream& os, const User& user)
std::ostream& operator<<(std::ostream& os, const User& user)
{
os << user.toString();
return os;
}
}