From 7d1ae452dc6be259c59b2e8df61ee458c119ae90 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Thu, 16 Mar 2023 18:08:12 -0400 Subject: [PATCH] refactor a lot of iterator based C++ for loops into C++ range for loops; correct bad opcode value (this was getting truncated to $3F anyway so no big deal but in code it should be proper); --- dmr/Slot.cpp | 8 +++---- dmr/lookups/DMRAffiliationLookup.cpp | 28 +++++++++++----------- lookups/AffiliationLookup.cpp | 30 +++++++++++------------ lookups/IdenTableLookup.cpp | 5 ++-- lookups/RadioIdLookup.cpp | 6 ++--- lookups/TalkgroupIdLookup.cpp | 6 ++--- network/RemoteControl.cpp | 6 ++--- nxdn/Control.cpp | 8 +++---- p25/Control.cpp | 11 ++++----- p25/P25Defines.h | 2 +- p25/lookups/P25AffiliationLookup.cpp | 4 ++-- p25/packet/Data.cpp | 7 +++--- p25/packet/Trunk.cpp | 36 +++++++++++++--------------- 13 files changed, 72 insertions(+), 85 deletions(-) diff --git a/dmr/Slot.cpp b/dmr/Slot.cpp index 4904fc94..9493661d 100644 --- a/dmr/Slot.cpp +++ b/dmr/Slot.cpp @@ -674,17 +674,15 @@ void Slot::setSiteData(const std::vector voiceChNo, const std::unorder m_channelNo = channelNo; std::vector<::lookups::IdenTable> entries = m_idenTable->list(); - for (auto it = entries.begin(); it != entries.end(); ++it) { - ::lookups::IdenTable entry = *it; + for (auto entry : entries) { if (entry.channelId() == channelId) { m_idenEntry = entry; break; } } - std::vector availCh = voiceChNo; - for (auto it = availCh.begin(); it != availCh.end(); ++it) { - m_affiliations->addRFCh(*it); + for (uint32_t chNo : voiceChNo) { + m_affiliations->addRFCh(chNo); } m_affiliations->setRFChData(voiceChData); diff --git a/dmr/lookups/DMRAffiliationLookup.cpp b/dmr/lookups/DMRAffiliationLookup.cpp index 2e062fa6..cb2f7006 100644 --- a/dmr/lookups/DMRAffiliationLookup.cpp +++ b/dmr/lookups/DMRAffiliationLookup.cpp @@ -133,14 +133,14 @@ bool DMRAffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll) LogWarning(LOG_HOST, "%s, force releasing all channel grants", m_name); std::vector gntsToRel = std::vector(); - for (auto it = m_grantChTable.begin(); it != m_grantChTable.end(); ++it) { - uint32_t dstId = it->first; + for (auto entry : m_grantChTable) { + uint32_t dstId = entry.first; gntsToRel.push_back(dstId); } // release grants - for (auto it = gntsToRel.begin(); it != gntsToRel.end(); ++it) { - releaseGrant(*it, false); + for (uint32_t dstId : gntsToRel) { + releaseGrant(dstId, false); } return true; @@ -190,15 +190,15 @@ bool DMRAffiliationLookup::isChBusy(uint32_t chNo) const } // lookup dynamic channel grant table entry - for (auto it = m_grantChTable.begin(); it != m_grantChTable.end(); ++it) { - if (it->second == chNo) { + for (auto grantEntry : m_grantChTable) { + if (grantEntry.second == chNo) { uint8_t slotCount = 0U; if (chNo == m_tsccChNo) { slotCount++; // one slot is *always* used for TSCC } - for (auto it = m_grantChSlotTable.begin(); it != m_grantChSlotTable.end(); ++it) { - uint32_t foundChNo = std::get<0>(it->second); + for (auto slotEntry : m_grantChSlotTable) { + uint32_t foundChNo = std::get<0>(slotEntry.second); if (foundChNo == chNo) slotCount++; } @@ -226,9 +226,9 @@ uint8_t DMRAffiliationLookup::getGrantedSlot(uint32_t dstId) const } // lookup dynamic channel grant table entry - for (auto it = m_grantChSlotTable.begin(); it != m_grantChSlotTable.end(); ++it) { - if (it->first == dstId) { - uint8_t slot = std::get<1>(it->second); + for (auto entry : m_grantChSlotTable) { + if (entry.first == dstId) { + uint8_t slot = std::get<1>(entry.second); return slot; } } @@ -269,11 +269,11 @@ uint8_t DMRAffiliationLookup::getAvailableSlotForChannel(uint32_t chNo) const // lookup dynamic channel slot grant table entry bool grantedSlot = false; int slotCount = 0U; - for (auto it = m_grantChSlotTable.begin(); it != m_grantChSlotTable.end(); ++it) { - uint32_t foundChNo = std::get<0>(it->second); + for (auto entry : m_grantChSlotTable) { + uint32_t foundChNo = std::get<0>(entry.second); if (foundChNo == chNo) { - uint8_t foundSlot = std::get<1>(it->second); + uint8_t foundSlot = std::get<1>(entry.second); if (slot == foundSlot) { switch (foundSlot) { case 1U: diff --git a/lookups/AffiliationLookup.cpp b/lookups/AffiliationLookup.cpp index ae2dd09e..70a30e5d 100644 --- a/lookups/AffiliationLookup.cpp +++ b/lookups/AffiliationLookup.cpp @@ -215,16 +215,16 @@ std::vector AffiliationLookup::clearGroupAff(uint32_t dstId, bool rele if (dstId == 0U && releaseAll) { LogWarning(LOG_HOST, "%s, releasing all group affiliations", m_name); - for (auto it = m_grpAffTable.begin(); it != m_grpAffTable.end(); ++it) { - uint32_t srcId = it->first; + for (auto entry : m_grpAffTable) { + uint32_t srcId = entry.first; srcToRel.push_back(srcId); } } else { LogWarning(LOG_HOST, "%s, releasing group affiliations, dstId = %u", m_name, dstId); - for (auto it = m_grpAffTable.begin(); it != m_grpAffTable.end(); ++it) { - uint32_t srcId = it->first; - uint32_t grpId = it->second; + for (auto entry : m_grpAffTable) { + uint32_t srcId = entry.first; + uint32_t grpId = entry.second; if (grpId == dstId) { srcToRel.push_back(srcId); } @@ -300,14 +300,14 @@ bool AffiliationLookup::releaseGrant(uint32_t dstId, bool releaseAll) LogWarning(LOG_HOST, "%s, force releasing all channel grants", m_name); std::vector gntsToRel = std::vector(); - for (auto it = m_grantChTable.begin(); it != m_grantChTable.end(); ++it) { - uint32_t dstId = it->first; + for (auto entry : m_grantChTable) { + uint32_t dstId = entry.first; gntsToRel.push_back(dstId); } // release grants - for (auto it = gntsToRel.begin(); it != gntsToRel.end(); ++it) { - releaseGrant(*it, false); + for (uint32_t dstId : gntsToRel) { + releaseGrant(dstId, false); } return true; @@ -350,8 +350,8 @@ bool AffiliationLookup::isChBusy(uint32_t chNo) const } // lookup dynamic channel grant table entry - for (auto it = m_grantChTable.begin(); it != m_grantChTable.end(); ++it) { - if (it->second == chNo) { + for (auto entry : m_grantChTable) { + if (entry.second == chNo) { return true; } } @@ -431,8 +431,8 @@ void AffiliationLookup::clock(uint32_t ms) { // clock all the grant timers std::vector gntsToRel = std::vector(); - for (auto it = m_grantChTable.begin(); it != m_grantChTable.end(); ++it) { - uint32_t dstId = it->first; + for (auto entry : m_grantChTable) { + uint32_t dstId = entry.first; m_grantTimers[dstId].clock(ms); if (m_grantTimers[dstId].isRunning() && m_grantTimers[dstId].hasExpired()) { @@ -441,7 +441,7 @@ void AffiliationLookup::clock(uint32_t ms) } // release grants that have timed out - for (auto it = gntsToRel.begin(); it != gntsToRel.end(); ++it) { - releaseGrant(*it, false); + for (uint32_t dstId : gntsToRel) { + releaseGrant(dstId, false); } } diff --git a/lookups/IdenTableLookup.cpp b/lookups/IdenTableLookup.cpp index 114c07ce..0faf4903 100644 --- a/lookups/IdenTableLookup.cpp +++ b/lookups/IdenTableLookup.cpp @@ -98,9 +98,8 @@ std::vector IdenTableLookup::list() { std::vector list = std::vector(); if (m_table.size() > 0) { - for (auto it = m_table.begin(); it != m_table.end(); ++it) { - IdenTable entry = it->second; - list.push_back(entry); + for (auto entry : m_table) { + list.push_back(entry.second); } } diff --git a/lookups/RadioIdLookup.cpp b/lookups/RadioIdLookup.cpp index 7ea70ad5..132ce7c9 100644 --- a/lookups/RadioIdLookup.cpp +++ b/lookups/RadioIdLookup.cpp @@ -198,15 +198,15 @@ bool RadioIdLookup::load() std::vector parsed; char delim = ','; - for (auto it = line.begin(); it != line.end(); it++) { - if (*it == delim) { + for (char c : line) { + if (c == delim) { if (!next.empty()) { parsed.push_back(next); next.clear(); } } else - next += *it; + next += c; } if (!next.empty()) parsed.push_back(next); diff --git a/lookups/TalkgroupIdLookup.cpp b/lookups/TalkgroupIdLookup.cpp index 020aec19..8de5befd 100644 --- a/lookups/TalkgroupIdLookup.cpp +++ b/lookups/TalkgroupIdLookup.cpp @@ -161,15 +161,15 @@ bool TalkgroupIdLookup::load() std::vector parsed; char delim = ','; - for (auto it = line.begin(); it != line.end(); it++) { - if (*it == delim) { + for (char c : line) { + if (c == delim) { if (!next.empty()) { parsed.push_back(next); next.clear(); } } else - next += *it; + next += c; } if (!next.empty()) parsed.push_back(next); diff --git a/network/RemoteControl.cpp b/network/RemoteControl.cpp index 9a1d56d7..8bff252f 100644 --- a/network/RemoteControl.cpp +++ b/network/RemoteControl.cpp @@ -1107,9 +1107,9 @@ std::string RemoteControl::rcdGetVoiceCh(Host* host, dmr::Control* dmr, p25::Con std::string reply = ""; if (host->m_voiceChData.size() > 0) { - for (auto it = host->m_voiceChData.begin(); it != host->m_voiceChData.end(); ++it) { - uint32_t chNo = it->first; - lookups::VoiceChData data = it->second; + for (auto entry : host->m_voiceChData) { + uint32_t chNo = entry.first; + lookups::VoiceChData data = entry.second; reply += string_format("\r\n%u, %s:%u", chNo, data.address().c_str(), data.port()); } diff --git a/nxdn/Control.cpp b/nxdn/Control.cpp index 05e4393a..8b1f6c04 100644 --- a/nxdn/Control.cpp +++ b/nxdn/Control.cpp @@ -268,9 +268,8 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::stri m_siteData = SiteData(locId, channelId, channelNo, serviceClass, false); m_siteData.setCallsign(cwCallsign); - std::vector availCh = voiceChNo; - for (auto it = availCh.begin(); it != availCh.end(); ++it) { - m_affiliations.addRFCh(*it); + for (uint32_t ch : voiceChNo) { + m_affiliations.addRFCh(ch); } m_affiliations.setRFChData(voiceChData); @@ -279,8 +278,7 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::stri lc::RCCH::setCallsign(cwCallsign); std::vector entries = m_idenTable->list(); - for (auto it = entries.begin(); it != entries.end(); ++it) { - lookups::IdenTable entry = *it; + for (auto entry : entries) { if (entry.channelId() == channelId) { m_idenEntry = entry; break; diff --git a/p25/Control.cpp b/p25/Control.cpp index 553690fe..0d5080eb 100644 --- a/p25/Control.cpp +++ b/p25/Control.cpp @@ -304,19 +304,16 @@ void Control::setOptions(yaml::Node& conf, bool controlPermitTG, const std::stri lc::TSBK::setSiteData(m_siteData); std::vector<::lookups::IdenTable> entries = m_idenTable->list(); - for (auto it = entries.begin(); it != entries.end(); ++it) { - ::lookups::IdenTable entry = *it; + for (auto entry : entries) { if (entry.channelId() == channelId) { m_idenEntry = entry; break; } } - std::vector availCh = voiceChNo; - m_siteData.setChCnt((uint8_t)availCh.size()); - - for (auto it = availCh.begin(); it != availCh.end(); ++it) { - m_affiliations.addRFCh(*it); + m_siteData.setChCnt((uint8_t)voiceChNo.size()); + for (uint32_t ch : voiceChNo) { + m_affiliations.addRFCh(ch); } m_affiliations.setRFChData(voiceChData); diff --git a/p25/P25Defines.h b/p25/P25Defines.h index c5aca261..5406c6e2 100644 --- a/p25/P25Defines.h +++ b/p25/P25Defines.h @@ -354,7 +354,7 @@ namespace p25 const uint8_t TSBK_OSP_MOT_PSH_CCH = 0x0EU; // MOT PSH CCH - Motorola / Planned Control Channel Shutdown // TSBK Motorola Outbound Signalling Packet (OSP) Opcode(s) - const uint8_t TSBK_OSP_DVM_GIT_HASH = 0x7BU; // + const uint8_t TSBK_OSP_DVM_GIT_HASH = 0x3FU; // // Data Unit ID(s) const uint8_t P25_DUID_HDU = 0x00U; // Header Data Unit diff --git a/p25/lookups/P25AffiliationLookup.cpp b/p25/lookups/P25AffiliationLookup.cpp index c08cd3ea..520eeabd 100644 --- a/p25/lookups/P25AffiliationLookup.cpp +++ b/p25/lookups/P25AffiliationLookup.cpp @@ -88,8 +88,8 @@ std::vector P25AffiliationLookup::clearGroupAff(uint32_t dstId, bool r std::vector srcToRel = ::lookups::AffiliationLookup::clearGroupAff(dstId, releaseAll); if (srcToRel.size() > 0U) { // release affiliations - for (auto it = srcToRel.begin(); it != srcToRel.end(); ++it) { - m_p25->m_trunk->writeRF_TSDU_U_Dereg_Ack(*it); + for (uint32_t srcId : srcToRel) { + m_p25->m_trunk->writeRF_TSDU_U_Dereg_Ack(srcId); } } diff --git a/p25/packet/Data.cpp b/p25/packet/Data.cpp index da79654b..d71212b2 100644 --- a/p25/packet/Data.cpp +++ b/p25/packet/Data.cpp @@ -557,8 +557,8 @@ void Data::clock(uint32_t ms) { // clock all the connect timers std::vector connToClear = std::vector(); - for (auto it = m_connQueueTable.begin(); it != m_connQueueTable.end(); ++it) { - uint32_t llId = it->first; + for (auto entry : m_connQueueTable) { + uint32_t llId = entry.first; m_connTimerTable[llId].clock(ms); if (m_connTimerTable[llId].isRunning() && m_connTimerTable[llId].hasExpired()) { @@ -567,8 +567,7 @@ void Data::clock(uint32_t ms) } // handle PDU connection registration - for (auto it = connToClear.begin(); it != connToClear.end(); ++it) { - uint32_t llId = *it; + for (uint32_t llId : connToClear) { uint8_t mfId = std::get<0>(m_connQueueTable[llId]); uint64_t ipAddr = std::get<1>(m_connQueueTable[llId]); diff --git a/p25/packet/Trunk.cpp b/p25/packet/Trunk.cpp index 539b3b58..ab223bda 100644 --- a/p25/packet/Trunk.cpp +++ b/p25/packet/Trunk.cpp @@ -958,10 +958,9 @@ void Trunk::clock(uint32_t ms) m_adjSiteUpdateTimer.clock(ms); if (m_adjSiteUpdateTimer.isRunning() && m_adjSiteUpdateTimer.hasExpired()) { // update adjacent site data - for (auto it = m_adjSiteUpdateCnt.begin(); it != m_adjSiteUpdateCnt.end(); ++it) { - uint8_t siteId = it->first; - - uint8_t updateCnt = it->second; + for (auto& entry : m_adjSiteUpdateCnt) { + uint8_t siteId = entry.first; + uint8_t updateCnt = entry.second; if (updateCnt > 0U) { updateCnt--; } @@ -972,14 +971,13 @@ void Trunk::clock(uint32_t ms) siteData.sysId(), siteData.rfssId(), siteData.siteId(), siteData.channelId(), siteData.channelNo(), siteData.serviceClass()); } - m_adjSiteUpdateCnt[siteId] = updateCnt; + entry.second = updateCnt; } // update SCCB data - for (auto it = m_sccbUpdateCnt.begin(); it != m_sccbUpdateCnt.end(); ++it) { - uint8_t rfssId = it->first; - - uint8_t updateCnt = it->second; + for (auto& entry : m_sccbUpdateCnt) { + uint8_t rfssId = entry.first; + uint8_t updateCnt = entry.second; if (updateCnt > 0U) { updateCnt--; } @@ -990,7 +988,7 @@ void Trunk::clock(uint32_t ms) siteData.sysId(), siteData.rfssId(), siteData.siteId(), siteData.channelId(), siteData.channelNo(), siteData.serviceClass()); } - m_sccbUpdateCnt[rfssId] = updateCnt; + entry.second = updateCnt; } m_adjSiteUpdateTimer.setTimeout(m_adjSiteUpdateInterval); @@ -1858,15 +1856,15 @@ void Trunk::queueRF_TSBK_Ctrl(uint8_t lco) bool noData = false; uint8_t i = 0U; std::unordered_map grantTable = m_p25->m_affiliations.grantTable(); - for (auto it = grantTable.begin(); it != grantTable.end(); ++it) { + for (auto entry : grantTable) { // no good very bad way of skipping entries... if (i != m_mbfGrpGrntCnt) { i++; continue; } else { - uint32_t dstId = it->first; - uint32_t chNo = it->second; + uint32_t dstId = entry.first; + uint32_t chNo = entry.second; if (chNo == 0U) { noData = true; @@ -1906,15 +1904,13 @@ void Trunk::queueRF_TSBK_Ctrl(uint8_t lco) m_mbfIdenCnt = 0U; uint8_t i = 0U; - for (auto it = entries.begin(); it != entries.end(); ++it) { + for (auto entry : entries) { // no good very bad way of skipping entries... if (i != m_mbfIdenCnt) { i++; continue; } else { - ::lookups::IdenTable entry = *it; - // LogDebug(LOG_P25, "baseFrequency = %uHz, txOffsetMhz = %fMHz, chBandwidthKhz = %fKHz, chSpaceKhz = %fKHz", // entry.baseFrequency(), entry.txOffsetMhz(), entry.chBandwidthKhz(), entry.chSpaceKhz()); @@ -1969,14 +1965,14 @@ void Trunk::queueRF_TSBK_Ctrl(uint8_t lco) std::unique_ptr osp = new_unique(OSP_ADJ_STS_BCAST); uint8_t i = 0U; - for (auto it = m_adjSiteTable.begin(); it != m_adjSiteTable.end(); ++it) { + for (auto entry : m_adjSiteTable) { // no good very bad way of skipping entries... if (i != m_mbfAdjSSCnt) { i++; continue; } else { - SiteData site = it->second; + SiteData site = entry.second; uint8_t cfva = P25_CFVA_NETWORK; if (m_adjSiteUpdateCnt[site.siteId()] == 0U) { @@ -2018,14 +2014,14 @@ void Trunk::queueRF_TSBK_Ctrl(uint8_t lco) std::unique_ptr osp = new_unique(OSP_SCCB_EXP); uint8_t i = 0U; - for (auto it = m_sccbTable.begin(); it != m_sccbTable.end(); ++it) { + for (auto entry : m_sccbTable) { // no good very bad way of skipping entries... if (i != m_mbfSCCBCnt) { i++; continue; } else { - SiteData site = it->second; + SiteData site = entry.second; // transmit SCCB broadcast osp->setLCO(TSBK_OSP_SCCB_EXP);