-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type templates Optional<T> and Required<T>, simplify parsers
- Loading branch information
Showing
13 changed files
with
153 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef TGBOT_OPTIONAL_H | ||
#define TGBOT_OPTIONAL_H | ||
|
||
#include <boost/optional.hpp> | ||
|
||
namespace TgBot { | ||
|
||
template<typename T> | ||
using Optional = boost::optional<T>; | ||
|
||
// use for: OptionalPtr<std::shared/unique_ptr<TYPE>> | ||
// for pointers, we assume optional value == nullptr (or not owned, etc) | ||
template<typename T> | ||
using OptionalPtr = T; | ||
|
||
template<typename T> | ||
using Required = T; | ||
|
||
} | ||
|
||
#endif //TGBOT_OPTIONAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#ifndef TGBOT_MESSAGEENTITY_H | ||
#define TGBOT_MESSAGEENTITY_H | ||
|
||
#include "tgbot/Optional.h" | ||
#include "tgbot/types/User.h" | ||
|
||
#include <cstdint> | ||
|
@@ -33,40 +34,40 @@ class MessageEntity { | |
* | ||
* Currently, can be Type::Mention (@username), Type::Hashtag (#hashtag), Type::Cashtag ($USD), Type::BotCommand (/start@jobs_bot), Type::Url (https://telegram.org), Type::Email ([email protected]), Type::PhoneNumber (+1-212-555-0123), Type::Bold (bold text), Type::Italic (italic text), Type::Underline (underlined text), Type::Strikethrough (strikethrough text), Type::Spoiler (spoiler message), Type::Blockquote (block quotation), Type::Code (monowidth string), Type::Pre (monowidth block), Type::TextLink (for clickable text URLs), Type::TextMention (for users [without usernames](https://telegram.org/blog/edit#new-mentions)), Type::CustomEmoji (for inline custom emoji stickers) | ||
*/ | ||
Type type; | ||
Required<Type> type; | ||
|
||
/** | ||
* @brief Offset in [UTF-16 code units](https://core.telegram.org/api/entities#entity-length) to the start of the entity | ||
* | ||
*/ | ||
std::int32_t offset; | ||
Required<std::int32_t> offset; | ||
|
||
/** | ||
* @brief Length of the entity in [UTF-16 code units](https://core.telegram.org/api/entities#entity-length) | ||
*/ | ||
std::int32_t length; | ||
Required<std::int32_t> length; | ||
|
||
/** | ||
* @brief Optional. For Type::TextLink only, URL that will be opened after user taps on the text | ||
*/ | ||
std::string url; | ||
Optional<std::string> url; | ||
|
||
/** | ||
* @brief Optional. For Type::TextMention only, the mentioned user | ||
*/ | ||
User::Ptr user; | ||
OptionalPtr<User::Ptr> user; | ||
|
||
/** | ||
* @brief Optional. For Type::Pre only, the programming language of the entity text | ||
*/ | ||
std::string language; | ||
Optional<std::string> language; | ||
|
||
/** | ||
* @brief Optional. For Type::CustomEmoji only, unique identifier of the custom emoji. | ||
* | ||
* Use Api::getCustomEmojiStickers to get full information about the sticker | ||
*/ | ||
std::string customEmojiId; | ||
Optional<std::string> customEmojiId; | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.