diff --git a/include/telebotxx/Attachment.hpp b/include/telebotxx/Attachment.hpp index 86a8a54..4353de4 100644 --- a/include/telebotxx/Attachment.hpp +++ b/include/telebotxx/Attachment.hpp @@ -1,13 +1,133 @@ #ifndef TELEBOTXX_ATTACHMENT_HPP #define TELEBOTXX_ATTACHMENT_HPP +#include "Optional.hpp" + #include -#include -#include #include +#include +#include namespace telebotxx { +class PhotoSize +{ +public: + 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); + + const optional& getFileSize() const; + void setFileSize(optional fileSize); + +private: + std::string fileId_; + int width_; + int height_; + optional fileSize_; +}; + +using PhotoSizeArray = std::vector; + +class Audio +{ +public: + Audio(); + + const std::string& getFileId() const; + void setFileId(const std::string& fileId); + + int getDuration() const; + void setDuration(int duration); + + const optional& getPerformer() const; + void setPerformer(optional performer); + + const optional& getTitle() const; + void setTitle(optional title); + + const optional& getMimeType() const; + void setMimeType(optional mimeType); + + const optional& getFileSize() const; + void setFileSize(optional fileSize); + +private: + std::string fileId_; + int duration_; + optional performer_; + optional title_; + optional mimeType_; + optional fileSize_; +}; + +class Document +{ +public: + Document(); + + const std::string& getFileId() const; + void setFileId(std::string fileId); + + const optional& getThumb() const; + void setThumb(optional thumb); + + const optional& getFileName() const; + void setFileName(optional fileName); + + const optional& getMimeType() const; + void setMimeType(optional mimeType); + + const optional& getFileSize() const; + void setFileSize(optional fileSize); + +private: + std::string fileId_; + optional thumb_; + optional fileName_; + optional mimeType_; + optional fileSize_; +}; + +class Sticker +{ +public: + 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 optional& getThumb() const; + void setThumb(optional thumb); + + const optional& getEmoji() const; + void setEmoji(optional emoji); + + const optional& getFileSize() const; + void setFileSize(optional fileSize); + +private: + std::string fileId_; + int width_; + int height_; + optional thumb_; + optional emoji_; + optional fileSize_; +}; + class Attachment { public: @@ -25,194 +145,23 @@ public: Venue }; - Attachment(Type type); - Attachment(const Attachment&); - Attachment(Attachment&&); - virtual ~Attachment() = 0; + Attachment(PhotoSizeArray); + Attachment(Audio); + Attachment(Document); + Attachment(Sticker); Type getType() const; - void swap(Attachment& other) noexcept; + const PhotoSizeArray& getPhotoSizeArray() const; + const Audio& getAudio() const; + const Document& getDocument() const; + const Sticker& getSticker() const; private: - Type attachmentType_; + Type type_; + boost::variant value_; }; -using AttachmentPtr = std::shared_ptr; - -class PhotoSize -{ -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 PhotoSizeArray : public Attachment -{ -public: - PhotoSizeArray(); - PhotoSizeArray(const PhotoSizeArray&); - PhotoSizeArray(PhotoSizeArray&&); - ~PhotoSizeArray(); - - const std::vector& getArray() const; - void setArray(const std::vector& array); - - void swap(PhotoSizeArray& other) noexcept; - - const PhotoSizeArray& operator=(PhotoSizeArray other) noexcept; - -private: - std::vector array_; -}; - -using PhotoSizeArrayPtr = 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(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 diff --git a/include/telebotxx/Chat.hpp b/include/telebotxx/Chat.hpp index 4939b7e..1a5091c 100644 --- a/include/telebotxx/Chat.hpp +++ b/include/telebotxx/Chat.hpp @@ -1,6 +1,8 @@ #ifndef TELEBOTXX_CHAT_HPP #define TELEBOTXX_CHAT_HPP +#include "Optional.hpp" + #include #include #include @@ -19,9 +21,6 @@ public: }; Chat(); - Chat(const Chat&); - Chat(Chat&&); - ~Chat(); std::int64_t getId() const; void setId(std::int64_t id); @@ -29,39 +28,31 @@ public: Type getType() const; void setType(Type type); - const std::string& getTitle() const; - void setTitle(const std::string& title); + const optional& getTitle() const; + void setTitle(optional title); - const std::string& getUsername() const; - void setUsername(const std::string& username); + const optional& getUsername() const; + void setUsername(optional username); - const std::string& getFirstName() const; - void setFirstName(const std::string& firstName); + const optional& getFirstName() const; + void setFirstName(optional firstName); - const std::string& getLastName() const; - void setLastName(const std::string& lastName); + const optional& getLastName() const; + void setLastName(optional lastName); bool isAllAdmins() const; void setAllAdmins(bool allAdmins); - void swap(Chat& other) noexcept; - - const Chat& operator=(Chat other) noexcept; - private: std::int64_t id_; Type type_; - std::string title_; - std::string username_; - std::string firstName_; - std::string lastName_; + optional title_; + optional username_; + optional firstName_; + optional lastName_; bool allAdmins_; }; -using ChatPtr = std::shared_ptr; - -void swap(Chat& lhs, Chat& rhs); - Chat::Type chatTypeFromString(const std::string& str); } diff --git a/include/telebotxx/Exception.hpp b/include/telebotxx/Exception.hpp index 091491f..9a5a79f 100644 --- a/include/telebotxx/Exception.hpp +++ b/include/telebotxx/Exception.hpp @@ -17,8 +17,8 @@ public: class ApiError : public std::runtime_error { public: - ApiError(int code, const std::string& message) - : std::runtime_error(message), code_(code) + ApiError(int code, std::string message) + : std::runtime_error(std::move(message)), code_(code) { } diff --git a/include/telebotxx/Message.hpp b/include/telebotxx/Message.hpp index fdd235a..e461fc1 100644 --- a/include/telebotxx/Message.hpp +++ b/include/telebotxx/Message.hpp @@ -4,10 +4,12 @@ #include "User.hpp" #include "Chat.hpp" #include "Attachment.hpp" +#include "Optional.hpp" #include #include #include +#include namespace telebotxx { @@ -30,9 +32,6 @@ public: }; MessageEntity(); - MessageEntity(const MessageEntity&); - MessageEntity(MessageEntity&&); - ~MessageEntity(); Type getType() const; void setType(Type type); @@ -43,22 +42,18 @@ public: size_t getLength() const; void setLength(size_t length); - const std::string& getUrl() const; - void setUrl(const std::string& url); + const optional& getUrl() const; + void setUrl(std::string url); - const User& getUser() const; - void setUser(const User& user); - - void swap(MessageEntity& other) noexcept; - - const MessageEntity& operator=(MessageEntity other); + const optional& getUser() const; + void setUser(User user); private: Type type_; int offset_; std::size_t length_; - std::string url_; - User user_; + optional url_; + optional user_; }; MessageEntity::Type messageEntityTypeFromString(const std::string& str); @@ -72,60 +67,57 @@ class Message { public: Message(); - Message(const Message&); - Message(Message&&); - ~Message(); int getId() const; void setId(int id); - const UserPtr getFrom() const; - void setFrom(UserPtr from); + const optional& getFrom() const; + void setFrom(optional from); time_t getDate() const; void setDate(time_t date); const Chat& getChat() const; - void setChat(const Chat& chat); + void setChat(Chat chat); - const UserPtr getForwardFrom() const; - void setForwardFrom(UserPtr forwardFrom); + const optional& getForwardFrom() const; + void setForwardFrom(optional forwardFrom); - const ChatPtr getForwardFromChat() const; - void setForwardFromChat(ChatPtr forwardFromChat); + const optional& getForwardFromChat() const; + void setForwardFromChat(optional forwardFromChat); - time_t getForwardDate() const; - void setForwardDate(time_t forwardDate); + const optional& getForwardDate() const; + void setForwardDate(optional forwardDate); - const MessagePtr getReplyToMessage() const; + MessagePtr getReplyToMessage() const; void setReplyToMessage(MessagePtr replyToMessage); - time_t getEditDate() const; - void setEditDate(time_t editDate); + const optional& getEditDate() const; + void setEditDate(optional editDate); - const std::string& getText() const; - void setText(const std::string& text); + const optional& getText() const; + void setText(optional text); - const MessageEntities& getEntities() const; - void setEntities(MessageEntities&& entities); + const optional& getEntities() const; + void setEntities(optional entities); - const AttachmentPtr getAttachment() const; - void setAttachment(AttachmentPtr attachment); + const optional& getAttachment() const; + void setAttachment(optional attachment); - const std::string& getCaption() const; - void setCaption(const std::string& caption); + const optional& getCaption() const; + void setCaption(optional caption); - const UserPtr getNewChatMember() const; - void setNewChatMember(UserPtr newChatMember); + const optional& getNewChatMember() const; + void setNewChatMember(optional newChatMember); - const UserPtr getLeftChatMember() const; - void setLeftChatMember(UserPtr leftChatMember); + const optional& getLeftChatMember() const; + void setLeftChatMember(optional leftChatMember); - const std::string& getNewChatTitle() const; - void setNewChatTitle(const std::string& newChatTitle); + const optional& getNewChatTitle() const; + void setNewChatTitle(optional newChatTitle); - const PhotoSizeArrayPtr getNewChatPhoto() const; - void setNewChatPhoto(PhotoSizeArrayPtr newChatPhoto); + const optional getNewChatPhoto() const; + void setNewChatPhoto(optional newChatPhoto); bool isDeleteChatPhoto() const; void setDeleteChatPhoto(bool deleteChatPhoto); @@ -139,48 +131,43 @@ public: bool isChannelChatCreated() const; void setChannelChatCreated(bool channelChatCreated); - std::int64_t getMigrateToChatId() const; - void setMigrateToChatId(std::int64_t migrateToChatId); + const optional& getMigrateToChatId() const; + void setMigrateToChatId(optional migrateToChatId); - std::int64_t getMigrateFromChatId() const; - void setMigrateFromChatId(std::int64_t migrateFromChatId); + const optional& getMigrateFromChatId() const; + void setMigrateFromChatId(optional migrateFromChatId); - const MessagePtr getPinnedMessage() const; + MessagePtr getPinnedMessage() const; void setPinnedMessage(MessagePtr pinnedMessage); - void swap(Message& other) noexcept; - - const Message& operator=(Message other) noexcept; - private: int id_; - UserPtr from_; + optional from_; std::time_t date_; Chat chat_; - UserPtr forwardFrom_; - ChatPtr forwardFromChat_; - std::time_t forwardDate_; + optional forwardFrom_; + optional forwardFromChat_; + optional forwardFromMessageId_; + optional forwardDate_; MessagePtr replyToMessage_; - std::time_t editDate_; - std::string text_; - MessageEntities entities_; - AttachmentPtr attachment_; - std::string caption_; - UserPtr newChatMember_; - UserPtr leftChatMember_; - std::string newChatTitle_; - PhotoSizeArrayPtr newChatPhoto_; + optional editDate_; + optional text_; + optional entities_; + optional attachment_; + optional caption_; + optional newChatMember_; + optional leftChatMember_; + optional newChatTitle_; + optional newChatPhoto_; bool deleteChatPhoto_; bool groupChatCreated_; bool superGroupChatCreated_; bool channelChatCreated_; - std::int64_t migrateToChatId_; - std::int64_t migrateFromChatId_; + optional migrateToChatId_; + optional migrateFromChatId_; MessagePtr pinnedMessage_; }; -void swap(Message& lhs, Message& rhs); - } #endif // TELEBOTXX_MESSAGE_HPP diff --git a/include/telebotxx/Optional.hpp b/include/telebotxx/Optional.hpp new file mode 100644 index 0000000..7512c34 --- /dev/null +++ b/include/telebotxx/Optional.hpp @@ -0,0 +1,15 @@ +#ifndef TELEBOTXX_OPTIONAL_HPP +#define TELEBOTXX_OPTIONAL_HPP + +#include + +namespace telebotxx { + +template +using optional = boost::optional; + +const auto none = boost::none; + +} + +#endif // TELEBOTXX_OPTIONAL_HPP diff --git a/include/telebotxx/RequestOptions.hpp b/include/telebotxx/RequestOptions.hpp index 33bd2b7..d299b5f 100644 --- a/include/telebotxx/RequestOptions.hpp +++ b/include/telebotxx/RequestOptions.hpp @@ -31,9 +31,6 @@ class ChatId public: ChatId(int); ChatId(const std::string&); - ChatId(const ChatId&); - ChatId(ChatId&&); - ~ChatId(); enum class Type { Id, Username }; Type getType() const; @@ -92,9 +89,6 @@ public: explicit Photo(const Buffer&); explicit Photo(const File&); explicit Photo(const Url&); - Photo(const Photo&); - Photo(Photo&&); - ~Photo(); enum class Type { Id, Buffer, File, Url }; Type getType() const; diff --git a/include/telebotxx/Update.hpp b/include/telebotxx/Update.hpp index 0703021..f978f1a 100644 --- a/include/telebotxx/Update.hpp +++ b/include/telebotxx/Update.hpp @@ -14,55 +14,27 @@ public: enum class Type { Message, + EditedMessage, + ChannelPost, + EditedChannelPost, InlineQuery, ChosenInlineResult, CallbackQuery }; - Update(int id, Type type); - Update(const Update&); - Update(Update&&); - virtual ~Update() = 0; + Update(int id, Type type, std::unique_ptr); int getId() const; Type getType() const; - - void swap(Update& other) noexcept; + MessagePtr getMessage() const; private: int id_; - Type updateType_; + Type type_; + boost::variant value_; }; -using UpdatePtr = std::shared_ptr; -using Updates = std::vector; - -class MessageUpdate : public Update -{ -public: - enum class MessageType - { - Message, - EditedMessage, - ChannelPost, - EditedChannelPost - }; - - MessageUpdate(int id, MessageType type, const Message& message); - MessageUpdate(const MessageUpdate&); - MessageUpdate(MessageUpdate&&); - ~MessageUpdate(); - - MessageType getMessageType() const; - const Message& getMessage() const; - - void swap(MessageUpdate& other) noexcept; - const MessageUpdate& operator=(MessageUpdate other); - -private: - MessageType type_; - Message message_; -}; +using Updates = std::vector; } diff --git a/include/telebotxx/User.hpp b/include/telebotxx/User.hpp index a36ad83..06fb128 100644 --- a/include/telebotxx/User.hpp +++ b/include/telebotxx/User.hpp @@ -1,6 +1,7 @@ #ifndef TELEBOTXX_USER_H #define TELEBOTXX_USER_H +#include "Optional.hpp" #include #include @@ -10,9 +11,6 @@ class User { public: User(); - User(const User&); - User(User&&); - ~User(); /// \brief Get id int getId() const; @@ -24,36 +22,30 @@ public: const std::string& getFirstName() const; /// \brief Set first name - void setFirstName(const std::string& firstName); + void setFirstName(std::string firstName); /// \brief Get last name - const std::string& getLastName() const; + const optional& getLastName() const; /// \brief Set last name - void setLastName(const std::string& lastName); + void setLastName(optional lastName); /// \brief Get username - const std::string& getUsername() const; + const optional& getUsername() const; /// \brief Set username - void setUsername(const std::string& username); + void setUsername(optional username); /// \brief Get string representation of user const std::string toString() const; - void swap(User&) noexcept; - - const User& operator=(User other); - private: int id_; std::string firstName_; - std::string lastName_; - std::string username_; + optional lastName_; + optional username_; }; -using UserPtr = std::shared_ptr; - std::ostream& operator<<(std::ostream& os, const User& user); } diff --git a/src/Attachment.cpp b/src/Attachment.cpp index 66b391b..cb18aca 100644 --- a/src/Attachment.cpp +++ b/src/Attachment.cpp @@ -1,30 +1,9 @@ #include +#include + 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() : width_(-1), height_(-1), @@ -32,12 +11,6 @@ PhotoSize::PhotoSize() { } -PhotoSize::PhotoSize(const PhotoSize&) = default; - -PhotoSize::PhotoSize(PhotoSize&&) = default; - -PhotoSize::~PhotoSize() = default; - const std::string& PhotoSize::getFileId() const { return fileId_; @@ -68,81 +41,24 @@ void PhotoSize::setHeight(int height) height_ = height; } -int PhotoSize::getFileSize() const +const optional& PhotoSize::getFileSize() const { return fileSize_; } -void PhotoSize::setFileSize(int fileSize) +void PhotoSize::setFileSize(optional fileSize) { fileSize_ = fileSize; } -void PhotoSize::swap(PhotoSize& other) noexcept -{ - 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; -} - -//////////////////////////////////////////////////////////////// - -PhotoSizeArray::PhotoSizeArray() - : Attachment(Attachment::Type::PhotoSizeArray) -{ -} - -PhotoSizeArray::PhotoSizeArray(const PhotoSizeArray&) = default; - -PhotoSizeArray::PhotoSizeArray(PhotoSizeArray&&) = default; - -PhotoSizeArray::~PhotoSizeArray() = default; - -const std::vector& PhotoSizeArray::getArray() const -{ - return array_; -} - -void PhotoSizeArray::setArray(const std::vector& array) -{ - array_ = array; -} - -void PhotoSizeArray::swap(PhotoSizeArray& other) noexcept -{ - using std::swap; - swap(array_, other.array_); -} - -const PhotoSizeArray& PhotoSizeArray::operator=(PhotoSizeArray other) noexcept -{ - swap(other); - return *this; -} - //////////////////////////////////////////////////////////////// Audio::Audio() - : Attachment(Type::Audio), - duration_(-1), + : duration_(-1), fileSize_(-1) { } -Audio::Audio(const Audio&) = default; - -Audio::Audio(Audio&&) = default; - -Audio::~Audio() = default; - const std::string& Audio::getFileId() const { return fileId_; @@ -163,159 +79,110 @@ void Audio::setDuration(int duration) duration_ = duration; } -const std::string& Audio::getPerformer() const +const optional& Audio::getPerformer() const { return performer_; } -void Audio::setPerformer(const std::string& performer) +void Audio::setPerformer(optional performer) { - performer_ = performer; + performer_ = std::move(performer); } -const std::string& Audio::getTitle() const +const optional& Audio::getTitle() const { return title_; } -void Audio::setTitle(const std::string& title) +void Audio::setTitle(optional title) { title_ = title; } -const std::string& Audio::getMimeType() const +const optional& Audio::getMimeType() const { return mimeType_; } -void Audio::setMimeType(const std::string& mimeType) +void Audio::setMimeType(optional mimeType) { mimeType_ = mimeType; } -int Audio::getFileSize() const +const optional& Audio::getFileSize() const { return fileSize_; } -void Audio::setFileSize(int fileSize) +void Audio::setFileSize(optional 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) + : 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) +void Document::setFileId(std::string fileId) { fileId_ = fileId; } -const PhotoSizePtr Document::getThumb() const +const optional& Document::getThumb() const { return thumb_; } -void Document::setThumb(const PhotoSizePtr& thumb) +void Document::setThumb(optional thumb) { thumb_ = thumb; } -const std::string& Document::getFileName() const +const optional& Document::getFileName() const { return fileName_; } -void Document::setFileName(const std::string& fileName) +void Document::setFileName(optional fileName) { fileName_ = fileName; } -const std::string& Document::getMimeType() const +const optional& Document::getMimeType() const { return mimeType_; } -void Document::setMimeType(const std::string& mimeType) +void Document::setMimeType(optional mimeType) { mimeType_ = mimeType; } -int Document::getFileSize() const +const optional& Document::getFileSize() const { return fileSize_; } -void Document::setFileSize(int fileSize) +void Document::setFileSize(optional 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) + : fileSize_(-1) { } -Sticker::Sticker(const Sticker&) = default; - -Sticker::Sticker(Sticker&&) = default; - -Sticker::~Sticker() = default; - const std::string& Sticker::getFileId() const { return fileId_; @@ -346,79 +213,81 @@ void Sticker::setHeight(int height) height_ = height; } -const PhotoSizePtr Sticker::getThumb() const +const optional& Sticker::getThumb() const { return thumb_; } -void Sticker::setThumb(const PhotoSizePtr& thumb) +void Sticker::setThumb(optional thumb) { thumb_ = thumb; } -const std::string& Sticker::getEmoji() const +const optional& Sticker::getEmoji() const { return emoji_; } -void Sticker::setEmoji(const std::string& emoji) +void Sticker::setEmoji(optional emoji) { emoji_ = emoji; } -int Sticker::getFileSize() const +const optional& Sticker::getFileSize() const { return fileSize_; } -void Sticker::setFileSize(int fileSize) +void Sticker::setFileSize(optional 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 swap(PhotoSize& lhs, PhotoSize& rhs) +Attachment::Attachment(PhotoSizeArray photos) + : type_(Type::PhotoSizeArray), value_(std::move(photos)) { - lhs.swap(rhs); } -void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs) +Attachment::Attachment(Audio audio) + : type_(Type::Audio), value_(std::move(audio)) { - lhs.swap(rhs); } -void swap(Audio& lhs, Audio& rhs) +Attachment::Attachment(Document document) + : type_(Type::Document), value_(std::move(document)) { - lhs.swap(rhs); } -void swap(Document& lhs, Document& rhs) +Attachment::Attachment(Sticker sticker) + : type_(Type::Sticker), value_(std::move(sticker)) { - lhs.swap(rhs); } -void swap(Sticker& lhs, Sticker& rhs) +Attachment::Type Attachment::getType() const { - lhs.swap(rhs); + return type_; +} + +const PhotoSizeArray& Attachment::getPhotoSizeArray() const +{ + return boost::get(value_); +} + +const Audio& Attachment::getAudio() const +{ + return boost::get