From 10dda01a61cec2593e46b433aebb2386f09d6be7 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Fri, 14 Oct 2016 23:48:02 +0300 Subject: [PATCH] Class Chat implemented. --- include/telebotxx/Chat.hpp | 64 +++++++++++++++++++ src/CMakeLists.txt | 1 + src/Chat.cpp | 122 +++++++++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 include/telebotxx/Chat.hpp create mode 100644 src/Chat.cpp diff --git a/include/telebotxx/Chat.hpp b/include/telebotxx/Chat.hpp new file mode 100644 index 0000000..683f666 --- /dev/null +++ b/include/telebotxx/Chat.hpp @@ -0,0 +1,64 @@ +#ifndef TELEBOTXX_CHAT_HPP +#define TELEBOTXX_CHAT_HPP + +#include + +namespace telebotxx +{ + class Chat + { + public: + enum class Type + { + Private, + Group, + Supergroup, + Channel + }; + + Chat(); + Chat(const Chat&); + Chat(Chat&&); + ~Chat(); + + int getId() const; + void setId(int id); + + Type getType() const; + void setType(Type type); + + const std::string& getTitle() const; + void setTitle(const std::string& title); + + const std::string& getUsername() const; + void setUsername(const std::string& username); + + const std::string& getFirstName() const; + void setFirstName(const std::string& firstName); + + const std::string& getLastName() const; + void setLastName(const std::string& lastName); + + bool isAllAdmins() const; + void setAllAdmins(bool allAdmins); + + void swap(Chat& other) noexcept; + + const Chat& operator=(Chat other) noexcept; + + private: + int id_; + Type type_; + std::string title_; + std::string username_; + std::string firstName_; + std::string lastName_; + bool allAdmins_; + }; + + void swap(Chat& lhs, Chat& rhs); + + Chat::Type chatTypeFromString(const std::string& str); +} + +#endif // TELEBOTXX_CHAT_HPP diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c9e1cea..b8e1192 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,7 @@ endif(NOT WIN32) set(LIBRARY_OUTPUT_PATH "../lib") set(SOURCE_FILES BotApi.cpp + Chat.cpp Logging.cpp User.cpp ) diff --git a/src/Chat.cpp b/src/Chat.cpp new file mode 100644 index 0000000..51402d7 --- /dev/null +++ b/src/Chat.cpp @@ -0,0 +1,122 @@ +#include +#include + +using namespace telebotxx; + +Chat::Chat() + : id_(-1), + type_(Type::Private), + allAdmins_(false) +{ +} + +Chat::Chat(const Chat&) = default; +Chat::Chat(Chat&&) = default; +Chat::~Chat() = default; + +int Chat::getId() const +{ + return id_; +} + +void Chat::setId(int id) +{ + id_ = id; +} + +Chat::Type Chat::getType() const +{ + return type_; +} + +void Chat::setType(Chat::Type type) +{ + type_ = type; +} + +const std::string& Chat::getTitle() const +{ + return title_; +} + +void Chat::setTitle(const std::string& title) +{ + title_ = title; +} + +const std::string& Chat::getUsername() const +{ + return username_; +} + +void Chat::setUsername(const std::string& username) +{ + username_ = username; +} + +const std::string& Chat::getFirstName() const +{ + return firstName_; +} + +void Chat::setFirstName(const std::string& firstName) +{ + firstName_ = firstName; +} + +const std::string& Chat::getLastName() const +{ + return lastName_; +} + +void Chat::setLastName(const std::string& lastName) +{ + lastName_ = lastName; +} + +bool Chat::isAllAdmins() const +{ + return allAdmins_; +} + +void Chat::setAllAdmins(bool allAdmins) +{ + allAdmins_ = allAdmins; +} + +void Chat::swap(Chat& other) noexcept +{ + using std::swap; + swap(id_, other.id_); + swap(type_, other.type_); + swap(title_, other.title_); + swap(username_, other.username_); + swap(firstName_, other.firstName_); + swap(lastName_, other.lastName_); + swap(allAdmins_, other.allAdmins_); +} + +const Chat& Chat::operator=(Chat other) noexcept +{ + swap(other); + return *this; +} + +void telebotxx::swap(Chat& lhs, Chat& rhs) +{ + lhs.swap(rhs); +} + +Chat::Type telebotxx::chatTypeFromString(const std::string& str) +{ + if (str == "private") + return Chat::Type::Private; + else if (str == "group") + return Chat::Type::Group; + else if (str == "supergroup") + return Chat::Type::Supergroup; + else if (str == "channel") + return Chat::Type::Channel; + else + throw std::invalid_argument("Unknown chat type"); +}