From dc83c209c933795b847ec6e2e6b5f818d255bbe7 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Tue, 31 May 2016 12:02:13 +0200 Subject: [PATCH] [my-place] Tizen coding convention - Omit brackets ("{", "}") in one-line "if" statements. Change-Id: I04ce028c825bd8d762554836ccca0e5828aabb07 Signed-off-by: Marcin Masternak --- src/my-place/user_places/graph.cpp | 7 ++- src/my-place/user_places/location_logger.cpp | 12 ++--- src/my-place/user_places/place_categer.cpp | 9 ++-- src/my-place/user_places/places_detector.cpp | 19 +++---- src/my-place/user_places/similarity.h | 9 ++-- src/my-place/user_places/user_places.cpp | 10 ++-- .../user_places/user_places_types.cpp | 24 +++------ src/my-place/user_places/visit_categer.cpp | 15 ++---- src/my-place/user_places/visit_detector.cpp | 22 +++----- src/my-place/user_places/wifi_logger.cpp | 52 +++++++------------ 10 files changed, 59 insertions(+), 120 deletions(-) diff --git a/src/my-place/user_places/graph.cpp b/src/my-place/user_places/graph.cpp index 2fdb6dc..1ad16e0 100644 --- a/src/my-place/user_places/graph.cpp +++ b/src/my-place/user_places/graph.cpp @@ -24,9 +24,9 @@ std::shared_ptr ctx::graph::connectedComponents(Graph &g std::set fringe; for (Node i = 0; i < static_cast(graph.size()); i++) { - if (!graph[i]) { + if (!graph[i]) continue; - } + // neighbourhood of node i exists (was not removed) std::shared_ptr c = std::make_shared(); ccs->push_back(c); @@ -38,9 +38,8 @@ std::shared_ptr ctx::graph::connectedComponents(Graph &g std::shared_ptr currNhood = graph[currNode]; for (Node nhoodNode : *currNhood) { - if (graph[nhoodNode] && fringe.find(nhoodNode) == fringe.end()) { + if (graph[nhoodNode] && fringe.find(nhoodNode) == fringe.end()) fringe.insert(nhoodNode); - } } graph[currNode].reset(); // removing current node } diff --git a/src/my-place/user_places/location_logger.cpp b/src/my-place/user_places/location_logger.cpp index 3d611e2..cdb7fb1 100644 --- a/src/my-place/user_places/location_logger.cpp +++ b/src/my-place/user_places/location_logger.cpp @@ -220,9 +220,8 @@ ctx::LocationLogger::LocationLogger(ILocationListener *listener) : __locationManagerCreate(); - if (LOCATION_LOGGER_DATABASE) { + if (LOCATION_LOGGER_DATABASE) __dbCreateTable(); - } __locationManagerSetServiceStateChangedCb(); __locationManagerSetSettingChangedCb(); @@ -479,12 +478,10 @@ void ctx::LocationLogger::__broadcast(ctx::LocationEvent locationEvent) { _D(""); __locationCount++; - if (__listener) { + if (__listener) __listener->onNewLocation(locationEvent); - } - if (LOCATION_LOGGER_DATABASE) { + if (LOCATION_LOGGER_DATABASE) __dbInsertLog(locationEvent); - } } bool ctx::LocationLogger::onTimerExpired(int id) @@ -533,9 +530,8 @@ bool ctx::LocationLogger::onTimerExpired(int id) void ctx::LocationLogger::__activeRequestTimerStart() { int minutes = LOCATION_LOGGER_ACTIVE_REQUEST_TIMEOUT_SECONDS / 60; - if (LOCATION_LOGGER_ACTIVE_REQUEST_TIMEOUT_SECONDS % 60) { + if (LOCATION_LOGGER_ACTIVE_REQUEST_TIMEOUT_SECONDS % 60) minutes++; - } __timerPurpose = LOCATION_LOGGER_WAITING_FOR_ACTIVE_REQUEST; _D("LOCATION_LOGGER_WAITING_FOR_ACTIVE_REQUEST (minutes=%d)", minutes); __timerStart(minutes); diff --git a/src/my-place/user_places/place_categer.cpp b/src/my-place/user_places/place_categer.cpp index 09fc2e5..5ec32e4 100644 --- a/src/my-place/user_places/place_categer.cpp +++ b/src/my-place/user_places/place_categer.cpp @@ -35,9 +35,8 @@ void ctx::PlaceCateger::reduceOutliers(ctx::Visits &visits) }), visits.end()); int newSize = visits.size(); - if (size != newSize) { + if (size != newSize) _D("Visits number from %d to %d (visits min scores checking)", size, newSize); - } } /* @@ -73,9 +72,8 @@ void ctx::PlaceCateger::categorize(ctx::Visits &visits, ctx::Place &place) place.categId = categId; } } - if (sumScore > 0) { + if (sumScore > 0) place.categConfidence = maxScore / sumScore; - } if (__reduceCategory(place.categId, visits)) { place.categId = PLACE_CATEG_ID_OTHER; place.categConfidence = 0.0; @@ -90,9 +88,8 @@ std::vector ctx::PlaceCateger::categVectorFromVisits(const ctx::Visi std::vector vec; for (auto &visit : visits) { auto search = visit.categs.find(categId); - if (search != visit.categs.end()) { + if (search != visit.categs.end()) vec.push_back(search->second); - } } return vec; } diff --git a/src/my-place/user_places/places_detector.cpp b/src/my-place/user_places/places_detector.cpp index 95585d5..a85a557 100644 --- a/src/my-place/user_places/places_detector.cpp +++ b/src/my-place/user_places/places_detector.cpp @@ -211,9 +211,8 @@ void ctx::PlacesDetector::reduceOutliers(ctx::Visits &visits) }), visits.end()); int newSize = visits.size(); - if (size != newSize) { + if (size != newSize) _D("Visits number from %d to %d (to short and to long reduction)", size, newSize); - } } void ctx::PlacesDetector::__processVisits(ctx::Visits &visits) @@ -228,22 +227,18 @@ void ctx::PlacesDetector::__processVisits(ctx::Visits &visits) #endif /* TIZEN_ENGINEER_MODE */ for (std::shared_ptr component : *components) { // Small places outliers reduction - if (!__testMode && component->size() < PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE) { + if (!__testMode && component->size() < PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE) continue; - } - std::shared_ptr merged = std::make_shared(); for (graph::Node i : *component) { merged->push_back(visits[i]); } std::shared_ptr place = __placeFromMergedVisits(*merged); - if (place->categId == PLACE_CATEG_ID_NONE) { + if (place->categId == PLACE_CATEG_ID_NONE) continue; - } newDetectedPlaces.push_back(place); - if (!__testMode) { + if (!__testMode) __dbInsertPlace(*place); - } #ifdef TIZEN_ENGINEER_MODE { // TODO: Only for debug -> remove in final solution @@ -332,9 +327,8 @@ void ctx::PlacesDetector::reduceOutliers(std::shared_ptr }), cc->end()); int newSize = cc->size(); - if (size != newSize) { + if (size != newSize) _D("Connected components from %d to %d (min visit per place)", size, newSize); - } } std::shared_ptr ctx::PlacesDetector::__mergeVisits(const std::vector &visits) @@ -392,9 +386,8 @@ ctx::PlacesDetector::PlacesDetector(bool testMode): __testMode(testMode), __dbManager(testMode ? nullptr : new DatabaseManager()) { - if (testMode) { + if (testMode) return; - } __dbCreateTable(); std::vector records = __dbGetPlaces(); std::vector> dbPlaces = __placesFromJsons(records); diff --git a/src/my-place/user_places/similarity.h b/src/my-place/user_places/similarity.h index c38a23e..93054a8 100644 --- a/src/my-place/user_places/similarity.h +++ b/src/my-place/user_places/similarity.h @@ -25,14 +25,12 @@ namespace similarity { template ctx::share_t overlap1stOver2nd(const T &s1, const T &s2) { - if (s2.empty()) { + if (s2.empty()) return 0; - } int count = 0; for (auto e : s2) { - if (s1.find(e) != s1.end()) { + if (s1.find(e) != s1.end()) count++; - } } return (ctx::share_t) count / s2.size(); } @@ -49,9 +47,8 @@ namespace similarity { template bool isJoint(const T &s1, const T &s2) { for (auto e : s2) { - if (s1.find(e) != s1.end()) { + if (s1.find(e) != s1.end()) return true; - } } return false; } diff --git a/src/my-place/user_places/user_places.cpp b/src/my-place/user_places/user_places.cpp index ccc1e8a..e9b43d8 100755 --- a/src/my-place/user_places/user_places.cpp +++ b/src/my-place/user_places/user_places.cpp @@ -59,13 +59,10 @@ ctx::UserPlaces::~UserPlaces() _D("PlacesDetector timer removed"); } - if (__visitDetector) { + if (__visitDetector) delete __visitDetector; - } - - if (__placesDetector) { + if (__placesDetector) delete __placesDetector; - } }; std::vector> ctx::UserPlaces::__getPlaces() @@ -137,7 +134,6 @@ ctx::Json ctx::UserPlaces::__composeJson(std::vector> pla void ctx::UserPlaces::setMode(PlaceRecogMode energyMode) { - if (__visitDetector) { + if (__visitDetector) __visitDetector->setMode(energyMode); - } } diff --git a/src/my-place/user_places/user_places_types.cpp b/src/my-place/user_places/user_places_types.cpp index 7a9768d..f11a702 100644 --- a/src/my-place/user_places/user_places_types.cpp +++ b/src/my-place/user_places/user_places_types.cpp @@ -55,13 +55,11 @@ std::istream& ctx::operator>>(std::istream &input, ctx::Mac &mac) input >> std::hex; input >> h; mac.c[i] = h; - if (i + 1 >= ctx::Mac::MAC_SIZE) { + if (i + 1 >= ctx::Mac::MAC_SIZE) break; - } input >> colon; - if (colon != __MAC_STRING_COMPONENTS_SEPARATOR) { + if (colon != __MAC_STRING_COMPONENTS_SEPARATOR) throw std::runtime_error("Invalid MAC format"); - } } input >> std::dec; return input; @@ -74,9 +72,8 @@ std::ostream& ctx::operator<<(std::ostream &output, const ctx::Mac &mac) output << std::hex << std::setfill('0') << std::setw(2); output << static_cast(mac.c[i]); i++; - if (i >= Mac::MAC_SIZE) { + if (i >= Mac::MAC_SIZE) break; - } output << __MAC_STRING_COMPONENTS_SEPARATOR; } output << std::dec; @@ -93,9 +90,8 @@ ctx::Mac::operator std::string() const bool ctx::operator==(const Mac &m1, const Mac &m2) { for (size_t i = 0; i < Mac::MAC_SIZE; i++) { - if (m1.c[i] != m2.c[i]) { + if (m1.c[i] != m2.c[i]) return false; - } } return true; } @@ -111,12 +107,10 @@ bool ctx::operator<(const Mac &m1, const Mac &m2) for (size_t i = 0; i < Mac::MAC_SIZE; i++) { c1 = m1.c[i]; c2 = m2.c[i]; - if (c1 < c2) { + if (c1 < c2) return true; - } - if (c1 > c2) { + if (c1 > c2) return false; - } } return false; // they are equal } @@ -133,9 +127,8 @@ std::istream& ctx::operator>>(std::istream &input, ctx::MacSet &macSet) break; } macSet.insert(mac); - if (input.eof()) { + if (input.eof()) break; - } delimeter = input.get(); if (delimeter != __MAC_SET_STRING_DELIMITER) { input.unget(); @@ -244,7 +237,6 @@ std::shared_ptr ctx::macSetsUnion(const std::vector 4; @@ -322,9 +321,8 @@ int ctx::VisitCateger::weeksScope(const TimeFeatures &startF, const Interval &in int durationMinutes = (interval.end - interval.start) / 60; int scopeMinutes = startF.minutesSinceBeginingOfTheWeek + durationMinutes; int weeksScope = scopeMinutes / __MINUTES_IN_WEEK; - if (scopeMinutes % __MINUTES_IN_WEEK > 0) { + if (scopeMinutes % __MINUTES_IN_WEEK > 0) weeksScope++; - } return weeksScope; } @@ -335,16 +333,12 @@ ctx::num_t ctx::VisitCateger::__sum(const std::vector model, const size_t _E("'to' exceeds model size"); toSecure = model.size() - 1; } - - if (from > to) { + if (from > to) _E("'from' greater than 'to'"); - } - num_t result = 0.0; for (size_t i = from; i <= toSecure; i++) { result += model[i]; } - return result; } @@ -364,9 +358,8 @@ ctx::num_t ctx::VisitCateger::__weekModelMeanValue(PlaceCategId categ, const Int ret += __sum(prob_features::weekModel[categ], startIndex, endIndex); minutes += endIndex - startIndex + 1; } - if (minutes > 0) { + if (minutes > 0) return ret / minutes; - } return ret; } diff --git a/src/my-place/user_places/visit_detector.cpp b/src/my-place/user_places/visit_detector.cpp index 8cb287f..f10fed6 100644 --- a/src/my-place/user_places/visit_detector.cpp +++ b/src/my-place/user_places/visit_detector.cpp @@ -143,9 +143,8 @@ void ctx::VisitDetector::__detectEntranceOrDeparture(std::shared_ptr bool ctx::VisitDetector::__isDisjoint(const ctx::Macs2Counts &macs2Counts, const ctx::MacSet &macSet) { for (auto &mac : macSet) { - if (macs2Counts.find(mac) != macs2Counts.end()) { + if (macs2Counts.find(mac) != macs2Counts.end()) return false; - } } return true; } @@ -153,9 +152,8 @@ bool ctx::VisitDetector::__isDisjoint(const ctx::Macs2Counts &macs2Counts, const bool ctx::VisitDetector::__protrudesFrom(const ctx::Macs2Counts &macs2Counts, const ctx::MacSet &macSet) { for (auto &macCount : macs2Counts) { - if (macSet.find(macCount.first) == macSet.end()) { + if (macSet.find(macCount.first) == macSet.end()) return true; - } } return false; } @@ -256,9 +254,8 @@ void ctx::VisitDetector::__processBuffer(std::shared_ptr frame) __historyFrames.push_back(__bufferedFrames[0]); for (size_t i = 1; i < __bufferedFrames.size(); i++) { __detectEntrance(__bufferedFrames[i]); - if (__entranceToPlace) { + if (__entranceToPlace) break; - } } } } @@ -280,10 +277,8 @@ void ctx::VisitDetector::__detectEntrance(std::shared_ptr currentFra if (similarity::overlapBiggerOverSmaller(*currentBeacons, *__stayMacs) > VISIT_DETECTOR_OVERLAP) { __stableCounter++; __historyFrames.push_back(currentFrame); - - if (__stableCounter == VISIT_DETECTOR_STABLE_DEPTH) { // entrance detected + if (__stableCounter == VISIT_DETECTOR_STABLE_DEPTH) // entrance detected __visitStartDetected(); - } } else { __resetHistory(currentFrame); } @@ -328,9 +323,8 @@ ctx::share_t ctx::VisitDetector::__calcMaxShare(const ctx::Macs2Shares &macs2Sha { ctx::share_t maxShare = 0.0; for (auto &macShare : macs2Shares) { - if (macShare.second > maxShare) { + if (macShare.second > maxShare) maxShare = macShare.second; - } } return maxShare; } @@ -339,9 +333,8 @@ std::shared_ptr ctx::VisitDetector::__macSetOfGreaterOrEqualShare(c { std::shared_ptr macSet = std::make_shared(); for (auto &macShare : macs2Shares) { - if (macShare.second >= threshold) { + if (macShare.second >= threshold) macSet->insert(macShare.first); - } } return macSet; } @@ -442,7 +435,6 @@ void ctx::VisitDetector::setMode(PlaceRecogMode energyMode) { _D(""); __setPeriod(energyMode); - if (__wifiLogger) { + if (__wifiLogger) __wifiLogger->setMode(energyMode); - } } diff --git a/src/my-place/user_places/wifi_logger.cpp b/src/my-place/user_places/wifi_logger.cpp index 6a25112..6260bd1 100644 --- a/src/my-place/user_places/wifi_logger.cpp +++ b/src/my-place/user_places/wifi_logger.cpp @@ -82,16 +82,16 @@ ctx::WifiLogger::WifiLogger(IWifiListener * listener, PlaceRecogMode energyMode) __setInterval(energyMode); - if (WIFI_LOGGER_DATABASE) { + if (WIFI_LOGGER_DATABASE) __dbCreateTable(); - } __logs = std::vector(); __wifiSetDeviceStateChangedCbRequest(); - if (WIFI_LOGGER_LOW_POWER_MODE) { + + if (WIFI_LOGGER_LOW_POWER_MODE) __wifiSetConnectionStateChangedCbRequest(); - } + wifi_connection_state_e state = __wifiGetConnectionStateRequest(); __connectedToWifiAp = (state == WIFI_CONNECTION_STATE_CONNECTED); _D("__connectedToWifiAp = %d, __duringVisit = %d IN CONSTRUCTOR", @@ -111,15 +111,13 @@ void ctx::WifiLogger::__wifiDeviceStateChangedCb(wifi_device_state_e state, void switch (state) { case WIFI_DEVICE_STATE_DEACTIVATED: _D("WIFI setting OFF"); - if (wifiLogger->__started) { + if (wifiLogger->__started) wifiLogger->__stopLogging(); - } break; case WIFI_DEVICE_STATE_ACTIVATED: _D("WIFI setting ON"); - if (wifiLogger->__started) { + if (wifiLogger->__started) wifiLogger->__startLogging(); - } break; default: break; @@ -149,15 +147,13 @@ bool ctx::WifiLogger::__wifiFoundApCb(wifi_ap_h ap, void *userData) char *bssid = NULL; int ret = wifiLogger->__wifiApGetBssidRequest(ap, &bssid); - if (ret != WIFI_ERROR_NONE) { + if (ret != WIFI_ERROR_NONE) return false; - } char *essid = NULL; ret = wifiLogger->__wifiApGetEssidRequest(ap, &essid); - if (ret != WIFI_ERROR_NONE) { + if (ret != WIFI_ERROR_NONE) return false; - } Mac mac; try { @@ -176,9 +172,8 @@ bool ctx::WifiLogger::__wifiFoundApCb(wifi_ap_h ap, void *userData) wifiLogger->__lastScansPool.insert(std::string(bssid)); } } - if (WIFI_LOGGER_DATABASE) { + if (WIFI_LOGGER_DATABASE) wifiLogger->__logs.push_back(log); - } return true; } @@ -240,12 +235,10 @@ void ctx::WifiLogger::__wifiScanFinishedCb(wifi_error_e errorCode, void *userDat wifiLogger->__lastScanTime = now; int ret = wifiLogger->__wifiForeachFoundApsRequest(userData); - if (ret != WIFI_ERROR_NONE) { + if (ret != WIFI_ERROR_NONE) return; - } - if (WIFI_LOGGER_DATABASE) { + if (WIFI_LOGGER_DATABASE) wifiLogger->__dbInsertLogs(); - } } bool ctx::WifiLogger::__checkWifiIsActivated() @@ -341,14 +334,10 @@ bool ctx::WifiLogger::onTimerExpired(int id) { time_t now = time(nullptr); _D(""); - if (__checkTimerId(id) == false) { - // Incorrect callback call + if (__checkTimerId(id) == false) // Incorrect callback call return false; - } - if (__checkTimerTime(now) == false) { - // Prevention from double callback call bug + if (__checkTimerTime(now) == false) // Prevention from double callback call bug return __timerOn; - } _D("__connectedToWifiAp = %d, __duringVisit = %d, __lastScansPool.size() = %d", static_cast(__connectedToWifiAp), static_cast(__duringVisit), @@ -383,18 +372,16 @@ void ctx::WifiLogger::startLogging() void ctx::WifiLogger::__startLogging() { _D(""); - if (!__checkWifiIsActivated() || __running) { + if (!__checkWifiIsActivated() || __running) return; - } __running = true; if (WIFI_LOGGER_ACTIVE_SCANNING) { __timerStart(__intervalMinutes); __wifiScanRequest(); } - if (WIFI_LOGGER_PASSIVE_SCANNING) { + if (WIFI_LOGGER_PASSIVE_SCANNING) __wifiSetBackgroundScanCbRequest(); - } } void ctx::WifiLogger::stopLogging() @@ -407,18 +394,16 @@ void ctx::WifiLogger::stopLogging() void ctx::WifiLogger::__stopLogging() { _D(""); - if (!__running) { + if (!__running) return; - } if (WIFI_LOGGER_ACTIVE_SCANNING) { // Unset timer __timerOn = false; // Remove timer __timerManager.remove(__timerId); } - if (WIFI_LOGGER_PASSIVE_SCANNING) { + if (WIFI_LOGGER_PASSIVE_SCANNING) __wifiWrapper.unsetBackgroundScanCb(); - } __running = false; } @@ -466,7 +451,6 @@ void ctx::WifiLogger::setMode(PlaceRecogMode energyMode) { _D(""); __setInterval(energyMode); - if (WIFI_LOGGER_ACTIVE_SCANNING && __timerOn) { + if (WIFI_LOGGER_ACTIVE_SCANNING && __timerOn) __timerRestart(); - } } -- 2.34.1