uint32_t FeaturesLayerMatcher::GetMatchingStreetImpl(uint32_t houseId, FeatureType & houseFeature) { // Check if this feature is modified - the logic will be different. string streetName; bool const edited = osm::Editor::Instance().GetEditedFeatureStreet(houseFeature.GetID(), streetName); // Check the cached result value. auto entry = m_matchingStreetsCache.Get(houseId); if (!edited && !entry.second) return entry.first; // Load feature if needed. if (!houseFeature.GetID().IsValid()) GetByIndex(houseId, houseFeature); // Get nearby streets and calculate the resulting index. auto const & streets = GetNearbyStreets(houseId, houseFeature); uint32_t & result = entry.first; result = kInvalidId; if (edited) { auto const ret = find_if(streets.begin(), streets.end(), [&streetName](TStreet const & st) { return st.m_name == streetName; }); if (ret != streets.end()) result = ret->m_id.m_index; } else { uint32_t index; if (m_context->GetStreetIndex(houseId, index) && index < streets.size()) result = streets[index].m_id.m_index; } // If there is no saved street for feature, assume that it's a nearest street if it's too close. if (result == kInvalidId && !streets.empty() && streets[0].m_distanceMeters < kMaxApproxStreetDistanceM) { result = streets[0].m_id.m_index; } return result; }
FeaturesLayerMatcher::TStreets const & FeaturesLayerMatcher::GetNearbyStreetsImpl( uint32_t featureId, FeatureType & feature) { auto entry = m_nearbyStreetsCache.Get(featureId); if (!entry.second) return entry.first; if (!feature.GetID().IsValid()) GetByIndex(featureId, feature); auto & streets = entry.first; m_reverseGeocoder.GetNearbyStreets(feature, streets); for (size_t i = 0; i < streets.size(); ++i) { if (streets[i].m_distanceMeters > ReverseGeocoder::kLookupRadiusM) { streets.resize(i); break; } } return streets; }
bool CPVRChannelGroupInternal::UpdateGroupEntries(const CPVRChannelGroup &channels) { bool bChanged = false; int iCurSize = size(); CPVRChannelGroup *newChannels = new CPVRChannelGroup(m_bRadio); CPVRDatabase *database = g_PVRManager.GetTVDatabase(); if (!database || !database->Open()) return bChanged; /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { const CPVRChannel *channel = channels.at(iChannelPtr).channel; /* check if this channel is present in this container */ CPVRChannel *existingChannel = (CPVRChannel *) GetByClient(channel->UniqueID(), channel->ClientID()); if (existingChannel) { /* if it's present, update the current tag */ if (existingChannel->UpdateFromClient(*channel)) { bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } } else { /* new channel */ CPVRChannel *newChannel = new CPVRChannel(m_bRadio); newChannel->SetUniqueID(channel->UniqueID(), false); newChannel->UpdateFromClient(*channel); newChannels->AddToGroup(newChannel); int iChannelNumber = iCurSize == 0 ? channel->ClientChannelNumber() : 0; InsertInGroup(newChannel, iChannelNumber, false); bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - added %s channel '%s' at position %d", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), iChannelNumber); } } /* persist changes */ for (unsigned int iChannelPtr = 0; iChannelPtr < newChannels->size(); iChannelPtr++) ((CPVRChannel *) newChannels->GetByIndex(iChannelPtr))->Persist(false); /* write immediately to get a db id */ delete newChannels; /* check for deleted channels */ unsigned int iSize = size(); for (unsigned int iChannelPtr = 0; iChannelPtr < iSize; iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) GetByIndex(iChannelPtr); if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - deleted %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); /* remove this channel from all non-system groups */ ((CPVRChannelGroups *) g_PVRChannelGroups->Get(m_bRadio))->RemoveFromAllGroups(channel); delete at(iChannelPtr).channel; erase(begin() + iChannelPtr); iChannelPtr--; iSize--; bChanged = true; } } database->Close(); /* try to find channel icons */ SearchAndSetChannelIcons(); CacheIcons(); if (bChanged || HasChanges()) { /* remove invalid channels */ RemoveInvalidChannels(); /* sort by client channel number if this is the first time */ if (iCurSize == 0) SortByClientChannelNumber(); /* renumber to make sure all channels have a channel number. new channels were added at the back, so they'll get the highest numbers */ Renumber(); return Persist(); } else { return true; } }
const CCountryFlags::CCountryFlag *CCountryFlags::GetByCountryCode(int CountryCode) const { return GetByIndex(m_CodeIndexLUT[max(0, (CountryCode-CODE_LB)%CODE_RANGE)]-1); }
bool CPVRChannelGroup::UpdateGroupEntries(const CPVRChannelGroup &channels) { bool bChanged(false); CSingleLock lock(m_critSection); int iCurSize = size(); CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) return false; /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { CPVRChannel *channel = channels.at(iChannelPtr).channel; int iChannelNumber = channels.at(iChannelPtr).iChannelNumber; if (!channel) continue; CPVRChannel *realChannel = (CPVRChannel *) CPVRManager::GetChannelGroups()->GetGroupAll(m_bRadio)->GetByClient(channel->UniqueID(), channel->ClientID()); if (!realChannel) continue; if (!IsGroupMember(realChannel)) { AddToGroup(realChannel, iChannelNumber, false); bChanged = true; m_bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroup - %s - added %s channel '%s' at position %d in group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", realChannel->ChannelName().c_str(), iChannelNumber, GroupName().c_str()); } } /* check for deleted channels */ unsigned int iSize = size(); for (unsigned int iChannelPtr = 0; iChannelPtr < iSize; iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) GetByIndex(iChannelPtr); if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroup - %s - deleted %s channel '%s' from group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), GroupName().c_str()); /* remove this channel from all non-system groups */ RemoveFromGroup(channel); m_bChanged = true; bChanged = true; iChannelPtr--; iSize--; } } if (bChanged) { /* sort by client channel number if this is the first time */ if (iCurSize == 0) SortByClientChannelNumber(); /* renumber to make sure all channels have a channel number. new channels were added at the back, so they'll get the highest numbers */ Renumber(); return Persist(); } return true; }
const CCertStoreEntry& CCertStoreEntryList::GetByHandleL(TInt aHandle) const { TInt index = IndexForHandle(aHandle); User::LeaveIfError(index); return GetByIndex(index); }