diff --git a/Doxyfile.in b/Doxyfile.in index 905008e..4a75184 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -1567,7 +1567,7 @@ ENABLE_PREPROCESSING = YES # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the diff --git a/include/telebotxx/RequestOptions.hpp b/include/telebotxx/RequestOptions.hpp index 0e5e617..b1ff334 100644 --- a/include/telebotxx/RequestOptions.hpp +++ b/include/telebotxx/RequestOptions.hpp @@ -4,6 +4,24 @@ #include #include +#define TELEBOTXX_DECLARE_BOOL_PARAM_CLASS(Name, DEFAULT) class Name \ +{ \ +public: \ + explicit Name(bool value = DEFAULT); \ + bool getValue() const; \ +private: \ + bool value_; \ +}; + +#define TELEBOTXX_DECLARE_STRING_PARAM_CLASS(Name) class Name \ +{ \ +public: \ + explicit Name(const std::string& value); \ + const std::string& getValue() const; \ +private: \ + std::string value_; \ +}; + namespace telebotxx { class ChatId @@ -28,8 +46,8 @@ private: }; }; -using Text = std::string; -using Caption = std::string; +TELEBOTXX_DECLARE_STRING_PARAM_CLASS(Text); +TELEBOTXX_DECLARE_STRING_PARAM_CLASS(Caption); enum class ParseMode { @@ -38,23 +56,9 @@ enum class ParseMode Html }; -class DisableWebPagePreview -{ -public: - DisableWebPagePreview(bool disabled = true); - bool value() const; -private: - bool disable_; -}; +TELEBOTXX_DECLARE_BOOL_PARAM_CLASS(DisableWebPagePreview, true) -class DisableNotification -{ -public: - DisableNotification(bool disabled = true); - bool value() const; -private: - bool disable_; -}; +TELEBOTXX_DECLARE_BOOL_PARAM_CLASS(DisableNotification, true) class ReplyTo { @@ -79,23 +83,9 @@ private: std::string filename_; }; -class File -{ -public: - explicit File(const std::string& filename); - const std::string& getFilename() const; -private: - std::string filename_; -}; +TELEBOTXX_DECLARE_STRING_PARAM_CLASS(File) -class Url -{ -public: - explicit Url(const std::string& url); - const std::string& getUrl() const; -private: - std::string url_; -}; +TELEBOTXX_DECLARE_STRING_PARAM_CLASS(Url) class Photo { diff --git a/src/RequestOptions.cpp b/src/RequestOptions.cpp index 54d3f5f..3472e33 100644 --- a/src/RequestOptions.cpp +++ b/src/RequestOptions.cpp @@ -1,5 +1,11 @@ #include +#define TELEBOTXX_DEFINE_BOOL_PARAM_CLASS(Name) Name::Name(bool value) : value_(value) { } \ +bool Name::getValue() const { return value_; } + +#define TELEBOTXX_DEFINE_STRING_PARAM_CLASS(Name) Name::Name(const std::string& value) : value_(value) { } \ +const std::string& Name::getValue() const { return value_; } + namespace telebotxx { ChatId::ChatId(int id) @@ -59,27 +65,19 @@ const std::string ChatId::getUsername() const //////////////////////////////////////////////////////////////// -DisableWebPagePreview::DisableWebPagePreview(bool disabled) - : disable_(disabled) -{ -} - -bool DisableWebPagePreview::value() const -{ - return disable_; -} +TELEBOTXX_DEFINE_STRING_PARAM_CLASS(Text) //////////////////////////////////////////////////////////////// -DisableNotification::DisableNotification(bool disabled) - : disable_(disabled) -{ -} +TELEBOTXX_DEFINE_STRING_PARAM_CLASS(Caption) -bool DisableNotification::value() const -{ - return disable_; -} +//////////////////////////////////////////////////////////////// + +TELEBOTXX_DEFINE_BOOL_PARAM_CLASS(DisableWebPagePreview) + +//////////////////////////////////////////////////////////////// + +TELEBOTXX_DEFINE_BOOL_PARAM_CLASS(DisableNotification) //////////////////////////////////////////////////////////////// @@ -122,27 +120,11 @@ const std::string Buffer::filename() const //////////////////////////////////////////////////////////////// -File::File(const std::string& filename) - : filename_(filename) -{ -} - -const std::string& File::getFilename() const -{ - return filename_; -} +TELEBOTXX_DEFINE_STRING_PARAM_CLASS(File) //////////////////////////////////////////////////////////////// -const std::string& Url::getUrl() const -{ - return url_; -} - -Url::Url(const std::string& url) - : url_(url) -{ -} +TELEBOTXX_DEFINE_STRING_PARAM_CLASS(Url) //////////////////////////////////////////////////////////////// diff --git a/src/SendMessageRequest.cpp b/src/SendMessageRequest.cpp index aeca2ad..7ec45e8 100644 --- a/src/SendMessageRequest.cpp +++ b/src/SendMessageRequest.cpp @@ -56,7 +56,7 @@ public: writer.String(chatId_.getUsername().c_str()); writer.String("text"); - writer.String(text_.c_str()); + writer.String(text_.getValue().c_str()); // Add parse_mode if (parseMode_) @@ -70,14 +70,14 @@ public: if (disableWebPagePreview_) { writer.String("disable_web_page_preview"); - writer.Bool(disableWebPagePreview_->value()); + writer.Bool(disableWebPagePreview_->getValue()); } // Add disable_notification if (disableNotification_) { writer.String("disable_notification"); - writer.Bool(disableNotification_->value()); + writer.Bool(disableNotification_->getValue()); } // Add reply_to_message_id diff --git a/src/SendPhotoRequest.cpp b/src/SendPhotoRequest.cpp index d53dd89..6fadf10 100644 --- a/src/SendPhotoRequest.cpp +++ b/src/SendPhotoRequest.cpp @@ -55,17 +55,17 @@ public: multipart.parts.push_back({"photo", cpr::Buffer(data, data + size, filename)}); } else if (photo_.getType() == Photo::Type::File) - multipart.parts.push_back({"photo", cpr::File(photo_.getFile().getFilename())}); + multipart.parts.push_back({"photo", cpr::File(photo_.getFile().getValue())}); else if (photo_.getType() == Photo::Type::Url) - multipart.parts.push_back({"photo", photo_.getUrl().getUrl()}); + multipart.parts.push_back({"photo", photo_.getUrl().getValue()}); // Add caption if (caption_) - multipart.parts.push_back({"caption", *caption_}); + multipart.parts.push_back({"caption", caption_->getValue()}); // Add disable_notification if (disableNotification_) - multipart.parts.push_back({"disable_notification", disableNotification_->value()}); + multipart.parts.push_back({"disable_notification", disableNotification_->getValue()}); // Add reply_to_message_id if (replyToMessageId_)