-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic metadata support * include the table and type name in the debug message * render the optional typemaps generic * fully generic optional * simplify the optional typemap using $*1_ltype * use colored YES/NO * final version * this is not a problem anymore * fix optional returning an array in TS and test one string
- Loading branch information
Showing
9 changed files
with
196 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
%nn_shared_ptr(osgeo::proj::metadata::Identifier); | ||
%nn_shared_ptr(osgeo::proj::metadata::Citation); | ||
%nn_shared_ptr(osgeo::proj::metadata::Extent); | ||
%nn_shared_ptr(osgeo::proj::metadata::GeographicBoundingBox); | ||
%nn_shared_ptr(osgeo::proj::metadata::TemporalExtent); | ||
%nn_shared_ptr(osgeo::proj::metadata::VerticalExtent); | ||
%nn_shared_ptr(osgeo::proj::metadata::PositionalAccuracy); | ||
|
||
%define IDENTIFIER_DOWNCAST_TABLE_ENTRY(TYPE) | ||
identifier_downcast_table.insert({typeid(TYPE).hash_code(), $descriptor(TYPE *)}) | ||
%enddef | ||
|
||
%fragment("identifier_downcast_table", "header", fragment="include_map") { | ||
std::map<std::size_t, swig_type_info *> identifier_downcast_table; | ||
|
||
void init_identifier_downcast_table() { | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Identifier); | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Citation); | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::Extent); | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::GeographicBoundingBox); | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::TemporalExtent); | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::VerticalExtent); | ||
IDENTIFIER_DOWNCAST_TABLE_ENTRY(osgeo::proj::metadata::PositionalAccuracy); | ||
} | ||
} | ||
|
||
%init { | ||
init_identifier_downcast_table(); | ||
} | ||
|
||
// See util.i for the downcasting mechanics | ||
// This overwrites the typemap created by %nn_shared_ptr | ||
%typemap(out, fragment="identifier_downcast_table") dropbox::oxygen::nn<std::shared_ptr<osgeo::proj::metadata::Identifier>> { | ||
TRY_DOWNCASTING($1, $result, osgeo::proj::metadata::Identifier, identifier_downcast_table) | ||
} | ||
|
||
// Extent is nullable when not an nn pointer | ||
%typemap(ts) osgeo::proj::metadata::ExtentPtr "Extent | null"; | ||
%typemap(ts) const osgeo::proj::metadata::ExtentPtr & "Extent | null"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,79 @@ | ||
// C++ osgeo::proj::util::optional<std::string> <-> JS string | ||
// osgeo::proj::util::optional | ||
|
||
// This is almost a string, but not quite | ||
/* | ||
* Input arguments | ||
*/ | ||
|
||
// Input argument, plain object, conversion by copying | ||
%typemap(in) osgeo::proj::util::optional<std::string> { | ||
// Input argument, plain object, conversion by copying using the underlying object typemap | ||
%typemap(in) osgeo::proj::util::optional { | ||
if (!$input.IsNull()) { | ||
std::string opt_string; | ||
$typemap(in, std::string, input=$input, 1=opt_string, argnum=$argnum); | ||
$1 = osgeo::proj::util::optional<std::string>{opt_string}; | ||
$T0type obj; | ||
$typemap(in, $T0type, input=$input, 1=obj, argnum=$argnum); | ||
$1 = osgeo::proj::util::optional<$T0type>{obj}; | ||
} | ||
} | ||
// Input argument, const reference, conversion by constructing an 'optional' | ||
// around the object held by JS | ||
// (DataEpoch & Measure do not support operator=, thus the unique_ptr gymnastics) | ||
%typemap(in) const osgeo::proj::util::optional & (std::unique_ptr<$*1_ltype> opt_object) { | ||
if (!$input.IsNull()) { | ||
$T0type *obj; | ||
$typemap(in, const $T0type &, input=$input, 1=obj, argnum=$argnum); | ||
opt_object = std::make_unique<$*1_ltype>(*obj); | ||
} else { | ||
opt_object = std::make_unique<$*1_ltype>(); | ||
} | ||
$1 = opt_object.get(); | ||
} | ||
|
||
// string and double are special cases, these are copied | ||
%typemap(in) const osgeo::proj::util::optional<std::string> & (osgeo::proj::util::optional<std::string> opt_string) { | ||
if (!$input.IsNull()) { | ||
$typemap(in, std::string, input=$input, 1=opt_string, argnum=$argnum); | ||
} | ||
$1 = &opt_string; | ||
} | ||
%typemap(in) const osgeo::proj::util::optional<double> & (osgeo::proj::util::optional<double> opt_double) { | ||
if (!$input.IsNull()) { | ||
$typemap(in, double, input=$input, 1=opt_double, argnum=$argnum); | ||
} | ||
$1 = &opt_double; | ||
} | ||
|
||
%typemap(ts) osgeo::proj::util::optional, const osgeo::proj::util::optional & "$typemap(ts, $T0type)"; | ||
|
||
%typemap(ts) osgeo::proj::util::optional<std::string>, const osgeo::proj::util::optional<std::string> & "string"; | ||
/* | ||
* Return values | ||
*/ | ||
|
||
// Return value, plain object, conversion by copying | ||
%typemap(out) osgeo::proj::util::optional<std::string> { | ||
%typemap(out) osgeo::proj::util::optional { | ||
if ($1.has_value()) { | ||
$typemap(out, std::string, 1=(*$1), result=$result, argnum=$argnum); | ||
$typemap(out, $T0type, 1=(*$1), result=$result, argnum=$argnum); | ||
} else { | ||
$result = env.Null(); | ||
} | ||
} | ||
// Return value, const reference, conversion by wrapping a constant object | ||
%typemap(out) const osgeo::proj::util::optional & { | ||
if ($1->has_value()) { | ||
$typemap(out, const $T0type &, 1=&(*$1), result=$result, argnum=$argnum); | ||
} else { | ||
$result = env.Null(); | ||
} | ||
} | ||
// string and double are special cases, these are copied | ||
%typemap(out) const osgeo::proj::util::optional<std::string> & { | ||
if ($1->has_value()) { | ||
$typemap(out, const std::string &, 1=(*$1), result=$result, argnum=$argnum); | ||
} else { | ||
$result = env.Null(); | ||
} | ||
} | ||
%typemap(out) const osgeo::proj::util::optional<double> & { | ||
if ($1->has_value()) { | ||
$typemap(out, double, 1=(**$1), result=$result, argnum=$argnum); | ||
} else { | ||
$result = env.Null(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { assert } from 'chai'; | ||
|
||
import qPROJ from 'proj.js'; | ||
import type * as PROJ from 'proj.js'; | ||
|
||
describe('metadata with automatic import', () => { | ||
let PROJ: Awaited<typeof qPROJ>; | ||
|
||
let dbContext: PROJ.DatabaseContext; | ||
let authFactory: PROJ.AuthorityFactory; | ||
let authFactoryEPSG: PROJ.AuthorityFactory; | ||
|
||
before('init', async () => { | ||
PROJ = await qPROJ; | ||
dbContext = PROJ.DatabaseContext.create(); | ||
authFactory = PROJ.AuthorityFactory.create(dbContext, 'string'); | ||
authFactoryEPSG = PROJ.AuthorityFactory.create(dbContext, 'EPSG'); | ||
}); | ||
|
||
it('static properties', () => { | ||
assert.isString(PROJ.Identifier.AUTHORITY_KEY); | ||
assert.isString(PROJ.Identifier.CODESPACE_KEY); | ||
}); | ||
|
||
it('IdentifiedObject properties', () => { | ||
const crs = authFactoryEPSG.createCoordinateReferenceSystem('3857'); | ||
const metadata = crs.identifiers(); | ||
assert.isArray(metadata); | ||
for (const m of metadata) { | ||
assert.instanceOf(m, PROJ.Identifier); | ||
assert.instanceOf(m, PROJ.BaseObject); | ||
assert.isString(m.code()); | ||
assert.isString(m.codeSpace()); | ||
assert.strictEqual(m.code(), '3857'); | ||
assert.strictEqual(m.codeSpace(), 'EPSG'); | ||
assert.isNull(m.authority()); | ||
assert.isNull(m.uri()); | ||
} | ||
}); | ||
|
||
}); |