From d5fce8062a04977fc55cd6a2cb6a86e39369f735 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 15 Oct 2016 01:55:17 +0300 Subject: [PATCH] Classes Attachment, PhotoSize, Audio, Document and Sticker implemented. --- include/telebotxx/Attachment.hpp | 195 ++++++++++++++++ src/Attachment.cpp | 374 +++++++++++++++++++++++++++++++ src/CMakeLists.txt | 3 +- 3 files changed, 571 insertions(+), 1 deletion(-) create mode 100644 include/telebotxx/Attachment.hpp create mode 100644 src/Attachment.cpp diff --git a/include/telebotxx/Attachment.hpp b/include/telebotxx/Attachment.hpp new file mode 100644 index 0000000..a07ea25 --- /dev/null +++ b/include/telebotxx/Attachment.hpp @@ -0,0 +1,195 @@ +#ifndef TELEBOTXX_ATTACHMENT_HPP +#define TELEBOTXX_ATTACHMENT_HPP + +#include +#include +#include +#include + +namespace telebotxx +{ + class Attachment + { + public: + enum class Type + { + Audio, + Document, + Game, + PhotoSize, + Sticker, + Video, + Voice, + Contact, + Location, + Venue + }; + + Attachment(Type type); + Attachment(const Attachment&); + Attachment(Attachment&&); + virtual ~Attachment() = 0; + + Type getType() const; + + void swap(Attachment& other) noexcept; + + private: + Type attachmentType_; + }; + + using AttachmentPtr = std::shared_ptr; + + class PhotoSize : public Attachment + { + public: + PhotoSize(); + PhotoSize(const PhotoSize&); + PhotoSize(PhotoSize&&); + ~PhotoSize(); + + const std::string& getFileId() const; + void setFileId(const std::string& fileId); + + int getWidth() const; + void setWidth(int width); + + int getHeight() const; + void setHeight(int height); + + int getFileSize() const; + void setFileSize(int fileSize); + + void swap(PhotoSize& other) noexcept; + + const PhotoSize& operator=(PhotoSize other) noexcept; + + private: + std::string fileId_; + int width_; + int height_; + int fileSize_; + }; + + using PhotoSizePtr = std::shared_ptr; + + class Audio : public Attachment + { + public: + Audio(); + Audio(const Audio&); + Audio(Audio&&); + ~Audio(); + + const std::string& getFileId() const; + void setFileId(const std::string& fileId); + + int getDuration() const; + void setDuration(int duration); + + const std::string& getPerformer() const; + void setPerformer(const std::string& performer); + + const std::string& getTitle() const; + void setTitle(const std::string& title); + + const std::string& getMimeType() const; + void setMimeType(const std::string& mimeType); + + int getFileSize() const; + void setFileSize(int fileSize); + + void swap(Audio& other) noexcept; + + const Audio& operator=(Audio other) noexcept; + + private: + std::string fileId_; + int duration_; + std::string performer_; + std::string title_; + std::string mimeType_; + int fileSize_; + }; + + class Document : public Attachment + { + public: + Document(); + Document(const Document&); + Document(Document&&); + ~Document(); + + const std::string& getFileId() const; + void setFileId(const std::string& fileId); + + const PhotoSizePtr getThumb() const; + void setThumb(const PhotoSizePtr& thumb); + + const std::string& getFileName() const; + void setFileName(const std::string& fileName); + + const std::string& getMimeType() const; + void setMimeType(const std::string& mimeType); + + int getFileSize() const; + void setFileSize(int fileSize); + + void swap(Document& other) noexcept; + + const Document& operator=(Document other) noexcept; + + private: + std::string fileId_; + PhotoSizePtr thumb_; + std::string fileName_; + std::string mimeType_; + int fileSize_; + }; + + class Sticker : public Attachment + { + public: + Sticker(); + Sticker(const Sticker&); + Sticker(Sticker&&); + ~Sticker(); + + const std::string& getFileId() const; + void setFileId(const std::string& fileId); + + int getWidth() const; + void setWidth(int width); + + int getHeight() const; + void setHeight(int height); + + const PhotoSizePtr getThumb() const; + void setThumb(const PhotoSizePtr& thumb); + + const std::string& getEmoji() const; + void setEmoji(const std::string& emoji); + + int getFileSize() const; + void setFileSize(int fileSize); + + void swap(Sticker& other) noexcept; + + const Sticker& operator=(Sticker other) noexcept; + + private: + std::string fileId_; + int width_; + int height_; + PhotoSizePtr thumb_; + std::string emoji_; + int fileSize_; + }; + + void swap(PhotoSize& lhs, PhotoSize& rhs); + void swap(Audio& lhs, Audio& rhs); + void swap(Document& lhs, Document& rhs); + void swap(Sticker& lhs, Sticker& rhs); +} + +#endif // TELEBOTXX_ATTACHMENT_HPP diff --git a/src/Attachment.cpp b/src/Attachment.cpp new file mode 100644 index 0000000..e9c35aa --- /dev/null +++ b/src/Attachment.cpp @@ -0,0 +1,374 @@ +#include + +using namespace telebotxx; + +Attachment::Attachment(Type type) + : attachmentType_(type) +{ +} + +Attachment::Attachment(const Attachment&) = default; +Attachment::Attachment(Attachment&&) = default; +Attachment::~Attachment() = default; + +Attachment::Type Attachment::getType() const +{ + return attachmentType_; +} + +void Attachment::swap(Attachment& other) noexcept +{ + std::swap(attachmentType_, other.attachmentType_); +} + +//////////////////////////////////////////////////////////////// + +PhotoSize::PhotoSize() + : Attachment(Type::PhotoSize), + width_(-1), + height_(-1), + fileSize_(-1) +{ +} + +PhotoSize::PhotoSize(const PhotoSize&) = default; +PhotoSize::PhotoSize(PhotoSize&&) = default; +PhotoSize::~PhotoSize() = default; + +const std::string& PhotoSize::getFileId() const +{ + return fileId_; +} + +void PhotoSize::setFileId(const std::string& fileId) +{ + fileId_ = fileId; +} + +int PhotoSize::getWidth() const +{ + return width_; +} + +void PhotoSize::setWidth(int width) +{ + width_ = width; +} + +int PhotoSize::getHeight() const +{ + return height_; +} + +void PhotoSize::setHeight(int height) +{ + height_ = height; +} + +int PhotoSize::getFileSize() const +{ + return fileSize_; +} + +void PhotoSize::setFileSize(int fileSize) +{ + fileSize_ = fileSize; +} + +void PhotoSize::swap(PhotoSize& other) noexcept +{ + Attachment::swap(other); + using std::swap; + swap(fileId_, other.fileId_); + swap(width_, other.width_); + swap(height_, other.height_); + swap(fileSize_, other.fileSize_); +} + +const PhotoSize& PhotoSize::operator=(PhotoSize other) noexcept +{ + swap(other); + return *this; +} + +//////////////////////////////////////////////////////////////// + +Audio::Audio() + : Attachment(Type::Audio), + duration_(-1), + fileSize_(-1) +{ +} + +Audio::Audio(const Audio&) = default; +Audio::Audio(Audio&&) = default; +Audio::~Audio() = default; + +const std::string& Audio::getFileId() const +{ + return fileId_; +} + +void Audio::setFileId(const std::string& fileId) +{ + fileId_ = fileId; +} + +int Audio::getDuration() const +{ + return duration_; +} + +void Audio::setDuration(int duration) +{ + duration_ = duration; +} + +const std::string& Audio::getPerformer() const +{ + return performer_; +} + +void Audio::setPerformer(const std::string& performer) +{ + performer_ = performer; +} + +const std::string& Audio::getTitle() const +{ + return title_; +} + +void Audio::setTitle(const std::string& title) +{ + title_ = title; +} + +const std::string& Audio::getMimeType() const +{ + return mimeType_; +} + +void Audio::setMimeType(const std::string& mimeType) +{ + mimeType_ = mimeType; +} + +int Audio::getFileSize() const +{ + return fileSize_; +} + +void Audio::setFileSize(int fileSize) +{ + fileSize_ = fileSize; +} + +void Audio::swap(Audio& other) noexcept +{ + Attachment::swap(other); + using std::swap; + swap(fileId_, other.fileId_); + swap(duration_, other.duration_); + swap(performer_, other.performer_); + swap(title_, other.title_); + swap(mimeType_, other.mimeType_); + swap(fileSize_, other.fileSize_); +} + +const Audio& Audio::operator=(Audio other) noexcept +{ + swap(other); + return *this; +} + +//////////////////////////////////////////////////////////////// + +Document::Document() + : Attachment(Type::Document), + fileSize_(-1) +{ +} + +Document::Document(const Document&) = default; +Document::Document(Document&&) = default; +Document::~Document() = default; + +const std::string& Document::getFileId() const +{ + return fileId_; +} + +void Document::setFileId(const std::string& fileId) +{ + fileId_ = fileId; +} + +const PhotoSizePtr Document::getThumb() const +{ + return thumb_; +} + +void Document::setThumb(const PhotoSizePtr& thumb) +{ + thumb_ = thumb; +} + +const std::string& Document::getFileName() const +{ + return fileName_; +} + +void Document::setFileName(const std::string& fileName) +{ + fileName_ = fileName; +} + +const std::string& Document::getMimeType() const +{ + return mimeType_; +} + +void Document::setMimeType(const std::string& mimeType) +{ + mimeType_ = mimeType; +} + +int Document::getFileSize() const +{ + return fileSize_; +} + +void Document::setFileSize(int fileSize) +{ + fileSize_ = fileSize; +} + +void Document::swap(Document& other) noexcept +{ + Attachment::swap(other); + using std::swap; + swap(fileId_, other.fileId_); + swap(thumb_, other.thumb_); + swap(fileName_, other.fileName_); + swap(mimeType_, other.mimeType_); + swap(fileSize_, other.fileSize_); +} + +const Document& Document::operator=(Document other) noexcept +{ + swap(other); + return *this; +} + +//////////////////////////////////////////////////////////////// + +Sticker::Sticker() + : Attachment(Type::Sticker), + fileSize_(-1) +{ +} + +Sticker::Sticker(const Sticker&) = default; +Sticker::Sticker(Sticker&&) = default; +Sticker::~Sticker() = default; + +const std::string& Sticker::getFileId() const +{ + return fileId_; +} + +void Sticker::setFileId(const std::string& fileId) +{ + fileId_ = fileId; +} + +int Sticker::getWidth() const +{ + return width_; +} + +void Sticker::setWidth(int width) +{ + width_ = width; +} + +int Sticker::getHeight() const +{ + return height_; +} + +void Sticker::setHeight(int height) +{ + height_ = height; +} + +const PhotoSizePtr Sticker::getThumb() const +{ + return thumb_; +} + +void Sticker::setThumb(const PhotoSizePtr& thumb) +{ + thumb_ = thumb; +} + +const std::string& Sticker::getEmoji() const +{ + return emoji_; +} + +void Sticker::setEmoji(const std::string& emoji) +{ + emoji_ = emoji; +} + +int Sticker::getFileSize() const +{ + return fileSize_; +} + +void Sticker::setFileSize(int fileSize) +{ + fileSize_ = fileSize; +} + +void Sticker::swap(Sticker& other) noexcept +{ + Attachment::swap(other); + using std::swap; + swap(fileId_, other.fileId_); + swap(width_, other.width_); + swap(height_, other.height_); + swap(thumb_, other.thumb_); + swap(emoji_, other.emoji_); + swap(fileSize_, other.fileSize_); +} + +const Sticker& Sticker::operator=(Sticker other) noexcept +{ + swap(other); + return *this; +} + +//////////////////////////////////////////////////////////////// + +void telebotxx::swap(PhotoSize& lhs, PhotoSize& rhs) +{ + lhs.swap(rhs); +} + +void telebotxx::swap(Audio& lhs, Audio& rhs) +{ + lhs.swap(rhs); +} + +void telebotxx::swap(Document& lhs, Document& rhs) +{ + lhs.swap(rhs); +} + +void telebotxx::swap(Sticker& lhs, Sticker& rhs) +{ + lhs.swap(rhs); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8e1192..8429621 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,8 @@ endif(NOT WIN32) # Put compiled library to 'lib' directory set(LIBRARY_OUTPUT_PATH "../lib") -set(SOURCE_FILES BotApi.cpp +set(SOURCE_FILES Attachment.cpp + BotApi.cpp Chat.cpp Logging.cpp User.cpp