This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository mapcode.
commit 248b6ee6bf199487150daebcef655fd0a315f51c Author: Bas Couwenberg <sebas...@xs4all.nl> Date: Sun Jan 28 19:07:21 2018 +0100 New upstream version 2.5.5 --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- mapcodelib/mapcoder.c | 12 ++++++++++ mapcodelib/mapcoder.h | 14 ++++++++++- test/run_compare.sh | 9 +++---- test/run_gcov.sh | 4 +--- test/run_gprof.sh | 5 +--- test/run_normal.sh | 5 +--- test/run_sanitizer.sh | 5 +--- test/run_valgrind.sh | 5 +--- 9 files changed, 98 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index fc7e19f..f78b81e 100644 --- a/README.md +++ b/README.md @@ -177,9 +177,73 @@ To add individual support support for other languages (of all territory names), The list of support languages may grow over time. +## Using the C Library in an Xcode iOS Swift project + +You can use this C library in an iOS application, built with Swift in Xcode, fairly easily. +All you need to do is: + +First, copy the directory `mapcodelib` to the source directory of your iOS application. + +Then, add a text file called `module.modulemap` in the directory `mapcodelib` to export all symbols +from the C library to Swift (note that `#defines` are not exported): + +``` +module mapcodelib [system][extern_c]{ + header "mapcode_alphabets.h" + header "mapcode_territories.h" + header "mapcoder.h" + export * +} +``` + +Now, you can access the C library methods like this in a Swift project: + +``` +// Example of decoding a full mapcode to a lat/lon: +let territory = getTerritoryCode(context, TERRITORY_NONE) +var lat: Double = 0.0 +var lon: Double = 0.0 +let mapcodeError = decodeMapcodeToLatLonUtf8(&lat, &lon, fullMapcode, territory, nil) +if mapcodeError == ERR_OK { + // Use the decoded lat and lon. +} else { + // Something went wrong decoding the full mapcode string. +} +``` +Or encode a latitude, longitude pair to a set of Mapcodes like this: + +``` +let buffer = UnsafeMutablePointer<Int8>.allocate(capacity: Int(_MAX_MAPCODE_RESULT_ASCII_LEN)) +buffer.initialize(to: 0, count: Int(_MAX_MAPCODE_RESULT_ASCII_LEN)) +var total: Int32 = 0; +var i: Int32 = 0 +repeat { + total = encodeLatLonToSelectedMapcode(buffer, lat, lon, TERRITORY_NONE, 0, i) + if (total > 0) { + let mapcode = String.init(cString: buffer); + } + i = i + 1 +} while (i < total) +``` + +Or get a territory name like this: + +``` +let buffer = UnsafeMutablePointer<CChar>.allocate(capacity: Int(MAX_TERRITORY_FULLNAME_UTF8_LEN + 1)) +buffer.initialize(to: 0, count: Int(_MAX_TERRITORY_FULLNAME_UTF8_LEN + 1)) + +// Get alpha code. +getTerritoryIsoName(buffer, TERRITORY_NLD, 0) +let alphaCode = String.init(cString: buffer) + +// Get full name. +getFullTerritoryNameEnglish(buffer, TERRITORY_NLD, 0) +let fullName = String.init(cString: buffer) +``` + ## Release Notes -### 2.5.4 +### 2.5.4 - 2.5.5 * Added `encodeLatLonToSelectedMapcode` as a convenience for languages that use the C library, but have difficulties dealing with multi-dimensional arrays (like Swift). diff --git a/mapcodelib/mapcoder.c b/mapcodelib/mapcoder.c index 464dc9e..312b6d8 100644 --- a/mapcodelib/mapcoder.c +++ b/mapcodelib/mapcoder.c @@ -53,6 +53,18 @@ #include "internal_territory_names_tr.h" #include "internal_territory_names_uk.h" +// The constants are also exported as variables, to allow other languages to use them. +char *_MAPCODE_C_VERSION = MAPCODE_C_VERSION; +int _MAX_NR_OF_MAPCODE_RESULTS = MAX_NR_OF_MAPCODE_RESULTS; +int _MAX_PRECISION_DIGITS = MAX_PRECISION_DIGITS; +int _MAX_PROPER_MAPCODE_ASCII_LEN = MAX_PROPER_MAPCODE_ASCII_LEN; +int _MAX_ISOCODE_ASCII_LEN = MAX_ISOCODE_ASCII_LEN; +int _MAX_CLEAN_MAPCODE_ASCII_LEN = MAX_CLEAN_MAPCODE_ASCII_LEN; +int _MAX_MAPCODE_RESULT_ASCII_LEN = MAX_MAPCODE_RESULT_ASCII_LEN; +int _MAX_TERRITORY_FULLNAME_UTF8_LEN = MAX_TERRITORY_FULLNAME_UTF8_LEN; +int _MAX_MAPCODE_RESULT_UTF8_LEN = MAX_MAPCODE_RESULT_UTF8_LEN; +int _MAX_MAPCODE_RESULT_UTF16_LEN = MAX_MAPCODE_RESULT_UTF16_LEN; +int _MAX_ALPHABETS_PER_TERRITORY = MAX_ALPHABETS_PER_TERRITORY; #ifdef DEBUG diff --git a/mapcodelib/mapcoder.h b/mapcodelib/mapcoder.h index 6f13948..8a89461 100644 --- a/mapcodelib/mapcoder.h +++ b/mapcodelib/mapcoder.h @@ -58,7 +58,7 @@ extern "C" { #define MAPCODE_SUPPORT_LANGUAGE_UK #endif -#define MAPCODE_C_VERSION "2.5.3" +#define MAPCODE_C_VERSION "2.5.5" #define UWORD unsigned short int // 2-byte unsigned integer. #define MAX_NR_OF_MAPCODE_RESULTS 22 // Max. number of results ever returned by encoder (e.g. for 26.904899, 95.138515). @@ -73,6 +73,18 @@ extern "C" { #define MAX_MAPCODE_RESULT_UTF8_LEN (MAX_MAPCODE_RESULT_ASCII_LEN * 3) // One mapcode character can become at most 3 UTF8characters. #define MAX_MAPCODE_RESULT_UTF16_LEN (MAX_MAPCODE_RESULT_ASCII_LEN) // Each mapcode character can become one UTF16 word. +// The constants are also exported as variables, to allow other languages to use them. +extern char* _MAPCODE_C_VERSION; +extern int _MAX_NR_OF_MAPCODE_RESULTS; +extern int _MAX_PRECISION_DIGITS; +extern int _MAX_PROPER_MAPCODE_ASCII_LEN; +extern int _MAX_ISOCODE_ASCII_LEN; +extern int _MAX_CLEAN_MAPCODE_ASCII_LEN; +extern int _MAX_MAPCODE_RESULT_ASCII_LEN; +extern int _MAX_TERRITORY_FULLNAME_UTF8_LEN; +extern int _MAX_MAPCODE_RESULT_UTF8_LEN; +extern int _MAX_MAPCODE_RESULT_UTF16_LEN; +extern int _MAX_ALPHABETS_PER_TERRITORY; /** * The type Mapcodes hold a number of mapcodes, for example from an encoding call. diff --git a/test/run_compare.sh b/test/run_compare.sh index 2113ed1..7b777c2 100755 --- a/test/run_compare.sh +++ b/test/run_compare.sh @@ -1,8 +1,8 @@ #!/bin/sh -OPTS="-Wall -Werror -Wextra -Wno-pointer-to-int-cast" +OPTS="-Wall -Wextra -Wno-pointer-to-int-cast" -NEW=../utility/mapcode -OLD=$HOME/bin/mapcode-2.3.1 +NEW=../mapcode-2.5.5 +OLD=../mapcode-2.5.2 NEWFILE=_new.txt OLDFILE=_old.txt @@ -91,6 +91,3 @@ else rm -f $NEWFILE $OLDFILE fi echo "!! -------------------------------------------------------------" - -echo "" -echo "Report in: $REPORT" diff --git a/test/run_gcov.sh b/test/run_gcov.sh index c33c270..b508ee6 100755 --- a/test/run_gcov.sh +++ b/test/run_gcov.sh @@ -1,5 +1,5 @@ #!/bin/sh -OPTS="-Wall -Werror -Wextra -Wno-pointer-to-int-cast -fprofile-arcs -ftest-coverage" +OPTS="-Wall -Wextra -Wno-pointer-to-int-cast -fprofile-arcs -ftest-coverage" LIB="../mapcodelib/mapcoder.o" TEST=$(which gcov) @@ -29,5 +29,3 @@ echo "!! -------------------------------------------------------------" echo "!! Coverage reports in: *.gcov files" echo "!! -------------------------------------------------------------" -echo "" -echo "Report in: $REPORT" diff --git a/test/run_gprof.sh b/test/run_gprof.sh index 558cd24..4595327 100755 --- a/test/run_gprof.sh +++ b/test/run_gprof.sh @@ -1,5 +1,5 @@ #!/bin/sh -OPTS="-Wall -Werror -Wextra -Wno-pointer-to-int-cast" +OPTS="-Wall -Wextra -Wno-pointer-to-int-cast" LIB="../mapcodelib/mapcoder.o" TEST=$(which gprof) @@ -33,6 +33,3 @@ gcc $OPTS -g -O3 unittest.c -lm -lpthread -o unittest $LIB -pg ./unittest gprof ./unittest echo "!! -------------------------------------------------------------" - -echo "" -echo "Report in: $REPORT" diff --git a/test/run_normal.sh b/test/run_normal.sh index d4d7769..33b7c44 100755 --- a/test/run_normal.sh +++ b/test/run_normal.sh @@ -1,5 +1,5 @@ #!/bin/sh -OPTS="-Wall -Werror -Wextra -Wno-pointer-to-int-cast" +OPTS="-Wall -Wextra -Wno-pointer-to-int-cast" echo "!! -------------------------------------------------------------" echo "Run normal..." @@ -23,6 +23,3 @@ cd ../test gcc $OPTS -O3 unittest.c -lm -lpthread -o unittest ../mapcodelib/mapcoder.o ./unittest echo "!! -------------------------------------------------------------" - -echo "" -echo "Report in: $REPORT" diff --git a/test/run_sanitizer.sh b/test/run_sanitizer.sh index 2478dd5..c301b9b 100755 --- a/test/run_sanitizer.sh +++ b/test/run_sanitizer.sh @@ -1,5 +1,5 @@ #!/bin/sh -OPTS="-Wall -Werror -Wextra -Wno-pointer-to-int-cast" +OPTS="-Wall -Wextra -Wno-pointer-to-int-cast" LIB="../mapcodelib/mapcoder.o" export ASAN_OPTIONS=debug=true:strict_string_checks=1:detect_stack_use_after_return=true:detect_invalid_pointer_pairs=99999:detect_container_overflow=true:detect_odr_violation=2:check_initialization_order=true:strict_init_order=true @@ -45,6 +45,3 @@ cd ../test gcc $OPTS -O3 unittest.c -lm -lpthread -fsanitize=address -o unittest $LIB ./unittest echo "!! -------------------------------------------------------------" - -echo "" -echo "Report in: $REPORT" diff --git a/test/run_valgrind.sh b/test/run_valgrind.sh index 4d13ebe..20fff57 100755 --- a/test/run_valgrind.sh +++ b/test/run_valgrind.sh @@ -1,5 +1,5 @@ #!/bin/sh -OPTS="-Wall -Werror -Wextra -Wno-pointer-to-int-cast" +OPTS="-Wall -Wextra -Wno-pointer-to-int-cast" LIB="../mapcodelib/mapcoder.o" TEST=$(which valgrind) @@ -22,6 +22,3 @@ cd ../test gcc $OPTS -g -O0 unittest.c -lm -lpthread -o unittest $LIB valgrind --leak-check=yes ./unittest echo "!! -------------------------------------------------------------" - -echo "" tee -a $REPORT -echo "Report in: $REPORT" -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapcode.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel