From: Marcin Masternak Date: Tue, 31 May 2016 14:19:44 +0000 (+0200) Subject: [my-place][places_detector] Refactor getting place from Json. X-Git-Tag: submit/tizen/20160622.045445~1^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d50e2afaf5985a9d1faaf89370080ef587fc9b88;p=platform%2Fcore%2Fcontext%2Fcontext-provider.git [my-place][places_detector] Refactor getting place from Json. Change-Id: Ie67cf431797e68313348407fb03f9cd149d702de Signed-off-by: Marcin Masternak --- diff --git a/src/my-place/user_places/places_detector.cpp b/src/my-place/user_places/places_detector.cpp index a85a557..11ddbb2 100644 --- a/src/my-place/user_places/places_detector.cpp +++ b/src/my-place/user_places/places_detector.cpp @@ -160,31 +160,40 @@ ctx::Visits ctx::PlacesDetector::__visitsFromJsons(std::vector& records) std::shared_ptr ctx::PlacesDetector::__placeFromJson(Json &row) { std::shared_ptr place = std::make_shared(); - { // category - int categId; - row.get(NULL, PLACE_COLUMN_CATEG_ID, &categId); - // This is due to the fact the JSON module API interface doesn't handle enum - place->categId = static_cast(categId); - } + __placeCategoryFromJson(row, *place); row.get(NULL, PLACE_COLUMN_NAME, &(place->name)); row.get(NULL, PLACE_COLUMN_WIFI_APS, &(place->wifiAps)); - { // location - int locationValidInt; - row.get(NULL, PLACE_COLUMN_LOCATION_VALID, &locationValidInt); - place->locationValid = (bool) locationValidInt; - row.get(NULL, PLACE_COLUMN_LOCATION_LATITUDE, &(place->location.latitude)); - row.get(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, &(place->location.longitude)); - } - { // createDate - int createDate; - row.get(NULL, PLACE_COLUMN_CREATE_DATE, &(createDate)); - // This is due to the fact the JSON module API interface doesn't handle time_t - place->createDate = static_cast(createDate); - } - _D("db_result: categId: %d; place: name: %s; wifiAps: %s; locationValid: %d; latitude: %lf, longitude: %lf, createDate: %d", place->categId, place->name.c_str(), place->wifiAps.c_str(), place->locationValid, place->location.latitude, place->location.longitude, place->createDate); + __placeLocationFromJson(row, *place); + __placeCreateDateFromJson(row, *place); + _D("db_result: categId: %d; place: name: %s; locationValid: %d; latitude: %lf, longitude: %lf, createDate: %d", place->categId, place->name.c_str(), place->locationValid, place->location.latitude, place->location.longitude, place->createDate); return place; } +void ctx::PlacesDetector::__placeCategoryFromJson(Json &row, ctx::Place &place) +{ + int categId; + row.get(NULL, PLACE_COLUMN_CATEG_ID, &categId); + // This is due to the fact the JSON module API interface doesn't handle enum + place.categId = static_cast(categId); +} + +void ctx::PlacesDetector::__placeLocationFromJson(Json &row, ctx::Place &place) +{ + int locationValidInt; + row.get(NULL, PLACE_COLUMN_LOCATION_VALID, &locationValidInt); + place.locationValid = (bool) locationValidInt; + row.get(NULL, PLACE_COLUMN_LOCATION_LATITUDE, &(place.location.latitude)); + row.get(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, &(place.location.longitude)); +} + +void ctx::PlacesDetector::__placeCreateDateFromJson(Json &row, ctx::Place &place) +{ + int createDate; + row.get(NULL, PLACE_COLUMN_CREATE_DATE, &(createDate)); + // This is due to the fact the JSON module API interface doesn't handle time_t + place.createDate = static_cast(createDate); +} + std::vector> ctx::PlacesDetector::__placesFromJsons(std::vector& records) { std::vector> places; diff --git a/src/my-place/user_places/places_detector.h b/src/my-place/user_places/places_detector.h index 0cf6885..492fb23 100644 --- a/src/my-place/user_places/places_detector.h +++ b/src/my-place/user_places/places_detector.h @@ -38,6 +38,9 @@ namespace ctx { Visit __visitFromJson(Json &row); Visits __visitsFromJsons(std::vector& records); std::shared_ptr __placeFromJson(Json &row); + void __placeCategoryFromJson(Json &row, ctx::Place &place); + void __placeLocationFromJson(Json &row, ctx::Place &place); + void __placeCreateDateFromJson(Json &row, ctx::Place &place); std::vector> __placesFromJsons(std::vector& records); std::shared_ptr __graphFromVisits(const std::vector &visits);