diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-11-28 14:52:56 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-11-29 12:10:13 +0100 |
| commit | cf855b24d2b901054bee90309cdc5df00dfb3085 (patch) | |
| tree | cfed6be67bd51c6e8cd198def30d840fe9f67a89 /scripts | |
| parent | 6d9a1a909886762cc99e1d8f289e2b60ea787bf7 (diff) | |
| download | PROJ-cf855b24d2b901054bee90309cdc5df00dfb3085.tar.gz PROJ-cf855b24d2b901054bee90309cdc5df00dfb3085.zip | |
C API extensions and renaming
- proj_obj_create_projected_XXXXX() are renamed to
proj_obj_create_conversion_snake_case() and just instanciate
a Conversion object
- Advanced manipulation functions are moved to a dedicated
section at bottom of proj.h
- New C API needed for GDAL OGRSpatialReference
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/create_c_api_projections.py | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/scripts/create_c_api_projections.py b/scripts/create_c_api_projections.py index 5d10a16b..a56e99b3 100755 --- a/scripts/create_c_api_projections.py +++ b/scripts/create_c_api_projections.py @@ -56,6 +56,21 @@ cppfile.write("\n"); test_cppfile.write("/* BEGIN: Generated by scripts/create_c_api_projections.py*/\n") +def snake_casify(s): + out = '' + lastWasLowerAlpha = False + for c in s: + if c.isupper(): + if lastWasLowerAlpha: + out += '_' + out += c.lower() + lastWasLowerAlpha = False + else: + out += c + lastWasLowerAlpha = c.isalpha() + return out + + for sectiondef in compounddef.iter('sectiondef'): if sectiondef.attrib['kind'] == 'public-static-func': for func in sectiondef.iter('memberdef'): @@ -79,22 +94,31 @@ for sectiondef in compounddef.iter('sectiondef'): params.append((type, paramname)) shortName = name[len('create'):] + c_shortName = snake_casify(shortName) - decl = "proj_obj_create_projected_crs_" - decl += shortName + decl = "proj_obj_create_conversion_" + decl += c_shortName decl += "(\n" - decl += " PJ_OBJ* geodetic_crs, const char* crs_name,\n" + decl += " PJ_CONTEXT *ctx,\n" + has_output_params = False for param in params: + if has_output_params: + decl += ",\n" + if param[0] in ('int', 'bool'): - decl += " int " + param[1] + ",\n" + decl += " int " + param[1] else: - decl += " double " + param[1] + ",\n" + decl += " double " + param[1] + has_output_params = True + if has_angle: + if has_output_params: + decl += ",\n" decl += " const char* angUnitName, double angUnitConvFactor" - if has_linear: - decl += "," - decl += "\n" + has_output_params = True if has_linear: + if has_output_params: + decl += ",\n" decl += " const char* linearUnitName, double linearUnitConvFactor" decl += ")" @@ -113,9 +137,8 @@ for sectiondef in compounddef.iter('sectiondef'): cppfile.write(" * Angular parameters are expressed in (angUnitName, angUnitConvFactor).\n") cppfile.write(" */\n") cppfile.write("PJ_OBJ* " + decl + "{\n"); - if not has_linear: - cppfile.write(" const auto& linearUnit = UnitOfMeasure::METRE;\n") - else: + cppfile.write(" try {\n"); + if has_linear: cppfile.write(" UnitOfMeasure linearUnit(createLinearUnit(linearUnitName, linearUnitConvFactor));\n") if has_angle: cppfile.write(" UnitOfMeasure angUnit(createAngularUnit(angUnitName, angUnitConvFactor));\n") @@ -133,12 +156,16 @@ for sectiondef in compounddef.iter('sectiondef'): cppfile.write(", Scale(" + param[1] + ")") cppfile.write(");\n") - cppfile.write(" return proj_obj_create_projected_crs(geodetic_crs, crs_name, conv, linearUnit);\n") + cppfile.write(" return proj_obj_create_conversion(ctx, conv);\n") + cppfile.write(" } catch (const std::exception &e) {\n"); + cppfile.write(" proj_log_error(ctx, __FUNCTION__, e.what());\n") + cppfile.write(" }\n") + cppfile.write(" return nullptr;\n") cppfile.write("}\n") test_cppfile.write("{\n") - test_cppfile.write(" auto projCRS = proj_obj_create_projected_crs_" + shortName + "(\n") - test_cppfile.write(" geogCRS, nullptr") + test_cppfile.write(" auto projCRS = proj_obj_create_conversion_" + c_shortName + "(\n") + test_cppfile.write(" m_ctxt") for param in params: test_cppfile.write(", 0") if has_angle: |
