Skip to content

Commit 4f291b5

Browse files
committed
Use anonymous namespaces for internal linkage
1 parent c4c41fd commit 4f291b5

7 files changed

+38
-6
lines changed

Diff for: src/coastline_polygons.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class OGRSpatialReference;
3636
extern SRS srs;
3737
extern bool debug;
3838

39-
static std::unique_ptr<OGRPolygon> create_rectangular_polygon(double x1, double y1, double x2, double y2, double expand) {
39+
namespace {
40+
41+
std::unique_ptr<OGRPolygon> create_rectangular_polygon(double x1, double y1, double x2, double y2, double expand) {
4042
OGREnvelope e;
4143

4244
e.MinX = x1 - expand;
@@ -61,7 +63,7 @@ static std::unique_ptr<OGRPolygon> create_rectangular_polygon(double x1, double
6163
return polygon;
6264
}
6365

64-
static bool add_segment_to_line(OGRLineString* line, OGRPoint* point1, OGRPoint* point2) {
66+
bool add_segment_to_line(OGRLineString* line, OGRPoint* point1, OGRPoint* point2) {
6567
// segments along southern edge of the map are not added to line output
6668
if (point1->getY() < srs.min_y() && point2->getY() < srs.min_y()) {
6769
if (debug) {
@@ -86,6 +88,8 @@ static bool add_segment_to_line(OGRLineString* line, OGRPoint* point1, OGRPoint*
8688
return true;
8789
}
8890

91+
} // anonymous namespace
92+
8993
unsigned int CoastlinePolygons::fix_direction() {
9094
unsigned int warnings = 0;
9195

Diff for: src/coastline_ring_collection.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ unsigned int CoastlineRingCollection::check_locations(bool output_missing) {
129129
return missing_locations;
130130
}
131131

132+
namespace {
133+
132134
bool is_valid_polygon(const OGRGeometry* geometry) {
133135
if (geometry && geometry->getGeometryType() == wkbPolygon && !geometry->IsEmpty()) {
134136
const auto *const polygon = static_cast<const OGRPolygon*>(geometry);
@@ -137,6 +139,8 @@ bool is_valid_polygon(const OGRGeometry* geometry) {
137139
return false;
138140
}
139141

142+
} // anonymous namespace
143+
140144
std::vector<OGRGeometry*> CoastlineRingCollection::add_polygons_to_vector() {
141145
std::vector<OGRGeometry*> vector;
142146
vector.reserve(m_list.size());
@@ -189,6 +193,8 @@ unsigned int CoastlineRingCollection::output_rings(OutputDatabase& output) {
189193
return warnings;
190194
}
191195

196+
namespace {
197+
192198
osmium::Location intersection(const osmium::Segment& s1, const osmium::Segment&s2) {
193199
if (s1.first() == s2.first() ||
194200
s1.first() == s2.second() ||
@@ -242,6 +248,8 @@ std::unique_ptr<OGRLineString> create_ogr_linestring(const osmium::Segment& segm
242248
return line;
243249
}
244250

251+
} // anonymous namespace
252+
245253
/**
246254
* Checks if there are intersections between any coastline segments.
247255
* Returns the number of intersections and overlaps.

Diff for: src/nodegrid2opl.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656

5757
const int id_offset = 100;
5858

59-
static bool add_node(std::vector<std::string>& nodes, char c, double x, double y) {
59+
namespace {
60+
61+
bool add_node(std::vector<std::string>& nodes, char c, double x, double y) {
6062
static std::set<int> ids;
6163
int id = id_offset;
6264

@@ -76,6 +78,8 @@ static bool add_node(std::vector<std::string>& nodes, char c, double x, double y
7678
return true;
7779
}
7880

81+
} // anonymous namespace
82+
7983
int main() {
8084
const double scale = 0.01;
8185
const double offset = 1;

Diff for: src/options.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
#include <osmium/io/pbf.hpp>
3737

38-
static void print_help() {
38+
namespace {
39+
40+
void print_help() {
3941
std::cout << "Usage: osmcoastline [OPTIONS] OSMFILE\n"
4042
<< "\nOptions:\n"
4143
<< " -h, --help - This help message\n"
@@ -61,7 +63,7 @@ static void print_help() {
6163
<< "\n";
6264
}
6365

64-
static void print_version() {
66+
void print_version() {
6567
std::cout << "osmcoastline " << get_osmcoastline_long_version() << "\n"
6668
<< get_libosmium_version() << '\n'
6769
<< "Supported PBF compression types:";
@@ -79,7 +81,7 @@ static void print_version() {
7981
* of specifying WGS84 or the "Web Mercator" SRS. More are currently
8082
* not supported.
8183
*/
82-
static int get_epsg(const char* text) {
84+
int get_epsg(const char* text) {
8385
if (!strcasecmp(text, "WGS84") || !std::strcmp(text, "4326")) {
8486
return 4326;
8587
}
@@ -94,6 +96,8 @@ static int get_epsg(const char* text) {
9496
std::exit(return_code_cmdline);
9597
}
9698

99+
} // anonymous namespace
100+
97101
int Options::parse(int argc, char* argv[]) {
98102
static struct option long_options[] = {
99103
{"bbox-overlap", required_argument, nullptr, 'b'},

Diff for: src/osmcoastline.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ SRS srs;
6464
// Global debug marker
6565
bool debug;
6666

67+
namespace {
68+
6769
// If there are more than this many warnings, the program exit code will indicate an error.
6870
const unsigned int max_warnings = 500;
6971

@@ -166,6 +168,8 @@ std::unique_ptr<OutputDatabase> open_output_database(const std::string& driver,
166168
return nullptr;
167169
}
168170

171+
} // anonymous namespace
172+
169173
/* ================================================== */
170174

171175
int main(int argc, char *argv[]) {

Diff for: src/osmcoastline_filter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
#include <string>
4747
#include <vector>
4848

49+
namespace {
50+
4951
void print_help() {
5052
std::cout << "Usage: osmcoastline_filter [OPTIONS] OSMFILE\n"
5153
<< "\nOptions:\n"
@@ -57,6 +59,8 @@ void print_help() {
5759
<< "\n";
5860
}
5961

62+
} // anonymous namespace
63+
6064
int main(int argc, char* argv[]) {
6165
std::string output_filename;
6266
std::string output_file_format{"pbf"};

Diff for: src/osmcoastline_segments.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class InputFile {
7979

8080
}; // class InputFile
8181

82+
namespace {
83+
8284
void print_help() {
8385
}
8486

@@ -110,6 +112,8 @@ void output_ogr(const std::string& filename, const std::string& driver_name, con
110112
layer.commit_transaction();
111113
}
112114

115+
} // anonymous namespace
116+
113117
int main(int argc, char *argv[]) {
114118
bool dump = false;
115119
std::string format = "ESRI Shapefile";

0 commit comments

Comments
 (0)