Skip to content

Commit

Permalink
sprintf->fmt for NMPs
Browse files Browse the repository at this point in the history
  • Loading branch information
yakra committed Jun 6, 2024
1 parent 970b67c commit dade6dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions siteupdate/cplusplus/classes/Route/Route.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define FMT_HEADER_ONLY
#include "Route.h"
#include "../Args/Args.h"
#include "../ConnectedRoute/ConnectedRoute.h"
Expand All @@ -9,6 +10,7 @@
#include "../Region/Region.h"
#include "../Waypoint/Waypoint.h"
#include "../../functions/tmstring.h"
#include <fmt/format.h>
#include <sys/stat.h>

std::unordered_map<std::string, Route*> Route::root_hash, Route::pri_list_hash, Route::alt_list_hash;
Expand Down Expand Up @@ -180,9 +182,9 @@ void Route::write_nmp_merged()
for (std::string &a : w.alt_labels) wptfile << a << ' ';
if (w.near_miss_points.empty())
{ wptfile << "http://www.openstreetmap.org/?lat=";
sprintf(fstr, "%.6f", w.lat);
*fmt::format_to(fstr, "{:.6f}", w.lat) = 0;
wptfile << fstr << "&lon=";
sprintf(fstr, "%.6f", w.lng);
*fmt::format_to(fstr, "{:.6f}", w.lng) = 0;
wptfile << fstr << '\n';
}
else { // for now, arbitrarily choose the northernmost
Expand All @@ -195,9 +197,9 @@ void Route::write_nmp_merged()
if (other_w->lng > lng) lng = other_w->lng;
}
wptfile << "https://www.openstreetmap.org/?lat=";
sprintf(fstr, "%.6f", lat);
*fmt::format_to(fstr, "{:.6f}", lat) = 0;
wptfile << fstr << "&lon=";
sprintf(fstr, "%.6f", lng);
*fmt::format_to(fstr, "{:.6f}", lng) = 0;
wptfile << fstr << '\n';
w.near_miss_points.clear();
}
Expand Down
12 changes: 7 additions & 5 deletions siteupdate/cplusplus/classes/Waypoint/Waypoint.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define FMT_HEADER_ONLY
#include "Waypoint.h"
#include "../Datacheck/Datacheck.h"
#include "../DBFieldLength/DBFieldLength.h"
Expand All @@ -7,6 +8,7 @@
#include "../../templates/contains.cpp"
#include <cmath>
#include <cstring>
#include <fmt/format.h>
#define pi 3.141592653589793238

bool sort_root_at_label(Waypoint *w1, Waypoint *w2)
Expand Down Expand Up @@ -75,9 +77,9 @@ Waypoint::Waypoint(char *line, Route *rte)

std::string Waypoint::str()
{ std::string ans = route->root + " " + label + " (";
char s[51]; int
e=sprintf(s,"%.15g",lat); if (lat==int(lat)) strcpy(s+e,".0"); ans+=s; ans+=',';
e=sprintf(s,"%.15g",lng); if (lng==int(lng)) strcpy(s+e,".0"); ans+=s;
char s[51];
*fmt::format_to(s,"{:.15}",lat)=0; ans+=s; if (lat==int(lat)) ans+=".0"; ans+=',';
*fmt::format_to(s,"{:.15}",lng)=0; ans+=s; if (lng==int(lng)) ans+=".0";
return ans + ')';
}

Expand Down Expand Up @@ -200,8 +202,8 @@ void Waypoint::nmplogs(std::unordered_set<std::string> &nmpfps, std::ofstream &n
// both ways (other_w in w's list, w in other_w's list)
if (sort_root_at_label(this, other_w))
{ char s[51];
#define PYTHON_STYLE_FLOAT(F) e=sprintf(s," %.15g",F); if (F==int(F)) strcpy(s+e,".0"); nmpnmp<<s;
nmpnmp << root_at_label(); int
#define PYTHON_STYLE_FLOAT(F) *fmt::format_to(s," {:.15}",F)=0; nmpnmp<<s; if (F==int(F)) nmpnmp<<".0";
nmpnmp << root_at_label();
PYTHON_STYLE_FLOAT(lat)
PYTHON_STYLE_FLOAT(lng)
if (fp || li)
Expand Down

0 comments on commit dade6dd

Please sign in to comment.