{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/54762686","id":54762686,"diff_hunk":"@@ -0,0 +1,223 @@\n+#include \"sample.hpp\"\n+\n+#include \"base/logging.hpp\"\n+#include \"base/string_utils.hpp\"\n+\n+#include \"std/sstream.hpp\"\n+#include \"std/string.hpp\"\n+\n+#include \"3party/jansson/myjansson.hpp\"\n+\n+namespace\n+{\n+void FromJSONObject(json_t * root, string & result) { result = string(json_string_value(root)); }\n+\n+void FromJSONObject(json_t * root, string const & field, string & result)\n+{\n+  if (!json_is_object(root))\n+    MYTHROW(my::Json::Exception, (\"Bad json object when parsing\", field));\n+  json_t * val = json_object_get(root, field.c_str());\n+  if (!val)\n+    MYTHROW(my::Json::Exception, (\"Obligatory field\", field, \"is absent.\"));\n+  if (!json_is_string(val))\n+    MYTHROW(my::Json::Exception, (\"The field\", field, \"must contain a json string.\"));\n+  result = string(json_string_value(val));\n+}\n+\n+void FromJSONObject(json_t * root, string const & field, strings::UniString & result)\n+{\n+  string s;\n+  FromJSONObject(root, field, s);\n+  result = strings::MakeUniString(s);\n+}\n+\n+void FromJSONObject(json_t * root, string const & field, double & result)\n+{\n+  if (!json_is_object(root))\n+    MYTHROW(my::Json::Exception, (\"Bad json object when parsing\", field));\n+  json_t * val = json_object_get(root, field.c_str());\n+  if (!val)\n+    MYTHROW(my::Json::Exception, (\"Obligatory field\", field, \"is absent.\"));\n+  if (!json_is_number(val))\n+    MYTHROW(my::Json::Exception, (\"The field\", field, \"must contain a json number.\"));\n+  result = json_number_value(val);\n+}\n+\n+void FromJSONObject(json_t * root, string const & field, m2::PointD & result)\n+{\n+  if (!json_is_object(root))\n+    MYTHROW(my::Json::Exception, (\"Bad json object when parsing\", field));\n+  json_t * val = json_object_get(root, field.c_str());\n+  if (!val)\n+    MYTHROW(my::Json::Exception, (\"Obligatory field\", field, \"is absent.\"));\n+  FromJSONObject(val, \"x\", result.x);\n+  FromJSONObject(val, \"y\", result.y);\n+}\n+\n+void FromJSONObject(json_t * root, string const & field, m2::RectD & result)\n+{\n+  json_t * rect = json_object_get(root, field.c_str());\n+  if (!rect)\n+    MYTHROW(my::Json::Exception, (\"Obligatory field\", field, \"is absent.\"));\n+  double minX, minY, maxX, maxY;\n+  FromJSONObject(rect, \"minx\", minX);\n+  FromJSONObject(rect, \"miny\", minY);\n+  FromJSONObject(rect, \"maxx\", maxX);\n+  FromJSONObject(rect, \"maxy\", maxY);\n+  result.setMinX(minX);\n+  result.setMinY(minY);\n+  result.setMaxX(maxX);\n+  result.setMaxY(maxY);\n+}\n+\n+void FromJSONObject(json_t * root, string const & field, vector<string> & result)\n+{\n+  json_t * arr = json_object_get(root, field.c_str());\n+  if (!arr)\n+    MYTHROW(my::Json::Exception, (\"Obligatory field\", field, \"is absent.\"));\n+  if (!json_is_array(arr))\n+    MYTHROW(my::Json::Exception, (\"The field\", field, \"must contain a json array.\"));\n+  size_t const sz = json_array_size(arr);\n+  result.resize(sz);\n+  for (size_t i = 0; i < sz; ++i)\n+  {\n+    json_t * elem = json_array_get(arr, i);\n+    if (!json_is_string(elem))\n+      MYTHROW(my::Json::Exception, (\"Wrong type:\", field, \"must contain an array of strings.\"));\n+    result[i] = json_string_value(elem);\n+  }\n+}\n+\n+void FromJSONObject(json_t * root, string const & field, search::Sample::Result::Relevance & r)\n+{\n+  string relevance;\n+  FromJSONObject(root, field, relevance);\n+  if (relevance == \"vital\")\n+    r = search::Sample::Result::Relevance::RELEVANCE_VITAL;\n+  else if (relevance == \"relevant\")\n+    r = search::Sample::Result::Relevance::RELEVANCE_RELEVANT;\n+  else\n+    r = search::Sample::Result::Relevance::RELEVANCE_IRRELEVANT;\n+}\n+\n+void FromJSONObject(json_t * root, search::Sample::Result & result)\n+{\n+  FromJSONObject(root, \"position\", result.m_pos);\n+  FromJSONObject(root, \"name\", result.m_name);\n+  FromJSONObject(root, \"houseNumber\", result.m_houseNumber);\n+  FromJSONObject(root, \"types\", result.m_types);\n+  FromJSONObject(root, \"relevancy\", result.m_relevance);\n+}\n+\n+template <typename T>\n+void FromJSONObject(json_t * root, string const & field, vector<T> & result)\n+{\n+  json_t * arr = json_object_get(root, field.c_str());\n+  if (!arr)\n+    MYTHROW(my::Json::Exception, (\"Obligatory field\", field, \"is absent.\"));\n+  if (!json_is_array(arr))\n+    MYTHROW(my::Json::Exception, (\"The field\", field, \"must contain a json array.\"));\n+  size_t sz = json_array_size(arr);\n+  result.resize(sz);\n+  for (size_t i = 0; i < sz; ++i)\n+    FromJSONObject(json_array_get(arr, i), result[i]);\n+}\n+}  // namespace\n+\n+namespace search\n+{\n+bool Sample::DeserializeFromJSON(string const & jsonStr)\n+{\n+  try\n+  {\n+    my::Json root(jsonStr.c_str());\n+    DeserializeFromJSONImpl(root.get());\n+    return true;\n+  }\n+  catch (my::Json::Exception const & e)\n+  {\n+    LOG(LDEBUG, (\"Can't parse sample:\", e.Msg(), jsonStr));\n+  }\n+  return false;\n+}\n+\n+// static\n+bool Sample::DeserializeFromJSON(string const & jsonStr, vector<Sample> & samples)\n+{\n+  try\n+  {\n+    my::Json root(jsonStr.c_str());\n+    if (!json_is_array(root.get()))\n+      MYTHROW(my::Json::Exception, (\"The field\", \"samples\", \"must contain a json array.\"));\n+    size_t numSamples = json_array_size(root.get());\n+    samples.resize(numSamples);\n+    for (size_t i = 0; i < numSamples; ++i)\n+      samples[i].DeserializeFromJSONImpl(json_array_get(root.get(), i));\n+    return true;\n+  }\n+  catch (my::Json::Exception const & e)\n+  {\n+    LOG(LERROR, (\"Can't parse samples:\", e.Msg(), jsonStr));\n+  }\n+  return false;\n+}\n+\n+string Sample::ToStringDebug() const","path":"search/sample.cpp","position":165,"original_position":165,"commit_id":"ba036443a6cee647e71e0b558be3f27938ded50a","original_commit_id":"ba036443a6cee647e71e0b558be3f27938ded50a","user":{"login":"mpimenov","id":10366009,"avatar_url":"https://avatars.githubusercontent.com/u/10366009?v=3","gravatar_id":"","url":"https://api.github.com/users/mpimenov","html_url":"https://github.com/mpimenov","followers_url":"https://api.github.com/users/mpimenov/followers","following_url":"https://api.github.com/users/mpimenov/following{/other_user}","gists_url":"https://api.github.com/users/mpimenov/gists{/gist_id}","starred_url":"https://api.github.com/users/mpimenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpimenov/subscriptions","organizations_url":"https://api.github.com/users/mpimenov/orgs","repos_url":"https://api.github.com/users/mpimenov/repos","events_url":"https://api.github.com/users/mpimenov/events{/privacy}","received_events_url":"https://api.github.com/users/mpimenov/received_events","type":"User","site_admin":false},"body":"А хотя.\r\nВообще открыл поля.","created_at":"2016-03-02T17:57:23Z","updated_at":"2016-03-02T17:57:23Z","html_url":"https://github.com/mapsme/omim/pull/1945#discussion_r54762686","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/1945","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/54762686"},"html":{"href":"https://github.com/mapsme/omim/pull/1945#discussion_r54762686"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1945"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/1945","id":59644331,"html_url":"https://github.com/mapsme/omim/pull/1945","diff_url":"https://github.com/mapsme/omim/pull/1945.diff","patch_url":"https://github.com/mapsme/omim/pull/1945.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/1945","number":1945,"state":"open","locked":false,"title":"[search] Added a json-serializable struct for search data samples.","user":{"login":"mpimenov","id":10366009,"avatar_url":"https://avatars.githubusercontent.com/u/10366009?v=3","gravatar_id":"","url":"https://api.github.com/users/mpimenov","html_url":"https://github.com/mpimenov","followers_url":"https://api.github.com/users/mpimenov/followers","following_url":"https://api.github.com/users/mpimenov/following{/other_user}","gists_url":"https://api.github.com/users/mpimenov/gists{/gist_id}","starred_url":"https://api.github.com/users/mpimenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpimenov/subscriptions","organizations_url":"https://api.github.com/users/mpimenov/orgs","repos_url":"https://api.github.com/users/mpimenov/repos","events_url":"https://api.github.com/users/mpimenov/events{/privacy}","received_events_url":"https://api.github.com/users/mpimenov/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-17T13:36:57Z","updated_at":"2016-03-02T17:57:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bff55b5ab6e515eb4935c73f6ac61a1763f19e1d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/1945/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/1945/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/1945/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/ba036443a6cee647e71e0b558be3f27938ded50a","head":{"label":"mpimenov:sample-parser","ref":"sample-parser","sha":"ba036443a6cee647e71e0b558be3f27938ded50a","user":{"login":"mpimenov","id":10366009,"avatar_url":"https://avatars.githubusercontent.com/u/10366009?v=3","gravatar_id":"","url":"https://api.github.com/users/mpimenov","html_url":"https://github.com/mpimenov","followers_url":"https://api.github.com/users/mpimenov/followers","following_url":"https://api.github.com/users/mpimenov/following{/other_user}","gists_url":"https://api.github.com/users/mpimenov/gists{/gist_id}","starred_url":"https://api.github.com/users/mpimenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpimenov/subscriptions","organizations_url":"https://api.github.com/users/mpimenov/orgs","repos_url":"https://api.github.com/users/mpimenov/repos","events_url":"https://api.github.com/users/mpimenov/events{/privacy}","received_events_url":"https://api.github.com/users/mpimenov/received_events","type":"User","site_admin":false},"repo":{"id":43427925,"name":"omim","full_name":"mpimenov/omim","owner":{"login":"mpimenov","id":10366009,"avatar_url":"https://avatars.githubusercontent.com/u/10366009?v=3","gravatar_id":"","url":"https://api.github.com/users/mpimenov","html_url":"https://github.com/mpimenov","followers_url":"https://api.github.com/users/mpimenov/followers","following_url":"https://api.github.com/users/mpimenov/following{/other_user}","gists_url":"https://api.github.com/users/mpimenov/gists{/gist_id}","starred_url":"https://api.github.com/users/mpimenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpimenov/subscriptions","organizations_url":"https://api.github.com/users/mpimenov/orgs","repos_url":"https://api.github.com/users/mpimenov/repos","events_url":"https://api.github.com/users/mpimenov/events{/privacy}","received_events_url":"https://api.github.com/users/mpimenov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mpimenov/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/mpimenov/omim","forks_url":"https://api.github.com/repos/mpimenov/omim/forks","keys_url":"https://api.github.com/repos/mpimenov/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mpimenov/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mpimenov/omim/teams","hooks_url":"https://api.github.com/repos/mpimenov/omim/hooks","issue_events_url":"https://api.github.com/repos/mpimenov/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mpimenov/omim/events","assignees_url":"https://api.github.com/repos/mpimenov/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mpimenov/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mpimenov/omim/tags","blobs_url":"https://api.github.com/repos/mpimenov/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mpimenov/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mpimenov/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mpimenov/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mpimenov/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mpimenov/omim/languages","stargazers_url":"https://api.github.com/repos/mpimenov/omim/stargazers","contributors_url":"https://api.github.com/repos/mpimenov/omim/contributors","subscribers_url":"https://api.github.com/repos/mpimenov/omim/subscribers","subscription_url":"https://api.github.com/repos/mpimenov/omim/subscription","commits_url":"https://api.github.com/repos/mpimenov/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mpimenov/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mpimenov/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mpimenov/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mpimenov/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mpimenov/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mpimenov/omim/merges","archive_url":"https://api.github.com/repos/mpimenov/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mpimenov/omim/downloads","issues_url":"https://api.github.com/repos/mpimenov/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mpimenov/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mpimenov/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mpimenov/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mpimenov/omim/labels{/name}","releases_url":"https://api.github.com/repos/mpimenov/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mpimenov/omim/deployments","created_at":"2015-09-30T10:55:18Z","updated_at":"2016-01-15T13:41:49Z","pushed_at":"2016-03-02T13:31:51Z","git_url":"git://github.com/mpimenov/omim.git","ssh_url":"git@github.com:mpimenov/omim.git","clone_url":"https://github.com/mpimenov/omim.git","svn_url":"https://github.com/mpimenov/omim","homepage":null,"size":2189914,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mapsme:new-search","ref":"new-search","sha":"4514a9d0f2482ca95bcefbf6040d64a835015248","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","deployments_url":"https://api.github.com/repos/mapsme/omim/deployments","created_at":"2015-09-20T02:57:13Z","updated_at":"2016-03-02T14:57:05Z","pushed_at":"2016-03-02T16:50:07Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":2251823,"stargazers_count":1638,"watchers_count":1638,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":227,"mirror_url":null,"open_issues_count":116,"forks":227,"open_issues":116,"watchers":1638,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1945"},"html":{"href":"https://github.com/mapsme/omim/pull/1945"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/1945"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/1945/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1945/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/1945/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/ba036443a6cee647e71e0b558be3f27938ded50a"}}}}