From 0ffcebabff966f39bc7c21dd32c3ce59fd2ce82e Mon Sep 17 00:00:00 2001 From: eric bryant Date: Tue, 13 Jan 2026 08:31:59 -0500 Subject: [PATCH] errorcheck for 0 valid csv lines interactive rebase 81d48f7 --- .../classes/ConnectedRoute/ConnectedRoute.cpp | 2 +- .../classes/HighwaySystem/HighwaySystem.cpp | 41 ++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp b/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp index 61fc415..834cb86 100644 --- a/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp +++ b/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp @@ -9,7 +9,7 @@ ConnectedRoute::ConnectedRoute(std::string &line, HighwaySystem *sys, ErrorList { mileage = 0; disconnected = 0; - // parse chopped routes csv line + // parse connected routes csv line system = sys; size_t NumFields = 5; std::string sys_str, roots_str; diff --git a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp index 2ebfd47..a2cb54b 100644 --- a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp +++ b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp @@ -73,6 +73,7 @@ HighwaySystem::HighwaySystem(std::string &line, ErrorList &el) std::cout /*<< systemname*/ << '.' << std::flush; // read chopped routes CSV + size_t chopped_lines = 1; file.open(Args::datapath+"/data/_systems/"+systemname+".csv"); if (!file) el.add_error("Could not open "+Args::datapath+"/data/_systems/"+systemname+".csv"); else { getline(file, line); // ignore header line @@ -82,14 +83,17 @@ HighwaySystem::HighwaySystem(std::string &line, ErrorList &el) while ( line.size() && strchr("\r\t ", line.back()) ) line.pop_back(); if (line.size()) lines.emplace_back(std::move(line)); } - Route* r = routes.alloc(lines.size()); - for (std::string& l : lines) - try { new(r) Route(l, this, el); - // placement new - r->region->routes.push_back(r); - r++; - } - catch (const int) {--routes.size;} + if ( (chopped_lines = lines.size()) ) + { Route* r = routes.alloc(lines.size()); + for (std::string& l : lines) + try { new(r) Route(l, this, el); + // placement new + r->region->routes.push_back(r); + r++; + } + catch (const int) {--routes.size;} + } + else el.add_error("0 valid lines in "+systemname+".csv"); } file.close(); @@ -103,15 +107,22 @@ HighwaySystem::HighwaySystem(std::string &line, ErrorList &el) while ( line.size() && strchr("\r\t ", line.back()) ) line.pop_back(); if (line.size()) lines.emplace_back(std::move(line)); } - ConnectedRoute* cr = con_routes.alloc(lines.size()); - for (std::string& l : lines) - try { new(cr) ConnectedRoute(l, this, el); - // placement new - cr++; - } - catch (const int) {--con_routes.size;} + if (lines.size()) + { ConnectedRoute* cr = con_routes.alloc(lines.size()); + for (std::string& l : lines) + try { new(cr) ConnectedRoute(l, this, el); + // placement new + cr++; + } + catch (const int) {--con_routes.size;} + } + else { el.add_error("0 valid lines in "+systemname+"_con.csv"); + throw 0xc0c57; + } } file.close(); + + if (!chopped_lines) throw 0xc57;; } void HighwaySystem::systems_csv(ErrorList& el)