From a4ea0f76663939479f73d39f21f4f3bfdefeb379 Mon Sep 17 00:00:00 2001 From: eric bryant Date: Sun, 1 Feb 2026 00:37:56 -0500 Subject: [PATCH] error check for duplicate graph names --- .../classes/GraphGeneration/GraphListEntry.cpp | 14 +++++++++++++- .../classes/GraphGeneration/GraphListEntry.h | 7 +++++-- siteupdate/cplusplus/tasks/graph_setup.cpp | 2 +- siteupdate/cplusplus/tasks/subgraphs/area.cpp | 2 +- siteupdate/cplusplus/tasks/subgraphs/continent.cpp | 2 +- siteupdate/cplusplus/tasks/subgraphs/country.cpp | 2 +- .../cplusplus/tasks/subgraphs/fullcustom.cpp | 2 +- .../cplusplus/tasks/subgraphs/multiregion.cpp | 2 +- .../cplusplus/tasks/subgraphs/multisystem.cpp | 2 +- siteupdate/cplusplus/tasks/subgraphs/region.cpp | 2 +- siteupdate/cplusplus/tasks/subgraphs/system.cpp | 2 +- 11 files changed, 27 insertions(+), 12 deletions(-) diff --git a/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp b/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp index e913e81a..ccd17989 100644 --- a/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp +++ b/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.cpp @@ -1,21 +1,33 @@ #define FMT_HEADER_ONLY #include "GraphListEntry.h" #include "PlaceRadius.h" +#include "../ErrorList/ErrorList.h" #include "../HighwaySystem/HighwaySystem.h" #include "../Region/Region.h" #include std::vector GraphListEntry::entries; size_t GraphListEntry::num; // iterator for entries +std::unordered_map GraphListEntry::unique_names; GraphListEntry::GraphListEntry(std::string r, std::string d, char f, char c, std::vector *rg, std::vector *sys, PlaceRadius *pr): regions(rg), systems(sys), placeradius(pr), root(r), descr(d), form(f), cat(c) {} -void GraphListEntry::add_group(std::string&& r, std::string&& d, char c, std::vector *rg, std::vector *sys, PlaceRadius *pr) +void GraphListEntry::add_group(std::string&& r, std::string&& d, char c, std::vector *rg, std::vector *sys, PlaceRadius *pr, ErrorList& el) { GraphListEntry::entries.emplace_back(r, d, 's', c, rg, sys, pr); GraphListEntry::entries.emplace_back(r, d, 'c', c, rg, sys, pr); GraphListEntry::entries.emplace_back(r, d, 't', c, rg, sys, pr); + GraphListEntry* this_one = &GraphListEntry::entries.back(); + auto ib = unique_names.emplace(r, this_one); + if (!ib.second) + { GraphListEntry* that_one = ib.first->second; + std::string err = "Duplicate graph name " + r + " in " + that_one->category(); + if (this_one->cat != that_one->cat) + err += " and " + this_one->category(); + err += " graphs"; + el.add_error(err); + } } std::string GraphListEntry::filename() diff --git a/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.h b/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.h index e734d32c..28bd3de2 100644 --- a/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.h +++ b/siteupdate/cplusplus/classes/GraphGeneration/GraphListEntry.h @@ -1,7 +1,9 @@ +class ErrorList; class HighwaySystem; class PlaceRadius; class Region; #include +#include #include class GraphListEntry @@ -26,8 +28,9 @@ class GraphListEntry static std::vector entries; static size_t num; // iterator for entries - std::string tag(); + static std::unordered_map unique_names; GraphListEntry(std::string, std::string, char, char, std::vector*, std::vector*, PlaceRadius*); - static void add_group(std::string&&, std::string&&, char, std::vector*, std::vector*, PlaceRadius*); + static void add_group(std::string&&, std::string&&, char, std::vector*, std::vector*, PlaceRadius*, ErrorList&); + std::string tag(); }; diff --git a/siteupdate/cplusplus/tasks/graph_setup.cpp b/siteupdate/cplusplus/tasks/graph_setup.cpp index 9c0882dc..ea6458ce 100644 --- a/siteupdate/cplusplus/tasks/graph_setup.cpp +++ b/siteupdate/cplusplus/tasks/graph_setup.cpp @@ -3,7 +3,7 @@ vector *systems; list> graph_types; // create list of graph information for the DB graph_types.push_back({"master", "All Travel Mapping Data", "These graphs contain all routes currently plotted in the Travel Mapping project."}); -GraphListEntry::add_group("tm-master", "All Travel Mapping Data", 'M', nullptr, nullptr, nullptr); +GraphListEntry::add_group("tm-master", "All Travel Mapping Data", 'M', nullptr, nullptr, nullptr, el); #include "subgraphs/continent.cpp" #include "subgraphs/multisystem.cpp" #include "subgraphs/system.cpp" diff --git a/siteupdate/cplusplus/tasks/subgraphs/area.cpp b/siteupdate/cplusplus/tasks/subgraphs/area.cpp index dee75c8f..d4c6eb73 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/area.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/area.cpp @@ -36,7 +36,7 @@ while (getline(file, line)) GraphListEntry::add_group( string(fields[1]) + fields[4] + "-area", string(fields[0]) + " (" + fields[4] + " mi radius)", - 'a', nullptr, nullptr, a); + 'a', nullptr, nullptr, a, el); delete[] cline; } file.close(); diff --git a/siteupdate/cplusplus/tasks/subgraphs/continent.cpp b/siteupdate/cplusplus/tasks/subgraphs/continent.cpp index 1558f432..439e6fd8 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/continent.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/continent.cpp @@ -11,7 +11,7 @@ for (auto c = Region::continents.data(), dummy = c+Region::continents.size()-1; else { GraphListEntry::add_group( c->first + "-continent", c->second + " All Routes on Continent", - 'C', regions, nullptr, nullptr); + 'C', regions, nullptr, nullptr, el); } } graph_types.push_back({"continent", "Routes Within a Continent", "These graphs contain the routes on a continent."}); diff --git a/siteupdate/cplusplus/tasks/subgraphs/country.cpp b/siteupdate/cplusplus/tasks/subgraphs/country.cpp index 4a628e5c..32e4ce50 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/country.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/country.cpp @@ -11,7 +11,7 @@ for (auto c = Region::countries.data(), dummy = c+Region::countries.size()-1; c else { GraphListEntry::add_group( c->first + "-country", c->second + " All Routes in Country", - 'c', regions, nullptr, nullptr); + 'c', regions, nullptr, nullptr, el); } } graph_types.push_back({"country", "Routes Within a Single Multi-Region Country", diff --git a/siteupdate/cplusplus/tasks/subgraphs/fullcustom.cpp b/siteupdate/cplusplus/tasks/subgraphs/fullcustom.cpp index c0c2e611..da5d0da8 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/fullcustom.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/fullcustom.cpp @@ -84,7 +84,7 @@ if (file.is_open()) } delete[] field; } - if (ok) GraphListEntry::add_group(std::move(root), std::move(descr), 'f', regions, systems, a); + if (ok) GraphListEntry::add_group(std::move(root), std::move(descr), 'f', regions, systems, a, el); else { delete regions; delete systems; delete a; diff --git a/siteupdate/cplusplus/tasks/subgraphs/multiregion.cpp b/siteupdate/cplusplus/tasks/subgraphs/multiregion.cpp index 4d879f39..7ef6e401 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/multiregion.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/multiregion.cpp @@ -29,7 +29,7 @@ while (getline(file, line)) catch (const out_of_range&) { el.add_error("unrecognized region code "+string(rg)+" in multiregion.csv line: "+line); } - if (regions->size()) GraphListEntry::add_group(fields[1], fields[0], 'R', regions, nullptr, nullptr); + if (regions->size()) GraphListEntry::add_group(fields[1], fields[0], 'R', regions, nullptr, nullptr, el); else delete regions; delete[] cline; } diff --git a/siteupdate/cplusplus/tasks/subgraphs/multisystem.cpp b/siteupdate/cplusplus/tasks/subgraphs/multisystem.cpp index 563547f0..7cdd1a5d 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/multisystem.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/multisystem.cpp @@ -33,7 +33,7 @@ while (getline(file, line)) catch (const std::out_of_range&) { el.add_error("unrecognized system code "+string(s)+" in multisystem.csv line: "+line); } - if (systems->size()) GraphListEntry::add_group(fields[1], fields[0], 'S', nullptr, systems, nullptr); + if (systems->size()) GraphListEntry::add_group(fields[1], fields[0], 'S', nullptr, systems, nullptr, el); else delete systems; delete[] cline; } diff --git a/siteupdate/cplusplus/tasks/subgraphs/region.cpp b/siteupdate/cplusplus/tasks/subgraphs/region.cpp index 4be89712..ffbf79f7 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/region.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/region.cpp @@ -4,7 +4,7 @@ for (Region& region : Region::allregions) GraphListEntry::add_group( region.code + "-region", region.name + " (" + region.type + ")", 'r', - new vector(1, ®ion), nullptr, nullptr); + new vector(1, ®ion), nullptr, nullptr, el); // deleted @ end of HighwayGraph::write_subgraphs_tmg } graph_types.push_back({"region", "Routes Within a Single Region", "These graphs contain all routes currently plotted within the given region."}); diff --git a/siteupdate/cplusplus/tasks/subgraphs/system.cpp b/siteupdate/cplusplus/tasks/subgraphs/system.cpp index 164f7538..8f1003b9 100644 --- a/siteupdate/cplusplus/tasks/subgraphs/system.cpp +++ b/siteupdate/cplusplus/tasks/subgraphs/system.cpp @@ -8,7 +8,7 @@ while (getline(file, line)) { GraphListEntry::add_group( h->systemname + "-system", h->systemname + " (" + h->fullname + ")", - 's', nullptr, new vector(1, h), nullptr); + 's', nullptr, new vector(1, h), nullptr, el); // deleted @ end of HighwayGraph::write_subgraphs_tmg h->is_subgraph_system = 1; } else el.add_error("devel system "+h->systemname+" in systemgraphs.csv");