Skip to content

Commit 3711f98

Browse files
committed
Split into internal_ and mapcode_ files.
1 parent e0e63bb commit 3711f98

21 files changed

+2494
-2086
lines changed

CMakeLists.txt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
1+
# Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -20,37 +20,48 @@ project(mapcode_cpp)
2020
#
2121
# export ASAN_OPTIONS=debug=true:strict_string_checks=1:detect_stack_use_after_return=true:detect_invalid_pointer_pairs=99999:
2222
# detect_container_overflow=true:detect_odr_violation=2:check_initialization_order=true
23+
#
24+
# And add -DNO_POSIX_THREADS to the compiler options if you do not want to use multi-threaded unit testing.
25+
26+
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -Wall -fsanitize=address -fno-common -fno-optimize-sibling-calls -fno-omit-frame-pointer")
27+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DDEBUG")
28+
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
29+
30+
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -std=c++11")
31+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DDEBUG -std=c++11")
32+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -std=c++11")
2333

24-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DNO_POSIX_THREADS -DDEBUG -Wall -fsanitize=address -fno-common -fno-optimize-sibling-calls -fno-omit-frame-pointer")
25-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -std=c++11")
26-
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
34+
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-fsanitize=address")
35+
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "")
36+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "")
2737

28-
set(SOURCE_FILES
29-
mapcodelib/basics.h
38+
set(SOURCE_FILES_MAPCODELIB
39+
mapcodelib/internal_data.h
40+
mapcodelib/internal_iso3166_data.h
41+
mapcodelib/internal_territory_alphabets.h
42+
mapcodelib/internal_territory_names_english.h
43+
mapcodelib/internal_territory_names_english_full.h
44+
mapcodelib/internal_territory_names_local.h
45+
mapcodelib/internal_territory_search.h
3046
mapcodelib/mapcode_alphabets.h
31-
mapcodelib/mapcode_countrynames.h
32-
mapcodelib/mapcode_countrynames_local.h
33-
mapcodelib/mapcode_countrynames_short.h
34-
mapcodelib/mapcode_fast_encode.h
35-
mapcodelib/mapcode_fastalpha.h
47+
mapcodelib/mapcode_legacy.c
3648
mapcodelib/mapcode_legacy.h
37-
mapcodelib/mapcode_territory_alphabets.h
3849
mapcodelib/mapcode_territories.h
3950
mapcodelib/mapcoder.c
40-
mapcodelib/mapcoder.h
41-
unittest/decode_test.h
42-
unittest/test_territories.c
43-
unittest/unittest.c
44-
utility/mapcode.cpp)
51+
mapcodelib/mapcoder.h)
4552

4653
set(SOURCE_FILES_UNITTEST
54+
unittest/decode_test.h
4755
unittest/unittest.c)
4856

4957
set(SOURCE_FILES_UTILITY
5058
utility/mapcode.cpp)
5159

52-
add_executable(fullset ${SOURCE_FILES})
60+
add_library(mapcodelib ${SOURCE_FILES_MAPCODELIB})
61+
target_include_directories(mapcodelib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
5362

5463
add_executable(unittest ${SOURCE_FILES_UNITTEST})
64+
target_link_libraries(unittest LINK_PUBLIC mapcodelib)
5565

5666
add_executable(mapcode ${SOURCE_FILES_UTILITY})
67+
target_link_libraries(mapcode LINK_PUBLIC mapcodelib)

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Original C library created by Pieter Geelen. Work on Java version
22
of the Mapcode library by Rijn Buve (original port by Matthew Lowden).
33

4-
Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
4+
Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ decode Mapcodes.
6161

6262
This produces the following help text:
6363

64-
MAPCODE (version 2.4.0)
65-
Copyright (C) 2014-2015 Stichting Mapcode Foundation
64+
MAPCODE (version 2.4.1)
65+
Copyright (C) 2014-2016 Stichting Mapcode Foundation
6666

6767
Usage:
6868
./mapcode [-d| --decode] <default-territory> <mapcode> [<mapcode> ...]
@@ -133,11 +133,13 @@ settings:
133133

134134
### 2.4.1
135135

136-
* Turned territories, alphabets and error codes into enums; Cleaned up source.
136+
* Renamed .h files to internal_*.h unless they are relevant to the interface.
137137

138-
* Split off legacy stuff into mapcode_legacy.h
138+
* Turned territories, alphabets and error codes into enums.
139139

140-
* Added mapcode_territories.h
140+
* Split off legacy stuff into `mapcode_legacy.h`.
141+
142+
* Added `convertUtf8ToUtf16`, `convertUtf16ToUtf8`, `recogniseAlphabetUtf8`, `recogniseAlphabetUtf16`.
141143

142144
### 2.4.0
143145

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,17 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef __BASICS_H__
17-
#define __BASICS_H__
16+
#ifndef __INTERNAL_DATA_H__
17+
#define __INTERNAL_DATA_H__
1818

1919

2020
// *** GENERATED FILE (coords.cpp), DO NOT CHANGE OR PRETTIFY ***
2121

2222
#define mapcode_dataversion "2.3.0" // coords 2.0.2
2323

24-
#define MAPCODE_NR_TERRITORIES 533 // nr of territories in this database
25-
26-
static const char *iso3166alpha[MAPCODE_NR_TERRITORIES] = {
24+
static const char *iso3166alpha[_TERRITORY_MAX - _TERRITORY_MIN - 1] = {
2725
"VAT", "MCO", "GIB", "TKL", "CCK", "BLM", "NRU", "TUV", "MAC", "SXM",
2826
"MAF", "NFK", "PCN", "BVT", "BMU", "IOT", "SMR", "GGY", "AIA", "MSR",
2927
"JEY", "CXR", "WLF", "VGB", "LIE", "ABW", "MHL", "ASM", "COK", "SPM",
@@ -111,33 +109,8 @@ static const char *iso3166alpha[MAPCODE_NR_TERRITORIES] = {
111109
};
112110

113111

114-
#define parents3 "USA,IND,CAN,AUS,MEX,BRA,RUS,CHN,"
115-
#define parents2 "US,IN,CA,AU,MX,BR,RU,CN,"
116-
117-
// 360 * cos(microdegrees>>19)
118-
static const int xdivider19[172] = {
119-
360, 360, 360, 360, 360, 360, 361, 361, 361, 361,
120-
362, 362, 362, 363, 363, 363, 364, 364, 365, 366,
121-
366, 367, 367, 368, 369, 370, 370, 371, 372, 373,
122-
374, 375, 376, 377, 378, 379, 380, 382, 383, 384,
123-
386, 387, 388, 390, 391, 393, 394, 396, 398, 399,
124-
401, 403, 405, 407, 409, 411, 413, 415, 417, 420,
125-
422, 424, 427, 429, 432, 435, 437, 440, 443, 446,
126-
449, 452, 455, 459, 462, 465, 469, 473, 476, 480,
127-
484, 488, 492, 496, 501, 505, 510, 515, 520, 525,
128-
530, 535, 540, 546, 552, 558, 564, 570, 577, 583,
129-
590, 598, 605, 612, 620, 628, 637, 645, 654, 664,
130-
673, 683, 693, 704, 715, 726, 738, 751, 763, 777,
131-
791, 805, 820, 836, 852, 869, 887, 906, 925, 946,
132-
968, 990, 1014, 1039, 1066, 1094, 1123, 1154, 1187, 1223,
133-
1260, 1300, 1343, 1389, 1438, 1490, 1547, 1609, 1676, 1749,
134-
1828, 1916, 2012, 2118, 2237, 2370, 2521, 2691, 2887, 3114,
135-
3380, 3696, 4077, 4547, 5139, 5910, 6952, 8443, 10747, 14784,
136-
23681, 59485
137-
};
138-
139112
// index of first rectangle record for x-th territory
140-
static const int data_start[MAPCODE_NR_TERRITORIES + 1] = {
113+
static const int data_start[_TERRITORY_MAX - _TERRITORY_MIN] = {
141114
0, 3, 6, 10, 14, 17, 19, 20, 31, 32,
142115
34, 36, 38, 43, 45, 48, 52, 59, 63, 65,
143116
67, 71, 73, 81, 87, 95, 97, 132, 139, 149,
@@ -194,18 +167,18 @@ static const int data_start[MAPCODE_NR_TERRITORIES + 1] = {
194167
16320, 16322, 16324, 16356
195168
};
196169

197-
#define MAPCODE_NR_RECS 16356
170+
#define MAPCODE_BOUNDARY_MAX 16356
198171

199172
typedef struct {
200173
int minx;
201174
int miny;
202175
int maxx;
203176
int maxy;
204177
int flags;
205-
} mminforec;
178+
} TerritoryBoundary;
206179

207180
#ifndef MAKE_SOURCE_DIGITAL
208-
static const mminforec mminfo[MAPCODE_NR_RECS + 1] = {
181+
static const TerritoryBoundary territoryBoundaries[MAPCODE_BOUNDARY_MAX + 1] = {
209182
{12433114, 41851944, 12548434, 41938434, 0x001000b}, // VAT
210183
{5850000, 35450000, 18560000, 55080000, 0x50a0216},
211184
{12444000, 41899000, 12460000, 41908000, 0x003021c},
@@ -16563,7 +16536,10 @@ static const mminforec mminfo[MAPCODE_NR_RECS + 1] = {
1656316536
{-180000000, 77183669, 180000000, 90000001, 0x001f097},
1656416537
{-180000000, -90000000, 180000000, 90000001, 0x000001d},
1656516538
};
16539+
16540+
#define territoryBoundary(m) (&territoryBoundaries[m])
16541+
1656616542
#endif // MAKE_SOURCE_DIGITAL
1656716543

16568-
#endif // __BASICS_H__
16544+
#endif // __INTERNAL_DATA_H__
1656916545

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,14 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef __MAPCODE_FASTALPHA_H__
18-
#define __MAPCODE_FASTALPHA_H__
17+
#ifndef __INTERNAL_ISO3166_DATA_H__
18+
#define __INTERNAL_ISO3166_DATA_H__
1919

2020
#include "mapcode_territories.h"
2121

2222
// *** GENERATED FILE (dividemaps/fast_territories), DO NOT CHANGE OR PRETTIFY ***
2323

24-
static const char parentletter[MAPCODE_NR_TERRITORIES + 1] = {
24+
static const char parentletter[_TERRITORY_MAX - _TERRITORY_MIN] = {
2525
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2626
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2727
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -42,7 +42,7 @@ static const char parentletter[MAPCODE_NR_TERRITORIES + 1] = {
4242
8, 0, 0, 0, 0, 0, 0};
4343

4444

45-
static const char parentnumber[MAPCODE_NR_TERRITORIES + 1] = {
45+
static const char parentnumber[_TERRITORY_MAX - _TERRITORY_MIN] = {
4646
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4747
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4848
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -987,4 +987,4 @@ static const alphaRec alphaSearch[NRTERREC] = {
987987
};
988988

989989
// produced by dividemaps.cpp : fast_territories.cpp
990-
#endif // __MAPCODE_FASTALPHA_H__
990+
#endif // __INTERNAL_ISO3166_DATA_H__
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,8 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef __MAPCODE_TERRITORY_ALPHABETS_H__
17-
#define __MAPCODE_TERRITORY_ALPHABETS_H__
16+
#ifndef __INTERNAL_TERRITORY_ALPHABETS_H__
17+
#define __INTERNAL_TERRITORY_ALPHABETS_H__
1818

1919

2020
// *** GENERATED FILE (coords.cpp), DO NOT CHANGE OR PRETTIFY ***
@@ -23,10 +23,9 @@
2323
extern "C" {
2424
#endif
2525

26-
#include "basics.h"
27-
#include "mapcode_alphabets.h"
26+
#include "mapcoder.h"
2827

29-
static const TerritoryAlphabets alphabetsForTerritory[MAPCODE_NR_TERRITORIES] = {
28+
static const TerritoryAlphabets alphabetsForTerritory[_TERRITORY_MAX - _TERRITORY_MIN - 1] = {
3029
{1, {ALPHABET_ROMAN}}, // VAT Vatican
3130
{1, {ALPHABET_ROMAN}}, // MCO Monaco
3231
{1, {ALPHABET_ROMAN}}, // GIB Gibraltar
@@ -566,5 +565,5 @@ static const TerritoryAlphabets alphabetsForTerritory[MAPCODE_NR_TERRITORIES] =
566565
}
567566
#endif
568567

569-
#endif // __MAPCODE_TERRITORY_ALPHABETS_H__
568+
#endif // __INTERNAL_TERRITORY_ALPHABETS_H__
570569

mapcodelib/mapcode_countrynames_short.h renamed to mapcodelib/internal_territory_names_english.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,8 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef __MAPCODE_COUNTRYNAMES_H__
17-
#define __MAPCODE_COUNTRYNAMES_H__
16+
#ifndef __INTERNAL_TERRITORY_NAMES_ENGLISH_H__
17+
#define __INTERNAL_TERRITORY_NAMES_ENGLISH_H__
1818

1919
// *** GENERATED FILE (coords.cpp), DO NOT CHANGE OR PRETTIFY ***
2020
static const char *isofullname[] = {
@@ -553,4 +553,4 @@ static const char *isofullname[] = {
553553
"International (Worldwide) (Earth)",
554554
"?"};
555555

556-
#endif
556+
#endif // __INTERNAL_TERRITORY_NAMES_ENGLISH_H__

mapcodelib/mapcode_countrynames.h renamed to mapcodelib/internal_territory_names_english_full.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,8 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef __MAPCODE_COUNTRYNAMES_H__
17-
#define __MAPCODE_COUNTRYNAMES_H__
16+
#ifndef __INTERNAL_TERRITORY_NAMES_ENGLISH_H__
17+
#define __INTERNAL_TERRITORY_NAMES_ENGLISH_H__
1818

1919
// *** GENERATED FILE (coords.cpp), DO NOT CHANGE OR PRETTIFY ***
2020
static const char *isofullname[] = {
@@ -553,4 +553,4 @@ static const char *isofullname[] = {
553553
"International (Worldwide) (Earth)",
554554
"?"};
555555

556-
#endif
556+
#endif // __INTERNAL_TERRITORY_NAMES_ENGLISH_H__

mapcodelib/mapcode_countrynames_local.h renamed to mapcodelib/internal_territory_names_local.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,14 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#ifndef __MAPCODE_LOCALNAMES_H__
17-
#define __MAPCODE_LOCALNAMES_H__
16+
#ifndef __INTERNAL_TERRITORY_NAMES_LOCAL_H__
17+
#define __INTERNAL_TERRITORY_NAMES_LOCAL_H__
1818
// *** GENERATED FILE (coords.cpp), DO NOT CHANGE OR PRETTIFY ***
1919

2020

2121
/*
2222
* The first N names are precisely in the alphabets
23-
* as listed in mapcode_territory_alphabets.
23+
* as listed in internal_territory_alphabets.
2424
* There may be even more names (for these, the alphabet is unspecified)
2525
*/
2626

@@ -560,4 +560,4 @@ static const char *localname_utf8[] = {
560560
"Earth",
561561
"?"};
562562

563-
#endif // __MAPCODE_LOCALNAMES_H__
563+
#endif // __INTERNAL_TERRITORY_NAMES_LOCAL_H__
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
2+
* Copyright (C) 2014-2016 Stichting Mapcode Foundation (http://www.mapcode.com)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,13 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
#ifndef __MAPCODE_FAST_ENCODE_H__
18-
#define __MAPCODE_FAST_ENCODE_H__
17+
#ifndef __INTERNAL_TERRITORY_SEARCH_H__
18+
#define __INTERNAL_TERRITORY_SEARCH_H__
1919

2020
// *** GENERATED FILE (dividemaps.cpp), DO NOT CHANGE OR PRETTIFY ***
2121

22-
#define REDIVAR_SIZE 2924
23-
static int redivar[REDIVAR_SIZE] = {
22+
static int redivar[] = {
2423
27984500, 1383,
2524
2537718, 676,
2625
12842450, 332,
@@ -811,4 +810,4 @@ static int redivar[REDIVAR_SIZE] = {
811810
TERRITORY_RU_SA, TERRITORY_RUS,
812811
0
813812
}; // 2924 records, data version 2.3.0
814-
#endif // __MAPCODE_FAST_ENCODE_H__
813+
#endif // __INTERNAL_TERRITORY_SEARCH_H__

0 commit comments

Comments
 (0)