diff options
-rw-r--r-- | include/tgbot/Api.h | 38 | ||||
-rw-r--r-- | include/tgbot/TgTypeParser.h | 2 | ||||
-rw-r--r-- | include/tgbot/net/HttpServer.h | 4 | ||||
-rw-r--r-- | include/tgbot/net/TgWebhookLocalServer.h | 2 | ||||
-rw-r--r-- | src/EventHandler.cpp | 6 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 102 | ||||
-rw-r--r-- | src/types/InputFile.cpp | 2 |
7 files changed, 78 insertions, 78 deletions
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index e5b8c5e..4eb63c7 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -75,7 +75,7 @@ public: * @param disableNotification Optional. Sends the message silenty. * @return On success, the sent message is returned. */ - Message::Ptr sendMessage(int64_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), const std::string& parseMode = "", bool disableNotification = false) const; + Message::Ptr sendMessage(int64_t chatId, const std::string& text, bool disableWebPagePreview = false, int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), const std::string& parseMode = "", bool disableNotification = false) const; /** * Use this method to forward messages of any kind. @@ -98,7 +98,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendPhoto(int64_t chatId, const InputFile::Ptr photo, const std::string& caption = "", int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send photos. @@ -111,7 +111,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendPhoto(int64_t chatId, const std::string& photoId, const std::string& caption = "", int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). @@ -128,7 +128,7 @@ public: */ Message::Ptr sendAudio(int64_t chatId, const InputFile::Ptr audio, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document). @@ -145,7 +145,7 @@ public: */ Message::Ptr sendAudio(int64_t chatId, const std::string& audioId, const std::string &caption = "", int32_t duration = 0, const std::string& performer = "", const std::string& title = "", int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send general files. @@ -158,7 +158,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendDocument(int64_t chatId, const InputFile::Ptr document, const std::string &caption = "", int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send general files. @@ -171,7 +171,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendDocument(int64_t chatId, const std::string& documentId, const std::string &caption = "", int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send .webp stickers. @@ -183,7 +183,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendSticker(int64_t chatId, const InputFile::Ptr sticker, int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send .webp stickers. @@ -195,7 +195,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendSticker(int64_t chatId, const std::string& stickerId, int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). @@ -211,7 +211,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendVideo(int64_t chatId, const InputFile::Ptr video, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", - int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). @@ -227,7 +227,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendVideo(int64_t chatId, const std::string& videoId, int32_t duration = 0, int32_t width = 0, int32_t height = 0, const std::string &caption = "", - int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. @@ -241,7 +241,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendVoice(int64_t chatId, const InputFile::Ptr voice, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. @@ -255,7 +255,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendVoice(int64_t chatId, const std::string& voiceId, const std::string &caption = "", int duration = 0, int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send point on the map. @@ -268,7 +268,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendLocation(int64_t chatId, float latitude, float longitude, int32_t replyToMessageId = 0, - const GenericReply::Ptr replyMarkup = GenericReply::Ptr(), bool disableNotification = false) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>(), bool disableNotification = false) const; /** * Use this method to send information about a venue. On success, the sent Message is returned. @@ -284,7 +284,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendVenue(int64_t chatId, float latitude, float longitude, std::string title, std::string address, std::string foursquareId = "", - bool disableNotification = false, int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; + bool disableNotification = false, int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * Use this method to send phone contacts. On success, the sent Message is returned. @@ -298,7 +298,7 @@ public: * @return On success, the sent message is returned. */ Message::Ptr sendContact(int64_t chatId, std::string phoneNumber, std::string firstName, std::string lastName = "", bool disableNotification = false, - int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; + int32_t replyToMessageId = 0, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). @@ -384,7 +384,7 @@ public: * @return Message object on success, otherwise nullptr */ Message::Ptr editMessageText(const std::string& text, int64_t chatId=0, int32_t messageId=0, const std::string& inlineMessageId="", - const std::string& parseMode = "", bool disableWebPagePreview = false, const GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; + const std::string& parseMode = "", bool disableWebPagePreview = false, const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). @@ -396,7 +396,7 @@ public: * @return Message object on success, otherwise nullptr */ Message::Ptr editMessageCaption(int64_t chatId = 0, int32_t messageId = 0, const std::string& caption = "", - const std::string& inlineMessageId = "", const GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; + const std::string& inlineMessageId = "", const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). @@ -407,7 +407,7 @@ public: * @return Message object on success, otherwise nullptr */ Message::Ptr editMessageReplyMarkup(int64_t chatId = 0, int32_t messageId = 0, const std::string& inlineMessageId = "", - const GenericReply::Ptr replyMarkup = GenericReply::Ptr()) const; + const GenericReply::Ptr replyMarkup = std::make_shared<GenericReply>()) const; /** * Use this method to delete messages sent by bot (or by other users if bot is admin). diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 2faaf45..9f56b8e 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -245,7 +245,7 @@ public: std::shared_ptr<T> tryParseJson(JsonToTgTypeFunc<T> parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { auto treeItem = data.find(keyName); if (treeItem == data.not_found()) { - return std::shared_ptr<T>(); + return std::make_shared<T>(); } return (this->*parseFunc)(treeItem->second); } diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h index 164bd2b..d68599f 100644 --- a/include/tgbot/net/HttpServer.h +++ b/include/tgbot/net/HttpServer.h @@ -51,8 +51,8 @@ public: * Starts receiving new connections. */ void start() { - std::shared_ptr<boost::asio::basic_stream_socket<Protocol>> socket(new boost::asio::basic_stream_socket<Protocol>(_acceptor->get_io_service())); - std::shared_ptr<Connection> connection(new Connection(socket, _handler)); + auto socket(std::make_shared<boost::asio::basic_stream_socket<Protocol>>(_acceptor->get_io_service())); + auto connection(std::make_shared<Connection>(socket, _handler)); _acceptor->async_accept(*connection->socket, [this, connection]() { connection->start(); start(); diff --git a/include/tgbot/net/TgWebhookLocalServer.h b/include/tgbot/net/TgWebhookLocalServer.h index 67268f5..99a0fba 100644 --- a/include/tgbot/net/TgWebhookLocalServer.h +++ b/include/tgbot/net/TgWebhookLocalServer.h @@ -39,7 +39,7 @@ public: TgWebhookLocalServer(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>& acceptor, const std::string& path, EventHandler* eventHandler) = delete; TgWebhookLocalServer(const std::string& path, const EventHandler* eventHandler) : - TgWebhookServer<boost::asio::local::stream_protocol>(std::shared_ptr<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>(new boost::asio::local::stream_protocol::acceptor(_ioService, boost::asio::local::stream_protocol::endpoint(path))), path, eventHandler) + TgWebhookServer<boost::asio::local::stream_protocol>(std::make_shared<boost::asio::basic_socket_acceptor<boost::asio::local::stream_protocol>>(_ioService, boost::asio::local::stream_protocol::endpoint(path)), path, eventHandler) { } diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index d679683..32efe3e 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -26,9 +26,9 @@ void EventHandler::handleMessage(const Message::Ptr message) const { _broadcaster->broadcastAnyMessage(message); if (StringTools::startsWith(message->text, "/")) { - unsigned long splitPosition; - unsigned long spacePosition = message->text.find(' '); - unsigned long atSymbolPosition = message->text.find('@'); + uint32_t splitPosition; + uint32_t spacePosition = message->text.find(' '); + uint32_t atSymbolPosition = message->text.find('@'); if (spacePosition == message->text.npos) { if (atSymbolPosition == message->text.npos) { splitPosition = message->text.size(); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 84a83df..1b80d7f 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -33,7 +33,7 @@ TgTypeParser& TgTypeParser::getInstance() { } Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { - Chat::Ptr result(new Chat); + auto result(make_shared<Chat>()); result->id = data.get<int64_t>("id"); string type = data.get<string>("type"); if (type == "private") { @@ -80,7 +80,7 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { } User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const { - User::Ptr result(new User); + auto result(make_shared<User>()); result->id = data.get<int32_t>("id"); result->firstName = data.get<string>("first_name"); result->lastName = data.get("last_name", ""); @@ -104,7 +104,7 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { } MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{ - MessageEntity::Ptr result(new MessageEntity); + auto result(make_shared<MessageEntity>()); result->type=data.get<string>("type"); result->offset=data.get<int32_t>("offset"); result->length=data.get<int32_t>("length"); @@ -114,7 +114,7 @@ MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{ } Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { - Message::Ptr result(new Message); + auto result(make_shared<Message>()); result->messageId = data.get<int32_t>("message_id"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->date = data.get<int32_t>("date"); @@ -189,7 +189,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { } PhotoSize::Ptr TgTypeParser::parseJsonAndGetPhotoSize(const ptree& data) const { - PhotoSize::Ptr result(new PhotoSize); + auto result(make_shared<PhotoSize>()); result->fileId = data.get<string>("file_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); @@ -213,7 +213,7 @@ string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const { } Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { - Audio::Ptr result(new Audio); + auto result(make_shared<Audio>()); result->fileId = data.get<string>("file_id"); result->duration = data.get<int32_t>("duration"); result->performer = data.get<string>("performer", ""); @@ -239,7 +239,7 @@ string TgTypeParser::parseAudio(const Audio::Ptr& object) const { } Document::Ptr TgTypeParser::parseJsonAndGetDocument(const ptree& data) const { - Document::Ptr result(new Document); + auto result(make_shared<Document>()); result->fileId = data.get<string>("file_id"); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->fileName = data.get("file_name", ""); @@ -265,7 +265,7 @@ string TgTypeParser::parseDocument(const Document::Ptr& object) const { } Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { - Sticker::Ptr result(new Sticker); + auto result(make_shared<Sticker>()); result->fileId = data.get<string>("file_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); @@ -293,7 +293,7 @@ string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { } Video::Ptr TgTypeParser::parseJsonAndGetVideo(const ptree& data) const { - Video::Ptr result(new Video); + auto result(make_shared<Video>()); result->fileId = data.get<string>("file_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); @@ -323,7 +323,7 @@ string TgTypeParser::parseVideo(const Video::Ptr& object) const { } Contact::Ptr TgTypeParser::parseJsonAndGetContact(const ptree& data) const { - Contact::Ptr result(new Contact); + auto result(make_shared<Contact>()); result->phoneNumber = data.get<string>("phone_number"); result->firstName = data.get<string>("first_name"); result->lastName = data.get("last_name", ""); @@ -347,7 +347,7 @@ string TgTypeParser::parseContact(const Contact::Ptr& object) const { } Location::Ptr TgTypeParser::parseJsonAndGetLocation(const ptree& data) const { - Location::Ptr result(new Location); + auto result(make_shared<Location>()); result->longitude = data.get<float>("longitude", 0); result->latitude = data.get<float>("latitude", 0); return result; @@ -367,7 +367,7 @@ string TgTypeParser::parseLocation(const Location::Ptr& object) const { } Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const { - Update::Ptr result(new Update); + auto result(make_shared<Update>()); result->updateId = data.get<int32_t>("update_id"); result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message"); result->editedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); @@ -399,7 +399,7 @@ string TgTypeParser::parseUpdate(const Update::Ptr& object) const { } UserProfilePhotos::Ptr TgTypeParser::parseJsonAndGetUserProfilePhotos(const ptree& data) const { - UserProfilePhotos::Ptr result(new UserProfilePhotos); + auto result(make_shared<UserProfilePhotos>()); result->totalCount = data.get<int32_t>("total_count"); result->photos = parseJsonAndGet2DArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photos"); return result; @@ -419,7 +419,7 @@ string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& object } File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const { - File::Ptr result(new File); + auto result(make_shared<File>()); result->fileId = data.get<string>("file_id"); result->fileSize = data.get<int32_t>("file_size", 0); result->filePath = data.get<string>("file_path", ""); @@ -441,7 +441,7 @@ string TgTypeParser::parseFile(const File::Ptr& object) const { } ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const { - ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup); + auto result(make_shared<ReplyKeyboardMarkup>()); for (const boost::property_tree::ptree::value_type& item : data.find("keyboard")->second){ result->keyboard.push_back(parseJsonAndGetArray<KeyboardButton>(&TgTypeParser::parseJsonAndGetKeyboardButton, item.second)); } @@ -479,7 +479,7 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt } KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const { - KeyboardButton::Ptr result(new KeyboardButton); + auto result(make_shared<KeyboardButton>()); result->text = data.get<string>("text"); result->requestContact = data.get<bool>("request_contact", false); result->requestLocation = data.get<bool>("request_location", false); @@ -501,7 +501,7 @@ std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) } ReplyKeyboardRemove::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const { - ReplyKeyboardRemove::Ptr result(new ReplyKeyboardRemove); + auto result(make_shared<ReplyKeyboardRemove>()); result->selective = data.get<bool>("selective", false); return result; } @@ -520,7 +520,7 @@ std::string TgTypeParser::parseReplyKeyboardRemove(const ReplyKeyboardRemove::Pt } ForceReply::Ptr TgTypeParser::parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const { - ForceReply::Ptr result(new ForceReply); + auto result(make_shared<ForceReply>()); result->selective = data.get<bool>("selective"); return result; } @@ -539,7 +539,7 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const { } ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const { - ChatMember::Ptr result(new ChatMember); + auto result(make_shared<ChatMember>()); result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); result->status = data.get<string>("status"); return result; @@ -559,7 +559,7 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { } ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const { - ResponseParameters::Ptr result(new ResponseParameters); + auto result(make_shared<ResponseParameters>()); result->migrateToChatId = data.get<int32_t>("migrate_to_chat_id", 0); result->retryAfter = data.get<int32_t>("retry_after", 0); return result; @@ -588,7 +588,7 @@ GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::propert } else if (data.find("inline_keyboard") != data.not_found()) { return static_pointer_cast<GenericReply>(parseJsonAndGetInlineKeyboardMarkup(data)); } - return GenericReply::Ptr(new GenericReply); + return make_shared<GenericReply>(); } std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) const { @@ -608,7 +608,7 @@ std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) con } InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const { - InlineQuery::Ptr result(new InlineQuery); + auto result(make_shared<InlineQuery>()); result->id = data.get<string>("id"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); @@ -773,7 +773,7 @@ std::string TgTypeParser::parseInlineQueryResult(const InlineQueryResult::Ptr& o InlineQueryResultCachedAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedAudio::Ptr result(new InlineQueryResultCachedAudio); + auto result(make_shared<InlineQueryResultCachedAudio>()); result->audioFileId = data.get<string>("audio_file_id"); return result; } @@ -792,7 +792,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedAudio(const InlineQueryRes InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedDocument::Ptr result(new InlineQueryResultCachedDocument); + auto result(make_shared<InlineQueryResultCachedDocument>()); result->documentFileId = data.get<string>("document_file_id"); result->description = data.get<string>("description", ""); return result; @@ -814,7 +814,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQuery InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedGif::Ptr result(new InlineQueryResultCachedGif); + auto result(make_shared<InlineQueryResultCachedGif>()); result->gifFileId = data.get<string>("gif_file_id"); return result; } @@ -834,7 +834,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResul InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedMpeg4Gif::Ptr result(new InlineQueryResultCachedMpeg4Gif); + auto result(make_shared<InlineQueryResultCachedMpeg4Gif>()); result->mpeg4FileId = data.get<string>("mpeg4_file_id"); return result; } @@ -854,7 +854,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQuery InlineQueryResultCachedPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedPhoto::Ptr result(new InlineQueryResultCachedPhoto); + auto result(make_shared<InlineQueryResultCachedPhoto>()); result->photoFileId = data.get<string>("photo_file_id"); result->description = data.get<string>("description", ""); return result; @@ -876,7 +876,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedPhoto(const InlineQueryRes InlineQueryResultCachedSticker::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedSticker::Ptr result(new InlineQueryResultCachedSticker); + auto result(make_shared<InlineQueryResultCachedSticker>()); result->stickerFileId = data.get<string>("sticker_file_id"); return result; } @@ -895,7 +895,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedSticker(const InlineQueryR InlineQueryResultCachedVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedVideo::Ptr result(new InlineQueryResultCachedVideo); + auto result(make_shared<InlineQueryResultCachedVideo>()); result->videoFileId = data.get<string>("video_file_id"); result->description = data.get<string>("description", ""); return result; @@ -917,7 +917,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedVideo(const InlineQueryRes InlineQueryResultCachedVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultCachedVoice::Ptr result(new InlineQueryResultCachedVoice); + auto result(make_shared<InlineQueryResultCachedVoice>()); result->voiceFileId = data.get<string>("voice_file_id"); return result; } @@ -936,7 +936,7 @@ std::string TgTypeParser::parseInlineQueryResultCachedVoice(const InlineQueryRes InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultArticle::Ptr result(new InlineQueryResultArticle); + auto result(make_shared<InlineQueryResultArticle>()); result->url = data.get<string>("url", ""); result->hideUrl = data.get("hide_url", false); result->description = data.get<string>("description", ""); @@ -965,7 +965,7 @@ std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultA InlineQueryResultAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultAudio::Ptr result(new InlineQueryResultAudio); + auto result(make_shared<InlineQueryResultAudio>()); result->audioUrl = data.get<string>("audio_url"); result->performer = data.get<string>("performer", ""); result->audioDuration = data.get<int32_t>("audio_duration", 0); @@ -989,7 +989,7 @@ std::string TgTypeParser::parseInlineQueryResultAudio(const InlineQueryResultAud InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultContact::Ptr result(new InlineQueryResultContact); + auto result(make_shared<InlineQueryResultContact>()); result->phoneNumber = data.get<string>("phone_number"); result->firstName = data.get<string>("first_name"); result->lastName = data.get<string>("last_name", ""); @@ -1019,7 +1019,7 @@ std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultC InlineQueryResultGame::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultGame::Ptr result(new InlineQueryResultGame); + auto result(make_shared<InlineQueryResultGame>()); result->gameShortName = data.get<string>("game_short_name"); return result; } @@ -1038,7 +1038,7 @@ std::string TgTypeParser::parseInlineQueryResultGame(const InlineQueryResultGame InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultDocument::Ptr result(new InlineQueryResultDocument); + auto result(make_shared<InlineQueryResultDocument>()); result->documentUrl = data.get<string>("document_url"); result->mimeType = data.get<string>("mime_type"); result->description = data.get<string>("description", ""); @@ -1067,7 +1067,7 @@ std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResult InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultLocation::Ptr result(new InlineQueryResultLocation); + auto result(make_shared<InlineQueryResultLocation>()); result->latitude = data.get<float>("latitude"); result->longitude = data.get<float>("longitude"); result->thumbUrl = data.get<string>("thumb_url", ""); @@ -1095,7 +1095,7 @@ std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResult InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultVenue::Ptr result(new InlineQueryResultVenue); + auto result(make_shared<InlineQueryResultVenue>()); result->latitude = data.get<float>("latitude"); result->longitude = data.get<float>("longitude"); result->address = data.get<string>("address"); @@ -1126,7 +1126,7 @@ std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVen InlineQueryResultVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultVoice::Ptr result(new InlineQueryResultVoice); + auto result(make_shared<InlineQueryResultVoice>()); result->voiceUrl = data.get<string>("voice_url"); result->voiceDuration = data.get<int32_t>("voice_duration", 0); return result; @@ -1147,7 +1147,7 @@ std::string TgTypeParser::parseInlineQueryResultVoice(const InlineQueryResultVoi InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultPhoto::Ptr result(new InlineQueryResultPhoto); + auto result(make_shared<InlineQueryResultPhoto>()); result->photoUrl = data.get<string>("photo_url", ""); result->thumbUrl = data.get<string>("thumb_url"); result->photoWidth = data.get("photo_width", 0); @@ -1174,7 +1174,7 @@ std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPho InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultGif::Ptr result(new InlineQueryResultGif); + auto result(make_shared<InlineQueryResultGif>()); result->gifUrl = data.get<string>("gif_url", ""); result->gifWidth = data.get("gif_width", 0); result->gifHeight = data.get("gif_height", 0); @@ -1198,7 +1198,7 @@ std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif:: InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultMpeg4Gif::Ptr result(new InlineQueryResultMpeg4Gif); + auto result(make_shared<InlineQueryResultMpeg4Gif>()); result->mpeg4Url = data.get<string>("mpeg4_url"); result->mpeg4Width = data.get("mpeg4_width", 0); result->mpeg4Height = data.get("mpeg4_height", 0); @@ -1223,7 +1223,7 @@ std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResult InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGgetInlineQueryResult(). - InlineQueryResultVideo::Ptr result(new InlineQueryResultVideo); + auto result(make_shared<InlineQueryResultVideo>()); result->videoUrl = data.get<string>("video_url"); result->mimeType = data.get<string>("mime_type"); result->thumbUrl = data.get<string>("thumb_url"); @@ -1253,7 +1253,7 @@ std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVid } ChosenInlineResult::Ptr TgTypeParser::parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const { - ChosenInlineResult::Ptr result(new ChosenInlineResult); + auto result(make_shared<ChosenInlineResult>()); result->resultId = data.get<string>("result_id"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); @@ -1278,7 +1278,7 @@ std::string TgTypeParser::parseChosenInlineResult(const ChosenInlineResult::Ptr& } CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const { - CallbackQuery::Ptr result(new CallbackQuery); + auto result(make_shared<CallbackQuery>()); result->id = data.get<string>("id"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message"); @@ -1309,7 +1309,7 @@ std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) c } InlineKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const { - InlineKeyboardMarkup::Ptr result(new InlineKeyboardMarkup); + auto result(make_shared<InlineKeyboardMarkup>()); for (const boost::property_tree::ptree::value_type& item : data.find("inline_keyboard")->second){ result->inlineKeyboard.push_back(parseJsonAndGetArray<InlineKeyboardButton>(&TgTypeParser::parseJsonAndGetInlineKeyboardButton, item.second)); } @@ -1339,7 +1339,7 @@ std::string TgTypeParser::parseInlineKeyboardMarkup(const InlineKeyboardMarkup:: } InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const { - InlineKeyboardButton::Ptr result(new InlineKeyboardButton); + auto result(make_shared<InlineKeyboardButton>()); result->text = data.get<string>("text"); result->url = data.get<string>("url", ""); result->callbackData = data.get<string>("callback_data", ""); @@ -1364,7 +1364,7 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: } WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const { - WebhookInfo::Ptr result(new WebhookInfo); + auto result(make_shared<WebhookInfo>()); result->url = data.get<string>("url"); result->hasCustomCertificate = data.get<bool>("has_custom_certificate"); result->pendingUpdateCount = data.get<int32_t>("pending_update_count"); @@ -1451,7 +1451,7 @@ std::string TgTypeParser::parseInputMessageContent(const InputMessageContent::Pt InputTextMessageContent::Ptr TgTypeParser::parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). - InputTextMessageContent::Ptr result(new InputTextMessageContent); + auto result(make_shared<InputTextMessageContent>()); result->messageText = data.get<string>("message_text"); result->parseMode = data.get<string>("parse_mode", ""); result->disableWebPagePreview = data.get<bool>("disable_web_page_preview", false); @@ -1473,7 +1473,7 @@ std::string TgTypeParser::parseInputTextMessageContent(const InputTextMessageCon InputLocationMessageContent::Ptr TgTypeParser::parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). - InputLocationMessageContent::Ptr result(new InputLocationMessageContent); + auto result(make_shared<InputLocationMessageContent>()); result->latitude = data.get<float>("latitude"); result->longitude = data.get<float>("longitude"); return result; @@ -1493,7 +1493,7 @@ std::string TgTypeParser::parseInputLocationMessageContent(const InputLocationMe InputVenueMessageContent::Ptr TgTypeParser::parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). - InputVenueMessageContent::Ptr result(new InputVenueMessageContent); + auto result(make_shared<InputVenueMessageContent>()); result->latitude = data.get<float>("latitude"); result->longitude = data.get<float>("longitude"); result->title = data.get<string>("title"); @@ -1519,7 +1519,7 @@ std::string TgTypeParser::parseInputVenueMessageContent(const InputVenueMessageC InputContactMessageContent::Ptr TgTypeParser::parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMessageContent(). - InputContactMessageContent::Ptr result(new InputContactMessageContent); + auto result(make_shared<InputContactMessageContent>()); result->phoneNumber = data.get<string>("phone_number"); result->firstName = data.get<string>("first_name"); result->lastName = data.get<string>("last_name", ""); diff --git a/src/types/InputFile.cpp b/src/types/InputFile.cpp index 0f6cb86..4884488 100644 --- a/src/types/InputFile.cpp +++ b/src/types/InputFile.cpp @@ -14,7 +14,7 @@ using namespace std; namespace TgBot { InputFile::Ptr InputFile::fromFile(const string& filePath, const string& mimeType) { - InputFile::Ptr result(new InputFile); + auto result(make_shared<InputFile>()); result->data = FileTools::read(filePath); result->mimeType = mimeType; result->fileName = StringTools::split(filePath, '/').back(); |