mirror of
https://github.com/UltraCoderRU/telebotxx.git
synced 2026-01-28 04:05:13 +00:00
Created macro for simple named param classes declaration and definition.
This commit is contained in:
parent
592751a50c
commit
ea28b547eb
5 changed files with 49 additions and 77 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,6 +4,24 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#include <telebotxx/RequestOptions.hpp>
|
||||
|
||||
#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)
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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_)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue