Skip to content

Commit cdfb903

Browse files
committed
Add type templates Optional<T> and NotOptional<T>
1 parent 66b89bf commit cdfb903

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

include/tgbot/Optional.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TGBOT_OPTIONAL_H
2+
#define TGBOT_OPTIONAL_H
3+
4+
#include <boost/optional.hpp>
5+
6+
namespace TgBot {
7+
8+
template<typename T>
9+
using Optional = boost::optional<T>;
10+
11+
template<typename T>
12+
using NotOptional = T;
13+
14+
}
15+
16+
#endif //TGBOT_OPTIONAL_H

include/tgbot/types/LinkPreviewOptions.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#ifndef TGBOT_LINKPREVIEWOPTIONS_H
22
#define TGBOT_LINKPREVIEWOPTIONS_H
33

4+
#include "tgbot/Optional.h"
5+
46
#include <memory>
57
#include <string>
6-
#include <boost/optional.hpp>
78

89
namespace TgBot {
910

@@ -20,29 +21,29 @@ class LinkPreviewOptions {
2021
/**
2122
* @brief Optional. True, if the link preview is disabled
2223
*/
23-
boost::optional<bool> isDisabled;
24+
Optional<bool> isDisabled;
2425

2526
/**
2627
* @brief Optional. URL to use for the link preview.
2728
*
2829
* If empty, then the first URL found in the message text will be used
2930
*/
30-
boost::optional<std::string> url;
31+
Optional<std::string> url;
3132

3233
/**
3334
* @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
3435
*/
35-
boost::optional<bool> preferSmallMedia;
36+
Optional<bool> preferSmallMedia;
3637

3738
/**
3839
* @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
3940
*/
40-
boost::optional<bool> preferLargeMedia;
41+
Optional<bool> preferLargeMedia;
4142

4243
/**
4344
* @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
4445
*/
45-
boost::optional<bool> showAboveText;
46+
Optional<bool> showAboveText;
4647
};
4748
}
4849

include/tgbot/types/ReplyParameters.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#define TGBOT_REPLYPARAMETERS_H
33

44
#include "tgbot/types/MessageEntity.h"
5+
#include "tgbot/Optional.h"
56

67
#include <cstdint>
78
#include <memory>
89
#include <string>
910
#include <vector>
10-
#include <boost/optional.hpp>
1111

1212
namespace TgBot {
1313

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

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

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

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

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

6666
/**
6767
* @brief Optional. Position of the quote in the original message in UTF-16 code units
6868
*/
69-
boost::optional<std::int32_t> quotePosition;
69+
Optional<std::int32_t> quotePosition;
7070
};
7171
}
7272

0 commit comments

Comments
 (0)