Skip to content

Commit

Permalink
Merge pull request #232 from mapbox/cplusplus
Browse files Browse the repository at this point in the history
Convert everything to C++
  • Loading branch information
e-n-f committed Apr 27, 2016
2 parents 8c7ac58 + 7449150 commit 666565e
Show file tree
Hide file tree
Showing 35 changed files with 1,166 additions and 1,119 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ matrix:


install:
- BUILDTYPE=${BUILDTYPE} make
- BUILDTYPE=${BUILDTYPE} make -j

script:
- BUILDTYPE=${BUILDTYPE} make test
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.11.0

* Convert C source files to C++

## 1.10.0

* Upgrade Clipper to fix potential crashes and improve polygon topology
Expand Down
23 changes: 9 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ man/tippecanoe.1: README.md

PG=

H = $(shell find . '(' -name '*.h' -o -name '*.hh' ')')
C = $(shell find . '(' -name '*.c' -o -name '*.cc' ')')
ALL_H = $(shell find . '(' -name '*.h' -o -name '*.hpp' ')')
H = $(wildcard *.h) $(wildcard *.hpp)
C = $(wildcard *.c) $(wildcard *.cpp)

INCLUDES = -I/usr/local/include -I.
LIBS = -L/usr/local/lib

tippecanoe: geojson.o jsonpull.o tile.o clip.o pool.o mbtiles.o geometry.o projection.o memfile.o clipper/clipper.o mvt.o
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o clipper/clipper.o mvt.o serial.o main.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread

tippecanoe-enumerate: enumerate.o
Expand All @@ -51,27 +52,21 @@ tippecanoe-enumerate: enumerate.o
tippecanoe-decode: decode.o projection.o mvt.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3

tile-join: tile-join.o projection.o pool.o mbtiles.o mvt.o
tile-join: tile-join.o projection.o pool.o mbtiles.o mvt.o memfile.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3

libjsonpull.a: jsonpull.o
$(AR) rc $@ $^
ranlib $@
%.o: %.c $(ALL_H)
$(CC) $(PG) $(INCLUDES) $(FINAL_FLAGS) $(CFLAGS) -c -o $@ $<

%.o: %.c $(H)
$(CC) $(PG) $(INCLUDES) $(FINAL_FLAGS) $(CFLAGS) -c $<

%.o: %.cc $(H)
$(CXX) $(PG) $(INCLUDES) $(FINAL_FLAGS) $(CXXFLAGS) -c $<
%.o: %.cpp $(ALL_H)
$(CXX) $(PG) $(INCLUDES) $(FINAL_FLAGS) $(CXXFLAGS) -c -o $@ $<

clean:
rm -f tippecanoe *.o

indent:
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false}" $(C) $(H)

geometry.o: clipper/clipper.hpp

TESTS = $(wildcard tests/*/out/*.json)
SPACE = $(NULL) $(NULL)

Expand Down
84 changes: 0 additions & 84 deletions clip.c

This file was deleted.

1 change: 0 additions & 1 deletion clip.h

This file was deleted.

23 changes: 10 additions & 13 deletions decode.cc → decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "mvt.hh"
#include "tile.h"

extern "C" {
#include "projection.h"
}
#include "mvt.hpp"
#include "projection.hpp"
#include "geometry.hpp"

void printq(const char *s) {
putchar('"');
Expand All @@ -32,12 +29,12 @@ void printq(const char *s) {
putchar('"');
}

struct draw {
struct lonlat {
int op;
double lon;
double lat;

draw(int op, double lon, double lat) {
lonlat(int op, double lon, double lat) {
this->op = op;
this->lon = lon;
this->lat = lat;
Expand Down Expand Up @@ -144,7 +141,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {

printf(" }, \"geometry\": { ");

std::vector<draw> ops;
std::vector<lonlat> ops;

for (size_t g = 0; g < feat.geometry.size(); g++) {
int op = feat.geometry[g].op;
Expand All @@ -159,9 +156,9 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
double lat, lon;
tile2latlon(wx, wy, 32, &lat, &lon);

ops.push_back(draw(op, lon, lat));
ops.push_back(lonlat(op, lon, lat));
} else {
ops.push_back(draw(op, 0, 0));
ops.push_back(lonlat(op, 0, 0));
}
}

Expand Down Expand Up @@ -215,12 +212,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
printf(" ] ]");
}
} else if (feat.type == VT_POLYGON) {
std::vector<std::vector<draw> > rings;
std::vector<std::vector<lonlat> > rings;
std::vector<double> areas;

for (size_t i = 0; i < ops.size(); i++) {
if (ops[i].op == VT_MOVETO) {
rings.push_back(std::vector<draw>());
rings.push_back(std::vector<lonlat>());
areas.push_back(0);
}

Expand Down
2 changes: 1 addition & 1 deletion enumerate.c → enumerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void enumerate(char *fname) {
exit(EXIT_FAILURE);
}

char *sql = "SELECT zoom_level, tile_column, tile_row from tiles;";
const char *sql = "SELECT zoom_level, tile_column, tile_row from tiles;";

sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
Expand Down
Loading

0 comments on commit 666565e

Please sign in to comment.