summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJellyBrick <shlee1503@naver.com>2018-06-08 15:26:25 +0900
committerJellyBrick <shlee1503@naver.com>2018-06-08 15:26:25 +0900
commit237684cfd042917a26274872c4ffe1e3cdd5c3a8 (patch)
treeff57c7fe069ddf35c8ba1f6c4500c18cc81ab133
parentc8d40dccabaaa406faed6c0797a92bac811c9d0f (diff)
Performance optimization
-rw-r--r--include/tgbot/EventBroadcaster.h6
-rw-r--r--include/tgbot/net/HttpParser.h8
-rw-r--r--src/Api.cpp596
-rw-r--r--src/net/HttpParser.cpp2
4 files changed, 306 insertions, 306 deletions
diff --git a/include/tgbot/EventBroadcaster.h b/include/tgbot/EventBroadcaster.h
index 5a41c70..0a4ebe9 100644
--- a/include/tgbot/EventBroadcaster.h
+++ b/include/tgbot/EventBroadcaster.h
@@ -26,7 +26,7 @@
#include <string>
#include <functional>
#include <vector>
-#include <map>
+#include <unordered_map>
#include "tgbot/types/Message.h"
#include "tgbot/types/InlineQuery.h"
@@ -133,7 +133,7 @@ private:
}
inline bool broadcastCommand(const std::string command, const Message::Ptr message) const {
- std::map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
+ std::unordered_map<std::string, MessageListener>::const_iterator iter = _onCommandListeners.find(command);
if (iter == _onCommandListeners.end()) {
return false;
}
@@ -162,7 +162,7 @@ private:
}
std::vector<MessageListener> _onAnyMessageListeners;
- std::map<std::string, MessageListener> _onCommandListeners;
+ std::unordered_map<std::string, MessageListener> _onCommandListeners;
std::vector<MessageListener> _onUnknownCommandListeners;
std::vector<MessageListener> _onNonCommandMessageListeners;
std::vector<InlineQueryListener> _onInlineQueryListeners;
diff --git a/include/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h
index ec4c077..d40619a 100644
--- a/include/tgbot/net/HttpParser.h
+++ b/include/tgbot/net/HttpParser.h
@@ -24,7 +24,7 @@
#define TGBOT_HTTPPARSER_H
#include <string>
-#include <map>
+#include <unordered_map>
#include <vector>
#include "tgbot/net/Url.h"
@@ -43,7 +43,7 @@ public:
std::string generateWwwFormUrlencoded(const std::vector<HttpReqArg>& args);
std::string generateResponse(const std::string& data, const std::string& mimeType = "text/plain", short unsigned statusCode = 200, const std::string& statusStr = "OK", bool isKeepAlive = false);
- inline std::string parseRequest(const std::string& data, std::map<std::string, std::string>& headers) {
+ inline std::string parseRequest(const std::string& data, std::unordered_map<std::string, std::string>& headers) {
return parseHttp(true, data, headers);
}
@@ -51,7 +51,7 @@ public:
return parseHttp(true, data);
}
- inline std::string parseResponse(const std::string& data, std::map<std::string, std::string>& headers) {
+ inline std::string parseResponse(const std::string& data, std::unordered_map<std::string, std::string>& headers) {
return parseHttp(false, data, headers);
}
@@ -60,7 +60,7 @@ public:
}
private:
- std::string parseHttp(bool isRequest, const std::string& data, std::map<std::string, std::string>& headers);
+ std::string parseHttp(bool isRequest, const std::string& data, std::unordered_map<std::string, std::string>& headers);
std::string parseHttp(bool isRequest, const std::string& data);
};
diff --git a/src/Api.cpp b/src/Api.cpp
index 11349e9..8e06951 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -35,519 +35,519 @@ Api::Api(const string& token) : _token(token) {
}
User::Ptr Api::getMe() const {
- return TgTypeParser::getInstance().parseJsonAndGetUser(sendRequest("getMe"));
+ return TgTypeParser::getInstance().parseJsonAndGetUser(sendRequest("getMe");
}
Message::Ptr Api::sendMessage(int64_t chatId, const string& text, bool disableWebPagePreview, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("text", text));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("text", text);
if (disableWebPagePreview) {
- args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview));
+ args.emplace_back("disable_web_page_preview", disableWebPagePreview);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendMessage", args));
}
Message::Ptr Api::forwardMessage(int64_t chatId, int64_t fromChatId, int32_t messageId, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("from_chat_id", fromChatId));
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("from_chat_id", fromChatId);
+ args.emplace_back("message_id", messageId);
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("forwardMessage", args));
}
Message::Ptr Api::sendPhoto(int64_t chatId, const InputFile::Ptr photo, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args));
}
Message::Ptr Api::sendPhoto(int64_t chatId, const string& photoId, const string& caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("photo", photoId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("photo", photoId);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendPhoto", args));
}
Message::Ptr Api::sendAudio(int64_t chatId, const InputFile::Ptr audio, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("audio", audio->data, true, audio->mimeType, audio->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("audio", audio->data, true, audio->mimeType, audio->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (!performer.empty()){
- args.push_back(HttpReqArg("performer", performer));
+ args.emplace_back("performer", performer);
}
if (!title.empty()){
- args.push_back(HttpReqArg("title", title));
+ args.emplace_back("title", title);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
Message::Ptr Api::sendAudio(int64_t chatId, const string& audioId, const string &caption, int32_t duration, const string& performer, const string& title, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("audio", audioId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("audio", audioId);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (!performer.empty()){
- args.push_back(HttpReqArg("performer", performer));
+ args.emplace_back("performer", performer);
}
if (!title.empty()){
- args.push_back(HttpReqArg("title", title));
+ args.emplace_back("title", title);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendAudio", args));
}
Message::Ptr Api::sendDocument(int64_t chatId, const InputFile::Ptr document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("document", document->data, true, document->mimeType, document->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("document", document->data, true, document->mimeType, document->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args));
}
Message::Ptr Api::sendDocument(int64_t chatId, const string& document, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("document", document));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("document", document);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendDocument", args));
}
Message::Ptr Api::sendSticker(int64_t chatId, const InputFile::Ptr sticker, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("sticker", sticker->data, true, sticker->mimeType, sticker->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sticker", sticker->data, true, sticker->mimeType, sticker->fileName);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args));
}
Message::Ptr Api::sendSticker(int64_t chatId, const string& stickerId, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("sticker", stickerId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sticker", stickerId);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendSticker", args));
}
StickerSet::Ptr Api::getStickerSet(const string& name) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("name", name));
+ args.emplace_back("name", name);
return TgTypeParser::getInstance().parseJsonAndGetStickerSet(sendRequest("getStickerSet", args));
}
File::Ptr Api::uploadStickerFile(int32_t userId, const InputFile::Ptr pngSticker) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("uploadStickerFile", args));
}
bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("contains_mask", containsMasks));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("contains_mask", containsMasks);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
bool Api::createNewStickerSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("contains_mask", containsMasks));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("contains_mask", containsMasks);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("createNewStickerSet", args).get<bool>("", false);
}
bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, InputFile::Ptr pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("addStickerToSet", args).get<bool>("", false);
}
bool Api::addStickerToSet(int32_t userId, const string& name, const string& title, const string& pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("name", name));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("png_sticker", pngSticker));
- args.push_back(HttpReqArg("emojis", emojis));
- args.push_back(HttpReqArg("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition)));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("name", name);
+ args.emplace_back("title", title);
+ args.emplace_back("png_sticker", pngSticker);
+ args.emplace_back("emojis", emojis);
+ args.emplace_back("mask_position", TgTypeParser::getInstance().parseMaskPosition(maskPosition));
return sendRequest("addStickerToSet", args).get<bool>("", false);
}
bool Api::setStickerPositionInSet(const string& sticker, uint32_t position) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("sticker", sticker));
- args.push_back(HttpReqArg("position", position));
+ args.emplace_back("sticker", sticker);
+ args.emplace_back("position", position);
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
bool Api::deleteStickerPositionInSet(const string& sticker) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("sticker", sticker));
+ args.emplace_back("sticker", sticker);
return sendRequest("setStickerPositionInSet", args).get<bool>("", false);
}
Message::Ptr Api::sendVideo(int64_t chatId, const InputFile::Ptr video, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video", video->data, true, video->mimeType, video->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video", video->data, true, video->mimeType, video->fileName);
if (supportsStreaming) {
- args.push_back(HttpReqArg("supports_streaming", supportsStreaming));
+ args.emplace_back("supports_streaming", supportsStreaming);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (width) {
- args.push_back(HttpReqArg("width", width));
+ args.emplace_back("width", width);
}
if (height) {
- args.push_back(HttpReqArg("height", height));
+ args.emplace_back("height", height);
}
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args));
}
Message::Ptr Api::sendVideo(int64_t chatId, const string& videoId, bool supportsStreaming, int32_t duration, int32_t width, int32_t height, const string &caption, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video", videoId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video", videoId);
if (supportsStreaming) {
- args.push_back(HttpReqArg("supports_streaming", supportsStreaming));
+ args.emplace_back("supports_streaming", supportsStreaming);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (width) {
- args.push_back(HttpReqArg("width", width));
+ args.emplace_back("width", width);
}
if (height) {
- args.push_back(HttpReqArg("height", height));
+ args.emplace_back("height", height);
}
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVideo", args));
}
Message::Ptr Api::sendVideoNote(int64_t chatId, const InputFile::Ptr videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video_note", videoNote));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video_note", videoNote);
if (disableNotification) {
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (length) {
- args.push_back(HttpReqArg("length", length));
+ args.emplace_back("length", length);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
Message::Ptr Api::sendVideoNote(int64_t chatId, const string &videoNote, int64_t replyToMessageId, bool disableNotification, int32_t duration, int32_t length, const GenericReply::Ptr replyMarkup) {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("video_note", videoNote));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("video_note", videoNote);
if (disableNotification) {
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
if (duration) {
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (length) {
- args.push_back(HttpReqArg("length", length));
+ args.emplace_back("length", length);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoiceNote", args));
}
vector<Message::Ptr> Api::sendMediaGroup(int64_t chatId, const vector<InputMedia::Ptr>& media, bool disableNotification, int32_t replyToMessageId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
string mediaJson = TgTypeParser::getInstance().parseArray<InputMedia>(&TgTypeParser::parseInputMedia, media);
- args.push_back(HttpReqArg("media", mediaJson));
- args.push_back(HttpReqArg("disable_notification", disableNotification));
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("media", mediaJson);
+ args.emplace_back("disable_notification", disableNotification);
+ args.emplace_back("reply_to_message_id", replyToMessageId);
return TgTypeParser::getInstance().parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args));
}
Message::Ptr Api::sendVoice(int64_t chatId, const InputFile::Ptr voice, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("voice", voice->data, true, voice->mimeType, voice->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("voice", voice->data, true, voice->mimeType, voice->fileName);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration){
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args));
}
Message::Ptr Api::sendVoice(int64_t chatId, const string& voiceId, const string &caption, int duration, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("voice", voiceId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("voice", voiceId);
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (duration){
- args.push_back(HttpReqArg("duration", duration));
+ args.emplace_back("duration", duration);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVoice", args));
}
Message::Ptr Api::sendGame(int64_t chatId, const std::string& gameShortName, int32_t replyToMessageId, const InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("game_short_name", gameShortName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("game_short_name", gameShortName);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendGame", args));
}
Message::Ptr Api::sendLocation(int64_t chatId, float latitude, float longitude, uint32_t livePeriod, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("latitude", latitude));
- args.push_back(HttpReqArg("longitude", longitude));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("latitude", latitude);
+ args.emplace_back("longitude", longitude);
if (livePeriod) {
- args.push_back(HttpReqArg("live_period", livePeriod));
+ args.emplace_back("live_period", livePeriod);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendLocation", args));
}
Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("latitude", latitude));
- args.push_back(HttpReqArg("longitude", longitude));
+ args.emplace_back("latitude", latitude);
+ args.emplace_back("longitude", longitude);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (inlineMessageId) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup));
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
}
@@ -555,141 +555,141 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, int64
Message::Ptr Api::stopMessageLiveLocation(int64_t chatId, int32_t messageId, int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const {
vector<HttpReqArg> args;
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (inlineMessageId) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseInlineKeyboardMarkup(replyMarkup));
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args));
}
bool Api::setChatStickerSet(int64_t chatId, const string& stickerSetName) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("sticker_set_name ", stickerSetName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("sticker_set_name ", stickerSetName);
return sendRequest("setChatStickerSet", args).get<bool>("", false);
}
bool Api::deleteChatStickerSet(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return sendRequest("deleteChatStickerSet", args).get<bool>("", false);
}
Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("latitude", latitude));
- args.push_back(HttpReqArg("longitude", longitude));
- args.push_back(HttpReqArg("title", title));
- args.push_back(HttpReqArg("address", address));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("latitude", latitude);
+ args.emplace_back("longitude", longitude);
+ args.emplace_back("title", title);
+ args.emplace_back("address", address);
if (!foursquareId.empty()) {
- args.push_back(HttpReqArg("foursquare_id", foursquareId));
+ args.emplace_back("foursquare_id", foursquareId);
}
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendVenue", args));
}
Message::Ptr Api::sendContact(int64_t chatId, const string& phoneNumber, const string& firstName, const string& lastName, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("phone_number", phoneNumber));
- args.push_back(HttpReqArg("first_name", firstName));
- args.push_back(HttpReqArg("last_name", lastName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("phone_number", phoneNumber);
+ args.emplace_back("first_name", firstName);
+ args.emplace_back("last_name", lastName);
if (replyToMessageId) {
- args.push_back(HttpReqArg("reply_to_message_id", replyToMessageId));
+ args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
if (disableNotification){
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("sendContact", args));
}
void Api::sendChatAction(int64_t chatId, const string& action) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("action", action));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("action", action);
sendRequest("sendChatAction", args);
}
UserProfilePhotos::Ptr Api::getUserProfilePhotos(int32_t userId, int32_t offset, int32_t limit) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
+ args.emplace_back("user_id", userId);
if (offset) {
- args.push_back(HttpReqArg("offset", offset));
+ args.emplace_back("offset", offset);
}
- limit = max(1, min(100, limit));
- args.push_back(HttpReqArg("limit", limit));
+ limit = max(1, min(100, limit);
+ args.emplace_back("limit", limit);
return TgTypeParser::getInstance().parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args));
}
File::Ptr Api::getFile(const string &fileId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("file_id", fileId));
+ args.emplace_back("file_id", fileId);
return TgTypeParser::getInstance().parseJsonAndGetFile(sendRequest("getFile", args));
}
bool Api::leaveChat(int64_t chatId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return sendRequest("leaveChat", args).get<bool>("", false);
}
Chat::Ptr Api::getChat(int64_t chatId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return TgTypeParser::getInstance().parseJsonAndGetChat(sendRequest("getChat", args));
}
vector<ChatMember::Ptr> Api::getChatAdministrators(int64_t chatId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return TgTypeParser::getInstance().parseJsonAndGetArray<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args));
}
int32_t Api::getChatMembersCount(int64_t chatId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return sendRequest("getChatMembersCount", args).get<int32_t>("", 0);
}
bool Api::answerCallbackQuery(const string & callbackQueryId, const string & text, bool showAlert, const string &url, int32_t cacheTime) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("callback_query_id", callbackQueryId));
+ args.emplace_back("callback_query_id", callbackQueryId);
if (!text.empty()) {
- args.push_back(HttpReqArg("text", text));
+ args.emplace_back("text", text);
}
if (showAlert) {
- args.push_back(HttpReqArg("show_alert", showAlert));
+ args.emplace_back("show_alert", showAlert);
}
if (!url.empty()) {
- args.push_back(HttpReqArg("url", url));
+ args.emplace_back("url", url);
}
if (cacheTime) {
- args.push_back(HttpReqArg("cache_time", cacheTime));
+ args.emplace_back("cache_time", cacheTime);
}
return sendRequest("answerCallbackQuery", args).get<bool>("", false);
}
@@ -698,24 +698,24 @@ Message::Ptr Api::editMessageText(const string& text, int64_t chatId, int32_t me
const string& parseMode, bool disableWebPagePreview, const GenericReply::Ptr replyMarkup) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("text", text));
+ args.emplace_back("text", text);
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (!parseMode.empty()) {
- args.push_back(HttpReqArg("parse_mode", parseMode));
+ args.emplace_back("parse_mode", parseMode);
}
if (disableWebPagePreview) {
- args.push_back(HttpReqArg("disable_web_page_preview", disableWebPagePreview));
+ args.emplace_back("disable_web_page_preview", disableWebPagePreview);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
ptree p = sendRequest("editMessageText", args);
if (p.get_child_optional("message_id")) {
@@ -730,19 +730,19 @@ Message::Ptr Api::editMessageCaption(int64_t chatId, int32_t messageId, const st
vector<HttpReqArg> args;
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!caption.empty()) {
- args.push_back(HttpReqArg("caption", caption));
+ args.emplace_back("caption", caption);
}
if (!inlineMessageId.empty()) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
ptree p = sendRequest("editMessageCaption", args);
if (p.get_child_optional("message_id")) {
@@ -758,16 +758,16 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons
vector<HttpReqArg> args;
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()) {
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
if (replyMarkup) {
- args.push_back(HttpReqArg("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup)));
+ args.emplace_back("reply_markup", TgTypeParser::getInstance().parseGenericReply(replyMarkup));
}
ptree p = sendRequest("editMessageReplyMarkup", args);
if (p.get_child_optional("message_id")) {
@@ -780,27 +780,27 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons
ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const
{
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
return TgTypeParser::getInstance().parseJsonAndGetChatMember(sendRequest("getChatMember", args));
}
vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeout, const StringArrayPtr &allowedUpdates) const {
vector<HttpReqArg> args;
if (offset) {
- args.push_back(HttpReqArg("offset", offset));
+ args.emplace_back("offset", offset);
}
- limit = max(1, min(100, limit));
- args.push_back(HttpReqArg("limit", limit));
+ limit = max(1, min(100, limit);
+ args.emplace_back("limit", limit);
if (timeout) {
- args.push_back(HttpReqArg("timeout", timeout));
+ args.emplace_back("timeout", timeout);
}
if (allowedUpdates != nullptr) {
string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<string>(
[](const string &s)->string {
return s;
}, *allowedUpdates);
- args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson));
+ args.emplace_back("allowed_updates", allowedUpdatesJson);
}
return TgTypeParser::getInstance().parseJsonAndGetArray<Update>(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args));
}
@@ -808,11 +808,11 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo
void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_t maxConnection, const StringArrayPtr &allowedUpdates) const {
vector<HttpReqArg> args;
if (!url.empty())
- args.push_back(HttpReqArg("url", url));
+ args.emplace_back("url", url);
if (certificate != nullptr)
- args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName));
+ args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName);
if (maxConnection != 40)
- args.push_back(HttpReqArg("max_connections", maxConnection));
+ args.emplace_back("max_connections", maxConnection);
if (allowedUpdates != nullptr)
{
@@ -820,7 +820,7 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_
[](const string &s)->string {
return s;
}, *allowedUpdates);
- args.push_back(HttpReqArg("allowed_updates", allowedUpdatesJson));
+ args.emplace_back("allowed_updates", allowedUpdatesJson);
}
sendRequest("setWebhook", args);
@@ -852,63 +852,63 @@ WebhookInfo::Ptr Api::getWebhookInfo() const
bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("inline_query_id", inlineQueryId));
+ args.emplace_back("inline_query_id", inlineQueryId);
string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results);
- args.push_back(HttpReqArg("results", resultsJson));
+ args.emplace_back("results", resultsJson);
if (cacheTime) {
- args.push_back(HttpReqArg("cache_time", cacheTime));
+ args.emplace_back("cache_time", cacheTime);
}
if (isPersonal) {
- args.push_back(HttpReqArg("is_personal", isPersonal));
+ args.emplace_back("is_personal", isPersonal);
}
if (!nextOffset.empty()) {
- args.push_back(HttpReqArg("next_offset", nextOffset));
+ args.emplace_back("next_offset", nextOffset);
}
if (!switchPmText.empty()) {
- args.push_back(HttpReqArg("switch_pm_text", switchPmText));
+ args.emplace_back("switch_pm_text", switchPmText);
}
if (!switchPmParameter.empty()) {
- args.push_back(HttpReqArg("switch_pm_parameter", switchPmParameter));
+ args.emplace_back("switch_pm_parameter", switchPmParameter);
}
return sendRequest("answerInlineQuery", args).get<bool>("", false);
}
bool Api::kickChatMember(int64_t chatId, int32_t userId, uint64_t untilDate) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
if (untilDate) {
- args.push_back(HttpReqArg("until_date", untilDate));
+ args.emplace_back("until_date", untilDate);
}
return sendRequest("kickChatMember", args).get<bool>("", false);
}
bool Api::unbanChatMember(int64_t chatId, int32_t userId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
return sendRequest("unbanChatMember", args).get<bool>("", false);
}
bool Api::restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate, bool canSendMessages,
bool canSendMediaMessages, bool canSendOtherMessages, bool canAddWebPagePreviews) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
if (untilDate) {
- args.push_back(HttpReqArg("until_date", untilDate));
+ args.emplace_back("until_date", untilDate);
}
if (canSendMessages) {
- args.push_back(HttpReqArg("can_send_messages", canSendMessages));
+ args.emplace_back("can_send_messages", canSendMessages);
}
if (canSendMediaMessages) {
- args.push_back(HttpReqArg("can_send_media_messages", canSendMediaMessages));
+ args.emplace_back("can_send_media_messages", canSendMediaMessages);
}
if (canSendOtherMessages) {
- args.push_back(HttpReqArg("can_send_other_messages", canSendOtherMessages));
+ args.emplace_back("can_send_other_messages", canSendOtherMessages);
}
if (canAddWebPagePreviews) {
- args.push_back(HttpReqArg("can_add_web_page_previews", canAddWebPagePreviews));
+ args.emplace_back("can_add_web_page_previews", canAddWebPagePreviews);
}
return sendRequest("restrictChatMember", args).get<bool>("", false);
}
@@ -916,121 +916,121 @@ bool Api::restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate,
bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, bool canPostMessages,
bool canEditMessages, bool canDeleteMessages, bool canInviteUsers, bool canPinMessages, bool canPromoteMembers) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("user_id", userId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("user_id", userId);
if (canChangeInfo) {
- args.push_back(HttpReqArg("can_change_info", canChangeInfo));
+ args.emplace_back("can_change_info", canChangeInfo);
}
if (canPostMessages) {
- args.push_back(HttpReqArg("can_post_messages", canPostMessages));
+ args.emplace_back("can_post_messages", canPostMessages);
}
if (canEditMessages) {
- args.push_back(HttpReqArg("can_edit_messages", canEditMessages));
+ args.emplace_back("can_edit_messages", canEditMessages);
}
if (canDeleteMessages) {
- args.push_back(HttpReqArg("can_delete_messages", canDeleteMessages));
+ args.emplace_back("can_delete_messages", canDeleteMessages);
}
if (canInviteUsers) {
- args.push_back(HttpReqArg("can_invite_users", canInviteUsers));
+ args.emplace_back("can_invite_users", canInviteUsers);
}
if (canPinMessages) {
- args.push_back(HttpReqArg("can_pin_messages", canPinMessages));
+ args.emplace_back("can_pin_messages", canPinMessages);
}
if (canPromoteMembers) {
- args.push_back(HttpReqArg("can_promote_members", canPromoteMembers));
+ args.emplace_back("can_promote_members", canPromoteMembers);
}
return sendRequest("promoteChatMember", args).get<bool>("", false);
}
string Api::exportChatInviteLink(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return sendRequest("exportChatInviteLink", args).get("", "");
}
bool Api::setChatPhoto(int64_t chatId, const InputFile::Ptr photo) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName);
return sendRequest("setChatPhoto", args).get<bool>("", false);
}
bool Api::deleteChatPhoto(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return sendRequest("deleteChatPhoto", args).get<bool>("", false);
}
bool Api::setChatTitle(int64_t chatId, const string& title) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("title", title));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("title", title);
return sendRequest("setChatTitle", args).get<bool>("", false);
}
bool Api::setChatDescription(int64_t chatId, const string& description) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("description", description));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("description", description);
return sendRequest("setChatDescription", args).get<bool>("", false);
}
bool Api::pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("message_id", messageId);
if (disableNotification) {
- args.push_back(HttpReqArg("disable_notification", disableNotification));
+ args.emplace_back("disable_notification", disableNotification);
}
return sendRequest("pinChatMessage", args).get<bool>("", false);
}
bool Api::unpinChatMessage(int64_t chatId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
return sendRequest("unpinChatMessage", args).get<bool>("", false);
}
Message::Ptr Api::setGameScore(int32_t userId, int32_t score, bool force, bool disableEditMessage, int64_t chatId, int32_t messageId, const std::string& inlineMessageId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("score", score));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("score", score);
if (force) {
- args.push_back(HttpReqArg("force", force));
+ args.emplace_back("force", force);
}
if (disableEditMessage) {
- args.push_back(HttpReqArg("disable_edit_message", disableEditMessage));
+ args.emplace_back("disable_edit_message", disableEditMessage);
}
if (chatId){
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId){
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()){
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetMessage(sendRequest("setGameScore", args));
}
vector<GameHighScore::Ptr> Api::getGameHighScores(int32_t userId, int32_t score, bool force, bool disableEditMessage, int64_t chatId, int32_t messageId, const std::string& inlineMessageId) const {
vector<HttpReqArg> args;
- args.push_back(HttpReqArg("user_id", userId));
- args.push_back(HttpReqArg("score", score));
+ args.emplace_back("user_id", userId);
+ args.emplace_back("score", score);
if (force) {
- args.push_back(HttpReqArg("force", force));
+ args.emplace_back("force", force);
}
if (disableEditMessage) {
- args.push_back(HttpReqArg("disable_edit_message", disableEditMessage));
+ args.emplace_back("disable_edit_message", disableEditMessage);
}
if (chatId) {
- args.push_back(HttpReqArg("chat_id", chatId));
+ args.emplace_back("chat_id", chatId);
}
if (messageId) {
- args.push_back(HttpReqArg("message_id", messageId));
+ args.emplace_back("message_id", messageId);
}
if (!inlineMessageId.empty()){
- args.push_back(HttpReqArg("inline_message_id", inlineMessageId));
+ args.emplace_back("inline_message_id", inlineMessageId);
}
return TgTypeParser::getInstance().parseJsonAndGetArray<GameHighScore>(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args));
}
@@ -1055,10 +1055,10 @@ ptree Api::sendRequest(const string& method, const vector<HttpReqArg>& args) con
if (result.get<bool>("ok", false)) {
return result.get_child("result");
} else {
- throw TgException(result.get("description", ""));
+ throw TgException(result.get("description", "");
}
} catch (boost::property_tree::ptree_error& e) {
- throw TgException("tgbot-cpp library can't parse json response. " + string(e.what()));
+ throw TgException("tgbot-cpp library can't parse json response. " + string(e.what());
}
}
diff --git a/src/net/HttpParser.cpp b/src/net/HttpParser.cpp
index befbc3b..3dd9215 100644
--- a/src/net/HttpParser.cpp
+++ b/src/net/HttpParser.cpp
@@ -149,7 +149,7 @@ string HttpParser::generateResponse(const string& data, const string& mimeType,
return result;
}
-string HttpParser::parseHttp(bool isRequest, const string& data, map<string, string>& headers) {
+string HttpParser::parseHttp(bool isRequest, const string& data, unordered_map<string, string>& headers) {
bool onlyNewLineChar = false;
size_t headerEnd = data.find("\r\n\r\n");
if (headerEnd == data.npos) {