From 1456810fa9e3b1e470408a3cb5d3436edc570a09 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Mon, 8 Nov 2021 20:16:31 +0000 Subject: [PATCH] Make FCS rooms numbering dynamic. --- YSFGateway/Version.h | 2 +- YSFGateway/YSFReflectors.cpp | 29 ++++++++++++++++++++++++----- YSFGateway/YSFReflectors.h | 4 +++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/YSFGateway/Version.h b/YSFGateway/Version.h index d7e0172..f2554c5 100644 --- a/YSFGateway/Version.h +++ b/YSFGateway/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20210922"; +const char* VERSION = "20211108"; #endif diff --git a/YSFGateway/YSFReflectors.cpp b/YSFGateway/YSFReflectors.cpp index 25cad3f..129b20c 100644 --- a/YSFGateway/YSFReflectors.cpp +++ b/YSFGateway/YSFReflectors.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016-2020 by Jonathan Naylor G4KLX +* Copyright (C) 2016-2021 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -252,13 +252,19 @@ bool CYSFReflectors::load() } } - unsigned int id = 10U; - for (std::vector>::const_iterator it = m_fcsRooms.cbegin(); it != m_fcsRooms.cend(); ++it, id++) { + unsigned int id = 9U; + for (std::vector>::const_iterator it1 = m_fcsRooms.cbegin(); it1 != m_fcsRooms.cend(); ++it1) { + bool used; + do { + id++; + used = findById(id); + } while (used); + char text[10U]; ::sprintf(text, "%05u", id); - std::string name = it->first; - std::string desc = it->second; + std::string name = it1->first; + std::string desc = it1->second; CYSFReflector* refl = new CYSFReflector; refl->m_id = text; @@ -303,6 +309,19 @@ CYSFReflector* CYSFReflectors::findById(const std::string& id) return NULL; } +bool CYSFReflectors::findById(unsigned int id) const +{ + char text[10U]; + ::sprintf(text, "%05u", id); + + for (std::vector::const_iterator it = m_newReflectors.cbegin(); it != m_newReflectors.cend(); ++it) { + if (text == (*it)->m_id) + return true; + } + + return false; +} + CYSFReflector* CYSFReflectors::findByName(const std::string& name) { std::string fullName = name; diff --git a/YSFGateway/YSFReflectors.h b/YSFGateway/YSFReflectors.h index f4dcf51..00c8184 100644 --- a/YSFGateway/YSFReflectors.h +++ b/YSFGateway/YSFReflectors.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2016-2020 by Jonathan Naylor G4KLX +* Copyright (C) 2016-2021 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -94,6 +94,8 @@ private: std::vector m_search; bool m_makeUpper; CTimer m_timer; + + bool findById(unsigned int id) const; }; #endif