Skip to content

Commit

Permalink
Add type templates Optional<T> and NotOptional<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
uralm1 committed Nov 17, 2024
1 parent 66b89bf commit cdfb903
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
16 changes: 16 additions & 0 deletions include/tgbot/Optional.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TGBOT_OPTIONAL_H
#define TGBOT_OPTIONAL_H

#include <boost/optional.hpp>

namespace TgBot {

template<typename T>
using Optional = boost::optional<T>;

template<typename T>
using NotOptional = T;

}

#endif //TGBOT_OPTIONAL_H
13 changes: 7 additions & 6 deletions include/tgbot/types/LinkPreviewOptions.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef TGBOT_LINKPREVIEWOPTIONS_H
#define TGBOT_LINKPREVIEWOPTIONS_H

#include "tgbot/Optional.h"

#include <memory>
#include <string>
#include <boost/optional.hpp>

namespace TgBot {

Expand All @@ -20,29 +21,29 @@ class LinkPreviewOptions {
/**
* @brief Optional. True, if the link preview is disabled
*/
boost::optional<bool> isDisabled;
Optional<bool> isDisabled;

/**
* @brief Optional. URL to use for the link preview.
*
* If empty, then the first URL found in the message text will be used
*/
boost::optional<std::string> url;
Optional<std::string> url;

/**
* @brief Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview
*/
boost::optional<bool> preferSmallMedia;
Optional<bool> preferSmallMedia;

/**
* @brief Optional. True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview
*/
boost::optional<bool> preferLargeMedia;
Optional<bool> preferLargeMedia;

/**
* @brief Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text
*/
boost::optional<bool> showAboveText;
Optional<bool> showAboveText;
};
}

Expand Down
14 changes: 7 additions & 7 deletions include/tgbot/types/ReplyParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#define TGBOT_REPLYPARAMETERS_H

#include "tgbot/types/MessageEntity.h"
#include "tgbot/Optional.h"

#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <boost/optional.hpp>

namespace TgBot {

Expand All @@ -31,42 +31,42 @@ class ReplyParameters {
*
* Not supported for messages sent on behalf of a business account.
*/
boost::optional<std::int64_t> chatId;
Optional<std::int64_t> chatId;

/**
* @brief Optional. Pass True if the message should be sent even if the specified message to be replied to is not found.
*
* Always False for replies in another chat or forum topic.
* Always True for messages sent on behalf of a business account.
*/
boost::optional<bool> allowSendingWithoutReply;
Optional<bool> allowSendingWithoutReply;

/**
* @brief Optional. Quoted part of the message to be replied to; 0-1024 characters after entities parsing.
*
* The quote must be an exact substring of the message to be replied to, including bold, italic, underline, strikethrough, spoiler, and customEmoji entities.
* The message will fail to send if the quote isn't found in the original message.
*/
boost::optional<std::string> quote;
Optional<std::string> quote;

/**
* @brief Optional. Mode for parsing entities in the quote.
*
* See [formatting options](https://core.telegram.org/bots/api#formatting-options) for more details.
*/
boost::optional<std::string> quoteParseMode;
Optional<std::string> quoteParseMode;

/**
* @brief Optional. A JSON-serialized list of special entities that appear in the quote.
*
* It can be specified instead of quoteParseMode.
*/
boost::optional<std::vector<MessageEntity::Ptr>> quoteEntities;
Optional<std::vector<MessageEntity::Ptr>> quoteEntities;

/**
* @brief Optional. Position of the quote in the original message in UTF-16 code units
*/
boost::optional<std::int32_t> quotePosition;
Optional<std::int32_t> quotePosition;
};
}

Expand Down

0 comments on commit cdfb903

Please sign in to comment.