summaryrefslogtreecommitdiff
path: root/src/TgTypeParser.cpp
diff options
context:
space:
mode:
authorOleg Morozenkov <omorozenkov@gmail.com>2015-08-11 22:13:23 +0300
committerOleg Morozenkov <omorozenkov@gmail.com>2015-08-11 22:13:23 +0300
commit376b88ec09ef8cf71dd823467406c58204485fcc (patch)
tree9ca599b854d18006c65b26003ce7dbdd416fdf18 /src/TgTypeParser.cpp
parentd7fbf7149d0e0c1c30972dab68d510ef6ac377dd (diff)
Fixed compiler's errors in TgTypeParser + fixed indentation + some other fixes
Diffstat (limited to 'src/TgTypeParser.cpp')
-rw-r--r--src/TgTypeParser.cpp792
1 files changed, 396 insertions, 396 deletions
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 9a1f93a..81d2119 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -28,463 +28,463 @@ using namespace boost::property_tree;
namespace TgBot {
TgTypeParser& TgTypeParser::getInstance() {
- static TgTypeParser result;
- return result;
+ static TgTypeParser result;
+ return result;
}
-User::Ptr TgTypeParser::parseUser(const ptree& data) const {
- User::Ptr result(new User);
- result->id = data.get<int32_t>("id");
- result->firstName = data.get<string>("first_name");
- result->lastName = data.get("last_name", "");
- result->username = data.get("username", "");
- return result;
+User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const {
+ User::Ptr result(new User);
+ result->id = data.get<int32_t>("id");
+ result->firstName = data.get<string>("first_name");
+ result->lastName = data.get("last_name", "");
+ result->username = data.get("username", "");
+ return result;
}
string TgTypeParser::parseUser(const User::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "first_name", object->firstName);
- appendToJson(result, "last_name", object->lastName);
- appendToJson(result, "username", object->username);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-GroupChat::Ptr TgTypeParser::parseGroupChat(const ptree& data) const {
- GroupChat::Ptr result(new GroupChat);
- result->id = data.get<int32_t>("id");
- result->title = data.get<string>("title");
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "first_name", object->firstName);
+ appendToJson(result, "last_name", object->lastName);
+ appendToJson(result, "username", object->username);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+GroupChat::Ptr TgTypeParser::parseJsonAndGetGroupChat(const ptree& data) const {
+ GroupChat::Ptr result(new GroupChat);
+ result->id = data.get<int32_t>("id");
+ result->title = data.get<string>("title");
+ return result;
}
string TgTypeParser::parseGroupChat(const GroupChat::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "title", object->title);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Message::Ptr TgTypeParser::parseMessage(const ptree& data) const {
- Message::Ptr result(new Message);
- result->messageId = data.get<int32_t>("message_id");
- result->from = parseUser(data.find("from")->second);
- result->date = data.get<int32_t>("date");
- result->chat = parseGenericChat(data.find("chat")->second);
- result->forwardFrom = tryParse<User>(parseUser, data, "forward_from");
- result->forwardDate = data.get("forward_date", 0);
- result->replyToMessage = tryParse<Message>(parseMessage, data, "reply_to_message");
- result->text = data.get("text", "");
- result->audio = tryParse<Audio>(parseAudio, data, "audio");
- result->document = tryParse<Document>(parseDocument, data, "document");
- result->photo = parseArray<PhotoSize>(parsePhotoSize, data, "photo");
- result->sticker = tryParse<Sticker>(parseSticker, data, "sticker");
- result->video = tryParse<Video>(parseVideo, data, "video");
- result->contact = tryParse<Contact>(parseContact, data, "contact");
- result->location = tryParse<Location>(parseLocation, data, "location");
- result->newChatParticipant = tryParse<User>(parseUser, data, "new_chat_participant");
- result->leftChatParticipant = tryParse<User>(parseUser, data, "left_chat_participant");
- result->newChatTitle = data.get("new_chat_title", "");
- result->newChatPhoto = parseArray<PhotoSize>(parsePhotoSize, data, "new_chat_photo");
- result->deleteChatPhoto = data.get("delete_chat_photo", false);
- result->groupChatCreated = data.get("group_chat_created", false);
- result->caption = data.get("caption", false);
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "id", object->id);
+ appendToJson(result, "title", object->title);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
+ Message::Ptr result(new Message);
+ result->messageId = data.get<int32_t>("message_id");
+ result->from = parseJsonAndGetUser(data.find("from")->second);
+ result->date = data.get<int32_t>("date");
+ result->chat = parseJsonAndGetGenericChat(data.find("chat")->second);
+ result->forwardFrom = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "forward_from");
+ result->forwardDate = data.get("forward_date", 0);
+ result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message");
+ result->text = data.get("text", "");
+ result->audio = tryParseJson<Audio>(&TgTypeParser::parseJsonAndGetAudio, data, "audio");
+ result->document = tryParseJson<Document>(&TgTypeParser::parseJsonAndGetDocument, data, "document");
+ result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo");
+ result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker");
+ result->video = tryParseJson<Video>(&TgTypeParser::parseJsonAndGetVideo, data, "video");
+ result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact");
+ result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location");
+ result->newChatParticipant = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "new_chat_participant");
+ result->leftChatParticipant = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "left_chat_participant");
+ result->newChatTitle = data.get("new_chat_title", "");
+ result->newChatPhoto = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "new_chat_photo");
+ result->deleteChatPhoto = data.get("delete_chat_photo", false);
+ result->groupChatCreated = data.get("group_chat_created", false);
+ result->caption = data.get("caption", false);
+ return result;
}
string TgTypeParser::parseMessage(const Message::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "message_id", object->messageId);
- appendToJson(result, "from", parseUser(object->from));
- appendToJson(result, "date", object->date);
- appendToJson(result, "chat", parseGenericChat(object->chat));
- appendToJson(result, "forward_from", parseUser(object->forwardFrom));
- appendToJson(result, "forward_date", object->forwardDate);
- appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage));
- appendToJson(result, "text", object->text);
- appendToJson(result, "audio", parseAudio(object->audio));
- appendToJson(result, "document", parseDocument(object->document));
- appendToJson(result, "photo", parseArray(parsePhotoSize, object->photo));
- appendToJson(result, "sticker", parseSticker(object->sticker));
- appendToJson(result, "video", parseVideo(object->video));
- appendToJson(result, "contact", parseContact(object->contact));
- appendToJson(result, "location", parseLocation(object->location));
- appendToJson(result, "new_chat_participant", parseUser(object->newChatParticipant));
- appendToJson(result, "left_chat_participant", parseUser(object->leftChatParticipant));
- appendToJson(result, "new_chat_title", object->newChatTitle);
- appendToJson(result, "new_chat_photo", parseArray(parsePhotoSize, object->newChatPhoto));
- appendToJson(result, "delete_chat_photo", object->deleteChatPhoto);
- appendToJson(result, "group_chat_created", object->groupChatCreated);
- appendToJson(result, "caption", object->caption);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-PhotoSize::Ptr TgTypeParser::parsePhotoSize(const ptree& data) const {
- PhotoSize::Ptr result(new PhotoSize);
- result->fileId = data.get<string>("file_id");
- result->width = data.get<int32_t>("width");
- result->height = data.get<int32_t>("height");
- result->fileSize = data.get("file_size", 0);
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "message_id", object->messageId);
+ appendToJson(result, "from", parseUser(object->from));
+ appendToJson(result, "date", object->date);
+ appendToJson(result, "chat", parseGenericChat(object->chat));
+ appendToJson(result, "forward_from", parseUser(object->forwardFrom));
+ appendToJson(result, "forward_date", object->forwardDate);
+ appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage));
+ appendToJson(result, "text", object->text);
+ appendToJson(result, "audio", parseAudio(object->audio));
+ appendToJson(result, "document", parseDocument(object->document));
+ appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo));
+ appendToJson(result, "sticker", parseSticker(object->sticker));
+ appendToJson(result, "video", parseVideo(object->video));
+ appendToJson(result, "contact", parseContact(object->contact));
+ appendToJson(result, "location", parseLocation(object->location));
+ appendToJson(result, "new_chat_participant", parseUser(object->newChatParticipant));
+ appendToJson(result, "left_chat_participant", parseUser(object->leftChatParticipant));
+ appendToJson(result, "new_chat_title", object->newChatTitle);
+ appendToJson(result, "new_chat_photo", parseArray(&TgTypeParser::parsePhotoSize, object->newChatPhoto));
+ appendToJson(result, "delete_chat_photo", object->deleteChatPhoto);
+ appendToJson(result, "group_chat_created", object->groupChatCreated);
+ appendToJson(result, "caption", object->caption);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+PhotoSize::Ptr TgTypeParser::parseJsonAndGetPhotoSize(const ptree& data) const {
+ PhotoSize::Ptr result(new PhotoSize);
+ result->fileId = data.get<string>("file_id");
+ result->width = data.get<int32_t>("width");
+ result->height = data.get<int32_t>("height");
+ result->fileSize = data.get("file_size", 0);
+ return result;
}
string TgTypeParser::parsePhotoSize(const PhotoSize::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "file_id", object->fileId);
- appendToJson(result, "width", object->width);
- appendToJson(result, "height", object->height);
- appendToJson(result, "file_size", object->fileSize);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Audio::Ptr TgTypeParser::parseAudio(const ptree& data) const {
- Audio::Ptr result(new Audio);
- result->fileId = data.get<string>("file_id");
- result->duration = data.get<int32_t>("duration");
- result->mimeType = data.get("mime_type", "");
- result->fileSize = data.get("file_size", 0);
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "file_id", object->fileId);
+ appendToJson(result, "width", object->width);
+ appendToJson(result, "height", object->height);
+ appendToJson(result, "file_size", object->fileSize);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const {
+ Audio::Ptr result(new Audio);
+ result->fileId = data.get<string>("file_id");
+ result->duration = data.get<int32_t>("duration");
+ result->mimeType = data.get("mime_type", "");
+ result->fileSize = data.get("file_size", 0);
+ return result;
}
string TgTypeParser::parseAudio(const Audio::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "file_id", object->fileId);
- appendToJson(result, "duration", object->duration);
- appendToJson(result, "mime_type", object->mimeType);
- appendToJson(result, "file_size", object->fileSize);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Document::Ptr TgTypeParser::parseDocument(const ptree& data) const {
- Document::Ptr result(new Document);
- result->fileId = data.get<string>("file_id");
- result->thumb = parsePhotoSize(data.find("thumb")->second);
- result->fileName = data.get("file_name", "");
- result->mimeType = data.get("mime_type", "");
- result->fileSize = data.get("file_size", 0);
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "file_id", object->fileId);
+ appendToJson(result, "duration", object->duration);
+ appendToJson(result, "mime_type", object->mimeType);
+ appendToJson(result, "file_size", object->fileSize);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Document::Ptr TgTypeParser::parseJsonAndGetDocument(const ptree& data) const {
+ Document::Ptr result(new Document);
+ result->fileId = data.get<string>("file_id");
+ result->thumb = parseJsonAndGetPhotoSize(data.find("thumb")->second);
+ result->fileName = data.get("file_name", "");
+ result->mimeType = data.get("mime_type", "");
+ result->fileSize = data.get("file_size", 0);
+ return result;
}
string TgTypeParser::parseDocument(const Document::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "file_id", object->fileId);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
- appendToJson(result, "file_name", object->fileName);
- appendToJson(result, "mime_type", object->mimeType);
- appendToJson(result, "file_size", object->fileSize);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Sticker::Ptr TgTypeParser::parseSticker(const ptree& data) const {
- Sticker::Ptr result(new Sticker);
- result->fileId = data.get<string>("file_id");
- result->width = data.get<int32_t>("width");
- result->height = data.get<int32_t>("height");
- result->thumb = parsePhotoSize(data.find("thumb")->second);
- result->fileSize = data.get("file_size", 0);
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "file_id", object->fileId);
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
+ appendToJson(result, "file_name", object->fileName);
+ appendToJson(result, "mime_type", object->mimeType);
+ appendToJson(result, "file_size", object->fileSize);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const {
+ Sticker::Ptr result(new Sticker);
+ result->fileId = data.get<string>("file_id");
+ result->width = data.get<int32_t>("width");
+ result->height = data.get<int32_t>("height");
+ result->thumb = parseJsonAndGetPhotoSize(data.find("thumb")->second);
+ result->fileSize = data.get("file_size", 0);
+ return result;
}
string TgTypeParser::parseSticker(const Sticker::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "file_id", object->fileId);
- appendToJson(result, "width", object->width);
- appendToJson(result, "height", object->height);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
- appendToJson(result, "file_size", object->fileSize);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Video::Ptr TgTypeParser::parseVideo(const ptree& data) const {
- Video::Ptr result(new Video);
- result->fileId = data.get<string>("file_id");
- result->width = data.get<int32_t>("width");
- result->height = data.get<int32_t>("height");
- result->duration = data.get<int32_t>("duration");
- result->thumb = parsePhotoSize(data.find("thumb")->second);
- result->mimeType = data.get("mime_type", "");
- result->fileSize = data.get("file_size", 0);
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "file_id", object->fileId);
+ appendToJson(result, "width", object->width);
+ appendToJson(result, "height", object->height);
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
+ appendToJson(result, "file_size", object->fileSize);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Video::Ptr TgTypeParser::parseJsonAndGetVideo(const ptree& data) const {
+ Video::Ptr result(new Video);
+ result->fileId = data.get<string>("file_id");
+ result->width = data.get<int32_t>("width");
+ result->height = data.get<int32_t>("height");
+ result->duration = data.get<int32_t>("duration");
+ result->thumb = parseJsonAndGetPhotoSize(data.find("thumb")->second);
+ result->mimeType = data.get("mime_type", "");
+ result->fileSize = data.get("file_size", 0);
+ return result;
}
string TgTypeParser::parseVideo(const Video::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "file_id", object->fileId);
- appendToJson(result, "width", object->width);
- appendToJson(result, "height", object->height);
- appendToJson(result, "duration", object->duration);
- appendToJson(result, "thumb", parsePhotoSize(object->thumb));
- appendToJson(result, "mime_type", object->mimeType);
- appendToJson(result, "file_size", object->fileSize);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Contact::Ptr TgTypeParser::parseContact(const ptree& data) const {
- Contact::Ptr result(new Contact);
- result->phoneNumber = data.get<string>("phone_number");
- result->firstName = data.get<string>("first_name");
- result->lastName = data.get("last_name", "");
- result->userId = data.get("user_id", "");
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "file_id", object->fileId);
+ appendToJson(result, "width", object->width);
+ appendToJson(result, "height", object->height);
+ appendToJson(result, "duration", object->duration);
+ appendToJson(result, "thumb", parsePhotoSize(object->thumb));
+ appendToJson(result, "mime_type", object->mimeType);
+ appendToJson(result, "file_size", object->fileSize);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Contact::Ptr TgTypeParser::parseJsonAndGetContact(const ptree& data) const {
+ Contact::Ptr result(new Contact);
+ result->phoneNumber = data.get<string>("phone_number");
+ result->firstName = data.get<string>("first_name");
+ result->lastName = data.get("last_name", "");
+ result->userId = data.get("user_id", "");
+ return result;
}
string TgTypeParser::parseContact(const Contact::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "phone_number", object->phoneNumber);
- appendToJson(result, "first_name", object->firstName);
- appendToJson(result, "last_name", object->lastName);
- appendToJson(result, "user_id", object->userId);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-Location::Ptr TgTypeParser::parseLocation(const ptree& data) const {
- Location::Ptr result(new Location);
- result->longitude = data.get<float>("longitude");
- result->latitude = data.get<float>("latitude");
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "phone_number", object->phoneNumber);
+ appendToJson(result, "first_name", object->firstName);
+ appendToJson(result, "last_name", object->lastName);
+ appendToJson(result, "user_id", object->userId);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+Location::Ptr TgTypeParser::parseJsonAndGetLocation(const ptree& data) const {
+ Location::Ptr result(new Location);
+ result->longitude = data.get<float>("longitude");
+ result->latitude = data.get<float>("latitude");
+ return result;
}
string TgTypeParser::parseLocation(const Location::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "longitude", object->longitude);
- appendToJson(result, "latitude", object->latitude);
- result.erase(result.length() - 1);
- result += '}';
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "longitude", object->longitude);
+ appendToJson(result, "latitude", object->latitude);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
}
-Update::Ptr TgTypeParser::parseUpdate(const ptree& data) const {
- Update::Ptr result(new Update);
- result->updateId = data.get<int32_t>("update_id");
- result->message = parseMessage(data.find("message")->second);
- return result;
+Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const ptree& data) const {
+ Update::Ptr result(new Update);
+ result->updateId = data.get<int32_t>("update_id");
+ result->message = parseJsonAndGetMessage(data.find("message")->second);
+ return result;
}
string TgTypeParser::parseUpdate(const Update::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "update_id", object->updateId);
- appendToJson(result, "message", parseMessage(object->message));
- result.erase(result.length() - 1);
- result += '}';
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "update_id", object->updateId);
+ appendToJson(result, "message", parseMessage(object->message));
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
}
-UserProfilePhotos::Ptr TgTypeParser::parseUserProfilePhotos(const ptree& data) const {
- UserProfilePhotos::Ptr result(new UserProfilePhotos);
- result->totalCount = data.get<int32_t>("total_count");
- result->photos = parse2DArray<PhotoSize>(parsePhotoSize, data, "photos");
- return result;
+UserProfilePhotos::Ptr TgTypeParser::parseJsonAndGetUserProfilePhotos(const ptree& data) const {
+ UserProfilePhotos::Ptr result(new UserProfilePhotos);
+ result->totalCount = data.get<int32_t>("total_count");
+ result->photos = parseJsonAndGet2DArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photos");
+ return result;
}
string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "total_count", object->totalCount);
- appendToJson(result, "photos", parse2DArray(parsePhotoSize, object->photos));
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-ReplyKeyboardMarkup::Ptr TgTypeParser::parseReplyKeyboardMarkup(const boost::property_tree::ptree& data) const {
- ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup);
- for (const pair<const string, ptree>& item : data.find("keyboard")->second) {
- vector<string> array;
- for (const pair<const string, ptree>& innerItem : item.second) {
- array.push_back(innerItem.second.data());
- }
- result->keyboard.push_back(array);
- }
- result->resizeKeyboard = data.get<bool>("resize_keyboard");
- result->oneTimeKeyboard = data.get<bool>("one_time_keyboard");
- result->selective = data.get<bool>("selective");
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "total_count", object->totalCount);
+ appendToJson(result, "photos", parse2DArray(&TgTypeParser::parsePhotoSize, object->photos));
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const {
+ ReplyKeyboardMarkup::Ptr result(new ReplyKeyboardMarkup);
+ for (const pair<const string, ptree>& item : data.find("keyboard")->second) {
+ vector<string> array;
+ for (const pair<const string, ptree>& innerItem : item.second) {
+ array.push_back(innerItem.second.data());
+ }
+ result->keyboard.push_back(array);
+ }
+ result->resizeKeyboard = data.get<bool>("resize_keyboard");
+ result->oneTimeKeyboard = data.get<bool>("one_time_keyboard");
+ result->selective = data.get<bool>("selective");
+ return result;
}
std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- result += "\"keyboard\":[";
- for (vector<string>& item : object->keyboard) {
- result += '[';
- for (string& innerItem : item) {
- result += '"';
- result += innerItem;
- result += "\",";
- }
- result.erase(result.length() - 1);
- result += "],";
- }
- result.erase(result.length() - 1);
- result += "],";
- appendToJson(result, "resize_keyboard", object->resizeKeyboard);
- appendToJson(result, "one_time_keyboard", object->oneTimeKeyboard);
- appendToJson(result, "selective", object->selective);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
-ReplyKeyboardHide::Ptr TgTypeParser::parseReplyKeyboardHide(const boost::property_tree::ptree& data) const {
- ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide);
- result->selective = data.get<bool>("selective");
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ result += "\"keyboard\":[";
+ for (vector<string>& item : object->keyboard) {
+ result += '[';
+ for (string& innerItem : item) {
+ result += '"';
+ result += innerItem;
+ result += "\",";
+ }
+ result.erase(result.length() - 1);
+ result += "],";
+ }
+ result.erase(result.length() - 1);
+ result += "],";
+ appendToJson(result, "resize_keyboard", object->resizeKeyboard);
+ appendToJson(result, "one_time_keyboard", object->oneTimeKeyboard);
+ appendToJson(result, "selective", object->selective);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
+}
+
+ReplyKeyboardHide::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardHide(const boost::property_tree::ptree& data) const {
+ ReplyKeyboardHide::Ptr result(new ReplyKeyboardHide);
+ result->selective = data.get<bool>("selective");
+ return result;
}
std::string TgTypeParser::parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "selective", object->selective);
- result.erase(result.length() - 1);
- result += '}';
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "selective", object->selective);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
}
-ForceReply::Ptr TgTypeParser::parseForceReply(const boost::property_tree::ptree& data) const {
- ForceReply::Ptr result(new ForceReply);
- result->selective = data.get<bool>("selective");
- return result;
+ForceReply::Ptr TgTypeParser::parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const {
+ ForceReply::Ptr result(new ForceReply);
+ result->selective = data.get<bool>("selective");
+ return result;
}
std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "selective", object->selective);
- result.erase(result.length() - 1);
- result += '}';
- return result;
+ if (!object) {
+ return "";
+ }
+ string result;
+ result += '{';
+ appendToJson(result, "selective", object->selective);
+ result.erase(result.length() - 1);
+ result += '}';
+ return result;
}
-GenericChat::Ptr TgTypeParser::parseGenericChat(const ptree& data) const {
- if (data.find("first_name") == data.not_found()) {
- return static_pointer_cast<GenericChat>(parseGroupChat(data));
- } else {
- return static_pointer_cast<GenericChat>(parseUser(data));
- }
+GenericChat::Ptr TgTypeParser::parseJsonAndGetGenericChat(const ptree& data) const {
+ if (data.find("first_name") == data.not_found()) {
+ return static_pointer_cast<GenericChat>(parseJsonAndGetGroupChat(data));
+ } else {
+ return static_pointer_cast<GenericChat>(parseJsonAndGetUser(data));
+ }
}
string TgTypeParser::parseGenericChat(const GenericChat::Ptr& object) const {
- if (!object) {
- return "";
- }
- if (dynamic_pointer_cast<User>(object) == nullptr) {
- return parseGroupChat(static_pointer_cast<GroupChat>(object));
- } else {
- return parseUser(static_pointer_cast<User>(object));
- }
-}
-
-GenericReply::Ptr TgTypeParser::parseGenericReply(const boost::property_tree::ptree& data) const {
- if (data.find("force_reply") != data.not_found()) {
- return static_pointer_cast<GenericReply>(parseForceReply(data));
- } else if (data.find("hide_keyboard") != data.not_found()) {
- return static_pointer_cast<GenericReply>(parseReplyKeyboardHide(data));
- } else {
- return static_pointer_cast<GenericReply>(parseReplyKeyboardMarkup(data));
- }
+ if (!object) {
+ return "";
+ }
+ if (dynamic_pointer_cast<User>(object) == nullptr) {
+ return parseGroupChat(static_pointer_cast<GroupChat>(object));
+ } else {
+ return parseUser(static_pointer_cast<User>(object));
+ }
+}
+
+GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const {
+ if (data.find("force_reply") != data.not_found()) {
+ return static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data));
+ } else if (data.find("hide_keyboard") != data.not_found()) {
+ return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardHide(data));
+ } else {
+ return static_pointer_cast<GenericReply>(parseJsonAndGetReplyKeyboardMarkup(data));
+ }
}
std::string TgTypeParser::parseGenericReply(const GenericReply::Ptr& object) const {
- if (!object) {
- return "";
- }
- if (dynamic_pointer_cast<ForceReply>(object) != nullptr) {
- return parseForceReply(static_pointer_cast<ForceReply>(object));
- } else if (dynamic_pointer_cast<ReplyKeyboardHide>(object) != nullptr) {
- return parseReplyKeyboardHide(static_pointer_cast<ReplyKeyboardHide>(object));
- } else {
- return parseReplyKeyboardMarkup(static_pointer_cast<ReplyKeyboardMarkup>(object));
- }
+ if (!object) {
+ return "";
+ }
+ if (dynamic_pointer_cast<ForceReply>(object) != nullptr) {
+ return parseForceReply(static_pointer_cast<ForceReply>(object));
+ } else if (dynamic_pointer_cast<ReplyKeyboardHide>(object) != nullptr) {
+ return parseReplyKeyboardHide(static_pointer_cast<ReplyKeyboardHide>(object));
+ } else {
+ return parseReplyKeyboardMarkup(static_pointer_cast<ReplyKeyboardMarkup>(object));
+ }
}
void TgTypeParser::appendToJson(string& json, const string& varName, const string& value) const {
- if (value.empty()) {
- return;
- }
- json += '"';
- json += varName;
- json += "\":";
- if (value.front() != '{') {
- json += '"';
- }
- json += value;
- if (value.back() != '}') {
- json += '"';
- }
- json += ',';
-}
-
-} \ No newline at end of file
+ if (value.empty()) {
+ return;
+ }
+ json += '"';
+ json += varName;
+ json += "\":";
+ if (value.front() != '{') {
+ json += '"';
+ }
+ json += value;
+ if (value.back() != '}') {
+ json += '"';
+ }
+ json += ',';
+}
+
+}