aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2018-12-26 10:53:01 +0100
committerGitHub <noreply@github.com>2018-12-26 10:53:01 +0100
commit81ec8c0b58d66333fccd3703dab62a11132a0331 (patch)
tree41b4675d169f849516649700ab4f50d4cffa4c02 /src
parent355d681ed88019e97742344bd642c2fd97e700a1 (diff)
parent80dad6ef2bed4a83008db06986dc168918d48476 (diff)
downloadPROJ-81ec8c0b58d66333fccd3703dab62a11132a0331.tar.gz
PROJ-81ec8c0b58d66333fccd3703dab62a11132a0331.zip
Merge pull request #1203 from rouault/cpp_conversion
Conversion of most C files to C++
Diffstat (limited to 'src')
-rw-r--r--src/4D_api.cpp (renamed from src/proj_4D_api.c)148
-rw-r--r--src/Makefile.am248
-rw-r--r--src/aasincos.cpp (renamed from src/aasincos.c)0
-rw-r--r--src/adjlon.cpp (renamed from src/adjlon.c)0
-rw-r--r--src/apply_gridshift.cpp (renamed from src/pj_apply_gridshift.c)30
-rw-r--r--src/apply_vgridshift.cpp (renamed from src/pj_apply_vgridshift.c)16
-rw-r--r--src/apps/cct.cpp (renamed from src/cct.c)30
-rw-r--r--src/apps/cs2cs.cpp (renamed from src/cs2cs.cpp)0
-rw-r--r--src/apps/emess.cpp (renamed from src/emess.c)4
-rw-r--r--src/apps/emess.h (renamed from src/emess.h)14
-rw-r--r--src/apps/gen_cheb.cpp (renamed from src/gen_cheb.c)42
-rw-r--r--src/apps/geod.cpp (renamed from src/geod.c)24
-rw-r--r--src/apps/geod_interface.cpp (renamed from src/geod_interface.c)0
-rw-r--r--src/apps/geod_interface.h (renamed from src/geod_interface.h)0
-rw-r--r--src/apps/geod_set.cpp (renamed from src/geod_set.c)30
-rw-r--r--src/apps/gie.cpp (renamed from src/gie.c)72
-rw-r--r--src/apps/nad2bin.cpp (renamed from src/nad2bin.c)8
-rw-r--r--src/apps/optargpm.h (renamed from src/optargpm.h)100
-rw-r--r--src/apps/p_series.cpp (renamed from src/p_series.c)0
-rw-r--r--src/apps/proj.cpp (renamed from src/proj.c)27
-rw-r--r--src/apps/proj_strtod.cpp (renamed from src/proj_strtod.c)14
-rw-r--r--src/apps/proj_strtod.h (renamed from src/proj_strtod.h)0
-rw-r--r--src/apps/projinfo.cpp (renamed from src/projinfo.cpp)2
-rw-r--r--src/auth.cpp (renamed from src/pj_auth.c)2
-rw-r--r--src/bch2bps.cpp (renamed from src/bch2bps.c)0
-rw-r--r--src/bchgen.cpp (renamed from src/bchgen.c)0
-rw-r--r--src/bin_cct.cmake4
-rw-r--r--src/bin_cs2cs.cmake8
-rw-r--r--src/bin_geod.cmake9
-rw-r--r--src/bin_geodtest.cmake2
-rw-r--r--src/bin_gie.cmake6
-rw-r--r--src/bin_nad2bin.cmake2
-rw-r--r--src/bin_proj.cmake8
-rw-r--r--src/bin_projinfo.cmake2
-rw-r--r--src/biveval.cpp (renamed from src/biveval.c)0
-rw-r--r--src/conversions/axisswap.cpp (renamed from src/PJ_axisswap.c)10
-rw-r--r--src/conversions/cart.cpp (renamed from src/PJ_cart.c)0
-rw-r--r--src/conversions/geoc.cpp (renamed from src/PJ_geoc.c)0
-rw-r--r--src/conversions/geocent.cpp (renamed from src/pj_geocent.c)0
-rw-r--r--src/conversions/unitconvert.cpp (renamed from src/PJ_unitconvert.c)40
-rw-r--r--src/ctx.cpp (renamed from src/pj_ctx.c)36
-rw-r--r--src/datum_set.cpp (renamed from src/pj_datum_set.c)10
-rw-r--r--src/datums.cpp (renamed from src/pj_datums.c)4
-rw-r--r--src/deriv.cpp (renamed from src/pj_deriv.c)2
-rw-r--r--src/dmstor.cpp (renamed from src/dmstor.c)3
-rw-r--r--src/ell_set.cpp (renamed from src/pj_ell_set.c)56
-rw-r--r--src/ellps.cpp (renamed from src/pj_ellps.c)2
-rw-r--r--src/errno.cpp (renamed from src/pj_errno.c)2
-rw-r--r--src/factors.cpp (renamed from src/pj_factors.c)4
-rw-r--r--src/fileapi.cpp (renamed from src/pj_fileapi.c)8
-rw-r--r--src/fwd.cpp (renamed from src/pj_fwd.c)2
-rw-r--r--src/gauss.cpp (renamed from src/pj_gauss.c)8
-rw-r--r--src/gc_reader.cpp (renamed from src/pj_gc_reader.c)26
-rw-r--r--src/geocent.cpp (renamed from src/geocent.c)0
-rw-r--r--src/geodesic.c90
-rw-r--r--src/gridcatalog.cpp (renamed from src/pj_gridcatalog.c)42
-rw-r--r--src/gridinfo.cpp (renamed from src/pj_gridinfo.c)64
-rw-r--r--src/gridlist.cpp (renamed from src/pj_gridlist.c)26
-rw-r--r--src/init.cpp (renamed from src/pj_init.c)228
-rw-r--r--src/initcache.cpp (renamed from src/pj_initcache.c)22
-rw-r--r--src/internal.cpp639
-rw-r--r--src/inv.cpp (renamed from src/pj_inv.c)2
-rw-r--r--src/iso19111/c_api.cpp (renamed from src/c_api.cpp)0
-rw-r--r--src/iso19111/common.cpp (renamed from src/common.cpp)0
-rw-r--r--src/iso19111/coordinateoperation.cpp (renamed from src/coordinateoperation.cpp)0
-rw-r--r--src/iso19111/coordinatesystem.cpp (renamed from src/coordinatesystem.cpp)0
-rw-r--r--src/iso19111/crs.cpp (renamed from src/crs.cpp)0
-rw-r--r--src/iso19111/datum.cpp (renamed from src/datum.cpp)0
-rw-r--r--src/iso19111/factory.cpp (renamed from src/factory.cpp)0
-rw-r--r--src/iso19111/internal.cpp374
-rw-r--r--src/iso19111/io.cpp (renamed from src/io.cpp)4
-rw-r--r--src/iso19111/metadata.cpp (renamed from src/metadata.cpp)0
-rw-r--r--src/iso19111/static.cpp (renamed from src/static.cpp)0
-rw-r--r--src/iso19111/util.cpp (renamed from src/util.cpp)0
-rw-r--r--src/jniproj.cpp (renamed from src/jniproj.c)0
-rw-r--r--src/lib_proj.cmake387
-rw-r--r--src/list.cpp (renamed from src/pj_list.c)6
-rw-r--r--src/log.cpp (renamed from src/pj_log.c)2
-rw-r--r--src/malloc.cpp (renamed from src/pj_malloc.c)27
-rw-r--r--src/math.cpp (renamed from src/pj_math.c)0
-rw-r--r--src/mk_cheby.cpp (renamed from src/mk_cheby.c)22
-rw-r--r--src/mlfn.cpp (renamed from src/pj_mlfn.c)4
-rw-r--r--src/msfn.cpp (renamed from src/pj_msfn.c)0
-rw-r--r--src/mutex.cpp (renamed from src/pj_mutex.c)9
-rw-r--r--src/nad_cvt.cpp (renamed from src/nad_cvt.c)0
-rw-r--r--src/nad_init.cpp (renamed from src/nad_init.c)38
-rw-r--r--src/nad_intr.cpp (renamed from src/nad_intr.c)0
-rw-r--r--src/open_lib.cpp (renamed from src/pj_open_lib.c)40
-rw-r--r--src/param.cpp (renamed from src/pj_param.c)36
-rw-r--r--src/phi2.cpp (renamed from src/pj_phi2.c)0
-rw-r--r--src/pipeline.cpp (renamed from src/PJ_pipeline.c)118
-rw-r--r--src/pj_internal.c445
-rw-r--r--src/pr_list.cpp (renamed from src/pj_pr_list.c)4
-rw-r--r--src/proj.h4
-rw-r--r--src/proj_mdist.cpp (renamed from src/proj_mdist.c)6
-rw-r--r--src/projections/aea.cpp (renamed from src/PJ_aea.c)26
-rw-r--r--src/projections/aeqd.cpp (renamed from src/PJ_aeqd.c)30
-rw-r--r--src/projections/airy.cpp (renamed from src/PJ_airy.c)10
-rw-r--r--src/projections/aitoff.cpp (renamed from src/PJ_aitoff.c)16
-rw-r--r--src/projections/august.cpp (renamed from src/PJ_august.c)2
-rw-r--r--src/projections/bacon.cpp (renamed from src/PJ_bacon.c)16
-rw-r--r--src/projections/bertin1953.cpp (renamed from src/PJ_bertin1953.c)8
-rw-r--r--src/projections/bipc.cpp (renamed from src/PJ_bipc.c)10
-rw-r--r--src/projections/boggs.cpp (renamed from src/PJ_boggs.c)0
-rw-r--r--src/projections/bonne.cpp (renamed from src/PJ_bonne.c)26
-rw-r--r--src/projections/calcofi.cpp (renamed from src/PJ_calcofi.c)2
-rw-r--r--src/projections/cass.cpp (renamed from src/PJ_cass.c)26
-rw-r--r--src/projections/cc.cpp (renamed from src/PJ_cc.c)0
-rw-r--r--src/projections/ccon.cpp (renamed from src/PJ_ccon.c)20
-rw-r--r--src/projections/cea.cpp (renamed from src/PJ_cea.c)18
-rw-r--r--src/projections/chamb.cpp (renamed from src/PJ_chamb.c)8
-rw-r--r--src/projections/collg.cpp (renamed from src/PJ_collg.c)0
-rw-r--r--src/projections/comill.cpp (renamed from src/PJ_comill.c)0
-rw-r--r--src/projections/crast.cpp (renamed from src/PJ_crast.c)0
-rw-r--r--src/projections/denoy.cpp (renamed from src/PJ_denoy.c)0
-rw-r--r--src/projections/eck1.cpp (renamed from src/PJ_eck1.c)0
-rw-r--r--src/projections/eck2.cpp (renamed from src/PJ_eck2.c)0
-rw-r--r--src/projections/eck3.cpp (renamed from src/PJ_eck3.c)22
-rw-r--r--src/projections/eck4.cpp (renamed from src/PJ_eck4.c)0
-rw-r--r--src/projections/eck5.cpp (renamed from src/PJ_eck5.c)0
-rw-r--r--src/projections/eqc.cpp (renamed from src/PJ_eqc.c)10
-rw-r--r--src/projections/eqdc.cpp (renamed from src/PJ_eqdc.c)20
-rw-r--r--src/projections/eqearth.cpp (renamed from src/PJ_eqearth.c)22
-rw-r--r--src/projections/etmerc.cpp (renamed from src/proj_etmerc.c)16
-rw-r--r--src/projections/fahey.cpp (renamed from src/PJ_fahey.c)0
-rw-r--r--src/projections/fouc_s.cpp (renamed from src/PJ_fouc_s.c)10
-rw-r--r--src/projections/gall.cpp (renamed from src/PJ_gall.c)0
-rw-r--r--src/projections/geos.cpp (renamed from src/PJ_geos.c)16
-rw-r--r--src/projections/gins8.cpp (renamed from src/PJ_gins8.c)2
-rw-r--r--src/projections/gn_sinu.cpp (renamed from src/PJ_gn_sinu.c)38
-rw-r--r--src/projections/gnom.cpp (renamed from src/PJ_gnom.c)12
-rw-r--r--src/projections/goode.cpp (renamed from src/PJ_goode.c)24
-rw-r--r--src/projections/gstmerc.cpp (renamed from src/PJ_gstmerc.c)10
-rw-r--r--src/projections/hammer.cpp (renamed from src/PJ_hammer.c)10
-rw-r--r--src/projections/hatano.cpp (renamed from src/PJ_hatano.c)0
-rw-r--r--src/projections/healpix.cpp (renamed from src/PJ_healpix.c)58
-rw-r--r--src/projections/igh.cpp (renamed from src/PJ_igh.c)24
-rw-r--r--src/projections/imw_p.cpp (renamed from src/PJ_imw_p.c)28
-rw-r--r--src/projections/isea.cpp (renamed from src/PJ_isea.c)22
-rw-r--r--src/projections/krovak.cpp (renamed from src/PJ_krovak.c)10
-rw-r--r--src/projections/labrd.cpp (renamed from src/PJ_labrd.c)10
-rw-r--r--src/projections/laea.cpp (renamed from src/PJ_laea.c)28
-rw-r--r--src/projections/lagrng.cpp (renamed from src/PJ_lagrng.c)10
-rw-r--r--src/projections/larr.cpp (renamed from src/PJ_larr.c)0
-rw-r--r--src/projections/lask.cpp (renamed from src/PJ_lask.c)0
-rw-r--r--src/projections/latlong.cpp (renamed from src/PJ_latlong.c)0
-rw-r--r--src/projections/lcc.cpp (renamed from src/PJ_lcc.c)10
-rw-r--r--src/projections/lcca.cpp (renamed from src/PJ_lcca.c)20
-rw-r--r--src/projections/loxim.cpp (renamed from src/PJ_loxim.c)10
-rw-r--r--src/projections/lsat.cpp (renamed from src/PJ_lsat.c)12
-rw-r--r--src/projections/mbt_fps.cpp (renamed from src/PJ_mbt_fps.c)0
-rw-r--r--src/projections/mbtfpp.cpp (renamed from src/PJ_mbtfpp.c)0
-rw-r--r--src/projections/mbtfpq.cpp (renamed from src/PJ_mbtfpq.c)0
-rw-r--r--src/projections/merc.cpp (renamed from src/PJ_merc.c)0
-rw-r--r--src/projections/mill.cpp (renamed from src/PJ_mill.c)0
-rw-r--r--src/projections/misrsom.cpp (renamed from src/PJ_misrsom.c)12
-rw-r--r--src/projections/mod_ster.cpp (renamed from src/PJ_mod_ster.c)28
-rw-r--r--src/projections/moll.cpp (renamed from src/PJ_moll.c)20
-rw-r--r--src/projections/natearth.cpp (renamed from src/PJ_natearth.c)0
-rw-r--r--src/projections/natearth2.cpp (renamed from src/PJ_natearth2.c)0
-rw-r--r--src/projections/nell.cpp (renamed from src/PJ_nell.c)0
-rw-r--r--src/projections/nell_h.cpp (renamed from src/PJ_nell_h.c)0
-rw-r--r--src/projections/nicol.cpp (renamed from src/PJ_nocol.c)0
-rw-r--r--src/projections/nsper.cpp (renamed from src/PJ_nsper.c)18
-rw-r--r--src/projections/nzmg.cpp (renamed from src/PJ_nzmg.c)0
-rw-r--r--src/projections/ob_tran.cpp (renamed from src/PJ_ob_tran.c)46
-rw-r--r--src/projections/ocea.cpp (renamed from src/PJ_ocea.c)10
-rw-r--r--src/projections/oea.cpp (renamed from src/PJ_oea.c)10
-rw-r--r--src/projections/omerc.cpp (renamed from src/PJ_omerc.c)10
-rw-r--r--src/projections/ortho.cpp (renamed from src/PJ_ortho.c)12
-rw-r--r--src/projections/patterson.cpp (renamed from src/PJ_patterson.c)0
-rw-r--r--src/projections/poly.cpp (renamed from src/PJ_poly.c)24
-rw-r--r--src/projections/putp2.cpp (renamed from src/PJ_putp2.c)0
-rw-r--r--src/projections/putp3.cpp (renamed from src/PJ_putp3.c)14
-rw-r--r--src/projections/putp4p.cpp (renamed from src/PJ_putp4p.c)14
-rw-r--r--src/projections/putp5.cpp (renamed from src/PJ_putp5.c)14
-rw-r--r--src/projections/putp6.cpp (renamed from src/PJ_putp6.c)14
-rw-r--r--src/projections/qsc.cpp (renamed from src/PJ_qsc.c)14
-rw-r--r--src/projections/robin.cpp (renamed from src/PJ_robin.c)2
-rw-r--r--src/projections/rouss.cpp (renamed from src/proj_rouss.c)22
-rw-r--r--src/projections/rpoly.cpp (renamed from src/PJ_rpoly.c)8
-rw-r--r--src/projections/sch.cpp (renamed from src/PJ_sch.c)12
-rw-r--r--src/projections/sconics.cpp (renamed from src/PJ_sconics.c)16
-rw-r--r--src/projections/somerc.cpp (renamed from src/PJ_somerc.c)10
-rw-r--r--src/projections/stere.cpp (renamed from src/PJ_stere.c)26
-rw-r--r--src/projections/sterea.cpp (renamed from src/PJ_sterea.c)22
-rw-r--r--src/projections/sts.cpp (renamed from src/PJ_sts.c)30
-rw-r--r--src/projections/tcc.cpp (renamed from src/PJ_tcc.c)2
-rw-r--r--src/projections/tcea.cpp (renamed from src/PJ_tcea.c)0
-rw-r--r--src/projections/times.cpp (renamed from src/PJ_times.c)0
-rw-r--r--src/projections/tmerc.cpp (renamed from src/PJ_tmerc.c)30
-rw-r--r--src/projections/tobmerc.cpp (renamed from src/PJ_tobmerc.c)0
-rw-r--r--src/projections/tpeqd.cpp (renamed from src/PJ_tpeqd.c)10
-rw-r--r--src/projections/urm5.cpp (renamed from src/PJ_urm5.c)10
-rw-r--r--src/projections/urmfps.cpp (renamed from src/PJ_urmfps.c)26
-rw-r--r--src/projections/vandg.cpp (renamed from src/PJ_vandg.c)0
-rw-r--r--src/projections/vandg2.cpp (renamed from src/PJ_vandg2.c)12
-rw-r--r--src/projections/vandg4.cpp (renamed from src/PJ_vandg4.c)0
-rw-r--r--src/projections/wag2.cpp (renamed from src/PJ_wag2.c)0
-rw-r--r--src/projections/wag3.cpp (renamed from src/PJ_wag3.c)12
-rw-r--r--src/projections/wag7.cpp (renamed from src/PJ_wag7.c)2
-rw-r--r--src/projections/wink1.cpp (renamed from src/PJ_wink1.c)12
-rw-r--r--src/projections/wink2.cpp (renamed from src/PJ_wink2.c)16
-rw-r--r--src/projects.h19
-rw-r--r--src/qsfn.cpp (renamed from src/pj_qsfn.c)0
-rw-r--r--src/release.cpp (renamed from src/pj_release.c)0
-rw-r--r--src/rtodms.cpp (renamed from src/rtodms.c)0
-rw-r--r--src/strerrno.cpp (renamed from src/pj_strerrno.c)2
-rw-r--r--src/strtod.cpp (renamed from src/pj_strtod.c)4
-rw-r--r--src/tests/geodtest.cpp (renamed from src/geodtest.c)114
-rw-r--r--src/tests/multistresstest.cpp (renamed from src/multistresstest.c)12
-rw-r--r--src/tests/test228.cpp (renamed from src/test228.c)8
-rw-r--r--src/transform.cpp (renamed from src/pj_transform.c)107
-rw-r--r--src/transformations/affine.cpp (renamed from src/PJ_affine.c)20
-rw-r--r--src/transformations/deformation.cpp (renamed from src/PJ_deformation.c)26
-rw-r--r--src/transformations/helmert.cpp (renamed from src/PJ_helmert.c)14
-rw-r--r--src/transformations/hgridshift.cpp (renamed from src/PJ_hgridshift.c)14
-rw-r--r--src/transformations/horner.cpp (renamed from src/PJ_horner.c)80
-rw-r--r--src/transformations/molodensky.cpp (renamed from src/PJ_molodensky.c)6
-rw-r--r--src/transformations/vgridshift.cpp (renamed from src/PJ_vgridshift.c)14
-rw-r--r--src/tsfn.cpp (renamed from src/pj_tsfn.c)0
-rw-r--r--src/units.cpp (renamed from src/pj_units.c)4
-rw-r--r--src/utils.cpp (renamed from src/pj_utils.c)6
-rw-r--r--src/vector1.cpp (renamed from src/vector1.c)4
-rw-r--r--src/wkt1_generated_parser.c (renamed from src/pj_wkt1_generated_parser.c)10
-rw-r--r--src/wkt1_generated_parser.h (renamed from src/pj_wkt1_generated_parser.h)6
-rw-r--r--src/wkt1_grammar.y (renamed from src/pj_wkt1_grammar.y)2
-rw-r--r--src/wkt1_parser.cpp (renamed from src/pj_wkt1_parser.cpp)4
-rw-r--r--src/wkt1_parser.h (renamed from src/pj_wkt1_parser.h)2
-rw-r--r--src/wkt2_generated_parser.c (renamed from src/pj_wkt2_generated_parser.c)10
-rw-r--r--src/wkt2_generated_parser.h (renamed from src/pj_wkt2_generated_parser.h)6
-rw-r--r--src/wkt2_grammar.y (renamed from src/pj_wkt2_grammar.y)2
-rw-r--r--src/wkt2_parser.cpp (renamed from src/pj_wkt2_parser.cpp)4
-rw-r--r--src/wkt2_parser.h (renamed from src/pj_wkt2_parser.h)2
-rw-r--r--src/wkt_parser.cpp (renamed from src/pj_wkt_parser.cpp)2
-rw-r--r--src/wkt_parser.hpp (renamed from src/pj_wkt_parser.hpp)0
-rw-r--r--src/zpoly1.cpp (renamed from src/pj_zpoly1.c)0
237 files changed, 2881 insertions, 2539 deletions
diff --git a/src/proj_4D_api.c b/src/4D_api.cpp
index 75a061a0..88210348 100644
--- a/src/proj_4D_api.c
+++ b/src/4D_api.cpp
@@ -53,6 +53,10 @@ PJ_COORD proj_coord (double x, double y, double z, double t) {
return res;
}
+static PJ_DIRECTION opposite_direction(PJ_DIRECTION dir) {
+ return static_cast<PJ_DIRECTION>(-dir);
+}
+
/*****************************************************************************/
int proj_angular_input (PJ *P, enum PJ_DIRECTION dir) {
/******************************************************************************
@@ -72,7 +76,7 @@ int proj_angular_output (PJ *P, enum PJ_DIRECTION dir) {
operating in direction dir, 0 otherwise.
dir: {PJ_FWD, PJ_INV}
******************************************************************************/
- return proj_angular_input (P, -dir);
+ return proj_angular_input (P, opposite_direction(dir));
}
@@ -126,7 +130,7 @@ double proj_roundtrip (PJ *P, PJ_DIRECTION direction, int n, PJ_COORD *coord) {
int i;
PJ_COORD t, org;
- if (0==P)
+ if (nullptr==P)
return HUGE_VAL;
if (n < 1) {
@@ -142,10 +146,10 @@ double proj_roundtrip (PJ *P, PJ_DIRECTION direction, int n, PJ_COORD *coord) {
/* now we take n-1 full steps in inverse direction: We are */
/* out of phase due to the half step already taken */
for (i = 0; i < n - 1; i++)
- t = proj_trans (P, direction, proj_trans (P, -direction, t) );
+ t = proj_trans (P, direction, proj_trans (P, opposite_direction(direction), t) );
/* finally, we take the last half-step */
- t = proj_trans (P, -direction, t);
+ t = proj_trans (P, opposite_direction(direction), t);
/* checking for angular *input* since we do a roundtrip, and end where we begin */
if (proj_angular_input (P, direction))
@@ -165,10 +169,10 @@ available.
See also pj_approx_2D_trans and pj_approx_3D_trans in pj_internal.c, which work
similarly, but prefers the 2D resp. 3D interfaces if available.
***************************************************************************************/
- if (0==P)
+ if (nullptr==P)
return coord;
if (P->inverted)
- direction = -direction;
+ direction = opposite_direction(direction);
switch (direction) {
case PJ_FWD:
@@ -270,17 +274,17 @@ size_t proj_trans_generic (
size_t i, nmin;
double null_broadcast = 0;
- if (0==P)
+ if (nullptr==P)
return 0;
if (P->inverted)
- direction = -direction;
+ direction = opposite_direction(direction);
/* ignore lengths of null arrays */
- if (0==x) nx = 0;
- if (0==y) ny = 0;
- if (0==z) nz = 0;
- if (0==t) nt = 0;
+ if (nullptr==x) nx = 0;
+ if (nullptr==y) ny = 0;
+ if (nullptr==z) nz = 0;
+ if (nullptr==t) nt = 0;
/* and make the nullities point to some real world memory for broadcasting nulls */
if (0==nx) x = &null_broadcast;
@@ -429,7 +433,7 @@ Returns 1 on success, 0 on failure
PJ *Q;
paralist *p;
int do_cart = 0;
- if (0==P)
+ if (nullptr==P)
return 0;
/* Don't recurse when calling proj_create (which calls us back) */
@@ -441,13 +445,13 @@ Returns 1 on success, 0 on failure
/* Don't axisswap if data are already in "enu" order */
if (p && (0!=strcmp ("enu", p->param))) {
- char *def = malloc (100+strlen(P->axis));
- if (0==def)
+ char *def = static_cast<char*>(malloc (100+strlen(P->axis)));
+ if (nullptr==def)
return 0;
sprintf (def, "break_cs2cs_recursion proj=axisswap axis=%s", P->axis);
Q = proj_create (P->ctx, def);
free (def);
- if (0==Q)
+ if (nullptr==Q)
return 0;
P->axisswap = skip_prep_fin(Q);
}
@@ -456,13 +460,13 @@ Returns 1 on success, 0 on failure
p = pj_param_exists (P->params, "geoidgrids");
if (p && strlen (p->param) > strlen ("geoidgrids=")) {
char *gridnames = p->param + strlen ("geoidgrids=");
- char *def = malloc (100+strlen(gridnames));
- if (0==def)
+ char *def = static_cast<char*>(malloc (100+strlen(gridnames)));
+ if (nullptr==def)
return 0;
sprintf (def, "break_cs2cs_recursion proj=vgridshift grids=%s", gridnames);
Q = proj_create (P->ctx, def);
free (def);
- if (0==Q)
+ if (nullptr==Q)
return 0;
P->vgridshift = skip_prep_fin(Q);
}
@@ -471,19 +475,19 @@ Returns 1 on success, 0 on failure
p = pj_param_exists (P->params, "nadgrids");
if (p && strlen (p->param) > strlen ("nadgrids=")) {
char *gridnames = p->param + strlen ("nadgrids=");
- char *def = malloc (100+strlen(gridnames));
- if (0==def)
+ char *def = static_cast<char*>(malloc (100+strlen(gridnames)));
+ if (nullptr==def)
return 0;
sprintf (def, "break_cs2cs_recursion proj=hgridshift grids=%s", gridnames);
Q = proj_create (P->ctx, def);
free (def);
- if (0==Q)
+ if (nullptr==Q)
return 0;
P->hgridshift = skip_prep_fin(Q);
}
/* We ignore helmert if we have grid shift */
- p = P->hgridshift ? 0 : pj_param_exists (P->params, "towgs84");
+ p = P->hgridshift ? nullptr : pj_param_exists (P->params, "towgs84");
while (p) {
char *def;
char *s = p->param;
@@ -503,13 +507,13 @@ Returns 1 on success, 0 on failure
if (n <= 8) /* 8==strlen ("towgs84=") */
return 0;
- def = malloc (100+n);
- if (0==def)
+ def = static_cast<char*>(malloc (100+n));
+ if (nullptr==def)
return 0;
sprintf (def, "break_cs2cs_recursion proj=helmert exact %s convention=position_vector", s);
Q = proj_create (P->ctx, def);
free(def);
- if (0==Q)
+ if (nullptr==Q)
return 0;
pj_inherit_ellipsoid_def (P, Q);
P->helmert = skip_prep_fin (Q);
@@ -529,19 +533,19 @@ Returns 1 on success, 0 on failure
/* TODO later: use C++ ostringstream with imbue(std::locale::classic()) */
/* to be locale unaware */
char* next_pos;
- for (next_pos = def; (next_pos = strchr (next_pos, ',')) != NULL; next_pos++) {
+ for (next_pos = def; (next_pos = strchr (next_pos, ',')) != nullptr; next_pos++) {
*next_pos = '.';
}
}
Q = proj_create (P->ctx, def);
- if (0==Q)
+ if (nullptr==Q)
return 0;
P->cart = skip_prep_fin (Q);
if (!P->is_geocent) {
sprintf (def, "break_cs2cs_recursion proj=cart ellps=WGS84");
Q = proj_create (P->ctx, def);
- if (0==Q)
+ if (nullptr==Q)
return 0;
P->cart_wgs84 = skip_prep_fin (Q);
}
@@ -569,15 +573,15 @@ PJ *proj_create (PJ_CONTEXT *ctx, const char *definition) {
int ret;
int allow_init_epsg;
- if (0==ctx)
+ if (nullptr==ctx)
ctx = pj_get_default_ctx ();
/* Make a copy that we can manipulate */
n = strlen (definition);
args = (char *) malloc (n + 1);
- if (0==args) {
+ if (nullptr==args) {
proj_context_errno_set(ctx, ENOMEM);
- return 0;
+ return nullptr;
}
strcpy (args, definition);
@@ -585,7 +589,7 @@ PJ *proj_create (PJ_CONTEXT *ctx, const char *definition) {
if (argc==0) {
pj_dealloc (args);
proj_context_errno_set(ctx, PJD_ERR_NO_ARGS);
- return 0;
+ return nullptr;
}
argv = pj_trim_argv (argc, args);
@@ -620,18 +624,18 @@ indicator, as in {"+proj=utm", "+zone=32"}, or leave it out, as in {"proj=utm",
PJ *P;
const char *c;
- if (0==ctx)
+ if (nullptr==ctx)
ctx = pj_get_default_ctx ();
- if (0==argv) {
+ if (nullptr==argv) {
proj_context_errno_set(ctx, PJD_ERR_NO_ARGS);
- return 0;
+ return nullptr;
}
/* We assume that free format is used, and build a full proj_create compatible string */
c = pj_make_args (argc, argv);
- if (0==c) {
+ if (nullptr==c) {
proj_context_errno_set(ctx, ENOMEM);
- return 0;
+ return nullptr;
}
P = proj_create (ctx, c);
@@ -642,7 +646,7 @@ indicator, as in {"+proj=utm", "+zone=32"}, or leave it out, as in {"proj=utm",
/** Create an area of use */
PJ_AREA * proj_area_create(void) {
- return pj_calloc(1, sizeof(PJ_AREA));
+ return static_cast<PJ_AREA*>(pj_calloc(1, sizeof(PJ_AREA)));
}
/** Assign a bounding box to an area of use. */
@@ -668,7 +672,7 @@ void proj_area_destroy(PJ_AREA* area) {
/************************************************************************/
void proj_context_use_proj4_init_rules(PJ_CONTEXT *ctx, int enable) {
- if( ctx == NULL ) {
+ if( ctx == nullptr ) {
ctx = pj_get_default_ctx();
}
ctx->use_proj4_init_rules = enable;
@@ -693,7 +697,7 @@ static int EQUAL(const char* a, const char* b) {
int proj_context_get_use_proj4_init_rules(PJ_CONTEXT *ctx, int from_legacy_code_path) {
const char* val = getenv("PROJ_USE_PROJ4_INIT_RULES");
- if( ctx == NULL ) {
+ if( ctx == nullptr ) {
ctx = pj_get_default_ctx();
}
@@ -747,26 +751,26 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
PJ_OBJ_LIST* op_list;
PJ_OBJ* op;
const char* proj_string;
- const char* const optionsProj4Mode[] = { "USE_PROJ4_INIT_RULES=YES", NULL };
+ const char* const optionsProj4Mode[] = { "USE_PROJ4_INIT_RULES=YES", nullptr };
const char* const* optionsImportCRS =
- proj_context_get_use_proj4_init_rules(ctx, FALSE) ? optionsProj4Mode : NULL;
+ proj_context_get_use_proj4_init_rules(ctx, FALSE) ? optionsProj4Mode : nullptr;
src = proj_obj_create_from_user_input(ctx, source_crs, optionsImportCRS);
if( !src ) {
- return NULL;
+ return nullptr;
}
dst = proj_obj_create_from_user_input(ctx, target_crs, optionsImportCRS);
if( !dst ) {
proj_obj_destroy(src);
- return NULL;
+ return nullptr;
}
- operation_ctx = proj_create_operation_factory_context(ctx, NULL);
+ operation_ctx = proj_create_operation_factory_context(ctx, nullptr);
if( !operation_ctx ) {
proj_obj_destroy(src);
proj_obj_destroy(dst);
- return NULL;
+ return nullptr;
}
if( area && area->bbox_set ) {
@@ -789,24 +793,24 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
proj_obj_destroy(dst);
if( !op_list ) {
- return NULL;
+ return nullptr;
}
if( proj_obj_list_get_count(op_list) == 0 ) {
proj_obj_list_destroy(op_list);
- return NULL;
+ return nullptr;
}
op = proj_obj_list_get(ctx, op_list, 0);
proj_obj_list_destroy(op_list);
if( !op ) {
- return NULL;
+ return nullptr;
}
- proj_string = proj_obj_as_proj_string(ctx, op, PJ_PROJ_5, NULL);
+ proj_string = proj_obj_as_proj_string(ctx, op, PJ_PROJ_5, nullptr);
if( !proj_string) {
proj_obj_destroy(op);
- return NULL;
+ return nullptr;
}
if( proj_string[0] == '\0' ) {
@@ -823,7 +827,7 @@ PJ *proj_create_crs_to_crs (PJ_CONTEXT *ctx, const char *source_crs, const char
PJ *proj_destroy (PJ *P) {
pj_free (P);
- return 0;
+ return nullptr;
}
/*****************************************************************************/
@@ -840,7 +844,7 @@ int proj_context_errno (PJ_CONTEXT *ctx) {
Read an error directly from a context, without going through a PJ
belonging to that context.
******************************************************************************/
- if (0==ctx)
+ if (nullptr==ctx)
ctx = pj_get_default_ctx();
return pj_ctx_get_errno (ctx);
}
@@ -921,15 +925,15 @@ PJ_CONTEXT *proj_context_create (void) {
PJ_CONTEXT *proj_context_destroy (PJ_CONTEXT *ctx) {
- if (0==ctx)
- return 0;
+ if (nullptr==ctx)
+ return nullptr;
/* Trying to free the default context is a no-op (since it is statically allocated) */
if (pj_get_default_ctx ()==ctx)
- return 0;
+ return nullptr;
pj_ctx_free (ctx);
- return 0;
+ return nullptr;
}
@@ -948,32 +952,32 @@ static char *path_append (char *buf, const char *app, size_t *buf_size) {
char *p;
size_t len, applen = 0, buflen = 0;
#ifdef _WIN32
- char *delim = ";";
+ const char *delim = ";";
#else
- char *delim = ":";
+ const char *delim = ":";
#endif
/* Nothing to do? */
- if (0 == app)
+ if (nullptr == app)
return buf;
applen = strlen (app);
if (0 == applen)
return buf;
/* Start checking whether buf is long enough */
- if (0 != buf)
+ if (nullptr != buf)
buflen = strlen (buf);
len = buflen+applen+strlen (delim) + 1;
/* "pj_realloc", so to speak */
if (*buf_size < len) {
- p = pj_calloc (2 * len, sizeof (char));
- if (0==p) {
+ p = static_cast<char*>(pj_calloc (2 * len, sizeof (char)));
+ if (nullptr==p) {
pj_dealloc (buf);
- return 0;
+ return nullptr;
}
*buf_size = 2 * len;
- if (buf != 0)
+ if (buf != nullptr)
strcpy (p, buf);
pj_dealloc (buf);
buf = p;
@@ -988,7 +992,7 @@ static char *path_append (char *buf, const char *app, size_t *buf_size) {
static const char *empty = {""};
static char version[64] = {""};
-static PJ_INFO info = {0, 0, 0, 0, 0, 0, 0, 0};
+static PJ_INFO info = {0, 0, 0, nullptr, nullptr, nullptr, nullptr, 0};
static volatile int info_initialized = 0;
/*****************************************************************************/
@@ -1002,7 +1006,7 @@ PJ_INFO proj_info (void) {
size_t i, n;
size_t buf_size = 0;
- char *buf = 0;
+ char *buf = nullptr;
pj_acquire_lock ();
@@ -1061,7 +1065,7 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) {
/* proj_create_crs_to_crs in a future version that leverages the EPSG database. */
pjinfo.accuracy = -1.0;
- if (0==P)
+ if (nullptr==P)
return pjinfo;
/* projection id */
@@ -1076,7 +1080,7 @@ PJ_PROJ_INFO proj_pj_info(PJ *P) {
def = P->def_full;
else
def = pj_get_def(P, 0); /* pj_get_def takes a non-const PJ pointer */
- if (0==def)
+ if (nullptr==def)
pjinfo.definition = empty;
else
pjinfo.definition = pj_shrink (def);
@@ -1103,7 +1107,7 @@ PJ_GRID_INFO proj_grid_info(const char *gridname) {
memset(&grinfo, 0, sizeof(PJ_GRID_INFO));
/* in case the grid wasn't found */
- if (gridinfo->filename == NULL) {
+ if (gridinfo->filename == nullptr) {
pj_gridinfo_free(ctx, gridinfo);
strcpy(grinfo.format, "missing");
return grinfo;
@@ -1254,7 +1258,7 @@ PJ_FACTORS proj_factors(PJ *P, PJ_COORD lp) {
PJ_FACTORS factors = {0,0,0, 0,0,0, 0,0, 0,0,0,0};
struct FACTORS f;
- if (0==P)
+ if (nullptr==P)
return factors;
if (pj_factors(lp.lp, P, 0.0, &f))
diff --git a/src/Makefile.am b/src/Makefile.am
index f484acd8..e8b9977c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,20 +15,20 @@ include_HEADERS = proj.h proj_experimental.h proj_constants.h proj_api.h geodesi
EXTRA_DIST = bin_cct.cmake bin_gie.cmake bin_cs2cs.cmake \
bin_geod.cmake bin_nad2bin.cmake bin_proj.cmake bin_projinfo.cmake \
- lib_proj.cmake CMakeLists.txt bin_geodtest.cmake geodtest.c \
- pj_wkt1_grammar.y pj_wkt2_grammar.y
+ lib_proj.cmake CMakeLists.txt bin_geodtest.cmake tests/geodtest.cpp \
+ wkt1_grammar.y wkt2_grammar.y apps/emess.h
-proj_SOURCES = proj.c gen_cheb.c p_series.c
-projinfo_SOURCES = projinfo.cpp
-cs2cs_SOURCES = cs2cs.cpp gen_cheb.c p_series.c
-cct_SOURCES = cct.c proj_strtod.c proj_strtod.h optargpm.h
-nad2bin_SOURCES = nad2bin.c
-geod_SOURCES = geod.c geod_set.c geod_interface.c geod_interface.h
+proj_SOURCES = apps/proj.cpp apps/gen_cheb.cpp apps/p_series.cpp apps/emess.cpp
+projinfo_SOURCES = apps/projinfo.cpp
+cs2cs_SOURCES = apps/cs2cs.cpp apps/gen_cheb.cpp apps/p_series.cpp apps/emess.cpp
+cct_SOURCES = apps/cct.cpp apps/proj_strtod.cpp apps/proj_strtod.h apps/optargpm.h
+nad2bin_SOURCES = apps/nad2bin.cpp
+geod_SOURCES = apps/geod.cpp apps/geod_set.cpp apps/geod_interface.cpp apps/geod_interface.h apps/emess.cpp
-gie_SOURCES = gie.c proj_strtod.c proj_strtod.h optargpm.h
-multistresstest_SOURCES = multistresstest.c
-test228_SOURCES = test228.c
-geodtest_SOURCES = geodtest.c
+gie_SOURCES = apps/gie.cpp apps/proj_strtod.cpp apps/proj_strtod.h apps/optargpm.h
+multistresstest_SOURCES = tests/multistresstest.cpp
+test228_SOURCES = tests/test228.cpp
+geodtest_SOURCES = tests/geodtest.cpp
cct_LDADD = libproj.la
cs2cs_LDADD = libproj.la
@@ -48,71 +48,181 @@ libproj_la_LDFLAGS = -no-undefined -version-info 14:1:1
libproj_la_LIBADD = @SQLITE3_LDFLAGS@
libproj_la_SOURCES = \
- pj_list.h proj_internal.h proj_math.h projects.h\
- static.cpp util.cpp metadata.cpp common.cpp crs.cpp datum.cpp coordinatesystem.cpp coordinateoperation.cpp io.cpp \
- internal.cpp factory.cpp c_api.cpp \
- PJ_aeqd.c PJ_gnom.c PJ_laea.c PJ_mod_ster.c \
- PJ_nsper.c PJ_nzmg.c PJ_ortho.c PJ_stere.c PJ_sterea.c \
- PJ_aea.c PJ_bipc.c PJ_bonne.c PJ_eqdc.c PJ_isea.c PJ_ccon.c\
- PJ_imw_p.c PJ_krovak.c PJ_lcc.c PJ_poly.c \
- PJ_rpoly.c PJ_sconics.c proj_rouss.c \
- PJ_cass.c PJ_cc.c PJ_cea.c PJ_eqc.c PJ_gall.c PJ_geoc.c \
- PJ_labrd.c PJ_lsat.c PJ_misrsom.c PJ_merc.c \
- PJ_mill.c PJ_ocea.c PJ_omerc.c PJ_somerc.c \
- PJ_tcc.c PJ_tcea.c PJ_times.c PJ_tmerc.c PJ_tobmerc.c \
- PJ_airy.c PJ_aitoff.c PJ_august.c PJ_bacon.c \
- PJ_bertin1953.c PJ_chamb.c PJ_hammer.c PJ_lagrng.c PJ_larr.c \
- PJ_lask.c PJ_latlong.c PJ_nocol.c PJ_ob_tran.c PJ_oea.c \
- PJ_tpeqd.c PJ_vandg.c PJ_vandg2.c PJ_vandg4.c \
- PJ_wag7.c PJ_lcca.c PJ_geos.c proj_etmerc.c \
- PJ_boggs.c PJ_collg.c PJ_comill.c PJ_crast.c PJ_denoy.c \
- PJ_eck1.c PJ_eck2.c PJ_eck3.c PJ_eck4.c \
- PJ_eck5.c PJ_fahey.c PJ_fouc_s.c PJ_gins8.c PJ_gstmerc.c \
- PJ_gn_sinu.c PJ_goode.c PJ_igh.c PJ_hatano.c PJ_loxim.c \
- PJ_mbt_fps.c PJ_mbtfpp.c PJ_mbtfpq.c PJ_moll.c \
- PJ_nell.c PJ_nell_h.c PJ_patterson.c PJ_putp2.c PJ_putp3.c \
- PJ_putp4p.c PJ_putp5.c PJ_putp6.c PJ_qsc.c PJ_robin.c \
- PJ_sch.c PJ_sts.c PJ_urm5.c PJ_urmfps.c PJ_wag2.c \
- PJ_wag3.c PJ_wink1.c PJ_wink2.c pj_geocent.c \
- aasincos.c adjlon.c bch2bps.c bchgen.c \
- biveval.c dmstor.c mk_cheby.c pj_auth.c \
- pj_deriv.c pj_ell_set.c pj_ellps.c pj_errno.c \
- pj_factors.c pj_fwd.c pj_init.c pj_inv.c \
- pj_list.c pj_malloc.c pj_mlfn.c pj_msfn.c proj_mdist.c \
- pj_open_lib.c pj_param.c pj_phi2.c pj_pr_list.c \
- pj_qsfn.c pj_strerrno.c \
- pj_tsfn.c pj_units.c pj_ctx.c pj_log.c pj_zpoly1.c rtodms.c \
- vector1.c pj_release.c pj_gauss.c \
- PJ_healpix.c PJ_natearth.c PJ_natearth2.c PJ_calcofi.c pj_fileapi.c \
- PJ_eqearth.c \
+ pj_list.h proj_internal.h proj_math.h projects.h \
\
- pj_gc_reader.c pj_gridcatalog.c \
- nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \
- pj_apply_gridshift.c pj_datums.c pj_datum_set.c pj_transform.c \
- geocent.c geocent.h pj_utils.c pj_gridinfo.c pj_gridlist.c \
- jniproj.c pj_mutex.c pj_initcache.c pj_apply_vgridshift.c geodesic.c \
- pj_strtod.c pj_math.c\
+ iso19111/static.cpp \
+ iso19111/util.cpp \
+ iso19111/metadata.cpp \
+ iso19111/common.cpp \
+ iso19111/crs.cpp \
+ iso19111/datum.cpp \
+ iso19111/coordinatesystem.cpp \
+ iso19111/coordinateoperation.cpp \
+ iso19111/io.cpp \
+ iso19111/internal.cpp \
+ iso19111/factory.cpp \
+ iso19111/c_api.cpp \
\
- proj_4D_api.c PJ_cart.c PJ_pipeline.c PJ_horner.c PJ_helmert.c \
- PJ_vgridshift.c PJ_hgridshift.c PJ_unitconvert.c PJ_molodensky.c \
- PJ_deformation.c pj_internal.c PJ_axisswap.c PJ_affine.c \
- pj_wkt_parser.hpp pj_wkt_parser.cpp \
- pj_wkt1_parser.h pj_wkt1_parser.cpp \
- pj_wkt1_generated_parser.h pj_wkt1_generated_parser.c \
- pj_wkt2_parser.h pj_wkt2_parser.cpp \
- pj_wkt2_generated_parser.h pj_wkt2_generated_parser.c
+ projections/aeqd.cpp \
+ projections/gnom.cpp \
+ projections/laea.cpp \
+ projections/mod_ster.cpp \
+ projections/nsper.cpp \
+ projections/nzmg.cpp \
+ projections/ortho.cpp \
+ projections/stere.cpp \
+ projections/sterea.cpp \
+ projections/aea.cpp \
+ projections/bipc.cpp \
+ projections/bonne.cpp \
+ projections/eqdc.cpp \
+ projections/isea.cpp \
+ projections/ccon.cpp \
+ projections/imw_p.cpp \
+ projections/krovak.cpp \
+ projections/lcc.cpp \
+ projections/poly.cpp \
+ projections/rpoly.cpp \
+ projections/sconics.cpp \
+ projections/rouss.cpp \
+ projections/cass.cpp \
+ projections/cc.cpp \
+ projections/cea.cpp \
+ projections/eqc.cpp \
+ projections/gall.cpp \
+ projections/labrd.cpp \
+ projections/lsat.cpp \
+ projections/misrsom.cpp \
+ projections/merc.cpp \
+ projections/mill.cpp \
+ projections/ocea.cpp \
+ projections/omerc.cpp \
+ projections/somerc.cpp \
+ projections/tcc.cpp \
+ projections/tcea.cpp \
+ projections/times.cpp \
+ projections/tmerc.cpp \
+ projections/tobmerc.cpp \
+ projections/airy.cpp \
+ projections/aitoff.cpp \
+ projections/august.cpp \
+ projections/bacon.cpp \
+ projections/bertin1953.cpp \
+ projections/chamb.cpp \
+ projections/hammer.cpp \
+ projections/lagrng.cpp \
+ projections/larr.cpp \
+ projections/lask.cpp \
+ projections/latlong.cpp \
+ projections/nicol.cpp \
+ projections/ob_tran.cpp \
+ projections/oea.cpp \
+ projections/tpeqd.cpp \
+ projections/vandg.cpp \
+ projections/vandg2.cpp \
+ projections/vandg4.cpp \
+ projections/wag7.cpp \
+ projections/lcca.cpp \
+ projections/geos.cpp \
+ projections/etmerc.cpp \
+ projections/boggs.cpp \
+ projections/collg.cpp \
+ projections/comill.cpp \
+ projections/crast.cpp \
+ projections/denoy.cpp \
+ projections/eck1.cpp \
+ projections/eck2.cpp \
+ projections/eck3.cpp \
+ projections/eck4.cpp \
+ projections/eck5.cpp \
+ projections/fahey.cpp \
+ projections/fouc_s.cpp \
+ projections/gins8.cpp \
+ projections/gstmerc.cpp \
+ projections/gn_sinu.cpp \
+ projections/goode.cpp \
+ projections/igh.cpp \
+ projections/hatano.cpp \
+ projections/loxim.cpp \
+ projections/mbt_fps.cpp \
+ projections/mbtfpp.cpp \
+ projections/mbtfpq.cpp \
+ projections/moll.cpp \
+ projections/nell.cpp \
+ projections/nell_h.cpp \
+ projections/patterson.cpp \
+ projections/putp2.cpp \
+ projections/putp3.cpp \
+ projections/putp4p.cpp \
+ projections/putp5.cpp \
+ projections/putp6.cpp \
+ projections/qsc.cpp \
+ projections/robin.cpp \
+ projections/sch.cpp \
+ projections/sts.cpp \
+ projections/urm5.cpp \
+ projections/urmfps.cpp \
+ projections/wag2.cpp \
+ projections/wag3.cpp \
+ projections/wink1.cpp \
+ projections/wink2.cpp \
+ projections/healpix.cpp \
+ projections/natearth.cpp \
+ projections/natearth2.cpp \
+ projections/calcofi.cpp \
+ projections/eqearth.cpp \
+ \
+ conversions/axisswap.cpp \
+ conversions/cart.cpp \
+ conversions/geoc.cpp \
+ conversions/geocent.cpp \
+ conversions/unitconvert.cpp \
+ \
+ transformations/affine.cpp \
+ transformations/deformation.cpp \
+ transformations/helmert.cpp \
+ transformations/hgridshift.cpp \
+ transformations/horner.cpp \
+ transformations/molodensky.cpp \
+ transformations/vgridshift.cpp \
+ \
+ aasincos.cpp adjlon.cpp bch2bps.cpp bchgen.cpp \
+ biveval.cpp dmstor.cpp mk_cheby.cpp auth.cpp \
+ deriv.cpp ell_set.cpp ellps.cpp errno.cpp \
+ factors.cpp fwd.cpp init.cpp inv.cpp \
+ list.cpp malloc.cpp mlfn.cpp msfn.cpp proj_mdist.cpp \
+ open_lib.cpp param.cpp phi2.cpp pr_list.cpp \
+ qsfn.cpp strerrno.cpp \
+ tsfn.cpp units.cpp ctx.cpp log.cpp zpoly1.cpp rtodms.cpp \
+ vector1.cpp release.cpp gauss.cpp \
+ fileapi.cpp \
+ \
+ gc_reader.cpp gridcatalog.cpp \
+ nad_cvt.cpp nad_init.cpp nad_intr.cpp \
+ apply_gridshift.cpp datums.cpp datum_set.cpp transform.cpp \
+ geocent.cpp geocent.h utils.cpp gridinfo.cpp gridlist.cpp \
+ jniproj.cpp mutex.cpp initcache.cpp apply_vgridshift.cpp geodesic.c \
+ strtod.cpp math.cpp \
+ \
+ 4D_api.cpp pipeline.cpp \
+ internal.cpp \
+ wkt_parser.hpp wkt_parser.cpp \
+ wkt1_parser.h wkt1_parser.cpp \
+ wkt1_generated_parser.h wkt1_generated_parser.c \
+ wkt2_parser.h wkt2_parser.cpp \
+ wkt2_generated_parser.h wkt2_generated_parser.c
# The sed hack is to please MSVC
wkt1_parser:
- bison --no-lines -d -p pj_wkt1_ -o$(top_srcdir)/src/pj_wkt1_generated_parser.c $(top_srcdir)/src/pj_wkt1_grammar.y
- sed "s/\*yyssp = yystate/\*yyssp = (yytype_int16)yystate/" < $(top_srcdir)/src/pj_wkt1_generated_parser.c | sed "s/yyerrorlab:/#if 0\nyyerrorlab:/" | sed "s/yyerrlab1:/#endif\nyyerrlab1:/" | sed "s/for (yylen = 0; yystr\[yylen\]; yylen++)/for (yylen = 0; yystr \&\& yystr\[yylen\]; yylen++)/" > $(top_srcdir)/src/pj_wkt1_generated_parser.c.tmp
- mv $(top_srcdir)/src/pj_wkt1_generated_parser.c.tmp $(top_srcdir)/src/pj_wkt1_generated_parser.c
+ bison --no-lines -d -p pj_wkt1_ -o$(top_srcdir)/src/wkt1_generated_parser.c $(top_srcdir)/src/wkt1_grammar.y
+ sed "s/\*yyssp = yystate/\*yyssp = (yytype_int16)yystate/" < $(top_srcdir)/src/wkt1_generated_parser.c | sed "s/yyerrorlab:/#if 0\nyyerrorlab:/" | sed "s/yyerrlab1:/#endif\nyyerrlab1:/" | sed "s/for (yylen = 0; yystr\[yylen\]; yylen++)/for (yylen = 0; yystr \&\& yystr\[yylen\]; yylen++)/" > $(top_srcdir)/src/wkt1_generated_parser.c.tmp
+ mv $(top_srcdir)/src/wkt1_generated_parser.c.tmp $(top_srcdir)/src/wkt1_generated_parser.c
wkt2_parser:
- bison --no-lines -d -p pj_wkt2_ -o$(top_srcdir)/src/pj_wkt2_generated_parser.c $(top_srcdir)/src/pj_wkt2_grammar.y
- sed "s/\*yyssp = yystate/\*yyssp = (yytype_int16)yystate/" < $(top_srcdir)/src/pj_wkt2_generated_parser.c | sed "s/yyerrorlab:/#if 0\nyyerrorlab:/" | sed "s/yyerrlab1:/#endif\nyyerrlab1:/" | sed "s/for (yylen = 0; yystr\[yylen\]; yylen++)/for (yylen = 0; yystr \&\& yystr\[yylen\]; yylen++)/" > $(top_srcdir)/src/pj_wkt2_generated_parser.c.tmp
- mv $(top_srcdir)/src/pj_wkt2_generated_parser.c.tmp $(top_srcdir)/src/pj_wkt2_generated_parser.c
+ bison --no-lines -d -p pj_wkt2_ -o$(top_srcdir)/src/wkt2_generated_parser.c $(top_srcdir)/src/wkt2_grammar.y
+ sed "s/\*yyssp = yystate/\*yyssp = (yytype_int16)yystate/" < $(top_srcdir)/src/wkt2_generated_parser.c | sed "s/yyerrorlab:/#if 0\nyyerrorlab:/" | sed "s/yyerrlab1:/#endif\nyyerrlab1:/" | sed "s/for (yylen = 0; yystr\[yylen\]; yylen++)/for (yylen = 0; yystr \&\& yystr\[yylen\]; yylen++)/" > $(top_srcdir)/src/wkt2_generated_parser.c.tmp
+ mv $(top_srcdir)/src/wkt2_generated_parser.c.tmp $(top_srcdir)/src/wkt2_generated_parser.c
install-exec-local: install-binPROGRAMS
diff --git a/src/aasincos.c b/src/aasincos.cpp
index 4f9ea25f..4f9ea25f 100644
--- a/src/aasincos.c
+++ b/src/aasincos.cpp
diff --git a/src/adjlon.c b/src/adjlon.cpp
index 784a90aa..784a90aa 100644
--- a/src/adjlon.c
+++ b/src/adjlon.cpp
diff --git a/src/pj_apply_gridshift.c b/src/apply_gridshift.cpp
index 45ce5c8e..4c8115cc 100644
--- a/src/pj_apply_gridshift.c
+++ b/src/apply_gridshift.cpp
@@ -57,7 +57,7 @@ int pj_apply_gridshift( projCtx ctx, const char *nadgrids, int inverse,
gridlist = pj_gridlist_from_nadgrids( ctx, nadgrids, &grid_count );
- if( gridlist == NULL || grid_count == 0 )
+ if( gridlist == nullptr || grid_count == 0 )
return ctx->last_errno;
ret = pj_apply_gridshift_3( ctx, gridlist, grid_count, inverse,
@@ -86,18 +86,18 @@ int pj_apply_gridshift_2( PJ *defn, int inverse,
double *x, double *y, double *z )
{
- if( defn->catalog_name != NULL )
+ if( defn->catalog_name != nullptr )
return pj_gc_apply_gridshift( defn, inverse, point_count, point_offset,
x, y, z );
- if( defn->gridlist == NULL )
+ if( defn->gridlist == nullptr )
{
defn->gridlist =
pj_gridlist_from_nadgrids( pj_get_ctx( defn ),
pj_param(defn->ctx, defn->params,"snadgrids").s,
&(defn->gridlist_count) );
- if( defn->gridlist == NULL || defn->gridlist_count == 0 )
+ if( defn->gridlist == nullptr || defn->gridlist_count == 0 )
return defn->ctx->last_errno;
}
@@ -135,7 +135,7 @@ static struct CTABLE* find_ctable(projCtx ctx, LP input, int grid_count, PJ_GRID
{
PJ_GRIDINFO *child;
- for( child = gi->child; child != NULL; child = child->next )
+ for( child = gi->child; child != nullptr; child = child->next )
{
struct CTABLE *ct1 = child->ct;
epsilon = (fabs(ct1->del.phi)+fabs(ct1->del.lam))/10000.0;
@@ -150,24 +150,24 @@ static struct CTABLE* find_ctable(projCtx ctx, LP input, int grid_count, PJ_GRID
}
/* If we didn't find a child then nothing more to do */
- if( child == NULL ) break;
+ if( child == nullptr ) break;
/* Otherwise use the child, first checking it's children */
gi = child;
ct = child->ct;
}
/* load the grid shift info if we don't have it. */
- if( ct->cvs == NULL) {
+ if( ct->cvs == nullptr) {
if (!pj_gridinfo_load( ctx, gi ) ) {
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
- return NULL;
+ return nullptr;
}
}
/* if we get this far we have found a suitable grid */
return ct;
}
- return NULL;
+ return nullptr;
}
/************************************************************************/
@@ -185,7 +185,7 @@ int pj_apply_gridshift_3( projCtx ctx, PJ_GRIDINFO **gridlist, int gridlist_coun
static int debug_count = 0;
(void) z;
- if( gridlist== NULL || gridlist_count == 0 )
+ if( gridlist== nullptr || gridlist_count == 0 )
{
pj_ctx_set_errno(ctx, PJD_ERR_FAILED_TO_LOAD_GRID);
return PJD_ERR_FAILED_TO_LOAD_GRID;
@@ -205,7 +205,7 @@ int pj_apply_gridshift_3( projCtx ctx, PJ_GRIDINFO **gridlist, int gridlist_coun
output.lam = HUGE_VAL;
ct = find_ctable(ctx, input, gridlist_count, gridlist);
- if( ct != NULL )
+ if( ct != nullptr )
{
output = nad_cvt( input, inverse, ct );
@@ -280,14 +280,14 @@ int proj_hgrid_init(PJ* P, const char *grids) {
char *sgrids = (char *) pj_malloc( (strlen(grids)+1+1) *sizeof(char) );
sprintf(sgrids, "%s%s", "s", grids);
- if (P->gridlist == NULL) {
+ if (P->gridlist == nullptr) {
P->gridlist = pj_gridlist_from_nadgrids(
P->ctx,
pj_param(P->ctx, P->params, sgrids).s,
&(P->gridlist_count)
);
- if( P->gridlist == NULL || P->gridlist_count == 0 ) {
+ if( P->gridlist == nullptr || P->gridlist_count == 0 ) {
pj_dealloc(sgrids);
return 0;
}
@@ -311,7 +311,7 @@ LP proj_hgrid_value(PJ *P, LP lp) {
LP out = proj_coord_error().lp;
ct = find_ctable(P->ctx, lp, P->gridlist_count, P->gridlist);
- if (ct == 0) {
+ if (ct == nullptr) {
pj_ctx_set_errno( P->ctx, PJD_ERR_GRID_AREA);
return out;
}
@@ -340,7 +340,7 @@ LP proj_hgrid_apply(PJ *P, LP lp, PJ_DIRECTION direction) {
ct = find_ctable(P->ctx, lp, P->gridlist_count, P->gridlist);
- if (ct == NULL || ct->cvs == NULL) {
+ if (ct == nullptr || ct->cvs == nullptr) {
pj_ctx_set_errno( P->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
return out;
}
diff --git a/src/pj_apply_vgridshift.c b/src/apply_vgridshift.cpp
index c1344951..1facfed6 100644
--- a/src/pj_apply_vgridshift.c
+++ b/src/apply_vgridshift.cpp
@@ -70,11 +70,11 @@ static double read_vgrid_value( PJ *defn, LP input, int *gridlist_count_p, PJ_GR
continue;
/* If we have child nodes, check to see if any of them apply. */
- while( gi->child != NULL )
+ while( gi->child != nullptr )
{
PJ_GRIDINFO *child;
- for( child = gi->child; child != NULL; child = child->next )
+ for( child = gi->child; child != nullptr; child = child->next )
{
struct CTABLE *ct1 = child->ct;
@@ -87,7 +87,7 @@ static double read_vgrid_value( PJ *defn, LP input, int *gridlist_count_p, PJ_GR
}
/* we didn't find a more refined child node to use, so go with current grid */
- if( child == NULL )
+ if( child == nullptr )
{
break;
}
@@ -98,7 +98,7 @@ static double read_vgrid_value( PJ *defn, LP input, int *gridlist_count_p, PJ_GR
}
/* load the grid shift info if we don't have it. */
- if( ct->cvs == NULL && !pj_gridinfo_load( pj_get_ctx(defn), gi ) )
+ if( ct->cvs == nullptr && !pj_gridinfo_load( pj_get_ctx(defn), gi ) )
{
pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
return PJD_ERR_FAILED_TO_LOAD_GRID;
@@ -189,14 +189,14 @@ int pj_apply_vgridshift( PJ *defn, const char *listname,
PJ_GRIDINFO **tables;
struct CTABLE ct;
- if( *gridlist_p == NULL )
+ if( *gridlist_p == nullptr )
{
*gridlist_p =
pj_gridlist_from_nadgrids( pj_get_ctx(defn),
pj_param(defn->ctx,defn->params,listname).s,
gridlist_count_p );
- if( *gridlist_p == NULL || *gridlist_count_p == 0 )
+ if( *gridlist_p == nullptr || *gridlist_count_p == 0 )
return defn->ctx->last_errno;
}
@@ -288,14 +288,14 @@ int proj_vgrid_init(PJ* P, const char *grids) {
char *sgrids = (char *) pj_malloc( (strlen(grids)+1+1) *sizeof(char) );
sprintf(sgrids, "%s%s", "s", grids);
- if (P->vgridlist_geoid == NULL) {
+ if (P->vgridlist_geoid == nullptr) {
P->vgridlist_geoid = pj_gridlist_from_nadgrids(
P->ctx,
pj_param(P->ctx, P->params, sgrids).s,
&(P->vgridlist_geoid_count)
);
- if( P->vgridlist_geoid == NULL || P->vgridlist_geoid_count == 0 ) {
+ if( P->vgridlist_geoid == nullptr || P->vgridlist_geoid_count == 0 ) {
pj_dealloc(sgrids);
return 0;
}
diff --git a/src/cct.c b/src/apps/cct.cpp
index 54734b98..046257da 100644
--- a/src/cct.c
+++ b/src/apps/cct.cpp
@@ -187,7 +187,7 @@ static void print(PJ_LOG_LEVEL log_level, const char *fmt, ...) {
va_start( args, fmt );
msg_buf = (char *) malloc(100000);
- if( msg_buf == NULL ) {
+ if( msg_buf == nullptr ) {
va_end( args );
return;
}
@@ -211,12 +211,12 @@ int main(int argc, char **argv) {
char *comment;
char *comment_delimiter;
char *buf;
- int i, nfields = 4, direction = 1, skip_lines = 0, verbose;
+ int i, nfields = 4, skip_lines = 0, verbose;
double fixed_z = HUGE_VAL, fixed_time = HUGE_VAL;
int decimals_angles = 10;
int decimals_distances = 4;
int columns_xyzt[] = {1, 2, 3, 4};
- const char *longflags[] = {"v=verbose", "h=help", "I=inverse", "version", 0};
+ const char *longflags[] = {"v=verbose", "h=help", "I=inverse", "version", nullptr};
const char *longkeys[] = {
"o=output",
"c=columns",
@@ -224,12 +224,12 @@ int main(int argc, char **argv) {
"z=height",
"t=time",
"s=skip-lines",
- 0};
+ nullptr};
fout = stdout;
o = opt_parse (argc, argv, "hvI", "cdozts", longflags, longkeys);
- if (0==o)
+ if (nullptr==o)
return 0;
if (opt_given (o, "h") || argc==1) {
@@ -237,10 +237,10 @@ int main(int argc, char **argv) {
return 0;
}
- direction = opt_given (o, "I")? -1: 1;
+ PJ_DIRECTION direction = opt_given (o, "I")? PJ_INV: PJ_FWD;
verbose = MIN(opt_given (o, "v"), 3); /* log level can't be larger than 3 */
- proj_log_level (PJ_DEFAULT_CTX, verbose);
+ proj_log_level (PJ_DEFAULT_CTX, static_cast<PJ_LOG_LEVEL>(verbose));
proj_log_func (PJ_DEFAULT_CTX, (void *) fout, logger);
if (opt_given (o, "version")) {
@@ -250,7 +250,7 @@ int main(int argc, char **argv) {
if (opt_given (o, "o"))
fout = fopen (opt_arg (o, "output"), "wt");
- if (0==fout) {
+ if (nullptr==fout) {
print (PJ_LOG_ERROR, "%s: Cannot open '%s' for output\n", o->progname, opt_arg (o, "output"));
free (o);
return 1;
@@ -296,8 +296,8 @@ int main(int argc, char **argv) {
}
/* Setup transformation */
- P = proj_create_argv (0, o->pargc, o->pargv);
- if ((0==P) || (0==o->pargc)) {
+ P = proj_create_argv (nullptr, o->pargc, o->pargv);
+ if ((nullptr==P) || (0==o->pargc)) {
print (PJ_LOG_ERROR, "%s: Bad transformation arguments - (%s)\n '%s -h' for help\n",
o->progname, pj_strerrno (proj_errno(P)), o->progname);
free (o);
@@ -309,7 +309,7 @@ int main(int argc, char **argv) {
info = proj_pj_info (P);
print (PJ_LOG_TRACE, "Final: %s argc=%d pargc=%d\n", info.definition, argc, o->pargc);
- if (direction==-1) {
+ if (direction== PJ_INV) {
/* fail if an inverse operation is not available */
if (!info.has_inverse) {
print (PJ_LOG_ERROR, "Inverse operation not available\n");
@@ -320,11 +320,11 @@ int main(int argc, char **argv) {
/* We have no API call for inverting an operation, so we brute force it. */
P->inverted = !(P->inverted);
}
- direction = 1;
+ direction = PJ_FWD;
/* Allocate input buffer */
- buf = calloc (1, 10000);
- if (0==buf) {
+ buf = static_cast<char*>(calloc (1, 10000));
+ if (nullptr==buf) {
print (PJ_LOG_ERROR, "%s: Out of memory\n", o->progname);
pj_free (P);
free (o);
@@ -340,7 +340,7 @@ int main(int argc, char **argv) {
void *ret = fgets (buf, 10000, o->input);
char *c = column (buf, 1);
opt_eof_handler (o);
- if (0==ret) {
+ if (nullptr==ret) {
print (PJ_LOG_ERROR, "Read error in record %d\n", (int) o->record_index);
continue;
}
diff --git a/src/cs2cs.cpp b/src/apps/cs2cs.cpp
index f63bedcc..f63bedcc 100644
--- a/src/cs2cs.cpp
+++ b/src/apps/cs2cs.cpp
diff --git a/src/emess.c b/src/apps/emess.cpp
index eb2ac9d6..144e9e23 100644
--- a/src/emess.c
+++ b/src/apps/emess.cpp
@@ -29,11 +29,11 @@ emess(int code, const char *fmt, ...) {
va_start(args, fmt);
/* prefix program name, if given */
- if (fmt != NULL)
+ if (fmt != nullptr)
(void)fprintf(stderr,"%s\n<%s>: ",pj_get_release(),
emess_dat.Prog_name);
/* print file name and line, if given */
- if (emess_dat.File_name != NULL && *emess_dat.File_name) {
+ if (emess_dat.File_name != nullptr && *emess_dat.File_name) {
(void)fprintf(stderr,"while processing file: %s", emess_dat.File_name);
if (emess_dat.File_line > 0)
(void)fprintf(stderr,", line %d\n", emess_dat.File_line);
diff --git a/src/emess.h b/src/apps/emess.h
index cb6b38f4..4c6f6783 100644
--- a/src/emess.h
+++ b/src/apps/emess.h
@@ -2,10 +2,6 @@
#ifndef EMESS_H
#define EMESS_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
struct EMESS {
char *File_name, /* input file name */
*Prog_name; /* name of program */
@@ -15,7 +11,7 @@ struct EMESS {
#ifdef EMESS_ROUTINE /* use type */
/* for emess procedure */
-struct EMESS PROJ_DLL emess_dat = { (char *)0, (char *)0, 0 };
+struct EMESS emess_dat = { nullptr, nullptr, 0 };
#ifdef sun /* Archaic SunOs 4.1.1, etc. */
extern char *sys_errlist[];
@@ -24,14 +20,10 @@ extern char *sys_errlist[];
#else /* for for calling procedures */
-extern struct EMESS PROJ_DLL emess_dat;
+extern struct EMESS emess_dat;
#endif /* use type */
-void PROJ_DLL emess(int, const char *, ...);
-
-#ifdef __cplusplus
-}
-#endif
+void emess(int, const char *, ...);
#endif /* end EMESS_H */
diff --git a/src/gen_cheb.c b/src/apps/gen_cheb.cpp
index ab16b409..4ba514d4 100644
--- a/src/gen_cheb.c
+++ b/src/apps/gen_cheb.cpp
@@ -9,12 +9,40 @@
#define COEF_LINE_MAX 50
#endif
+static double strtod_type_safe(const char *s, const char ** endptr)
+{
+ char* l_endptr = nullptr;
+ double ret= strtod(s, &l_endptr);
+ if( endptr )
+ *endptr = static_cast<const char*>(l_endptr);
+ return ret;
+}
+
+static double dmstor_type_safe(const char *s, const char ** endptr)
+{
+ char* l_endptr = nullptr;
+ double ret= dmstor(s, &l_endptr);
+ if( endptr )
+ *endptr = static_cast<const char*>(l_endptr);
+ return ret;
+}
+
+static long strtol_type_safe(const char *s, const char ** endptr, int base)
+{
+ char* l_endptr = nullptr;
+ long ret = strtol(s, &l_endptr, base);
+ if( endptr )
+ *endptr = static_cast<const char*>(l_endptr);
+ return ret;
+}
+
+
/* FIXME: put the declaration in a header. Also used in proj.c */
-void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P,
+void gen_cheb(int inverse, projUV (*proj)(projUV), const char *s, PJ *P,
int iargc, char **iargv);
extern void p_series(Tseries *, FILE *, char *);
-void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P,
+void gen_cheb(int inverse, projUV (*proj)(projUV), const char *s, PJ *P,
int iargc, char **iargv) {
long NU = 15, NV = 15;
int errin = 0, pwr;
@@ -22,18 +50,18 @@ void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P,
char *arg, fmt[32];
projUV low, upp, resid;
Tseries *F;
- double (*input)(const char *, char **);
+ double (*input)(const char *, const char **);
- input = inverse ? strtod : dmstor;
+ input = inverse ? strtod_type_safe : dmstor_type_safe;
if (*s) low.u = input(s, &s); else { low.u = 0; ++errin; }
if (*s == ',') upp.u = input(s+1, &s); else { upp.u = 0; ++errin; }
if (*s == ',') low.v = input(s+1, &s); else { low.v = 0; ++errin; }
if (*s == ',') upp.v = input(s+1, &s); else { upp.v = 0; ++errin; }
if (errin)
emess(16,"null or absent -T parameters");
- if (*s == ',') if (*++s != ',') res = strtol(s, &s, 10);
- if (*s == ',') if (*++s != ',') NU = strtol(s, &s, 10);
- if (*s == ',') if (*++s != ',') NV = strtol(s, &s, 10);
+ if (*s == ',') if (*++s != ',') res = strtol_type_safe(s, &s, 10);
+ if (*s == ',') if (*++s != ',') NU = strtol_type_safe(s, &s, 10);
+ if (*s == ',') if (*++s != ',') NV = strtol_type_safe(s, &s, 10);
pwr = s && *s && !strcmp(s, ",P");
(void)printf("#proj_%s\n# run-line:\n",
pwr ? "Power" : "Chebyshev");
diff --git a/src/geod.c b/src/apps/geod.cpp
index bb52818e..7b6367c6 100644
--- a/src/geod.c
+++ b/src/apps/geod.cpp
@@ -16,12 +16,14 @@ fullout = 0, /* output full set of geodesic values */
tag = '#', /* beginning of line tag character */
pos_azi = 0, /* output azimuths as positive values */
inverse = 0; /* != 0 then inverse geodesic */
- static char
-*oform = (char *)0, /* output format for decimal degrees */
-*osform = "%.3f", /* output format for S */
-pline[50], /* work string */
-*usage =
+
+static const char *oform = nullptr; /* output format for decimal degrees */
+static const char *osform = "%.3f"; /* output format for S */
+
+static char pline[50]; /* work string */
+static const char *usage =
"%s\nusage: %s [ -afFIlptwW [args] ] [ +opts[=arg] ] [ files ]\n";
+
static void
printLL(double p, double l) {
if (oform) {
@@ -133,7 +135,7 @@ int main(int argc, char **argv) {
FILE *fid;
static int eargc = 0, c;
- if ((emess_dat.Prog_name = strrchr(*argv,'/')) != NULL) ++emess_dat.Prog_name;
+ if ((emess_dat.Prog_name = strrchr(*argv,'/')) != nullptr) ++emess_dat.Prog_name;
else emess_dat.Prog_name = *argv;
inverse = ! strncmp(emess_dat.Prog_name, "inv", 3);
if (argc <= 1 ) {
@@ -146,7 +148,7 @@ int main(int argc, char **argv) {
if(**++argv == '-') for(arg = *argv;;) {
switch(*++arg) {
case '\0': /* position of "stdin" */
- if (arg[-1] == '-') eargv[eargc++] = "-";
+ if (arg[-1] == '-') eargv[eargc++] = const_cast<char*>("-");
break;
case 'a': /* output full set of values */
fullout = 1;
@@ -217,13 +219,13 @@ noargument: emess(1,"missing argument for -%c",*arg);
do_geod();
else { /* process input file list */
if (eargc == 0) /* if no specific files force sysin */
- eargv[eargc++] = "-";
+ eargv[eargc++] = const_cast<char*>("-");
for ( ; eargc-- ; ++eargv) {
if (**eargv == '-') {
fid = stdin;
- emess_dat.File_name = "<stdin>";
+ emess_dat.File_name = const_cast<char*>("<stdin>");
} else {
- if ((fid = fopen(*eargv, "r")) == NULL) {
+ if ((fid = fopen(*eargv, "r")) == nullptr) {
emess(-2, *eargv, "input file");
continue;
}
@@ -232,7 +234,7 @@ noargument: emess(1,"missing argument for -%c",*arg);
emess_dat.File_line = 0;
process(fid);
(void)fclose(fid);
- emess_dat.File_name = (char *)0;
+ emess_dat.File_name = (char *)nullptr;
}
}
exit(0); /* normal completion */
diff --git a/src/geod_interface.c b/src/apps/geod_interface.cpp
index a30377ac..a30377ac 100644
--- a/src/geod_interface.c
+++ b/src/apps/geod_interface.cpp
diff --git a/src/geod_interface.h b/src/apps/geod_interface.h
index 255d505a..255d505a 100644
--- a/src/geod_interface.h
+++ b/src/apps/geod_interface.h
diff --git a/src/geod_set.c b/src/apps/geod_set.cpp
index b5bd0667..b9e9c42f 100644
--- a/src/geod_set.c
+++ b/src/apps/geod_set.cpp
@@ -11,7 +11,7 @@
void
geod_set(int argc, char **argv) {
- paralist *start = 0, *curr;
+ paralist *start = nullptr, *curr;
double es;
char *name;
int i;
@@ -22,7 +22,7 @@ geod_set(int argc, char **argv) {
start = curr = pj_mkparam(argv[0]);
if (!curr)
emess(1, "memory allocation failed");
- for (i = 1; curr != 0 && i < argc; ++i) {
+ for (i = 1; curr != nullptr && i < argc; ++i) {
curr->next = pj_mkparam(argv[i]);
if (!curr->next)
emess(1, "memory allocation failed");
@@ -31,7 +31,7 @@ geod_set(int argc, char **argv) {
/* set elliptical parameters */
if (pj_ell_set(pj_get_default_ctx(),start, &geod_a, &es)) emess(1,"ellipse setup failure");
/* set units */
- if ((name = pj_param(NULL,start, "sunits").s) != NULL) {
+ if ((name = pj_param(nullptr,start, "sunits").s) != nullptr) {
const char *s;
const struct PJ_UNITS *unit_list = proj_list_units();
for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ;
@@ -44,27 +44,27 @@ geod_set(int argc, char **argv) {
geod_f = es/(1 + sqrt(1 - es));
geod_ini();
/* check if line or arc mode */
- if (pj_param(NULL,start, "tlat_1").i) {
+ if (pj_param(nullptr,start, "tlat_1").i) {
double del_S;
#undef f
- phi1 = pj_param(NULL,start, "rlat_1").f;
- lam1 = pj_param(NULL,start, "rlon_1").f;
- if (pj_param(NULL,start, "tlat_2").i) {
- phi2 = pj_param(NULL,start, "rlat_2").f;
- lam2 = pj_param(NULL,start, "rlon_2").f;
+ phi1 = pj_param(nullptr,start, "rlat_1").f;
+ lam1 = pj_param(nullptr,start, "rlon_1").f;
+ if (pj_param(nullptr,start, "tlat_2").i) {
+ phi2 = pj_param(nullptr,start, "rlat_2").f;
+ lam2 = pj_param(nullptr,start, "rlon_2").f;
geod_inv();
geod_pre();
- } else if ((geod_S = pj_param(NULL,start, "dS").f) != 0.) {
- al12 = pj_param(NULL,start, "rA").f;
+ } else if ((geod_S = pj_param(nullptr,start, "dS").f) != 0.) {
+ al12 = pj_param(nullptr,start, "rA").f;
geod_pre();
geod_for();
} else emess(1,"incomplete geodesic/arc info");
- if ((n_alpha = pj_param(NULL,start, "in_A").i) > 0) {
- if ((del_alpha = pj_param(NULL,start, "rdel_A").f) == 0.0)
+ if ((n_alpha = pj_param(nullptr,start, "in_A").i) > 0) {
+ if ((del_alpha = pj_param(nullptr,start, "rdel_A").f) == 0.0)
emess(1,"del azimuth == 0");
- } else if ((del_S = fabs(pj_param(NULL,start, "ddel_S").f)) != 0.) {
+ } else if ((del_S = fabs(pj_param(nullptr,start, "ddel_S").f)) != 0.) {
n_S = (int)(geod_S / del_S + .5);
- } else if ((n_S = pj_param(NULL,start, "in_S").i) <= 0)
+ } else if ((n_S = pj_param(nullptr,start, "in_S").i) <= 0)
emess(1,"no interval divisor selected");
}
/* free up linked list */
diff --git a/src/gie.c b/src/apps/gie.cpp
index 4bb79f1f..3e4770a2 100644
--- a/src/gie.c
+++ b/src/apps/gie.cpp
@@ -194,7 +194,7 @@ typedef struct {
FILE *fout;
} gie_ctx;
-ffio *F = 0;
+ffio *F = nullptr;
static gie_ctx T;
int tests=0, succs=0, succ_fails=0, fail_fails=0, succ_rtps=0, fail_rtps=0;
@@ -236,8 +236,8 @@ static const char usage[] = {
int main (int argc, char **argv) {
int i;
- const char *longflags[] = {"v=verbose", "q=quiet", "h=help", "l=list", "version", 0};
- const char *longkeys[] = {"o=output", 0};
+ const char *longflags[] = {"v=verbose", "q=quiet", "h=help", "l=list", "version", nullptr};
+ const char *longkeys[] = {"o=output", nullptr};
OPTARGS *o;
memset (&T, 0, sizeof (T));
@@ -248,7 +248,7 @@ int main (int argc, char **argv) {
T.use_proj4_init_rules = FALSE;
o = opt_parse (argc, argv, "hlvq", "o", longflags, longkeys);
- if (0==o)
+ if (nullptr==o)
return 0;
if (opt_given (o, "h") || argc==1) {
@@ -274,7 +274,7 @@ int main (int argc, char **argv) {
if (opt_given (o, "o"))
T.fout = fopen (opt_arg (o, "output"), "rt");
- if (0==T.fout) {
+ if (nullptr==T.fout) {
fprintf (stderr, "%s: Cannot open '%s' for output\n", o->progname, opt_arg (o, "output"));
free (o);
return 1;
@@ -294,7 +294,7 @@ int main (int argc, char **argv) {
}
F = ffio_create (gie_tags, n_gie_tags, 1000);
- if (0==F) {
+ if (nullptr==F) {
fprintf (stderr, "%s: No memory\n", o->progname);
free (o);
return 1;
@@ -379,12 +379,12 @@ static int process_file (const char *fname) {
if (T.skip) {
proj_destroy (T.P);
- T.P = 0;
+ T.P = nullptr;
return 0;
}
f = fopen (fname, "rt");
- if (0==f) {
+ if (nullptr==f) {
if (T.verbosity > 0) {
fprintf (T.fout, "%sCannot open spec'd input file '%s' - bye!\n", delim, fname);
return 2;
@@ -400,7 +400,7 @@ static int process_file (const char *fname) {
while (get_inp(F)) {
if (SKIP==dispatch (F->tag, F->args)) {
proj_destroy (T.P);
- T.P = 0;
+ T.P = nullptr;
return 0;
}
}
@@ -591,10 +591,10 @@ either a conversion or a transformation)
if (T.P)
proj_destroy (T.P);
- proj_errno_reset (0);
- proj_context_use_proj4_init_rules(0, T.use_proj4_init_rules);
+ proj_errno_reset (nullptr);
+ proj_context_use_proj4_init_rules(nullptr, T.use_proj4_init_rules);
- T.P = proj_create (0, F->args);
+ T.P = proj_create (nullptr, F->args);
/* Checking that proj_create succeeds is first done at "expect" time, */
/* since we want to support "expect"ing specific error codes */
@@ -604,7 +604,7 @@ either a conversion or a transformation)
static PJ_COORD torad_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) {
size_t i, n;
- char *axis = "enut";
+ const char *axis = "enut";
paralist *l = pj_param_exists (P->params, "axis");
if (l && dir==PJ_INV)
axis = l->param + strlen ("axis=");
@@ -618,7 +618,7 @@ static PJ_COORD torad_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) {
static PJ_COORD todeg_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) {
size_t i, n;
- char *axis = "enut";
+ const char *axis = "enut";
paralist *l = pj_param_exists (P->params, "axis");
if (l && dir==PJ_FWD)
axis = l->param + strlen ("axis=");
@@ -715,7 +715,7 @@ Always returns 0.
char *endp;
PJ_COORD coo;
- if (0==T.P) {
+ if (nullptr==T.P) {
if (T.ignore == proj_errno(T.P))
return another_skip();
@@ -840,7 +840,7 @@ Tell GIE what to expect, when transforming the ACCEPTed input
if (T.ignore==proj_errno(T.P))
return another_skip ();
- if (0==T.P) {
+ if (nullptr==T.P) {
/* If we expect failure, and fail, then it's a success... */
if (expect_failure) {
/* Failed to fail correctly? */
@@ -1020,6 +1020,7 @@ static int dispatch (const char *cmnd, const char *args) {
+namespace { // anonymous namespace
struct errno_vs_err_const {const char *the_err_const; int the_errno;};
static const struct errno_vs_err_const lookup[] = {
{"pjd_err_no_args" , -1},
@@ -1084,6 +1085,7 @@ static const struct errno_vs_err_const lookup[] = {
{"pjd_err_unknown" , 9999},
{"pjd_err_enomem" , ENOMEM},
};
+} // anonymous namespace
static const struct errno_vs_err_const unknown = {"PJD_ERR_UNKNOWN", 9999};
@@ -1195,24 +1197,24 @@ static ffio *ffio_create (const char **tags, size_t n_tags, size_t max_record_si
/****************************************************************************************
Constructor for the ffio object.
****************************************************************************************/
- ffio *G = calloc (1, sizeof (ffio));
- if (0==G)
- return 0;
+ ffio *G = static_cast<ffio*>(calloc (1, sizeof (ffio)));
+ if (nullptr==G)
+ return nullptr;
if (0==max_record_size)
max_record_size = 1000;
- G->args = calloc (1, 5*max_record_size);
- if (0==G->args) {
+ G->args = static_cast<char*>(calloc (1, 5*max_record_size));
+ if (nullptr==G->args) {
free (G);
- return 0;
+ return nullptr;
}
- G->next_args = calloc (1, max_record_size);
- if (0==G->args) {
+ G->next_args = static_cast<char*>(calloc (1, max_record_size));
+ if (nullptr==G->args) {
free (G->args);
free (G);
- return 0;
+ return nullptr;
}
G->args_size = 5*max_record_size;
@@ -1236,7 +1238,7 @@ fclose has been called prior to ffio_destroy.
free (G->args);
free (G->next_args);
free (G);
- return 0;
+ return nullptr;
}
@@ -1253,10 +1255,10 @@ continues until a gie command verb is found at the start of a line
****************************************************************************************/
int i;
char *c;
- if (0==G)
+ if (nullptr==G)
return 0;
c = G->next_args;
- if (0==c)
+ if (nullptr==c)
return 0;
if (0==c[0])
return 0;
@@ -1277,7 +1279,7 @@ A start of a new command serves as an end delimiter for the current command
for (j = 0; j < G->n_tags; j++)
if (strncmp (G->next_args, G->tags[j], strlen(G->tags[j]))==0)
return G->tags[j];
- return 0;
+ return nullptr;
}
@@ -1291,7 +1293,7 @@ instruction, or a "decorative element", i.e. one of the "ascii art" style
block delimiters typically used to mark up block comments in a free format
file.
****************************************************************************************/
- if (G==0)
+ if (G==nullptr)
return 0;
if (at_decorative_element (G))
return 1;
@@ -1310,7 +1312,7 @@ Read next line of input file. Returns 1 on success, 0 on failure.
G->next_args[0] = 0;
if (T.skip)
return 0;
- if (0==fgets (G->next_args, (int) G->next_args_size - 1, G->f))
+ if (nullptr==fgets (G->next_args, (int) G->next_args_size - 1, G->f))
return 0;
if (feof (G->f))
return 0;
@@ -1354,7 +1356,7 @@ Make sure we're inside a <gie>-block. Return 1 on success, 0 otherwise.
G->next_args[0] = 0;
if (feof (G->f))
return 0;
- if (0==fgets (G->next_args, (int) G->next_args_size - 1, G->f))
+ if (nullptr==fgets (G->next_args, (int) G->next_args_size - 1, G->f))
return 0;
pj_chomp (G->next_args);
G->next_lineno++;
@@ -1412,8 +1414,8 @@ static int append_args (ffio *G) {
/* +2: 1 for the space separator and 1 for the NUL termination. */
if (G->args_size < args_len + next_len - skip_chars + 2) {
- void *p = realloc (G->args, 2 * G->args_size);
- if (0==p)
+ char *p = static_cast<char*>(realloc (G->args, 2 * G->args_size));
+ if (nullptr==p)
return 0;
G->args = p;
G->args_size = 2 * G->args_size;
@@ -1442,7 +1444,7 @@ whitespace etc. The block is stored in G->args. Returns 1 on success, 0 otherwis
return 0;
G->tag = at_tag (G);
- if (0==G->tag)
+ if (nullptr==G->tag)
return 0;
do {
diff --git a/src/nad2bin.c b/src/apps/nad2bin.cpp
index eb8672a5..ff8f2ebd 100644
--- a/src/nad2bin.c
+++ b/src/apps/nad2bin.cpp
@@ -61,7 +61,7 @@ int main(int argc, char **argv) {
long lam, laml, phi, phil;
FILE *fp;
- const char *output_file = NULL;
+ const char *output_file = nullptr;
const char *format = "ctable2";
const char *GS_TYPE = "SECONDS";
@@ -81,7 +81,7 @@ int main(int argc, char **argv) {
{
format = argv[++i];
}
- else if( output_file == NULL )
+ else if( output_file == nullptr )
{
output_file = argv[i];
}
@@ -89,7 +89,7 @@ int main(int argc, char **argv) {
Usage();
}
- if( output_file == NULL )
+ if( output_file == nullptr )
Usage();
fprintf( stdout, "Output Binary File Format: %s\n", format );
@@ -99,7 +99,7 @@ int main(int argc, char **argv) {
/* ==================================================================== */
memset(ct.id,0,MAX_TAB_ID);
- if ( NULL == fgets(ct.id, MAX_TAB_ID, stdin) ) {
+ if ( nullptr == fgets(ct.id, MAX_TAB_ID, stdin) ) {
perror("fgets");
exit(1);
}
diff --git a/src/optargpm.h b/src/apps/optargpm.h
index 48cb260b..035c6f92 100644
--- a/src/optargpm.h
+++ b/src/apps/optargpm.h
@@ -107,8 +107,8 @@ int main(int argc, char **argv) {
char *longkeys[] = {"o=output", "hello", 0};
o = opt_parse (argc, argv, "hv", "o", longflags, longkeys);
- if (0==o)
- return 0;
+ if (nullptr==o)
+ return nullptr;
if (opt_given (o, "h")) {
@@ -135,14 +135,14 @@ int main(int argc, char **argv) {
char buf[1000];
int ret = fgets (buf, 1000, o->input);
opt_eof_handler (o);
- if (0==ret) {
+ if (nullptr==ret) {
fprintf (stderr, "Read error in record %d\n", (int) o->record_index);
continue;
}
do_what_needs_to_be_done (buf);
}
- return 0;
+ return nullptr;
}
@@ -201,9 +201,9 @@ int opt_record (OPTARGS *opt);
int opt_input_loop (OPTARGS *opt, int binary);
static int opt_is_flag (OPTARGS *opt, int ordinal);
static int opt_raise_flag (OPTARGS *opt, int ordinal);
-static int opt_ordinal (OPTARGS *opt, char *option);
-int opt_given (OPTARGS *opt, char *option);
-char *opt_arg (OPTARGS *opt, char *option);
+static int opt_ordinal (OPTARGS *opt, const char *option);
+int opt_given (OPTARGS *opt, const char *option);
+char *opt_arg (OPTARGS *opt, const char *option);
const char *opt_strip_path (const char *full_name);
OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys, const char **longflags, const char **longkeys);
@@ -229,22 +229,22 @@ struct OPTARGS {
/* name of file currently read from */
char *opt_filename (OPTARGS *opt) {
- if (0==opt)
- return 0;
+ if (nullptr==opt)
+ return nullptr;
if (0==opt->fargc)
return opt->flaglevel;
return opt->fargv[opt->input_index];
}
static int opt_eof (OPTARGS *opt) {
- if (0==opt)
+ if (nullptr==opt)
return 1;
return feof (opt->input);
}
/* record number of most recently read record */
int opt_record (OPTARGS *opt) {
- if (0==opt)
+ if (nullptr==opt)
return 0;
return opt->record_index + 1;
}
@@ -252,11 +252,11 @@ int opt_record (OPTARGS *opt) {
/* handle closing/opening of a "stream-of-streams" */
int opt_input_loop (OPTARGS *opt, int binary) {
- if (0==opt)
+ if (nullptr==opt)
return 0;
/* most common case: increment record index and read on */
- if ( (opt->input!=0) && !feof (opt->input) ) {
+ if ( (opt->input!=nullptr) && !feof (opt->input) ) {
opt->record_index++;
return 1;
}
@@ -264,7 +264,7 @@ int opt_input_loop (OPTARGS *opt, int binary) {
opt->record_index = 0;
/* no input files specified - read from stdin */
- if ((0==opt->fargc) && (0==opt->input)) {
+ if ((0==opt->fargc) && (nullptr==opt->input)) {
opt->input = stdin;
return 1;
}
@@ -275,18 +275,18 @@ int opt_input_loop (OPTARGS *opt, int binary) {
return 0;
/* end if no more input */
- if (0!=opt->input)
+ if (nullptr!=opt->input)
fclose (opt->input);
if (opt->input_index >= opt->fargc)
return 0;
/* otherwise, open next input file */
opt->input = fopen (opt->fargv[opt->input_index++], binary? "rb": "rt");
- if (0 != opt->input)
+ if (nullptr != opt->input)
return 1;
/* ignore non-existing files - go on! */
- if (0==opt->input)
+ if (nullptr==opt->input)
return opt_input_loop (opt, binary);
return 0;
}
@@ -315,18 +315,18 @@ static int opt_raise_flag (OPTARGS *opt, int ordinal) {
}
/* Find the ordinal value of any (short or long) option */
-static int opt_ordinal (OPTARGS *opt, char *option) {
+static int opt_ordinal (OPTARGS *opt, const char *option) {
int i;
- if (0==opt)
+ if (nullptr==opt)
return 0;
- if (0==option)
+ if (nullptr==option)
return 0;
if (0==option[0])
return 0;
/* An ordinary -o style short option */
if (strlen (option)==1) {
/* Undefined option? */
- if (0==opt->optarg[(int) option[0]])
+ if (nullptr==opt->optarg[(int) option[0]])
return 0;
return (int) option[0];
}
@@ -334,9 +334,9 @@ static int opt_ordinal (OPTARGS *opt, char *option) {
/* --longname style long options are slightly harder */
for (i = 0; i < 64; i++) {
const char **f = opt->longflags;
- if (0==f)
+ if (nullptr==f)
break;
- if (0==f[i])
+ if (nullptr==f[i])
break;
if (0==strcmp(f[i], "END"))
break;
@@ -346,7 +346,7 @@ static int opt_ordinal (OPTARGS *opt, char *option) {
/* long alias? - return ordinal for corresponding short */
if ((strlen(f[i]) > 2) && (f[i][1]=='=') && (0==strcmp(f[i]+2, option))) {
/* Undefined option? */
- if (0==opt->optarg[(int) f[i][0]])
+ if (nullptr==opt->optarg[(int) f[i][0]])
return 0;
return (int) f[i][0];
}
@@ -354,9 +354,9 @@ static int opt_ordinal (OPTARGS *opt, char *option) {
for (i = 0; i < 64; i++) {
const char **v = opt->longkeys;
- if (0==v)
+ if (nullptr==v)
return 0;
- if (0==v[i])
+ if (nullptr==v[i])
return 0;
if (0==strcmp (v[i], "END"))
return 0;
@@ -366,20 +366,20 @@ static int opt_ordinal (OPTARGS *opt, char *option) {
/* long alias? - return ordinal for corresponding short */
if ((strlen(v[i]) > 2) && (v[i][1]=='=') && (0==strcmp(v[i]+2, option))) {
/* Undefined option? */
- if (0==opt->optarg[(int) v[i][0]])
+ if (nullptr==opt->optarg[(int) v[i][0]])
return 0;
return (int) v[i][0];
}
}
/* kill some potential compiler warnings about unused functions */
- (void) opt_eof (0);
+ (void) opt_eof (nullptr);
return 0;
}
/* Returns 0 if option was not given on command line, non-0 otherwise */
-int opt_given (OPTARGS *opt, char *option) {
+int opt_given (OPTARGS *opt, const char *option) {
int ordinal = opt_ordinal (opt, option);
if (0==ordinal)
return 0;
@@ -391,10 +391,10 @@ int opt_given (OPTARGS *opt, char *option) {
/* Returns the argument to a given option */
-char *opt_arg (OPTARGS *opt, char *option) {
+char *opt_arg (OPTARGS *opt, const char *option) {
int ordinal = opt_ordinal (opt, option);
if (0==ordinal)
- return 0;
+ return nullptr;
return opt->optarg[ordinal];
}
@@ -418,8 +418,8 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
OPTARGS *o;
o = (OPTARGS *) calloc (1, sizeof(OPTARGS));
- if (0==o)
- return 0;
+ if (nullptr==o)
+ return nullptr;
o->argc = argc;
o->argv = argv;
@@ -448,10 +448,10 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
continue;
if ('='!=longflags[i][1])
continue;
- if (0==strchr (flags, longflags[i][0])) {
+ if (nullptr==strchr (flags, longflags[i][0])) {
fprintf (stderr, "%s: Invalid alias - '%s'. Valid short flags are '%s'\n", o->progname, longflags[i], flags);
free (o);
- return 0;
+ return nullptr;
}
}
for (i = 0; longkeys && longkeys[i]; i++) {
@@ -460,10 +460,10 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
continue;
if ('='!=longkeys[i][1])
continue;
- if (0==strchr (keys, longkeys[i][0])) {
+ if (nullptr==strchr (keys, longkeys[i][0])) {
fprintf (stderr, "%s: Invalid alias - '%s'. Valid short flags are '%s'\n", o->progname, longkeys[i], keys);
free (o);
- return 0;
+ return nullptr;
}
}
@@ -471,20 +471,20 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
/* flaglevel array to provide a pseudo-filename for the case of reading from stdin */
strcpy (o->flaglevel, "<stdin>");
- for (i = 128; (longflags != 0) && (longflags[i - 128] != 0); i++) {
+ for (i = 128; (longflags != nullptr) && (longflags[i - 128] != nullptr); i++) {
if (i==192) {
free (o);
fprintf (stderr, "Too many flag style long options\n");
- return 0;
+ return nullptr;
}
o->optarg[i] = o->flaglevel;
}
- for (i = 192; (longkeys != 0) && (longkeys[i - 192] != 0); i++) {
+ for (i = 192; (longkeys != nullptr) && (longkeys[i - 192] != nullptr); i++) {
if (i==256) {
free (o);
fprintf (stderr, "Too many value style long options\n");
- return 0;
+ return nullptr;
}
o->optarg[i] = argv[0];
}
@@ -500,7 +500,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if ('-' != argv[i][0])
break;
- if (0==o->margv)
+ if (nullptr==o->margv)
o->margv = argv + i;
o->margc++;
@@ -526,7 +526,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
c = opt_ordinal (o, crepr);
if (0==c) {
fprintf (stderr, "Invalid option \"%s\"\n", crepr);
- return (OPTARGS *) 0;
+ return nullptr;
}
/* inline (gnu) --foo=bar style arg */
@@ -534,7 +534,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
*equals = '=';
if (opt_is_flag (o, c)) {
fprintf (stderr, "Option \"%s\" takes no arguments\n", crepr);
- return (OPTARGS *) 0;
+ return nullptr;
}
o->optarg[c] = equals + 1;
break;
@@ -544,7 +544,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if (!opt_is_flag (o, c)) {
if ((argc==i + 1) || ('+'==argv[i+1][0]) || ('-'==argv[i+1][0])) {
fprintf (stderr, "Missing argument for option \"%s\"\n", crepr);
- return (OPTARGS *) 0;
+ return nullptr;
}
o->optarg[c] = argv[i + 1];
i++; /* eat the arg */
@@ -553,7 +553,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if (!opt_is_flag (o, c)) {
fprintf (stderr, "Expected flag style long option here, but got \"%s\"\n", crepr);
- return (OPTARGS *) 0;
+ return nullptr;
}
/* Flag style option, i.e. taking no arguments */
@@ -562,9 +562,9 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
}
/* classic short options */
- if (0==o->optarg[c]) {
+ if (nullptr==o->optarg[c]) {
fprintf (stderr, "Invalid option \"%s\"\n", crepr);
- return (OPTARGS *) 0;
+ return nullptr;
}
/* Flag style option, i.e. taking no arguments */
@@ -580,7 +580,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if ((argc==i + 1) || ('+'==argv[i+1][0]) || ('-'==argv[i+1][0]))
{
fprintf (stderr, "Bad or missing arg for option \"%s\"\n", crepr);
- return (OPTARGS *) 0;
+ return nullptr;
}
o->optarg[(int) c] = argv[i + 1];
i++;
@@ -617,7 +617,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if ('-' == argv[i][0]) {
free (o);
fprintf (stderr, "+ and - style options must not be mixed\n");
- return 0;
+ return nullptr;
}
if ('+' != argv[i][0])
diff --git a/src/p_series.c b/src/apps/p_series.cpp
index cddea888..cddea888 100644
--- a/src/p_series.c
+++ b/src/apps/p_series.cpp
diff --git a/src/proj.c b/src/apps/proj.cpp
index 2405781c..b93fb04d 100644
--- a/src/proj.c
+++ b/src/apps/proj.cpp
@@ -20,7 +20,7 @@
#define MAX_PARGS 100
#define PJ_INVERS(P) (P->inv ? 1 : 0)
-extern void gen_cheb(int, projUV(*)(projUV), char *, PJ *, int, char **);
+extern void gen_cheb(int, projUV(*)(projUV), const char *, PJ *, int, char **);
static PJ *Proj;
static union {
@@ -42,10 +42,10 @@ static int
very_verby = 0, /* very verbose mode */
postscale = 0;
-static char
+static const char
*cheby_str, /* string controlling Chebychev evaluation */
- *oform = (char *)0, /* output format for x-y or decimal degrees */
- oform_buffer[16]; /* Buffer for oform when using -d */
+ *oform = nullptr; /* output format for x-y or decimal degrees */
+static char oform_buffer[16]; /* Buffer for oform when using -d */
static const char
*oterr = "*\t*", /* output line for unprojectable input */
@@ -74,7 +74,7 @@ static projUV int_proj(projUV data) {
/* file processing function */
static void process(FILE *fid) {
- char line[MAX_LINE+3], *s = 0, pline[40];
+ char line[MAX_LINE+3], *s = nullptr, pline[40];
PJ_COORD data;
for (;;) {
@@ -309,11 +309,12 @@ static void vprocess(FILE *fid) {
}
int main(int argc, char **argv) {
- char *arg, **eargv = argv, *pargv[MAX_PARGS], **iargv = argv;
+ char *arg, *pargv[MAX_PARGS], **iargv = argv;
+ char **eargv = argv;
FILE *fid;
int pargc = 0, iargc = argc, eargc = 0, mon = 0;
- if ( (emess_dat.Prog_name = strrchr(*argv,DIR_CHAR)) != NULL)
+ if ( (emess_dat.Prog_name = strrchr(*argv,DIR_CHAR)) != nullptr)
++emess_dat.Prog_name;
else emess_dat.Prog_name = *argv;
inverse = ! strncmp(emess_dat.Prog_name, "inv", 3);
@@ -327,7 +328,7 @@ int main(int argc, char **argv) {
if(**++argv == '-') for(arg = *argv;;) {
switch(*++arg) {
case '\0': /* position of "stdin" */
- if (arg[-1] == '-') eargv[eargc++] = "-";
+ if (arg[-1] == '-') eargv[eargc++] = const_cast<char*>("-");
break;
case 'b': /* binary I/O */
bin_in = bin_out = 1;
@@ -410,7 +411,7 @@ int main(int argc, char **argv) {
{
printf("%12s %-12s %-30s\n",
ld->id, ld->ellipse_id, ld->defn);
- if( ld->comments != NULL && strlen(ld->comments) > 0 )
+ if( ld->comments != nullptr && strlen(ld->comments) > 0 )
printf( "%25s %s\n", " ", ld->comments );
}
} else
@@ -482,7 +483,7 @@ int main(int argc, char **argv) {
eargv[eargc++] = *argv;
}
if (eargc == 0 && !cheby_str) /* if no specific files force sysin */
- eargv[eargc++] = "-";
+ eargv[eargc++] = const_cast<char*>("-");
else if (eargc > 0 && cheby_str) /* warning */
emess(4, "data files when generating Chebychev prohibited");
/* done with parameter and control input */
@@ -551,7 +552,7 @@ int main(int argc, char **argv) {
for ( ; eargc-- ; ++eargv) {
if (**eargv == '-') {
fid = stdin;
- emess_dat.File_name = "<stdin>";
+ emess_dat.File_name = const_cast<char*>("<stdin>");
if (bin_in)
{
@@ -559,7 +560,7 @@ int main(int argc, char **argv) {
}
} else {
- if ((fid = fopen(*eargv, "rb")) == NULL) {
+ if ((fid = fopen(*eargv, "rb")) == nullptr) {
emess(-2, *eargv, "input file");
continue;
}
@@ -571,7 +572,7 @@ int main(int argc, char **argv) {
else
process(fid);
(void)fclose(fid);
- emess_dat.File_name = 0;
+ emess_dat.File_name = nullptr;
}
if( Proj )
diff --git a/src/proj_strtod.c b/src/apps/proj_strtod.cpp
index a3bc7d40..b8edc6a3 100644
--- a/src/proj_strtod.c
+++ b/src/apps/proj_strtod.cpp
@@ -106,7 +106,7 @@ double proj_strtod(const char *str, char **endptr) {
int num_digits_after_comma = 0;
int num_prefixed_zeros = 0;
- if (0==str) {
+ if (nullptr==str) {
errno = EFAULT;
if (endptr)
*endptr = p;
@@ -125,7 +125,7 @@ double proj_strtod(const char *str, char **endptr) {
}
/* non-numeric? */
- if (0==strchr("0123456789+-._", *p)) {
+ if (nullptr==strchr("0123456789+-._", *p)) {
if (endptr)
*endptr = (char *) str;
return 0;
@@ -150,7 +150,7 @@ double proj_strtod(const char *str, char **endptr) {
}
/* stray sign, as in "+/-"? */
- if (0!=sign && (0==strchr ("0123456789._", *p) || 0==*p)) {
+ if (0!=sign && (nullptr==strchr ("0123456789._", *p) || 0==*p)) {
if (endptr)
*endptr = (char *) str;
return 0;
@@ -161,7 +161,7 @@ double proj_strtod(const char *str, char **endptr) {
p++;
/* zero? */
- if ((0==*p) || 0==strchr ("0123456789eE.", *p) || isspace(*p)) {
+ if ((0==*p) || nullptr==strchr ("0123456789eE.", *p) || isspace(*p)) {
if (endptr)
*endptr = p;
return sign==-1? -0: 0;
@@ -202,7 +202,7 @@ double proj_strtod(const char *str, char **endptr) {
}
/* if the next character is nonnumeric, we have reached the end */
- if (0==*p || 0==strchr ("_0123456789eE+-", *p)) {
+ if (0==*p || nullptr==strchr ("_0123456789eE+-", *p)) {
if (endptr)
*endptr = p;
if (sign==-1)
@@ -249,7 +249,7 @@ double proj_strtod(const char *str, char **endptr) {
p++;
/* Just a stray "e", as in 100elephants? */
- if (0==*p || 0==strchr ("0123456789+-_", *p)) {
+ if (0==*p || nullptr==strchr ("0123456789+-_", *p)) {
p--;
break;
}
@@ -315,7 +315,7 @@ double proj_strtod(const char *str, char **endptr) {
}
double proj_atof(const char *str) {
- return proj_strtod(str, (void *) 0);
+ return proj_strtod(str, nullptr);
}
#ifdef TEST
diff --git a/src/proj_strtod.h b/src/apps/proj_strtod.h
index 38c2d1f4..38c2d1f4 100644
--- a/src/proj_strtod.h
+++ b/src/apps/proj_strtod.h
diff --git a/src/projinfo.cpp b/src/apps/projinfo.cpp
index 89b42e12..d604365a 100644
--- a/src/projinfo.cpp
+++ b/src/apps/projinfo.cpp
@@ -56,6 +56,7 @@ using namespace NS_PROJ::internal;
// ---------------------------------------------------------------------------
+namespace { // anonymous namespace
struct OutputOptions {
bool quiet = false;
bool PROJ5 = false;
@@ -69,6 +70,7 @@ struct OutputOptions {
bool c_ify = false;
bool singleLine = false;
};
+} // anonymous namespace
// ---------------------------------------------------------------------------
diff --git a/src/pj_auth.c b/src/auth.cpp
index d6024671..cde60a29 100644
--- a/src/pj_auth.c
+++ b/src/auth.cpp
@@ -17,7 +17,7 @@
pj_authset(double es) {
double t, *APA;
- if ((APA = (double *)pj_malloc(APA_SIZE * sizeof(double))) != NULL) {
+ if ((APA = (double *)pj_malloc(APA_SIZE * sizeof(double))) != nullptr) {
APA[0] = es * P00;
t = es * es;
APA[0] += t * P01;
diff --git a/src/bch2bps.c b/src/bch2bps.cpp
index 3ee56993..3ee56993 100644
--- a/src/bch2bps.c
+++ b/src/bch2bps.cpp
diff --git a/src/bchgen.c b/src/bchgen.cpp
index c129f0c1..c129f0c1 100644
--- a/src/bchgen.c
+++ b/src/bchgen.cpp
diff --git a/src/bin_cct.cmake b/src/bin_cct.cmake
index 37752217..e400caf3 100644
--- a/src/bin_cct.cmake
+++ b/src/bin_cct.cmake
@@ -1,5 +1,5 @@
-set(CCT_SRC cct.c proj_strtod.c proj_strtod.h)
-set(CCT_INCLUDE optargpm.h)
+set(CCT_SRC apps/cct.cpp apps/proj_strtod.cpp apps/proj_strtod.h)
+set(CCT_INCLUDE apps/optargpm.h)
source_group("Source Files\\Bin" FILES ${CCT_SRC})
diff --git a/src/bin_cs2cs.cmake b/src/bin_cs2cs.cmake
index 9c013dcc..c9543e89 100644
--- a/src/bin_cs2cs.cmake
+++ b/src/bin_cs2cs.cmake
@@ -1,6 +1,8 @@
-set(CS2CS_SRC cs2cs.cpp
- gen_cheb.c
- p_series.c)
+set(CS2CS_SRC apps/cs2cs.cpp
+ apps/gen_cheb.cpp
+ apps/p_series.cpp
+ apps/emess.cpp
+)
source_group("Source Files\\Bin" FILES ${CS2CS_SRC})
diff --git a/src/bin_geod.cmake b/src/bin_geod.cmake
index 1f9ee788..049da318 100644
--- a/src/bin_geod.cmake
+++ b/src/bin_geod.cmake
@@ -1,6 +1,9 @@
-set(GEOD_SRC geod.c
- geod_set.c geod_interface.c )
-set(GEOD_INCLUDE geod_interface.h)
+set(GEOD_SRC apps/geod.cpp
+ apps/geod_set.cpp
+ apps/geod_interface.cpp
+ apps/emess.cpp
+)
+set(GEOD_INCLUDE apps/geod_interface.h)
source_group("Source Files\\Bin" FILES ${GEOD_SRC} ${GEOD_INCLUDE})
diff --git a/src/bin_geodtest.cmake b/src/bin_geodtest.cmake
index 743c630e..31de499d 100644
--- a/src/bin_geodtest.cmake
+++ b/src/bin_geodtest.cmake
@@ -1,4 +1,4 @@
-set(GEODTEST_SRC geodtest.c )
+set(GEODTEST_SRC tests/geodtest.cpp )
set(GEODTEST_INCLUDE)
source_group("Source Files\\Bin" FILES ${GEODTEST_SRC} ${GEODTEST_INCLUDE})
diff --git a/src/bin_gie.cmake b/src/bin_gie.cmake
index 596592fa..497315f9 100644
--- a/src/bin_gie.cmake
+++ b/src/bin_gie.cmake
@@ -1,5 +1,7 @@
-set(GIE_SRC gie.c proj_strtod.c proj_strtod.h)
-set(GIE_INCLUDE optargpm.h)
+set(GIE_SRC apps/gie.cpp
+ apps/proj_strtod.cpp
+ apps/proj_strtod.h)
+set(GIE_INCLUDE apps/optargpm.h)
source_group("Source Files\\Bin" FILES ${GIE_SRC})
diff --git a/src/bin_nad2bin.cmake b/src/bin_nad2bin.cmake
index 0d0fd473..271aac93 100644
--- a/src/bin_nad2bin.cmake
+++ b/src/bin_nad2bin.cmake
@@ -3,7 +3,7 @@ if(WIN32 AND BUILD_LIBPROJ_SHARED)
endif(WIN32 AND BUILD_LIBPROJ_SHARED)
-set(NAD2BIN_SRC nad2bin.c)
+set(NAD2BIN_SRC apps/nad2bin.cpp)
source_group("Source Files\\Bin" FILES ${NAD2BIN_SRC})
#Executable
diff --git a/src/bin_proj.cmake b/src/bin_proj.cmake
index fb7c885d..4bd690ff 100644
--- a/src/bin_proj.cmake
+++ b/src/bin_proj.cmake
@@ -1,6 +1,8 @@
-set(PROJ_SRC proj.c
- gen_cheb.c
- p_series.c)
+set(PROJ_SRC apps/proj.cpp
+ apps/gen_cheb.cpp
+ apps/p_series.cpp
+ apps/emess.cpp
+)
source_group("Source Files\\Bin" FILES ${PROJ_SRC})
diff --git a/src/bin_projinfo.cmake b/src/bin_projinfo.cmake
index a422a16d..ea6f1006 100644
--- a/src/bin_projinfo.cmake
+++ b/src/bin_projinfo.cmake
@@ -1,4 +1,4 @@
-set(PROJINFO_SRC projinfo.cpp)
+set(PROJINFO_SRC apps/projinfo.cpp)
source_group("Source Files\\Bin" FILES ${PROJINFO_SRC})
diff --git a/src/biveval.c b/src/biveval.cpp
index 05e83e21..05e83e21 100644
--- a/src/biveval.c
+++ b/src/biveval.cpp
diff --git a/src/PJ_axisswap.c b/src/conversions/axisswap.cpp
index 6db4a7d2..8714ec85 100644
--- a/src/PJ_axisswap.c
+++ b/src/conversions/axisswap.cpp
@@ -62,10 +62,12 @@ operation:
PROJ_HEAD(axisswap, "Axis ordering");
+namespace { // anonymous namespace
struct pj_opaque {
unsigned int axis[4];
int sign[4];
};
+} // anonymous namespace
static int sign(int x) {
return (x > 0) - (x < 0);
@@ -161,11 +163,11 @@ static PJ_COORD reverse_4d(PJ_COORD coo, PJ *P) {
/***********************************************************************/
PJ *CONVERSION(axisswap,0) {
/***********************************************************************/
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
char *s;
unsigned int i, j, n = 0;
- if (0==Q)
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;
@@ -187,7 +189,7 @@ PJ *CONVERSION(axisswap,0) {
/* check that all characters are valid */
for (i=0; i<strlen(order); i++)
- if (strchr("1234-,", order[i]) == 0) {
+ if (strchr("1234-,", order[i]) == nullptr) {
proj_log_error(P, "axisswap: unknown axis '%c'", order[i]);
return pj_default_destructor(P, PJD_ERR_AXIS);
}
@@ -273,7 +275,7 @@ PJ *CONVERSION(axisswap,0) {
}
- if (P->fwd4d == NULL && P->fwd3d == NULL && P->fwd == NULL) {
+ if (P->fwd4d == nullptr && P->fwd3d == nullptr && P->fwd == nullptr) {
proj_log_error(P, "swapaxis: bad axis order");
return pj_default_destructor(P, PJD_ERR_AXIS);
}
diff --git a/src/PJ_cart.c b/src/conversions/cart.cpp
index 6fed9985..6fed9985 100644
--- a/src/PJ_cart.c
+++ b/src/conversions/cart.cpp
diff --git a/src/PJ_geoc.c b/src/conversions/geoc.cpp
index 0455fada..0455fada 100644
--- a/src/PJ_geoc.c
+++ b/src/conversions/geoc.cpp
diff --git a/src/pj_geocent.c b/src/conversions/geocent.cpp
index 0e9d725e..0e9d725e 100644
--- a/src/pj_geocent.c
+++ b/src/conversions/geocent.cpp
diff --git a/src/PJ_unitconvert.c b/src/conversions/unitconvert.cpp
index 402941a4..b25fd5d2 100644
--- a/src/PJ_unitconvert.c
+++ b/src/conversions/unitconvert.cpp
@@ -78,19 +78,23 @@ PROJ_HEAD(unitconvert, "Unit conversion");
typedef double (*tconvert)(double);
+namespace { // anonymous namespace
struct TIME_UNITS {
- char *id; /* units keyword */
+ const char *id; /* units keyword */
tconvert t_in; /* unit -> mod. julian date function pointer */
tconvert t_out; /* mod. julian date > unit function pointer */
- char *name; /* comments */
+ const char *name; /* comments */
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque_unitconvert {
int t_in_id; /* time unit id for the time input unit */
int t_out_id; /* time unit id for the time output unit */
double xy_factor; /* unit conversion factor for horizontal components */
double z_factor; /* unit conversion factor for vertical components */
};
+} // anonymous namespace
/***********************************************************************/
@@ -272,7 +276,7 @@ static const struct TIME_UNITS time_units[] = {
{"decimalyear", decimalyear_to_mjd, mjd_to_decimalyear, "Decimal year"},
{"gps_week", gps_week_to_mjd, mjd_to_gps_week, "GPS Week"},
{"yyyymmdd", yyyymmdd_to_mjd, mjd_to_yyyymmdd, "YYYYMMDD date"},
- {NULL, NULL, NULL, NULL}
+ {nullptr, nullptr, nullptr, nullptr}
};
@@ -420,7 +424,7 @@ static double get_unit_conversion_factor(const char* name,
}
}
if( p_normalized_name ) {
- *p_normalized_name = NULL;
+ *p_normalized_name = nullptr;
}
if( p_is_linear ) {
*p_is_linear = -1;
@@ -431,8 +435,8 @@ static double get_unit_conversion_factor(const char* name,
/***********************************************************************/
PJ *CONVERSION(unitconvert,0) {
/***********************************************************************/
- struct pj_opaque_unitconvert *Q = pj_calloc (1, sizeof (struct pj_opaque_unitconvert));
- char *s, *name;
+ struct pj_opaque_unitconvert *Q = static_cast<struct pj_opaque_unitconvert*>(pj_calloc (1, sizeof (struct pj_opaque_unitconvert)));
+ const char *s, *name;
int i;
double f;
int xy_in_is_linear = -1; /* unknown */
@@ -440,7 +444,7 @@ PJ *CONVERSION(unitconvert,0) {
int z_in_is_linear = -1; /* unknown */
int z_out_is_linear = -1; /* unknown */
- if (0==Q)
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;
@@ -461,8 +465,8 @@ PJ *CONVERSION(unitconvert,0) {
Q->xy_factor = 1.0;
Q->z_factor = 1.0;
- if ((name = pj_param (P->ctx, P->params, "sxy_in").s) != NULL) {
- const char* normalized_name = NULL;
+ if ((name = pj_param (P->ctx, P->params, "sxy_in").s) != nullptr) {
+ const char* normalized_name = nullptr;
f = get_unit_conversion_factor(name, &xy_in_is_linear, &normalized_name);
if (f != 0.0) {
proj_log_debug(P, "xy_in unit: %s", normalized_name);
@@ -474,8 +478,8 @@ PJ *CONVERSION(unitconvert,0) {
Q->xy_factor *= f;
}
- if ((name = pj_param (P->ctx, P->params, "sxy_out").s) != NULL) {
- const char* normalized_name = NULL;
+ if ((name = pj_param (P->ctx, P->params, "sxy_out").s) != nullptr) {
+ const char* normalized_name = nullptr;
f = get_unit_conversion_factor(name, &xy_out_is_linear, &normalized_name);
if (f != 0.0) {
proj_log_debug(P, "xy_out unit: %s", normalized_name);
@@ -493,8 +497,8 @@ PJ *CONVERSION(unitconvert,0) {
return pj_default_destructor(P, PJD_ERR_INCONSISTENT_UNIT);
}
- if ((name = pj_param (P->ctx, P->params, "sz_in").s) != NULL) {
- const char* normalized_name = NULL;
+ if ((name = pj_param (P->ctx, P->params, "sz_in").s) != nullptr) {
+ const char* normalized_name = nullptr;
f = get_unit_conversion_factor(name, &z_in_is_linear, &normalized_name);
if (f != 0.0) {
proj_log_debug(P, "z_in unit: %s", normalized_name);
@@ -506,8 +510,8 @@ PJ *CONVERSION(unitconvert,0) {
Q->z_factor *= f;
}
- if ((name = pj_param (P->ctx, P->params, "sz_out").s) != NULL) {
- const char* normalized_name = NULL;
+ if ((name = pj_param (P->ctx, P->params, "sz_out").s) != nullptr) {
+ const char* normalized_name = nullptr;
f = get_unit_conversion_factor(name, &z_out_is_linear, &normalized_name);
if (f != 0.0) {
proj_log_debug(P, "z_out unit: %s", normalized_name);
@@ -525,7 +529,7 @@ PJ *CONVERSION(unitconvert,0) {
return pj_default_destructor(P, PJD_ERR_INCONSISTENT_UNIT);
}
- if ((name = pj_param (P->ctx, P->params, "st_in").s) != NULL) {
+ if ((name = pj_param (P->ctx, P->params, "st_in").s) != nullptr) {
for (i = 0; (s = time_units[i].id) && strcmp(name, s) ; ++i);
if (!s) return pj_default_destructor(P, PJD_ERR_UNKNOWN_UNIT_ID); /* unknown unit conversion id */
@@ -534,8 +538,8 @@ PJ *CONVERSION(unitconvert,0) {
proj_log_debug(P, "t_in unit: %s", time_units[i].name);
}
- s = 0;
- if ((name = pj_param (P->ctx, P->params, "st_out").s) != NULL) {
+ s = nullptr;
+ if ((name = pj_param (P->ctx, P->params, "st_out").s) != nullptr) {
for (i = 0; (s = time_units[i].id) && strcmp(name, s) ; ++i);
if (!s) return pj_default_destructor(P, PJD_ERR_UNKNOWN_UNIT_ID); /* unknown unit conversion id */
diff --git a/src/pj_ctx.c b/src/ctx.cpp
index 1c99e921..ab51d6c1 100644
--- a/src/pj_ctx.c
+++ b/src/ctx.cpp
@@ -42,9 +42,9 @@ static volatile int default_context_initialized = 0;
projCtx pj_get_ctx( projPJ pj )
{
- if (0==pj)
+ if (nullptr==pj)
return pj_get_default_ctx ();
- if (0==pj->ctx)
+ if (nullptr==pj->ctx)
return pj_get_default_ctx ();
return pj->ctx;
}
@@ -58,7 +58,7 @@ projCtx pj_get_ctx( projPJ pj )
void pj_set_ctx( projPJ pj, projCtx ctx )
{
- if (pj==0)
+ if (pj==nullptr)
return;
pj->ctx = ctx;
}
@@ -82,13 +82,13 @@ projCtx pj_get_default_ctx()
default_context.last_errno = 0;
default_context.debug_level = PJ_LOG_NONE;
default_context.logger = pj_stderr_logger;
- default_context.app_data = NULL;
+ default_context.app_data = nullptr;
default_context.fileapi = pj_get_default_fileapi();
- default_context.cpp_context = NULL;
+ default_context.cpp_context = nullptr;
default_context.use_proj4_init_rules = -1;
default_context.epsg_file_exists = -1;
- if( getenv("PROJ_DEBUG") != NULL )
+ if( getenv("PROJ_DEBUG") != nullptr )
{
if( atoi(getenv("PROJ_DEBUG")) >= -PJ_LOG_DEBUG_MINOR )
default_context.debug_level = atoi(getenv("PROJ_DEBUG"));
@@ -111,11 +111,11 @@ projCtx pj_ctx_alloc()
{
projCtx ctx = (projCtx_t *) malloc(sizeof(projCtx_t));
- if (0==ctx)
- return 0;
+ if (nullptr==ctx)
+ return nullptr;
memcpy( ctx, pj_get_default_ctx(), sizeof(projCtx_t) );
ctx->last_errno = 0;
- ctx->cpp_context = NULL;
+ ctx->cpp_context = nullptr;
ctx->use_proj4_init_rules = -1;
return ctx;
@@ -139,7 +139,7 @@ void pj_ctx_free( projCtx ctx )
int pj_ctx_get_errno( projCtx ctx )
{
- if (0==ctx)
+ if (nullptr==ctx)
return pj_get_default_ctx ()->last_errno;
return ctx->last_errno;
}
@@ -167,7 +167,7 @@ void pj_ctx_set_errno( projCtx ctx, int new_errno )
void pj_ctx_set_debug( projCtx ctx, int new_debug )
{
- if (0==ctx)
+ if (nullptr==ctx)
return;
ctx->debug_level = new_debug;
}
@@ -179,7 +179,7 @@ void pj_ctx_set_debug( projCtx ctx, int new_debug )
void pj_ctx_set_logger( projCtx ctx, void (*new_logger)(void*,int,const char*) )
{
- if (0==ctx)
+ if (nullptr==ctx)
return;
ctx->logger = new_logger;
}
@@ -191,7 +191,7 @@ void pj_ctx_set_logger( projCtx ctx, void (*new_logger)(void*,int,const char*) )
void pj_ctx_set_app_data( projCtx ctx, void *new_app_data )
{
- if (0==ctx)
+ if (nullptr==ctx)
return;
ctx->app_data = new_app_data;
}
@@ -203,8 +203,8 @@ void pj_ctx_set_app_data( projCtx ctx, void *new_app_data )
void *pj_ctx_get_app_data( projCtx ctx )
{
- if (0==ctx)
- return 0;
+ if (nullptr==ctx)
+ return nullptr;
return ctx->app_data;
}
@@ -215,7 +215,7 @@ void *pj_ctx_get_app_data( projCtx ctx )
void pj_ctx_set_fileapi( projCtx ctx, projFileAPI *fileapi )
{
- if (0==ctx)
+ if (nullptr==ctx)
return;
ctx->fileapi = fileapi;
}
@@ -227,7 +227,7 @@ void pj_ctx_set_fileapi( projCtx ctx, projFileAPI *fileapi )
projFileAPI *pj_ctx_get_fileapi( projCtx ctx )
{
- if (0==ctx)
- return 0;
+ if (nullptr==ctx)
+ return nullptr;
return ctx->fileapi;
}
diff --git a/src/pj_datum_set.c b/src/datum_set.cpp
index 466b56c5..c9dfdb80 100644
--- a/src/pj_datum_set.c
+++ b/src/datum_set.cpp
@@ -54,7 +54,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
/* definition will last into the pj_ell_set() function called */
/* after this one. */
/* -------------------------------------------------------------------- */
- if( (name = pj_param(ctx, pl,"sdatum").s) != NULL )
+ if( (name = pj_param(ctx, pl,"sdatum").s) != nullptr )
{
paralist *curr;
const char *s;
@@ -96,7 +96,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
/* Check for nadgrids parameter. */
/* -------------------------------------------------------------------- */
nadgrids = pj_param(ctx, pl,"snadgrids").s;
- if( nadgrids != NULL )
+ if( nadgrids != nullptr )
{
/* We don't actually save the value separately. It will continue
to exist int he param list for use in pj_apply_gridshift.c */
@@ -107,7 +107,7 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
/* -------------------------------------------------------------------- */
/* Check for grid catalog parameter, and optional date. */
/* -------------------------------------------------------------------- */
- else if( (catalog = pj_param(ctx, pl,"scatalog").s) != NULL )
+ else if( (catalog = pj_param(ctx, pl,"scatalog").s) != nullptr )
{
const char *date;
@@ -119,14 +119,14 @@ int pj_datum_set(projCtx ctx, paralist *pl, PJ *projdef)
}
date = pj_param(ctx, pl, "sdate").s;
- if( date != NULL)
+ if( date != nullptr)
projdef->datum_date = pj_gc_parsedate( ctx, date);
}
/* -------------------------------------------------------------------- */
/* Check for towgs84 parameter. */
/* -------------------------------------------------------------------- */
- else if( (towgs84 = pj_param(ctx, pl,"stowgs84").s) != NULL )
+ else if( (towgs84 = pj_param(ctx, pl,"stowgs84").s) != nullptr )
{
int parm_count = 0;
const char *s;
diff --git a/src/pj_datums.c b/src/datums.cpp
index 2951b7bd..acbe12f7 100644
--- a/src/pj_datums.c
+++ b/src/datums.cpp
@@ -65,7 +65,7 @@ C_NAMESPACE_VAR const struct PJ_DATUMS pj_datums[] = {
"intl", "New Zealand Geodetic Datum 1949"},
{"OSGB36", "towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894",
"airy", "Airy 1830"},
-{NULL, NULL, NULL, NULL}
+{nullptr, nullptr, nullptr, nullptr}
};
struct PJ_DATUMS *pj_get_datums_ref()
@@ -90,7 +90,7 @@ static const struct PJ_PRIME_MERIDIANS pj_prime_meridians[] = {
{"athens", "23d42'58.815\"E"},
{"oslo", "10d43'22.5\"E"},
{"copenhagen","12d34'40.35\"E"},
- {NULL, NULL}
+ {nullptr, nullptr}
};
const PJ_PRIME_MERIDIANS *proj_list_prime_meridians(void)
diff --git a/src/pj_deriv.c b/src/deriv.cpp
index 2c91e0cc..0e285265 100644
--- a/src/pj_deriv.c
+++ b/src/deriv.cpp
@@ -9,7 +9,7 @@ int pj_deriv(LP lp, double h, const PJ *P, struct DERIVS *der) {
XY t;
/* get rid of constness until we can do it for real */
PJ *Q = (PJ *) P;
- if (0==Q->fwd)
+ if (nullptr==Q->fwd)
return 1;
lp.lam += h;
diff --git a/src/dmstor.c b/src/dmstor.cpp
index ab8e33f4..967a9f18 100644
--- a/src/dmstor.c
+++ b/src/dmstor.cpp
@@ -27,7 +27,8 @@ dmstor(const char *is, char **rs) {
double
dmstor_ctx(projCtx ctx, const char *is, char **rs) {
int sign, n, nl;
- char *p, *s, work[MAX_WORK];
+ char *s, work[MAX_WORK];
+ const char* p;
double v, tv;
if (rs)
diff --git a/src/pj_ell_set.c b/src/ell_set.cpp
index e2d2750c..486230a5 100644
--- a/src/pj_ell_set.c
+++ b/src/ell_set.cpp
@@ -15,9 +15,9 @@ static int ellps_size (PJ *P);
static int ellps_shape (PJ *P);
static int ellps_spherification (PJ *P);
-static paralist *pj_get_param (paralist *list, char *key);
+static paralist *pj_get_param (paralist *list, const char *key);
static char *pj_param_value (paralist *list);
-static const PJ_ELLPS *pj_find_ellps (char *name);
+static const PJ_ELLPS *pj_find_ellps (const char *name);
/***************************************************************************************/
@@ -75,9 +75,9 @@ int pj_ellipsoid (PJ *P) {
****************************************************************************************/
int err = proj_errno_reset (P);
- char *empty = {""};
+ const char *empty = {""};
- P->def_size = P->def_shape = P->def_spherification = P->def_ellps = 0;
+ P->def_size = P->def_shape = P->def_spherification = P->def_ellps = nullptr;
/* Specifying R overrules everything */
if (pj_get_param (P->params, "R")) {
@@ -129,13 +129,13 @@ static int ellps_ellps (PJ *P) {
/***************************************************************************************/
PJ B;
const PJ_ELLPS *ellps;
- paralist *par = 0;
+ paralist *par = nullptr;
char *name;
int err;
/* Sail home if ellps=xxx is not specified */
par = pj_get_param (P->params, "ellps");
- if (0==par)
+ if (nullptr==par)
return 0;
/* Otherwise produce a fake PJ to make ellps_size/ellps_shape do the hard work for us */
@@ -148,7 +148,7 @@ static int ellps_ellps (PJ *P) {
return proj_errno_set (P, PJD_ERR_INVALID_ARG);
name = par->param + 6;
ellps = pj_find_ellps (name);
- if (0==ellps)
+ if (nullptr==ellps)
return proj_errno_set (P, PJD_ERR_UNKNOWN_ELLP_PARAM);
/* Now, get things ready for ellps_size/ellps_shape, make them do their thing, and clean up */
@@ -178,7 +178,7 @@ static int ellps_ellps (PJ *P) {
/***************************************************************************************/
static int ellps_size (PJ *P) {
/***************************************************************************************/
- paralist *par = 0;
+ paralist *par = nullptr;
int a_was_set = 0;
/* A size parameter *must* be given, but may have been given as ellps prior */
@@ -187,9 +187,9 @@ static int ellps_size (PJ *P) {
/* Check which size key is specified */
par = pj_get_param (P->params, "R");
- if (0==par)
+ if (nullptr==par)
par = pj_get_param (P->params, "a");
- if (0==par)
+ if (nullptr==par)
return a_was_set? 0: proj_errno_set (P, PJD_ERR_MAJOR_AXIS_NOT_GIVEN);
P->def_size = par->param;
@@ -211,12 +211,12 @@ static int ellps_size (PJ *P) {
/***************************************************************************************/
static int ellps_shape (PJ *P) {
/***************************************************************************************/
- char *keys[] = {"rf", "f", "es", "e", "b"};
- paralist *par = 0;
- char *def = 0;
+ const char *keys[] = {"rf", "f", "es", "e", "b"};
+ paralist *par = nullptr;
+ char *def = nullptr;
size_t i, len;
- par = 0;
+ par = nullptr;
len = sizeof (keys) / sizeof (char *);
/* Check which shape key is specified */
@@ -228,9 +228,9 @@ static int ellps_shape (PJ *P) {
/* Not giving a shape parameter means selecting a sphere, unless shape */
/* has been selected previously via ellps=xxx */
- if (0==par && P->es != 0)
+ if (nullptr==par && P->es != 0)
return 0;
- if (0==par && P->es==0) {
+ if (nullptr==par && P->es==0) {
P->es = P->f = 0;
P->b = P->a;
return 0;
@@ -317,16 +317,16 @@ static const double RV6 = 55/1296.;
/***************************************************************************************/
static int ellps_spherification (PJ *P) {
/***************************************************************************************/
- char *keys[] = {"R_A", "R_V", "R_a", "R_g", "R_h", "R_lat_a", "R_lat_g"};
+ const char *keys[] = {"R_A", "R_V", "R_a", "R_g", "R_h", "R_lat_a", "R_lat_g"};
size_t len, i;
- paralist *par = 0;
- char *def = 0;
+ paralist *par = nullptr;
+ char *def = nullptr;
double t;
char *v, *endp;
len = sizeof (keys) / sizeof (char *);
- P->def_spherification = 0;
+ P->def_spherification = nullptr;
/* Check which spherification key is specified */
for (i = 0; i < len; i++) {
@@ -400,7 +400,7 @@ static int ellps_spherification (PJ *P) {
/* locate parameter in list */
-static paralist *pj_get_param (paralist *list, char *key) {
+static paralist *pj_get_param (paralist *list, const char *key) {
size_t l = strlen(key);
while (list && !(0==strncmp(list->param, key, l) && (0==list->param[l] || list->param[l] == '=') ) )
list = list->next;
@@ -410,8 +410,8 @@ static paralist *pj_get_param (paralist *list, char *key) {
static char *pj_param_value (paralist *list) {
char *key, *value;
- if (0==list)
- return 0;
+ if (nullptr==list)
+ return nullptr;
key = list->param;
value = strchr (key, '=');
@@ -421,20 +421,20 @@ static char *pj_param_value (paralist *list) {
}
-static const PJ_ELLPS *pj_find_ellps (char *name) {
+static const PJ_ELLPS *pj_find_ellps (const char *name) {
int i;
const char *s;
const PJ_ELLPS *ellps;
- if (0==name)
- return 0;
+ if (nullptr==name)
+ return nullptr;
ellps = proj_list_ellps();
/* Search through internal ellipsoid list for name */
for (i = 0; (s = ellps[i].id) && strcmp(name, s) ; ++i);
- if (0==s)
- return 0;
+ if (nullptr==s)
+ return nullptr;
return ellps + i;
}
diff --git a/src/pj_ellps.c b/src/ellps.cpp
index 8b3b8f0a..f548d30d 100644
--- a/src/pj_ellps.c
+++ b/src/ellps.cpp
@@ -53,7 +53,7 @@ pj_ellps[] = {
{"WGS72", "a=6378135.0", "rf=298.26", "WGS 72"},
{"WGS84", "a=6378137.0", "rf=298.257223563", "WGS 84"},
{"sphere", "a=6370997.0", "b=6370997.0", "Normal Sphere (r=6370997)"},
-{NULL, NULL, NULL, NULL}
+{nullptr, nullptr, nullptr, nullptr}
};
const PJ_ELLPS *proj_list_ellps(void)
diff --git a/src/pj_errno.c b/src/errno.cpp
index 6e98cd73..f6ea9bfc 100644
--- a/src/pj_errno.c
+++ b/src/errno.cpp
@@ -2,7 +2,7 @@
#include "projects.h"
-C_NAMESPACE_VAR int pj_errno = 0;
+int pj_errno = 0;
/************************************************************************/
/* pj_get_errno_ref() */
diff --git a/src/pj_factors.c b/src/factors.cpp
index e4b871a1..768bf585 100644
--- a/src/pj_factors.c
+++ b/src/factors.cpp
@@ -21,10 +21,10 @@ int pj_factors(LP lp, const PJ *P, double h, struct FACTORS *fac) {
/* Failing the 3 initial checks will most likely be due to */
/* earlier errors, so we leave errno alone */
- if (0==fac)
+ if (nullptr==fac)
return 1;
- if (0==P)
+ if (nullptr==P)
return 1;
if (HUGE_VAL==lp.lam)
diff --git a/src/pj_fileapi.c b/src/fileapi.cpp
index eba96afd..3df73236 100644
--- a/src/pj_fileapi.c
+++ b/src/fileapi.cpp
@@ -75,9 +75,9 @@ static PAFile stdio_fopen(projCtx ctx, const char *filename,
FILE *fp;
fp = fopen(filename, access);
- if (fp == NULL)
+ if (fp == nullptr)
{
- return NULL;
+ return nullptr;
}
pafile = (stdio_pafile *) malloc(sizeof(stdio_pafile));
@@ -85,7 +85,7 @@ static PAFile stdio_fopen(projCtx ctx, const char *filename,
{
pj_ctx_set_errno(ctx, ENOMEM);
fclose(fp);
- return NULL;
+ return nullptr;
}
pafile->fp = fp;
@@ -193,7 +193,7 @@ char *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file)
line[size-1] = '\0';
bytes_read = pj_ctx_fread(ctx, line, 1, size-1, file);
if(bytes_read == 0)
- return NULL;
+ return nullptr;
if(bytes_read < (size_t)size)
{
line[bytes_read] = '\0';
diff --git a/src/pj_fwd.c b/src/fwd.cpp
index 38443f07..e8f73999 100644
--- a/src/pj_fwd.c
+++ b/src/fwd.cpp
@@ -74,7 +74,7 @@ static PJ_COORD fwd_prepare (PJ *P, PJ_COORD coo) {
if (P->hgridshift)
coo = proj_trans (P->hgridshift, PJ_INV, coo);
- else if (P->helmert || (P->cart_wgs84 != 0 && P->cart != 0)) {
+ else if (P->helmert || (P->cart_wgs84 != nullptr && P->cart != nullptr)) {
coo = proj_trans (P->cart_wgs84, PJ_FWD, coo); /* Go cartesian in WGS84 frame */
if( P->helmert )
coo = proj_trans (P->helmert, PJ_INV, coo); /* Step into local frame */
diff --git a/src/pj_gauss.c b/src/gauss.cpp
index 4520bb39..2db713ad 100644
--- a/src/pj_gauss.c
+++ b/src/gauss.cpp
@@ -32,12 +32,14 @@
#define MAX_ITER 20
+namespace { // anonymous namespace
struct GAUSS {
double C;
double K;
double e;
double ratexp;
};
+} // anonymous namespace
#define DEL_TOL 1e-14
static double srat(double esinp, double ratexp) {
@@ -48,8 +50,8 @@ void *pj_gauss_ini(double e, double phi0, double *chi, double *rc) {
double sphi, cphi, es;
struct GAUSS *en;
- if ((en = (struct GAUSS *)malloc(sizeof(struct GAUSS))) == NULL)
- return (NULL);
+ if ((en = (struct GAUSS *)malloc(sizeof(struct GAUSS))) == nullptr)
+ return (nullptr);
es = e * e;
en->e = e;
sphi = sin(phi0);
@@ -58,7 +60,7 @@ void *pj_gauss_ini(double e, double phi0, double *chi, double *rc) {
en->C = sqrt(1. + es * cphi * cphi / (1. - es));
if (en->C == 0.0) {
free(en);
- return NULL;
+ return nullptr;
}
*chi = asin(sphi / en->C);
en->ratexp = 0.5 * en->C * e;
diff --git a/src/pj_gc_reader.c b/src/gc_reader.cpp
index 493fc075..118aadf6 100644
--- a/src/pj_gc_reader.c
+++ b/src/gc_reader.cpp
@@ -50,8 +50,8 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
char line[302];
fid = pj_open_lib( ctx, catalog_name, "r" );
- if (fid == NULL)
- return NULL;
+ if (fid == nullptr)
+ return nullptr;
/* discard title line */
pj_ctx_fgets(ctx, line, sizeof(line)-1, fid);
@@ -61,7 +61,7 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
{
pj_ctx_set_errno(ctx, ENOMEM);
pj_ctx_fclose(ctx, fid);
- return NULL;
+ return nullptr;
}
catalog->catalog_name = pj_strdup(catalog_name);
@@ -69,7 +69,7 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
pj_ctx_set_errno(ctx, ENOMEM);
free(catalog);
pj_ctx_fclose(ctx, fid);
- return NULL;
+ return nullptr;
}
entry_max = 10;
@@ -80,7 +80,7 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
free(catalog->catalog_name);
free(catalog);
pj_ctx_fclose(ctx, fid);
- return NULL;
+ return nullptr;
}
while( gc_readentry( ctx, fid,
@@ -95,7 +95,7 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
new_entries = (PJ_GridCatalogEntry *)
realloc(catalog->entries,
entry_max * sizeof(PJ_GridCatalogEntry));
- if (new_entries == NULL )
+ if (new_entries == nullptr )
{
int i;
for( i = 0; i < catalog->entry_count; i++ )
@@ -104,7 +104,7 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
free( catalog->catalog_name );
free( catalog );
pj_ctx_fclose(ctx, fid);
- return NULL;
+ return nullptr;
}
catalog->entries = new_entries;
}
@@ -127,7 +127,7 @@ static int gc_read_csv_line( projCtx ctx, PAFile fid,
{
char line[302];
- while( pj_ctx_fgets(ctx, line, sizeof(line)-1, fid) != NULL )
+ while( pj_ctx_fgets(ctx, line, sizeof(line)-1, fid) != nullptr )
{
char *next = line;
int token_count = 0;
@@ -226,11 +226,11 @@ static int gc_readentry(projCtx ctx, PAFile fid, PJ_GridCatalogEntry *entry)
else
{
entry->definition = tokens[0];
- tokens[0] = NULL; /* We take ownership of tokens[0] */
- entry->region.ll_long = dmstor_ctx( ctx, tokens[1], NULL );
- entry->region.ll_lat = dmstor_ctx( ctx, tokens[2], NULL );
- entry->region.ur_long = dmstor_ctx( ctx, tokens[3], NULL );
- entry->region.ur_lat = dmstor_ctx( ctx, tokens[4], NULL );
+ tokens[0] = nullptr; /* We take ownership of tokens[0] */
+ entry->region.ll_long = dmstor_ctx( ctx, tokens[1], nullptr );
+ entry->region.ll_lat = dmstor_ctx( ctx, tokens[2], nullptr );
+ entry->region.ur_long = dmstor_ctx( ctx, tokens[3], nullptr );
+ entry->region.ur_lat = dmstor_ctx( ctx, tokens[4], nullptr );
if( token_count > 5 )
entry->priority = atoi( tokens[5] ); /* defaults to zero */
if( token_count > 6 )
diff --git a/src/geocent.c b/src/geocent.cpp
index c023bdd3..c023bdd3 100644
--- a/src/geocent.c
+++ b/src/geocent.cpp
diff --git a/src/geodesic.c b/src/geodesic.c
index 220dcd7f..5504cb3b 100644
--- a/src/geodesic.c
+++ b/src/geodesic.c
@@ -34,6 +34,10 @@
#define HAVE_C99_MATH 0
#endif
+#if !defined(__cplusplus)
+#define nullptr 0
+#endif
+
#define GEOGRAPHICLIB_GEODESIC_ORDER 6
#define nA1 GEOGRAPHICLIB_GEODESIC_ORDER
#define nC1 GEOGRAPHICLIB_GEODESIC_ORDER
@@ -507,13 +511,13 @@ real geod_genposition(const struct geod_geodesicline* l,
real omg12, lam12, lon12;
real ssig2, csig2, sbet2, cbet2, somg2, comg2, salp2, calp2, dn2;
unsigned outmask =
- (plat2 ? GEOD_LATITUDE : 0U) |
- (plon2 ? GEOD_LONGITUDE : 0U) |
- (pazi2 ? GEOD_AZIMUTH : 0U) |
- (ps12 ? GEOD_DISTANCE : 0U) |
- (pm12 ? GEOD_REDUCEDLENGTH : 0U) |
- (pM12 || pM21 ? GEOD_GEODESICSCALE : 0U) |
- (pS12 ? GEOD_AREA : 0U);
+ (plat2 ? GEOD_LATITUDE : GEOD_NONE) |
+ (plon2 ? GEOD_LONGITUDE : GEOD_NONE) |
+ (pazi2 ? GEOD_AZIMUTH : GEOD_NONE) |
+ (ps12 ? GEOD_DISTANCE : GEOD_NONE) |
+ (pm12 ? GEOD_REDUCEDLENGTH : GEOD_NONE) |
+ (pM12 || pM21 ? GEOD_GEODESICSCALE : GEOD_NONE) |
+ (pS12 ? GEOD_AREA : GEOD_NONE);
outmask &= l->caps & OUT_ALL;
if (!( TRUE /*Init()*/ &&
@@ -693,12 +697,12 @@ real geod_genposition(const struct geod_geodesicline* l,
void geod_setdistance(struct geod_geodesicline* l, real s13) {
l->s13 = s13;
- l->a13 = geod_genposition(l, GEOD_NOFLAGS, l->s13, 0, 0, 0, 0, 0, 0, 0, 0);
+ l->a13 = geod_genposition(l, GEOD_NOFLAGS, l->s13, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
}
static void geod_setarc(struct geod_geodesicline* l, real a13) {
l->a13 = a13; l->s13 = NaN;
- geod_genposition(l, GEOD_ARCMODE, l->a13, 0, 0, 0, &l->s13, 0, 0, 0, 0);
+ geod_genposition(l, GEOD_ARCMODE, l->a13, nullptr, nullptr, nullptr, &l->s13, nullptr, nullptr, nullptr, nullptr);
}
void geod_gensetdistance(struct geod_geodesicline* l,
@@ -710,7 +714,7 @@ void geod_gensetdistance(struct geod_geodesicline* l,
void geod_position(const struct geod_geodesicline* l, real s12,
real* plat2, real* plon2, real* pazi2) {
- geod_genposition(l, FALSE, s12, plat2, plon2, pazi2, 0, 0, 0, 0, 0);
+ geod_genposition(l, FALSE, s12, plat2, plon2, pazi2, nullptr, nullptr, nullptr, nullptr, nullptr);
}
real geod_gendirect(const struct geod_geodesic* g,
@@ -721,13 +725,13 @@ real geod_gendirect(const struct geod_geodesic* g,
real* pS12) {
struct geod_geodesicline l;
unsigned outmask =
- (plat2 ? GEOD_LATITUDE : 0U) |
- (plon2 ? GEOD_LONGITUDE : 0U) |
- (pazi2 ? GEOD_AZIMUTH : 0U) |
- (ps12 ? GEOD_DISTANCE : 0U) |
- (pm12 ? GEOD_REDUCEDLENGTH : 0U) |
- (pM12 || pM21 ? GEOD_GEODESICSCALE : 0U) |
- (pS12 ? GEOD_AREA : 0U);
+ (plat2 ? GEOD_LATITUDE : GEOD_NONE) |
+ (plon2 ? GEOD_LONGITUDE : GEOD_NONE) |
+ (pazi2 ? GEOD_AZIMUTH : GEOD_NONE) |
+ (ps12 ? GEOD_DISTANCE : GEOD_NONE) |
+ (pm12 ? GEOD_REDUCEDLENGTH : GEOD_NONE) |
+ (pM12 || pM21 ? GEOD_GEODESICSCALE : GEOD_NONE) |
+ (pS12 ? GEOD_AREA : GEOD_NONE);
geod_lineinit(&l, g, lat1, lon1, azi1,
/* Automatically supply GEOD_DISTANCE_IN if necessary */
@@ -742,7 +746,7 @@ void geod_direct(const struct geod_geodesic* g,
real s12,
real* plat2, real* plon2, real* pazi2) {
geod_gendirect(g, lat1, lon1, azi1, GEOD_NOFLAGS, s12, plat2, plon2, pazi2,
- 0, 0, 0, 0, 0);
+ nullptr, nullptr, nullptr, nullptr, nullptr);
}
static real geod_geninverse_int(const struct geod_geodesic* g,
@@ -764,10 +768,10 @@ static real geod_geninverse_int(const struct geod_geodesic* g,
real omg12 = 0, somg12 = 2, comg12 = 0;
unsigned outmask =
- (ps12 ? GEOD_DISTANCE : 0U) |
- (pm12 ? GEOD_REDUCEDLENGTH : 0U) |
- (pM12 || pM21 ? GEOD_GEODESICSCALE : 0U) |
- (pS12 ? GEOD_AREA : 0U);
+ (ps12 ? GEOD_DISTANCE : GEOD_NONE) |
+ (pm12 ? GEOD_REDUCEDLENGTH : GEOD_NONE) |
+ (pM12 || pM21 ? GEOD_GEODESICSCALE : GEOD_NONE) |
+ (pS12 ? GEOD_AREA : GEOD_NONE);
outmask &= OUT_ALL;
/* Compute longitude difference (AngDiff does this carefully). Result is
@@ -858,9 +862,9 @@ static real geod_geninverse_int(const struct geod_geodesic* g,
sig12 = atan2(maxx((real)(0), csig1 * ssig2 - ssig1 * csig2),
csig1 * csig2 + ssig1 * ssig2);
Lengths(g, g->n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
- cbet1, cbet2, &s12x, &m12x, 0,
- (outmask & GEOD_GEODESICSCALE) ? &M12 : 0,
- (outmask & GEOD_GEODESICSCALE) ? &M21 : 0,
+ cbet1, cbet2, &s12x, &m12x, nullptr,
+ (outmask & GEOD_GEODESICSCALE) ? &M12 : nullptr,
+ (outmask & GEOD_GEODESICSCALE) ? &M21 : nullptr,
Ca);
/* Add the check for sig12 since zero length geodesics might yield m12 <
* 0. Test case was
@@ -983,9 +987,9 @@ static real geod_geninverse_int(const struct geod_geodesic* g,
fabs(salp1 - salp1b) + (calp1 - calp1b) < tolb);
}
Lengths(g, eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
- cbet1, cbet2, &s12x, &m12x, 0,
- (outmask & GEOD_GEODESICSCALE) ? &M12 : 0,
- (outmask & GEOD_GEODESICSCALE) ? &M21 : 0, Ca);
+ cbet1, cbet2, &s12x, &m12x, nullptr,
+ (outmask & GEOD_GEODESICSCALE) ? &M12 : nullptr,
+ (outmask & GEOD_GEODESICSCALE) ? &M21 : nullptr, Ca);
m12x *= g->b;
s12x *= g->b;
a12 = sig12 / degree;
@@ -1115,9 +1119,9 @@ void geod_inverseline(struct geod_geodesicline* l,
real lat1, real lon1, real lat2, real lon2,
unsigned caps) {
real salp1, calp1,
- a12 = geod_geninverse_int(g, lat1, lon1, lat2, lon2, 0,
- &salp1, &calp1, 0, 0,
- 0, 0, 0, 0),
+ a12 = geod_geninverse_int(g, lat1, lon1, lat2, lon2, nullptr,
+ &salp1, &calp1, nullptr, nullptr,
+ nullptr, nullptr, nullptr, nullptr),
azi1 = atan2dx(salp1, calp1);
caps = caps ? caps : GEOD_DISTANCE_IN | GEOD_LONGITUDE;
/* Ensure that a12 can be converted to a distance */
@@ -1129,7 +1133,7 @@ void geod_inverseline(struct geod_geodesicline* l,
void geod_inverse(const struct geod_geodesic* g,
real lat1, real lon1, real lat2, real lon2,
real* ps12, real* pazi1, real* pazi2) {
- geod_geninverse(g, lat1, lon1, lat2, lon2, ps12, pazi1, pazi2, 0, 0, 0, 0);
+ geod_geninverse(g, lat1, lon1, lat2, lon2, ps12, pazi1, pazi2, nullptr, nullptr, nullptr, nullptr);
}
real SinCosSeries(boolx sinp, real sinx, real cosx, const real c[], int n) {
@@ -1371,7 +1375,7 @@ real InverseStart(const struct geod_geodesic* g,
* Inverse. */
Lengths(g, g->n, pi + bet12a,
sbet1, -cbet1, dn1, sbet2, cbet2, dn2,
- cbet1, cbet2, 0, &m12b, &m0, 0, 0, Ca);
+ cbet1, cbet2, nullptr, &m12b, &m0, nullptr, nullptr, Ca);
x = -1 + m12b / (cbet1 * cbet2 * m0 * pi);
betscale = x < -(real)(0.01) ? sbet12a / x :
-g->f * sq(cbet1) * pi;
@@ -1531,7 +1535,7 @@ real Lambda12(const struct geod_geodesic* g,
dlam12 = - 2 * g->f1 * dn1 / sbet1;
else {
Lengths(g, eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2,
- cbet1, cbet2, 0, &dlam12, 0, 0, 0, Ca);
+ cbet1, cbet2, nullptr, &dlam12, nullptr, nullptr, nullptr, Ca);
dlam12 *= g->f1 / (calp2 * cbet2);
}
}
@@ -1819,7 +1823,7 @@ int transit(real lon1, real lon2) {
/* Compute lon12 the same way as Geodesic::Inverse. */
lon1 = AngNormalize(lon1);
lon2 = AngNormalize(lon2);
- lon12 = AngDiff(lon1, lon2, 0);
+ lon12 = AngDiff(lon1, lon2, nullptr);
return lon1 <= 0 && lon2 > 0 && lon12 > 0 ? 1 :
(lon2 <= 0 && lon1 > 0 && lon12 < 0 ? -1 : 0);
}
@@ -1893,7 +1897,7 @@ void geod_polygon_addpoint(const struct geod_geodesic* g,
} else {
real s12, S12 = 0; /* Initialize S12 to stop Visual Studio warning */
geod_geninverse(g, p->lat, p->lon, lat, lon,
- &s12, 0, 0, 0, 0, 0, p->polyline ? 0 : &S12);
+ &s12, nullptr, nullptr, nullptr, nullptr, nullptr, p->polyline ? nullptr : &S12);
accadd(p->P, s12);
if (!p->polyline) {
accadd(p->A, S12);
@@ -1912,8 +1916,8 @@ void geod_polygon_addedge(const struct geod_geodesic* g,
* lon is to make CLang static analyzer happy. */
real lat = 0, lon = 0, S12 = 0;
geod_gendirect(g, p->lat, p->lon, azi, GEOD_LONG_UNROLL, s,
- &lat, &lon, 0,
- 0, 0, 0, 0, p->polyline ? 0 : &S12);
+ &lat, &lon, nullptr,
+ nullptr, nullptr, nullptr, nullptr, p->polyline ? nullptr : &S12);
accadd(p->P, s);
if (!p->polyline) {
accadd(p->A, S12);
@@ -1940,7 +1944,7 @@ unsigned geod_polygon_compute(const struct geod_geodesic* g,
return p->num;
}
geod_geninverse(g, p->lat, p->lon, p->lat0, p->lon0,
- &s12, 0, 0, 0, 0, 0, &S12);
+ &s12, nullptr, nullptr, nullptr, nullptr, nullptr, &S12);
if (pP) *pP = accsum(p->P, s12);
acccopy(p->A, t);
accadd(t, S12);
@@ -1989,7 +1993,7 @@ unsigned geod_polygon_testpoint(const struct geod_geodesic* g,
geod_geninverse(g,
i == 0 ? p->lat : lat, i == 0 ? p->lon : lon,
i != 0 ? p->lat0 : lat, i != 0 ? p->lon0 : lon,
- &s12, 0, 0, 0, 0, 0, p->polyline ? 0 : &S12);
+ &s12, nullptr, nullptr, nullptr, nullptr, nullptr, p->polyline ? nullptr : &S12);
perimeter += s12;
if (!p->polyline) {
tempsum += S12;
@@ -2051,12 +2055,12 @@ unsigned geod_polygon_testedge(const struct geod_geodesic* g,
happy. */
real lat = 0, lon = 0, s12, S12 = 0;
geod_gendirect(g, p->lat, p->lon, azi, GEOD_LONG_UNROLL, s,
- &lat, &lon, 0,
- 0, 0, 0, 0, &S12);
+ &lat, &lon, nullptr,
+ nullptr, nullptr, nullptr, nullptr, &S12);
tempsum += S12;
crossings += transitdirect(p->lon, lon);
geod_geninverse(g, lat, lon, p->lat0, p->lon0,
- &s12, 0, 0, 0, 0, 0, &S12);
+ &s12, nullptr, nullptr, nullptr, nullptr, nullptr, &S12);
perimeter += s12;
tempsum += S12;
crossings += transit(lon, p->lon0);
diff --git a/src/pj_gridcatalog.c b/src/gridcatalog.cpp
index ea9c4aa1..fef2df56 100644
--- a/src/pj_gridcatalog.c
+++ b/src/gridcatalog.cpp
@@ -34,7 +34,7 @@
#include "projects.h"
-static PJ_GridCatalog *grid_catalog_list = NULL;
+static PJ_GridCatalog *grid_catalog_list = nullptr;
/************************************************************************/
/* pj_gc_unloadall() */
@@ -47,7 +47,7 @@ void pj_gc_unloadall( projCtx ctx )
{
(void) ctx;
- while( grid_catalog_list != NULL )
+ while( grid_catalog_list != nullptr )
{
int i;
PJ_GridCatalog *catalog = grid_catalog_list;
@@ -75,7 +75,7 @@ PJ_GridCatalog *pj_gc_findcatalog( projCtx ctx, const char *name )
pj_acquire_lock();
- for( catalog=grid_catalog_list; catalog != NULL; catalog = catalog->next )
+ for( catalog=grid_catalog_list; catalog != nullptr; catalog = catalog->next )
{
if( strcmp(catalog->catalog_name, name) == 0 )
{
@@ -87,8 +87,8 @@ PJ_GridCatalog *pj_gc_findcatalog( projCtx ctx, const char *name )
pj_release_lock();
catalog = pj_gc_readcatalog( ctx, name );
- if( catalog == NULL )
- return NULL;
+ if( catalog == nullptr )
+ return nullptr;
pj_acquire_lock();
catalog->next = grid_catalog_list;
@@ -110,10 +110,10 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse,
int i;
(void) z;
- if( defn->catalog == NULL )
+ if( defn->catalog == nullptr )
{
defn->catalog = pj_gc_findcatalog( defn->ctx, defn->catalog_name );
- if( defn->catalog == NULL )
+ if( defn->catalog == nullptr )
return defn->ctx->last_errno;
}
@@ -130,7 +130,7 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse,
input.lam = x[io];
/* make sure we have appropriate "after" shift file available */
- if( defn->last_after_grid == NULL
+ if( defn->last_after_grid == nullptr
|| input.lam < defn->last_after_region.ll_long
|| input.lam > defn->last_after_region.ur_long
|| input.phi < defn->last_after_region.ll_lat
@@ -140,17 +140,17 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse,
1, input, defn->datum_date,
&(defn->last_after_region),
&(defn->last_after_date));
- if( defn->last_after_grid == NULL )
+ if( defn->last_after_grid == nullptr )
{
pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
return PJD_ERR_FAILED_TO_LOAD_GRID;
}
}
gi = defn->last_after_grid;
- assert( gi->child == NULL );
+ assert( gi->child == nullptr );
/* load the grid shift info if we don't have it. */
- if( gi->ct->cvs == NULL && !pj_gridinfo_load( defn->ctx, gi ) )
+ if( gi->ct->cvs == nullptr && !pj_gridinfo_load( defn->ctx, gi ) )
{
pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
return PJD_ERR_FAILED_TO_LOAD_GRID;
@@ -178,7 +178,7 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse,
}
/* make sure we have appropriate "before" shift file available */
- if( defn->last_before_grid == NULL
+ if( defn->last_before_grid == nullptr
|| input.lam < defn->last_before_region.ll_long
|| input.lam > defn->last_before_region.ur_long
|| input.phi < defn->last_before_region.ll_lat
@@ -188,7 +188,7 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse,
0, input, defn->datum_date,
&(defn->last_before_region),
&(defn->last_before_date));
- if( defn->last_before_grid == NULL )
+ if( defn->last_before_grid == nullptr )
{
pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
return PJD_ERR_FAILED_TO_LOAD_GRID;
@@ -196,10 +196,10 @@ int pj_gc_apply_gridshift( PJ *defn, int inverse,
}
gi = defn->last_before_grid;
- assert( gi->child == NULL );
+ assert( gi->child == nullptr );
/* load the grid shift info if we don't have it. */
- if( gi->ct->cvs == NULL && !pj_gridinfo_load( defn->ctx, gi ) )
+ if( gi->ct->cvs == nullptr && !pj_gridinfo_load( defn->ctx, gi ) )
{
pj_ctx_set_errno( defn->ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
return PJD_ERR_FAILED_TO_LOAD_GRID;
@@ -241,7 +241,7 @@ PJ_GRIDINFO *pj_gc_findgrid( projCtx ctx, PJ_GridCatalog *catalog, int after,
double *grid_date )
{
int iEntry;
- PJ_GridCatalogEntry *entry = NULL;
+ PJ_GridCatalogEntry *entry = nullptr;
for( iEntry = 0; iEntry < catalog->entry_count; iEntry++ )
{
@@ -263,13 +263,13 @@ PJ_GRIDINFO *pj_gc_findgrid( projCtx ctx, PJ_GridCatalog *catalog, int after,
break;
}
- if( entry == NULL )
+ if( entry == nullptr )
{
if( grid_date )
*grid_date = 0.0;
- if( optional_region != NULL )
+ if( optional_region != nullptr )
memset( optional_region, 0, sizeof(PJ_Region));
- return NULL;
+ return nullptr;
}
if( grid_date )
@@ -280,9 +280,9 @@ PJ_GRIDINFO *pj_gc_findgrid( projCtx ctx, PJ_GridCatalog *catalog, int after,
}
- if( entry->gridinfo == NULL )
+ if( entry->gridinfo == nullptr )
{
- PJ_GRIDINFO **gridlist = NULL;
+ PJ_GRIDINFO **gridlist = nullptr;
int grid_count = 0;
gridlist = pj_gridlist_from_nadgrids( ctx, entry->definition,
&grid_count);
diff --git a/src/pj_gridinfo.c b/src/gridinfo.cpp
index de0e8d31..046abfcc 100644
--- a/src/pj_gridinfo.c
+++ b/src/gridinfo.cpp
@@ -89,25 +89,25 @@ static double to_double( unsigned char* data )
void pj_gridinfo_free( projCtx ctx, PJ_GRIDINFO *gi )
{
- if( gi == NULL )
+ if( gi == nullptr )
return;
- if( gi->child != NULL )
+ if( gi->child != nullptr )
{
PJ_GRIDINFO *child, *next;
- for( child = gi->child; child != NULL; child=next)
+ for( child = gi->child; child != nullptr; child=next)
{
next=child->next;
pj_gridinfo_free( ctx, child );
}
}
- if( gi->ct != NULL )
+ if( gi->ct != nullptr )
nad_free( gi->ct );
free( gi->gridname );
- if( gi->filename != NULL )
+ if( gi->filename != nullptr )
free( gi->filename );
pj_dalloc( gi );
@@ -126,11 +126,11 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
{
struct CTABLE ct_tmp;
- if( gi == NULL || gi->ct == NULL )
+ if( gi == nullptr || gi->ct == nullptr )
return 0;
pj_acquire_lock();
- if( gi->ct->cvs != NULL )
+ if( gi->ct->cvs != nullptr )
{
pj_release_lock();
return 1;
@@ -148,7 +148,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
fid = pj_open_lib( ctx, gi->filename, "rb" );
- if( fid == NULL )
+ if( fid == nullptr )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
@@ -175,7 +175,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
fid = pj_open_lib( ctx, gi->filename, "rb" );
- if( fid == NULL )
+ if( fid == nullptr )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
@@ -207,7 +207,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
fid = pj_open_lib( ctx, gi->filename, "rb" );
- if( fid == NULL )
+ if( fid == nullptr )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
@@ -218,7 +218,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
row_buf = (double *) pj_malloc(gi->ct->lim.lam * sizeof(double) * 2);
ct_tmp.cvs = (FLP *) pj_malloc(gi->ct->lim.lam*gi->ct->lim.phi*sizeof(FLP));
- if( row_buf == NULL || ct_tmp.cvs == NULL )
+ if( row_buf == nullptr || ct_tmp.cvs == nullptr )
{
pj_dalloc( row_buf );
pj_dalloc( ct_tmp.cvs );
@@ -288,7 +288,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
fid = pj_open_lib( ctx, gi->filename, "rb" );
- if( fid == NULL )
+ if( fid == nullptr )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
@@ -299,7 +299,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
row_buf = (float *) pj_malloc(gi->ct->lim.lam * sizeof(float) * 4);
ct_tmp.cvs = (FLP *) pj_malloc(gi->ct->lim.lam*gi->ct->lim.phi*sizeof(FLP));
- if( row_buf == NULL || ct_tmp.cvs == NULL )
+ if( row_buf == nullptr || ct_tmp.cvs == nullptr )
{
pj_dalloc( row_buf );
pj_dalloc( ct_tmp.cvs );
@@ -363,7 +363,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
fid = pj_open_lib( ctx, gi->filename, "rb" );
- if( fid == NULL )
+ if( fid == nullptr )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
@@ -373,7 +373,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
pj_ctx_fseek( ctx, fid, gi->grid_offset, SEEK_SET );
ct_tmp.cvs = (FLP *) pj_malloc(words*sizeof(float));
- if( ct_tmp.cvs == NULL )
+ if( ct_tmp.cvs == nullptr )
{
pj_ctx_set_errno( ctx, ENOMEM );
pj_release_lock();
@@ -563,7 +563,7 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
return 0;
}
- ct->cvs = NULL;
+ ct->cvs = nullptr;
/* -------------------------------------------------------------------- */
/* Create a new gridinfo for this if we aren't processing the */
@@ -590,7 +590,7 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
pj_ctx_set_errno(ctx, ENOMEM);
return 0;
}
- gi->next = NULL;
+ gi->next = nullptr;
}
gi->must_swap = must_swap;
@@ -607,7 +607,7 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
{
PJ_GRIDINFO *lnk;
- for( lnk = gilist; lnk->next != NULL; lnk = lnk->next ) {}
+ for( lnk = gilist; lnk->next != nullptr; lnk = lnk->next ) {}
lnk->next = gi;
}
}
@@ -618,25 +618,25 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
PJ_GRIDINFO *gp = gridinfo_parent(gilist,
(const char*)header+24,8);
- if( gp == NULL )
+ if( gp == nullptr )
{
pj_log( ctx, PJ_LOG_ERROR,
"pj_gridinfo_init_ntv2(): "
"failed to find parent %8.8s for %s.",
(const char *) header+24, gi->ct->id );
- for( lnk = gilist; lnk->next != NULL; lnk = lnk->next ) {}
+ for( lnk = gilist; lnk->next != nullptr; lnk = lnk->next ) {}
lnk->next = gi;
}
else
{
- if( gp->child == NULL )
+ if( gp->child == nullptr )
{
gp->child = gi;
}
else
{
- for( lnk = gp->child; lnk->next != NULL; lnk = lnk->next ) {}
+ for( lnk = gp->child; lnk->next != nullptr; lnk = lnk->next ) {}
lnk->next = gi;
}
}
@@ -728,7 +728,7 @@ static int pj_gridinfo_init_ntv1( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi )
ct->ll.phi *= DEG_TO_RAD;
ct->del.lam *= DEG_TO_RAD;
ct->del.phi *= DEG_TO_RAD;
- ct->cvs = NULL;
+ ct->cvs = nullptr;
gi->ct = ct;
gi->grid_offset = (long) sizeof(header);
@@ -830,7 +830,7 @@ static int pj_gridinfo_init_gtx( projCtx ctx, PAFile fid, PJ_GRIDINFO *gi )
ct->ll.phi *= DEG_TO_RAD;
ct->del.lam *= DEG_TO_RAD;
ct->del.phi *= DEG_TO_RAD;
- ct->cvs = NULL;
+ ct->cvs = nullptr;
gi->ct = ct;
gi->grid_offset = 40;
@@ -867,20 +867,20 @@ PJ_GRIDINFO *pj_gridinfo_init( projCtx ctx, const char *gridname )
gilist = (PJ_GRIDINFO *) pj_calloc(1, sizeof(PJ_GRIDINFO));
if (!gilist) {
pj_ctx_set_errno(ctx, ENOMEM);
- return NULL;
+ return nullptr;
}
gilist->gridname = pj_strdup( gridname );
if (!gilist->gridname) {
pj_dalloc(gilist);
pj_ctx_set_errno(ctx, ENOMEM);
- return NULL;
+ return nullptr;
}
- gilist->filename = NULL;
+ gilist->filename = nullptr;
gilist->format = "missing";
gilist->grid_offset = 0;
- gilist->ct = NULL;
- gilist->next = NULL;
+ gilist->ct = nullptr;
+ gilist->next = nullptr;
/* -------------------------------------------------------------------- */
/* Open the file using the usual search rules. */
@@ -896,7 +896,7 @@ PJ_GRIDINFO *pj_gridinfo_init( projCtx ctx, const char *gridname )
pj_dalloc(gilist->gridname);
pj_dalloc(gilist);
pj_ctx_set_errno(ctx, ENOMEM);
- return NULL;
+ return nullptr;
}
/* -------------------------------------------------------------------- */
@@ -946,7 +946,7 @@ PJ_GRIDINFO *pj_gridinfo_init( projCtx ctx, const char *gridname )
gilist->format = "ctable2";
gilist->ct = ct;
- if (ct == NULL)
+ if (ct == nullptr)
{
pj_log( ctx, PJ_LOG_DEBUG_MAJOR,
"CTABLE V2 ct is NULL.");
@@ -966,7 +966,7 @@ PJ_GRIDINFO *pj_gridinfo_init( projCtx ctx, const char *gridname )
else
{
struct CTABLE *ct = nad_ctable_init( ctx, fp );
- if (ct == NULL)
+ if (ct == nullptr)
{
pj_log( ctx, PJ_LOG_DEBUG_MAJOR,
"CTABLE ct is NULL.");
diff --git a/src/pj_gridlist.c b/src/gridlist.cpp
index 332de8dd..169abcb9 100644
--- a/src/pj_gridlist.c
+++ b/src/gridlist.cpp
@@ -34,7 +34,7 @@
#include "projects.h"
-static PJ_GRIDINFO *grid_list = NULL;
+static PJ_GRIDINFO *grid_list = nullptr;
#define PJ_MAX_PATH_LENGTH 1024
/************************************************************************/
@@ -46,11 +46,11 @@ static PJ_GRIDINFO *grid_list = NULL;
void pj_deallocate_grids()
{
- while( grid_list != NULL )
+ while( grid_list != nullptr )
{
PJ_GRIDINFO *item = grid_list;
grid_list = grid_list->next;
- item->next = NULL;
+ item->next = nullptr;
pj_gridinfo_free( pj_get_default_ctx(), item );
}
@@ -71,21 +71,21 @@ static int pj_gridlist_merge_gridfile( projCtx ctx,
{
int got_match=0;
- PJ_GRIDINFO *this_grid, *tail = NULL;
+ PJ_GRIDINFO *this_grid, *tail = nullptr;
/* -------------------------------------------------------------------- */
/* Try to find in the existing list of loaded grids. Add all */
/* matching grids as with NTv2 we can get many grids from one */
/* file (one shared gridname). */
/* -------------------------------------------------------------------- */
- for( this_grid = grid_list; this_grid != NULL; this_grid = this_grid->next)
+ for( this_grid = grid_list; this_grid != nullptr; this_grid = this_grid->next)
{
if( strcmp(this_grid->gridname,gridname) == 0 )
{
got_match = 1;
/* don't add to the list if it is invalid. */
- if( this_grid->ct == NULL )
+ if( this_grid->ct == nullptr )
return 0;
/* do we need to grow the list? */
@@ -99,7 +99,7 @@ static int pj_gridlist_merge_gridfile( projCtx ctx,
pj_ctx_set_errno( ctx, ENOMEM );
return 0;
}
- if( *p_gridlist != NULL )
+ if( *p_gridlist != nullptr )
{
memcpy( new_list, *p_gridlist,
sizeof(void *) * (*p_gridmax) );
@@ -112,7 +112,7 @@ static int pj_gridlist_merge_gridfile( projCtx ctx,
/* add to the list */
(*p_gridlist)[(*p_gridcount)++] = this_grid;
- (*p_gridlist)[*p_gridcount] = NULL;
+ (*p_gridlist)[*p_gridcount] = nullptr;
}
tail = this_grid;
@@ -126,12 +126,12 @@ static int pj_gridlist_merge_gridfile( projCtx ctx,
/* -------------------------------------------------------------------- */
this_grid = pj_gridinfo_init( ctx, gridname );
- if( this_grid == NULL )
+ if( this_grid == nullptr )
{
return 0;
}
- if( tail != NULL )
+ if( tail != nullptr )
tail->next = this_grid;
else
grid_list = this_grid;
@@ -158,7 +158,7 @@ PJ_GRIDINFO **pj_gridlist_from_nadgrids( projCtx ctx, const char *nadgrids,
{
const char *s;
- PJ_GRIDINFO **gridlist = NULL;
+ PJ_GRIDINFO **gridlist = nullptr;
int grid_max = 0;
pj_errno = 0;
@@ -190,7 +190,7 @@ PJ_GRIDINFO **pj_gridlist_from_nadgrids( projCtx ctx, const char *nadgrids,
pj_dalloc( gridlist );
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
- return NULL;
+ return nullptr;
}
strncpy( name, s, end_char );
@@ -207,7 +207,7 @@ PJ_GRIDINFO **pj_gridlist_from_nadgrids( projCtx ctx, const char *nadgrids,
pj_dalloc( gridlist );
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_release_lock();
- return NULL;
+ return nullptr;
}
else
pj_errno = 0;
diff --git a/src/pj_init.c b/src/init.cpp
index 36a3276f..5710031c 100644
--- a/src/pj_init.c
+++ b/src/init.cpp
@@ -49,7 +49,7 @@ static paralist *string_to_paralist (PJ_CONTEXT *ctx, char *definition) {
Convert a string (presumably originating from get_init_string) to a paralist.
***************************************************************************************/
char *c = definition;
- paralist *first = 0, *next = 0;
+ paralist *first = nullptr, *next = nullptr;
while (*c) {
/* Find start of next substring */
@@ -57,23 +57,25 @@ static paralist *string_to_paralist (PJ_CONTEXT *ctx, char *definition) {
c++;
/* Keep a handle to the start of the list, so we have something to return */
- if (0==first)
+ if (nullptr==first)
first = next = pj_mkparam_ws (c);
else
next = next->next = pj_mkparam_ws (c);
- if (0==next)
- return pj_dealloc_params (ctx, first, ENOMEM);
+ if (nullptr==next) {
+ pj_dealloc_params (ctx, first, ENOMEM);
+ return nullptr;
+ }
/* And skip to the end of the substring */
while ((!isspace(*c)) && 0!=*c)
c++;
}
- if( next == 0 )
- return 0;
+ if( next == nullptr )
+ return nullptr;
/* Terminate list and return */
- next->next = 0;
+ next->next = nullptr;
return first;
}
@@ -89,42 +91,42 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
size_t current_buffer_size = 5 * (MAX_LINE_LENGTH + 1);
char *fname, *section;
const char *key;
- char *buffer = 0;
- char *line = 0;
+ char *buffer = nullptr;
+ char *line = nullptr;
PAFile fid;
size_t n;
- line = pj_malloc (MAX_LINE_LENGTH + 1);
- if (0==line)
- return 0;
+ line = static_cast<char*>(pj_malloc (MAX_LINE_LENGTH + 1));
+ if (nullptr==line)
+ return nullptr;
- fname = pj_malloc (MAX_PATH_FILENAME+ID_TAG_MAX+3);
- if (0==fname) {
+ fname = static_cast<char*>(pj_malloc (MAX_PATH_FILENAME+ID_TAG_MAX+3));
+ if (nullptr==fname) {
pj_dealloc (line);
- return 0;
+ return nullptr;
}
/* Support "init=file:section", "+init=file:section", and "file:section" format */
key = strstr (name, "init=");
- if (0==key)
+ if (nullptr==key)
key = name;
else
key += 5;
if (MAX_PATH_FILENAME + ID_TAG_MAX + 2 < strlen (key)) {
pj_dealloc (fname);
pj_dealloc (line);
- return 0;
+ return nullptr;
}
memmove (fname, key, strlen (key) + 1);
/* Locate the name of the section we search for */
section = strrchr(fname, ':');
- if (0==section) {
+ if (nullptr==section) {
proj_context_errno_set (ctx, PJD_ERR_NO_COLON_IN_INIT_STRING);
pj_dealloc (fname);
pj_dealloc (line);
- return 0;
+ return nullptr;
}
*section = 0;
section++;
@@ -134,24 +136,24 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
section, fname);
fid = pj_open_lib (ctx, fname, "rt");
- if (0==fid) {
+ if (nullptr==fid) {
pj_dealloc (fname);
pj_dealloc (line);
proj_context_errno_set (ctx, PJD_ERR_NO_OPTION_IN_INIT_FILE);
- return 0;
+ return nullptr;
}
/* Search for section in init file */
for (;;) {
/* End of file? */
- if (0==pj_ctx_fgets (ctx, line, MAX_LINE_LENGTH, fid)) {
+ if (nullptr==pj_ctx_fgets (ctx, line, MAX_LINE_LENGTH, fid)) {
pj_dealloc (buffer);
pj_dealloc (fname);
pj_dealloc (line);
pj_ctx_fclose (ctx, fid);
proj_context_errno_set (ctx, PJD_ERR_NO_OPTION_IN_INIT_FILE);
- return 0;
+ return nullptr;
}
/* At start of right section? */
@@ -167,12 +169,12 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
}
/* We're at the first line of the right section - copy line to buffer */
- buffer = pj_malloc (current_buffer_size);
- if (0==buffer) {
+ buffer = static_cast<char*>(pj_malloc (current_buffer_size));
+ if (nullptr==buffer) {
pj_dealloc (fname);
pj_dealloc (line);
pj_ctx_fclose (ctx, fid);
- return 0;
+ return nullptr;
}
/* Skip the "<section>" indicator, and copy the rest of the line over */
@@ -191,7 +193,7 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
}
/* End of file? - done! */
- if (0==pj_ctx_fgets (ctx, line, MAX_LINE_LENGTH, fid))
+ if (nullptr==pj_ctx_fgets (ctx, line, MAX_LINE_LENGTH, fid))
break;
/* Otherwise, handle the line. It MAY be the start of the next section, */
@@ -200,10 +202,10 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
pj_chomp (line); /* Remove '#' style comments */
next_length = strlen (line) + buffer_length + 2;
if (next_length > current_buffer_size) {
- char *b = pj_malloc (2 * current_buffer_size);
- if (0==b) {
+ char *b = static_cast<char*>(pj_malloc (2 * current_buffer_size));
+ if (nullptr==b) {
pj_dealloc (buffer);
- buffer = 0;
+ buffer = nullptr;
break;
}
strcpy (b, buffer);
@@ -218,8 +220,8 @@ static char *get_init_string (PJ_CONTEXT *ctx, const char *name) {
pj_ctx_fclose (ctx, fid);
pj_dealloc (fname);
pj_dealloc (line);
- if (0==buffer)
- return 0;
+ if (nullptr==buffer)
+ return nullptr;
pj_shrink (buffer);
pj_log (ctx, PJ_LOG_TRACE, "key=%s, value: [%s]", key, buffer);
return buffer;
@@ -233,12 +235,12 @@ static paralist *get_init(PJ_CONTEXT *ctx, const char *key, int allow_init_epsg)
Expand key from buffer or (if not in buffer) from init file
*************************************************************************/
const char *xkey;
- char *definition = 0;
- paralist *init_items = 0;
+ char *definition = nullptr;
+ paralist *init_items = nullptr;
/* support "init=file:section", "+init=file:section", and "file:section" format */
xkey = strstr (key, "init=");
- if (0==xkey)
+ if (nullptr==xkey)
xkey = key;
else
xkey += 5;
@@ -268,7 +270,7 @@ Expand key from buffer or (if not in buffer) from init file
}
if( !exists ) {
- const char* const optionsProj4Mode[] = { "USE_PROJ4_INIT_RULES=YES", NULL };
+ const char* const optionsProj4Mode[] = { "USE_PROJ4_INIT_RULES=YES", nullptr };
char szInitStr[7 + 64];
PJ_OBJ* src;
const char* proj_string;
@@ -277,23 +279,23 @@ Expand key from buffer or (if not in buffer) from init file
if( !allow_init_epsg ) {
pj_log (ctx, PJ_LOG_TRACE, "%s expansion disallowed", xkey);
- return 0;
+ return nullptr;
}
if( strlen(xkey) > 64 ) {
- return 0;
+ return nullptr;
}
strcpy(szInitStr, "+init=");
strcat(szInitStr, xkey);
src = proj_obj_create_from_user_input(ctx, szInitStr, optionsProj4Mode);
if( !src ) {
- return 0;
+ return nullptr;
}
- proj_string = proj_obj_as_proj_string(ctx, src, PJ_PROJ_4, NULL);
+ proj_string = proj_obj_as_proj_string(ctx, src, PJ_PROJ_4, nullptr);
if( !proj_string ) {
proj_obj_destroy(src);
- return 0;
+ return nullptr;
}
definition = (char*)calloc(1, strlen(proj_string)+1);
if( definition ) {
@@ -311,8 +313,8 @@ Expand key from buffer or (if not in buffer) from init file
definition = get_init_string (ctx, xkey);
}
- if (0==definition)
- return 0;
+ if (nullptr==definition)
+ return nullptr;
init_items = string_to_paralist (ctx, definition);
if (init_items)
pj_log (ctx, PJ_LOG_TRACE, "get_init: got [%s], paralist[0,1]: [%s,%s]",
@@ -320,8 +322,8 @@ Expand key from buffer or (if not in buffer) from init file
init_items->param,
init_items->next ? init_items->next->param : "(empty)");
pj_dealloc (definition);
- if (0==init_items)
- return 0;
+ if (nullptr==init_items)
+ return nullptr;
/* We found it in file - now insert into the cache, before returning */
pj_insert_initcache (xkey, init_items);
@@ -331,23 +333,23 @@ Expand key from buffer or (if not in buffer) from init file
static paralist *append_defaults_to_paralist (PJ_CONTEXT *ctx, paralist *start, const char *key, int allow_init_epsg) {
- paralist *defaults, *last = 0;
+ paralist *defaults, *last = nullptr;
char keystring[ID_TAG_MAX + 20];
paralist *next, *proj;
int err;
- if (0==start)
- return 0;
+ if (nullptr==start)
+ return nullptr;
if (strlen(key) > ID_TAG_MAX)
- return 0;
+ return nullptr;
/* Set defaults, unless inhibited (either explicitly through a "no_defs" token */
/* or implicitly, because we are initializing a pipeline) */
if (pj_param_exists (start, "no_defs"))
return start;
proj = pj_param_exists (start, "proj");
- if (0==proj)
+ if (nullptr==proj)
return start;
if (strlen (proj->param) < 6)
return start;
@@ -392,7 +394,7 @@ static paralist *append_defaults_to_paralist (PJ_CONTEXT *ctx, paralist *start,
/* If we're here, it's OK to append the current default item */
last = last->next = pj_mkparam(next->param);
}
- last->next = 0;
+ last->next = nullptr;
pj_dealloc_params (ctx, defaults, 0);
return last;
@@ -423,14 +425,14 @@ Note that 'init=foo:bar' stays in the list. It is ignored after expansion.
paralist *expn;
/* Nowhere to start? */
- if (0==init)
- return 0;
+ if (nullptr==init)
+ return nullptr;
expn = get_init(ctx, init->param, allow_init_epsg);
/* Nothing in expansion? */
- if (0==expn)
- return 0;
+ if (nullptr==expn)
+ return nullptr;
/* Locate the end of the list */
for (last = init; last && last->next; last = last->next);
@@ -467,12 +469,12 @@ pj_init_plus_ctx( projCtx ctx, const char *definition )
char *argv[MAX_ARG];
char *defn_copy;
int argc = 0, i, blank_count = 0;
- PJ *result = NULL;
+ PJ *result = nullptr;
/* make a copy that we can manipulate */
defn_copy = (char *) pj_malloc( strlen(definition)+1 );
if (!defn_copy)
- return NULL;
+ return nullptr;
strcpy( defn_copy, definition );
/* split into arguments based on '+' and trim white space */
@@ -495,7 +497,7 @@ pj_init_plus_ctx( projCtx ctx, const char *definition )
{
pj_dalloc( defn_copy );
pj_ctx_set_errno( ctx, PJD_ERR_UNPARSEABLE_CS_DEF );
- return 0;
+ return nullptr;
}
argv[argc++] = defn_copy + i + 1;
@@ -550,8 +552,8 @@ static PJ_CONSTRUCTOR locate_constructor (const char *name) {
const PJ_OPERATIONS *operations;
operations = proj_list_operations();
for (i = 0; (s = operations[i].id) && strcmp(name, s) ; ++i) ;
- if (0==s)
- return 0;
+ if (nullptr==s)
+ return nullptr;
return (PJ_CONSTRUCTOR) operations[i].proj;
}
@@ -572,20 +574,20 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
paralist *curr, *init, *start;
int i;
int err;
- PJ *PIN = 0;
+ PJ *PIN = nullptr;
int n_pipelines = 0;
int n_inits = 0;
const PJ_UNITS *units;
const PJ_PRIME_MERIDIANS *prime_meridians;
- if (0==ctx)
+ if (nullptr==ctx)
ctx = pj_get_default_ctx ();
ctx->last_errno = 0;
if (argc <= 0) {
pj_ctx_set_errno (ctx, PJD_ERR_NO_ARGS);
- return 0;
+ return nullptr;
}
/* count occurrences of pipelines and inits */
@@ -599,25 +601,29 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* can't have nested pipelines directly */
if (n_pipelines > 1) {
pj_ctx_set_errno (ctx, PJD_ERR_MALFORMED_PIPELINE);
- return 0;
+ return nullptr;
}
/* don't allow more than one +init in non-pipeline operations */
if (n_pipelines == 0 && n_inits > 1) {
pj_ctx_set_errno (ctx, PJD_ERR_TOO_MANY_INITS);
- return 0;
+ return nullptr;
}
/* put arguments into internal linked list */
start = curr = pj_mkparam(argv[0]);
- if (!curr)
- return pj_dealloc_params (ctx, start, ENOMEM);
+ if (!curr) {
+ pj_dealloc_params (ctx, start, ENOMEM);
+ return nullptr;
+ }
for (i = 1; i < argc; ++i) {
curr->next = pj_mkparam(argv[i]);
- if (!curr->next)
- return pj_dealloc_params (ctx, start, ENOMEM);
+ if (!curr->next) {
+ pj_dealloc_params (ctx, start, ENOMEM);
+ return nullptr;
+ }
curr = curr->next;
}
@@ -629,24 +635,34 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
init = pj_param_exists (start, "init");
if (init && n_pipelines == 0) {
init = pj_expand_init_internal (ctx, init, allow_init_epsg);
- if (!init)
- return pj_dealloc_params (ctx, start, PJD_ERR_NO_ARGS);
+ if (!init) {
+ pj_dealloc_params (ctx, start, PJD_ERR_NO_ARGS);
+ return nullptr;
+ }
+ }
+ if (ctx->last_errno) {
+ pj_dealloc_params (ctx, start, ctx->last_errno);
+ return nullptr;
}
- if (ctx->last_errno)
- return pj_dealloc_params (ctx, start, ctx->last_errno);
/* Find projection selection */
curr = pj_param_exists (start, "proj");
- if (0==curr)
- return pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
+ if (nullptr==curr) {
+ pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
+ return nullptr;
+ }
name = curr->param;
- if (strlen (name) < 6)
- return pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
+ if (strlen (name) < 6) {
+ pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
+ return nullptr;
+ }
name += 5;
proj = locate_constructor (name);
- if (0==proj)
- return pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID);
+ if (nullptr==proj) {
+ pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID);
+ return nullptr;
+ }
/* Append general and projection specific defaults to the definition list */
@@ -655,9 +671,11 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* Allocate projection structure */
- PIN = proj(0);
- if (0==PIN)
- return pj_dealloc_params (ctx, start, ENOMEM);
+ PIN = proj(nullptr);
+ if (nullptr==PIN) {
+ pj_dealloc_params (ctx, start, ENOMEM);
+ return nullptr;
+ }
PIN->ctx = ctx;
@@ -668,10 +686,10 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
PIN->long_wrap_center = 0.0;
strcpy( PIN->axis, "enu" );
- PIN->gridlist = NULL;
+ PIN->gridlist = nullptr;
PIN->gridlist_count = 0;
- PIN->vgridlist_geoid = NULL;
+ PIN->vgridlist_geoid = nullptr;
PIN->vgridlist_geoid_count = 0;
/* Set datum parameters. Similarly to +init parameters we want to expand */
@@ -737,16 +755,16 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
}
/* Axis orientation */
- if( (pj_param(ctx, start,"saxis").s) != NULL )
+ if( (pj_param(ctx, start,"saxis").s) != nullptr )
{
const char *axis_legal = "ewnsud";
const char *axis_arg = pj_param(ctx, start,"saxis").s;
if( strlen(axis_arg) != 3 )
return pj_default_destructor (PIN, PJD_ERR_AXIS);
- if( strchr( axis_legal, axis_arg[0] ) == NULL
- || strchr( axis_legal, axis_arg[1] ) == NULL
- || strchr( axis_legal, axis_arg[2] ) == NULL)
+ if( strchr( axis_legal, axis_arg[0] ) == nullptr
+ || strchr( axis_legal, axis_arg[1] ) == nullptr
+ || strchr( axis_legal, axis_arg[2] ) == nullptr)
return pj_default_destructor (PIN, PJD_ERR_AXIS);
/* TODO: it would be nice to validate we don't have on axis repeated */
@@ -777,8 +795,8 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* Set units */
units = proj_list_units();
- s = 0;
- if ((name = pj_param(ctx, start, "sunits").s) != NULL) {
+ s = nullptr;
+ if ((name = pj_param(ctx, start, "sunits").s) != nullptr) {
for (i = 0; (s = units[i].id) && strcmp(name, s) ; ++i) ;
if (!s)
return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_UNIT_ID);
@@ -794,7 +812,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
s += 2;
}
- factor = pj_strtod(s, 0);
+ factor = pj_strtod(s, nullptr);
if ((factor <= 0.0) || (1/factor==0))
return pj_default_destructor (PIN, PJD_ERR_UNIT_FACTOR_LESS_THAN_0);
@@ -805,17 +823,17 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
PIN->to_meter = PIN->fr_meter = 1.;
/* Set vertical units */
- s = 0;
- if ((name = pj_param(ctx, start, "svunits").s) != NULL) {
+ s = nullptr;
+ if ((name = pj_param(ctx, start, "svunits").s) != nullptr) {
for (i = 0; (s = units[i].id) && strcmp(name, s) ; ++i) ;
if (!s)
return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_UNIT_ID);
s = units[i].to_meter;
}
if (s || (s = pj_param(ctx, start, "svto_meter").s)) {
- PIN->vto_meter = pj_strtod(s, 0);
+ PIN->vto_meter = pj_strtod(s, nullptr);
if (*s == '/') /* ratio number */
- PIN->vto_meter /= pj_strtod(++s, 0);
+ PIN->vto_meter /= pj_strtod(++s, nullptr);
if (PIN->vto_meter <= 0.0)
return pj_default_destructor (PIN, PJD_ERR_UNIT_FACTOR_LESS_THAN_0);
PIN->vfr_meter = 1. / PIN->vto_meter;
@@ -826,12 +844,12 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
/* Prime meridian */
prime_meridians = proj_list_prime_meridians();
- s = 0;
- if ((name = pj_param(ctx, start, "spm").s) != NULL) {
- const char *value = NULL;
- char *next_str = NULL;
+ s = nullptr;
+ if ((name = pj_param(ctx, start, "spm").s) != nullptr) {
+ const char *value = nullptr;
+ char *next_str = nullptr;
- for (i = 0; prime_meridians[i].id != NULL; ++i )
+ for (i = 0; prime_meridians[i].id != nullptr; ++i )
{
if( strcmp(name,prime_meridians[i].id) == 0 )
{
@@ -840,21 +858,21 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
}
}
- if( value == NULL
+ if( value == nullptr
&& (dmstor_ctx(ctx,name,&next_str) != 0.0 || *name == '0')
&& *next_str == '\0' )
value = name;
if (!value)
return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_PRIME_MERIDIAN);
- PIN->from_greenwich = dmstor_ctx(ctx,value,NULL);
+ PIN->from_greenwich = dmstor_ctx(ctx,value,nullptr);
}
else
PIN->from_greenwich = 0.0;
/* Private object for the geodesic functions */
- PIN->geod = pj_calloc (1, sizeof (struct geod_geodesic));
- if (0==PIN->geod)
+ PIN->geod = static_cast<struct geod_geodesic*>(pj_calloc (1, sizeof (struct geod_geodesic)));
+ if (nullptr==PIN->geod)
return pj_default_destructor (PIN, ENOMEM);
geod_init(PIN->geod, PIN->a, (1 - sqrt (1 - PIN->es)));
@@ -863,7 +881,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i
PIN = proj(PIN);
if (proj_errno (PIN)) {
pj_free(PIN);
- return 0;
+ return nullptr;
}
proj_errno_restore (PIN, err);
return PIN;
diff --git a/src/pj_initcache.c b/src/initcache.cpp
index 3c347e4b..052a016c 100644
--- a/src/pj_initcache.c
+++ b/src/initcache.cpp
@@ -31,8 +31,8 @@
static int cache_count = 0;
static int cache_alloc = 0;
-static char **cache_key = NULL;
-static paralist **cache_paralist = NULL;
+static char **cache_key = nullptr;
+static paralist **cache_paralist = nullptr;
/************************************************************************/
/* pj_clone_paralist() */
@@ -42,18 +42,18 @@ static paralist **cache_paralist = NULL;
paralist *pj_clone_paralist( const paralist *list)
{
- paralist *list_copy = NULL, *next_copy = NULL;
+ paralist *list_copy = nullptr, *next_copy = nullptr;
- for( ; list != NULL; list = list->next )
+ for( ; list != nullptr; list = list->next )
{
paralist *newitem = (paralist *)
pj_malloc(sizeof(paralist) + strlen(list->param));
newitem->used = 0;
- newitem->next = 0;
+ newitem->next = nullptr;
strcpy( newitem->param, list->param );
- if( list_copy == NULL )
+ if( list_copy == nullptr )
list_copy = newitem;
else
next_copy->next = newitem;
@@ -85,7 +85,7 @@ void pj_clear_initcache()
pj_dalloc( cache_key[i] );
/* free parameter list elements */
- for (; t != NULL; t = n) {
+ for (; t != nullptr; t = n) {
n = t->next;
pj_dalloc(t);
}
@@ -95,8 +95,8 @@ void pj_clear_initcache()
pj_dalloc( cache_paralist );
cache_count = 0;
cache_alloc= 0;
- cache_key = NULL;
- cache_paralist = NULL;
+ cache_key = nullptr;
+ cache_paralist = nullptr;
pj_release_lock();
}
@@ -112,11 +112,11 @@ paralist *pj_search_initcache( const char *filekey )
{
int i;
- paralist *result = NULL;
+ paralist *result = nullptr;
pj_acquire_lock();
- for( i = 0; result == NULL && i < cache_count; i++)
+ for( i = 0; result == nullptr && i < cache_count; i++)
{
if( strcmp(filekey,cache_key[i]) == 0 )
{
diff --git a/src/internal.cpp b/src/internal.cpp
index c43605d1..3f3d191e 100644
--- a/src/internal.cpp
+++ b/src/internal.cpp
@@ -1,11 +1,14 @@
/******************************************************************************
+ * Project: PROJ.4
+ * Purpose: This is primarily material originating from pj_obs_api.c
+ * (now proj_4D_api.c), that does not fit into the API
+ * category. Hence this pile of tubings and fittings for
+ * PROJ.4 internal plumbing.
*
- * Project: PROJ
- * Purpose: ISO19111:2018 implementation
- * Author: Even Rouault <even dot rouault at spatialys dot com>
+ * Author: Thomas Knudsen, thokn@sdfe.dk, 2017-07-05
*
******************************************************************************
- * Copyright (c) 2018, Even Rouault <even dot rouault at spatialys dot com>
+ * Copyright (c) 2016, 2017, 2018, Thomas Knudsen/SDFE
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -24,351 +27,419 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
- ****************************************************************************/
+ *****************************************************************************/
+
+#include <ctype.h>
+#include <errno.h>
+#include <math.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
-#ifndef FROM_PROJ_CPP
-#define FROM_PROJ_CPP
-#endif
+#include "geodesic.h"
+#include "proj_internal.h"
+#include "projects.h"
-#include "proj/internal/internal.hpp"
-#include <cstdint>
-#include <cstring>
-#ifdef _MSC_VER
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#include <exception>
-#include <iomanip> // std::setprecision
-#include <locale>
-#include <sstream> // std::istringstream and std::ostringstream
-#include <string>
-
-#include "sqlite3.h"
-
-NS_PROJ_START
-
-namespace internal {
-
-// ---------------------------------------------------------------------------
-
-/**
- * Replace all occurrences of before with after.
- */
-std::string replaceAll(const std::string &str, const std::string &before,
- const std::string &after) {
- std::string ret(str);
- const size_t nBeforeSize = before.size();
- const size_t nAfterSize = after.size();
- if (nBeforeSize) {
- size_t nStartPos = 0;
- while ((nStartPos = ret.find(before, nStartPos)) != std::string::npos) {
- ret.replace(nStartPos, nBeforeSize, after);
- nStartPos += nAfterSize;
- }
- }
- return ret;
+enum pj_io_units pj_left (PJ *P) {
+ enum pj_io_units u = P->inverted? P->right: P->left;
+ if (u==PJ_IO_UNITS_CLASSIC)
+ return PJ_IO_UNITS_PROJECTED;
+ return u;
}
-// ---------------------------------------------------------------------------
-
-inline static bool EQUALN(const char *a, const char *b, size_t size) {
-#ifdef _MSC_VER
- return _strnicmp(a, b, size) == 0;
-#else
- return strncasecmp(a, b, size) == 0;
-#endif
+enum pj_io_units pj_right (PJ *P) {
+ enum pj_io_units u = P->inverted? P->left: P->right;
+ if (u==PJ_IO_UNITS_CLASSIC)
+ return PJ_IO_UNITS_PROJECTED;
+ return u;
}
-/**
- * Case-insensitive equality test
- */
-bool ci_equal(const std::string &a, const std::string &b) noexcept {
- const auto size = a.size();
- if (size != b.size()) {
- return false;
- }
- return EQUALN(a.c_str(), b.c_str(), size);
+
+/* Work around non-constness of MSVC HUGE_VAL by providing functions rather than constants */
+PJ_COORD proj_coord_error (void) {
+ PJ_COORD c;
+ c.v[0] = c.v[1] = c.v[2] = c.v[3] = HUGE_VAL;
+ return c;
}
-bool ci_equal(const std::string &a, const char *b) noexcept {
- const auto size = a.size();
- if (size != strlen(b)) {
- return false;
+
+
+/**************************************************************************************/
+PJ_COORD pj_approx_2D_trans (PJ *P, PJ_DIRECTION direction, PJ_COORD coo) {
+/***************************************************************************************
+Behave mostly as proj_trans, but attempt to use 2D interfaces only.
+Used in gie.c, to enforce testing 2D code, and by PJ_pipeline.c to implement
+chained calls starting out with a call to its 2D interface.
+***************************************************************************************/
+ if (nullptr==P)
+ return coo;
+ if (P->inverted)
+ direction = static_cast<PJ_DIRECTION>(-direction);
+ switch (direction) {
+ case PJ_FWD:
+ coo.xy = pj_fwd (coo.lp, P);
+ return coo;
+ case PJ_INV:
+ coo.lp = pj_inv (coo.xy, P);
+ return coo;
+ case PJ_IDENT:
+ return coo;
+ default:
+ break;
}
- return EQUALN(a.c_str(), b, size);
+ proj_errno_set (P, EINVAL);
+ return proj_coord_error ();
}
-bool ci_equal(const char *a, const char *b) noexcept {
- const auto size = strlen(a);
- if (size != strlen(b)) {
- return false;
+
+/**************************************************************************************/
+PJ_COORD pj_approx_3D_trans (PJ *P, PJ_DIRECTION direction, PJ_COORD coo) {
+/***************************************************************************************
+Companion to pj_approx_2D_trans.
+
+Behave mostly as proj_trans, but attempt to use 3D interfaces only.
+Used in gie.c, to enforce testing 3D code, and by PJ_pipeline.c to implement
+chained calls starting out with a call to its 3D interface.
+***************************************************************************************/
+ if (nullptr==P)
+ return coo;
+ if (P->inverted)
+ direction = static_cast<PJ_DIRECTION>(-direction);
+ switch (direction) {
+ case PJ_FWD:
+ coo.xyz = pj_fwd3d (coo.lpz, P);
+ return coo;
+ case PJ_INV:
+ coo.lpz = pj_inv3d (coo.xyz, P);
+ return coo;
+ case PJ_IDENT:
+ return coo;
+ default:
+ break;
}
- return EQUALN(a, b, size);
+ proj_errno_set (P, EINVAL);
+ return proj_coord_error ();
}
-// ---------------------------------------------------------------------------
-
-bool ci_less(const std::string &a, const std::string &b) noexcept {
-#ifdef _MSC_VER
- return _stricmp(a.c_str(), b.c_str()) < 0;
-#else
- return strcasecmp(a.c_str(), b.c_str()) < 0;
-#endif
+/**************************************************************************************/
+int pj_has_inverse(PJ *P) {
+/***************************************************************************************
+Check if a a PJ has an inverse.
+***************************************************************************************/
+ return ( (P->inverted && (P->fwd || P->fwd3d || P->fwd4d) ) ||
+ ( P->inv || P->inv3d || P->inv4d) );
}
-// ---------------------------------------------------------------------------
-/**
- * Convert to lower case.
- */
+/* Move P to a new context - or to the default context if 0 is specified */
+void proj_context_set (PJ *P, PJ_CONTEXT *ctx) {
+ if (nullptr==ctx)
+ ctx = pj_get_default_ctx ();
+ pj_set_ctx (P, ctx);
+}
-std::string tolower(const std::string &str)
-{
- std::string ret(str);
- for (size_t i = 0; i < ret.size(); i++)
- ret[i] = static_cast<char>(::tolower(ret[i]));
- return ret;
+void proj_context_inherit (PJ *parent, PJ *child) {
+ if (nullptr==parent)
+ pj_set_ctx (child, pj_get_default_ctx());
+ else
+ pj_set_ctx (child, pj_get_ctx(parent));
}
-// ---------------------------------------------------------------------------
-/**
- * Convert to upper case.
- */
-std::string toupper(const std::string &str)
+/*****************************************************************************/
+char *pj_chomp (char *c) {
+/******************************************************************************
+Strip pre- and postfix whitespace. Inline comments (indicated by '#') are
+considered whitespace.
+******************************************************************************/
+ size_t i, n;
+ char *comment;
+ char *start = c;
+
+ if (nullptr==c)
+ return nullptr;
+
+ comment = strchr (c, '#');
+ if (comment)
+ *comment = 0;
+
+ n = strlen (c);
+ if (0==n)
+ return c;
+
+ /* Eliminate postfix whitespace */
+ for (i = n - 1; (i > 0) && (isspace (c[i]) || ';'==c[i]); i--)
+ c[i] = 0;
+
+ /* Find start of non-whitespace */
+ while (0 != *start && (';'==*start || isspace (*start)))
+ start++;
+
+ n = strlen (start);
+ if (0==n) {
+ c[0] = 0;
+ return c;
+ }
-{
- std::string ret(str);
- for (size_t i = 0; i < ret.size(); i++)
- ret[i] = static_cast<char>(::toupper(ret[i]));
- return ret;
+ memmove (c, start, n + 1);
+ return c;
}
-// ---------------------------------------------------------------------------
-/** Strip leading and trailing double quote characters */
-std::string stripQuotes(const std::string &str) {
- if (str.size() >= 2 && str[0] == '"' && str.back() == '"') {
- return str.substr(1, str.size() - 2);
- }
- return str;
-}
-// ---------------------------------------------------------------------------
-
-size_t ci_find(const std::string &str, const char *needle) noexcept {
- const size_t needleSize = strlen(needle);
- for (size_t i = 0; i + needleSize <= str.size(); i++) {
- if (EQUALN(str.c_str() + i, needle, needleSize)) {
- return i;
+/*****************************************************************************/
+char *pj_shrink (char *c) {
+/******************************************************************************
+Collapse repeated whitespace. Remove '+' and ';'. Make ',' and '=' greedy,
+consuming their surrounding whitespace.
+******************************************************************************/
+ size_t i, j, n;
+
+ /* Flag showing that a whitespace (ws) has been written after last non-ws */
+ size_t ws;
+
+ if (nullptr==c)
+ return nullptr;
+
+ pj_chomp (c);
+ n = strlen (c);
+
+ /* First collapse repeated whitespace (including +/;) */
+ i = 0;
+ ws = 0;
+ for (j = 0; j < n; j++) {
+
+ /* Eliminate prefix '+', only if preceded by whitespace */
+ /* (i.e. keep it in 1.23e+08) */
+ if ((i > 0) && ('+'==c[j]) && ws)
+ c[j] = ' ';
+ if ((i==0) && ('+'==c[j]))
+ c[j] = ' ';
+
+ if (isspace (c[j]) || ';'==c[j]) {
+ if (0==ws && (i > 0))
+ c[i++] = ' ';
+ ws = 1;
+ continue;
}
- }
- return std::string::npos;
-}
-
-// ---------------------------------------------------------------------------
-
-size_t ci_find(const std::string &str, const std::string &needle,
- size_t startPos) noexcept {
- const size_t needleSize = needle.size();
- for (size_t i = startPos; i + needleSize <= str.size(); i++) {
- if (EQUALN(str.c_str() + i, needle.c_str(), needleSize)) {
- return i;
+ else {
+ ws = 0;
+ c[i++] = c[j];
}
}
- return std::string::npos;
-}
-
-// ---------------------------------------------------------------------------
+ c[i] = 0;
+ n = strlen(c);
+
+ /* Then make ',' and '=' greedy */
+ i = 0;
+ for (j = 0; j < n; j++) {
+ if (i==0) {
+ c[i++] = c[j];
+ continue;
+ }
-/*
-bool starts_with(const std::string &str, const std::string &prefix) noexcept {
- if (str.size() < prefix.size()) {
- return false;
- }
- return std::memcmp(str.c_str(), prefix.c_str(), prefix.size()) == 0;
-}
-*/
+ /* Skip space before '='/',' */
+ if ('='==c[j] || ','==c[j]) {
+ if (c[i - 1]==' ')
+ c[i - 1] = c[j];
+ else
+ c[i++] = c[j];
+ continue;
+ }
-// ---------------------------------------------------------------------------
+ if (' '==c[j] && ('='==c[i - 1] || ','==c[i - 1]) )
+ continue;
-/*
-bool starts_with(const std::string &str, const char *prefix) noexcept {
- const size_t prefixSize = std::strlen(prefix);
- if (str.size() < prefixSize) {
- return false;
+ c[i++] = c[j];
}
- return std::memcmp(str.c_str(), prefix, prefixSize) == 0;
+ c[i] = 0;
+ return c;
}
-*/
-// ---------------------------------------------------------------------------
-bool ci_starts_with(const char *str, const char *prefix) noexcept {
- const auto str_size = strlen(str);
- const auto prefix_size = strlen(prefix);
- if (str_size < prefix_size) {
- return false;
- }
- return EQUALN(str, prefix, prefix_size);
-}
-// ---------------------------------------------------------------------------
-
-bool ci_starts_with(const std::string &str,
- const std::string &prefix) noexcept {
- if (str.size() < prefix.size()) {
- return false;
+/*****************************************************************************/
+size_t pj_trim_argc (char *args) {
+/******************************************************************************
+Trim all unnecessary whitespace (and non-essential syntactic tokens) from the
+argument string, args, and count its number of elements.
+******************************************************************************/
+ size_t i, m, n;
+ pj_shrink (args);
+ n = strlen (args);
+ if (n==0)
+ return 0;
+ for (i = m = 0; i < n; i++) {
+ if (' '==args[i]) {
+ args[i] = 0;
+ m++;
+ }
}
- return EQUALN(str.c_str(), prefix.c_str(), prefix.size());
+ return m + 1;
}
-// ---------------------------------------------------------------------------
-bool ends_with(const std::string &str, const std::string &suffix) noexcept {
- if (str.size() < suffix.size()) {
- return false;
- }
- return std::memcmp(str.c_str() + str.size() - suffix.size(), suffix.c_str(),
- suffix.size()) == 0;
-}
-// ---------------------------------------------------------------------------
-
-double c_locale_stod(const std::string &s) {
-
- const auto s_size = s.size();
- // Fast path
- if (s_size > 0 && s_size < 15) {
- std::int64_t acc = 0;
- std::int64_t div = 1;
- bool afterDot = false;
- size_t i = 0;
- if (s[0] == '-') {
- ++i;
- div = -1;
- } else if (s[0] == '+') {
- ++i;
- }
- for (; i < s_size; ++i) {
- const auto ch = s[i];
- if (ch >= '0' && ch <= '9') {
- acc = acc * 10 + ch - '0';
- if (afterDot) {
- div *= 10;
- }
- } else if (ch == '.') {
- afterDot = true;
- } else {
- div = 0;
- }
- }
- if (div) {
- return static_cast<double>(acc) / div;
+/*****************************************************************************/
+char **pj_trim_argv (size_t argc, char *args) {
+/******************************************************************************
+Create an argv-style array from elements placed in the argument string, args.
+
+args is a trimmed string as returned by pj_trim_argc(), and argc is the number
+of trimmed strings found (i.e. the return value of pj_trim_args()). Hence,
+ int argc = pj_trim_argc (args);
+ char **argv = pj_trim_argv (argc, args);
+will produce a classic style (argc, argv) pair from a string of whitespace
+separated args. No new memory is allocated for storing the individual args
+(they stay in the args string), but for the pointers to the args a new array
+is allocated and returned.
+
+It is the duty of the caller to free this array.
+******************************************************************************/
+ size_t i, j;
+ char **argv;
+
+ if (nullptr==args)
+ return nullptr;
+ if (0==argc)
+ return nullptr;
+
+
+ /* turn the input string into an array of strings */
+ argv = (char **) calloc (argc, sizeof (char *));
+ if (nullptr==argv)
+ return nullptr;
+ argv[0] = args;
+ j = 1;
+ for (i = 0; ; i++) {
+ if (0==args[i]) {
+ argv[j++] = args + (i + 1);
}
+ if (j==argc)
+ break;
}
-
- std::istringstream iss(s);
- iss.imbue(std::locale::classic());
- double d;
- iss >> d;
- if (!iss.eof() || iss.fail()) {
- throw std::invalid_argument("non double value");
- }
- return d;
+ return argv;
}
-// ---------------------------------------------------------------------------
-std::vector<std::string> split(const std::string &str, char separator) {
- std::vector<std::string> res;
- size_t lastPos = 0;
- size_t newPos = 0;
- while ((newPos = str.find(separator, lastPos)) != std::string::npos) {
- res.push_back(str.substr(lastPos, newPos - lastPos));
- lastPos = newPos + 1;
+
+/*****************************************************************************/
+char *pj_make_args (size_t argc, char **argv) {
+/******************************************************************************
+pj_make_args is the inverse of the pj_trim_argc/pj_trim_argv combo: It
+converts free format command line input to something proj_create can consume.
+
+Allocates, and returns, an array of char, large enough to hold a whitespace
+separated copy of the args in argv. It is the duty of the caller to free this
+array.
+******************************************************************************/
+ size_t i, n;
+ char *p;
+
+ for (i = n = 0; i < argc; i++)
+ n += strlen (argv[i]);
+
+ p = static_cast<char*>(pj_calloc (n + argc + 1, sizeof (char)));
+ if (nullptr==p)
+ return nullptr;
+ if (0==argc)
+ return p;
+
+ for (i = 0; i < argc; i++) {
+ strcat (p, argv[i]);
+ strcat (p, " ");
}
- res.push_back(str.substr(lastPos));
- return res;
+ return pj_shrink (p);
}
-// ---------------------------------------------------------------------------
-#ifdef _WIN32
-// For some reason, sqlite3_snprintf() in the sqlite3 builds used on AppVeyor
-// doesn't round identically to the Unix builds, and thus breaks a number of
-// unit test. So to avoid this, use the stdlib formatting
-
-std::string toString(int val) {
- std::ostringstream buffer;
- buffer.imbue(std::locale::classic());
- buffer << val;
- return buffer.str();
+/*****************************************************************************/
+void proj_context_errno_set (PJ_CONTEXT *ctx, int err) {
+/******************************************************************************
+Raise an error directly on a context, without going through a PJ belonging
+to that context.
+******************************************************************************/
+ if (nullptr==ctx)
+ ctx = pj_get_default_ctx();
+ pj_ctx_set_errno (ctx, err);
}
-std::string toString(double val, int precision) {
- std::ostringstream buffer;
- buffer.imbue(std::locale::classic());
- buffer << std::setprecision(precision);
- buffer << val;
- auto str = buffer.str();
- if (precision == 15 && str.find("9999999999") != std::string::npos) {
- buffer.str("");
- buffer.clear();
- buffer << std::setprecision(14);
- buffer << val;
- return buffer.str();
- }
- return str;
+/* logging */
+
+/* pj_vlog resides in pj_log.c and relates to pj_log as vsprintf relates to sprintf */
+void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args );
+
+
+/***************************************************************************************/
+PJ_LOG_LEVEL proj_log_level (PJ_CONTEXT *ctx, PJ_LOG_LEVEL log_level) {
+/****************************************************************************************
+ Set logging level 0-3. Higher number means more debug info. 0 turns it off
+****************************************************************************************/
+ PJ_LOG_LEVEL previous;
+ if (nullptr==ctx)
+ ctx = pj_get_default_ctx();
+ if (nullptr==ctx)
+ return PJ_LOG_TELL;
+ previous = static_cast<PJ_LOG_LEVEL>(abs (ctx->debug_level));
+ if (PJ_LOG_TELL==log_level)
+ return previous;
+ ctx->debug_level = log_level;
+ return previous;
}
-#else
-std::string toString(int val) {
- // use sqlite3 API that is slighly faster than std::ostringstream
- // with forcing the C locale. sqlite3_snprintf() emulates a C locale.
- constexpr int BUF_SIZE = 16;
- char szBuffer[BUF_SIZE];
- sqlite3_snprintf(BUF_SIZE, szBuffer, "%d", val);
- return szBuffer;
-}
-
-std::string toString(double val, int precision) {
- // use sqlite3 API that is slighly faster than std::ostringstream
- // with forcing the C locale. sqlite3_snprintf() emulates a C locale.
- constexpr int BUF_SIZE = 32;
- char szBuffer[BUF_SIZE];
- sqlite3_snprintf(BUF_SIZE, szBuffer, "%.*g", precision, val);
- if (precision == 15 && strstr(szBuffer, "9999999999")) {
- sqlite3_snprintf(BUF_SIZE, szBuffer, "%.14g", val);
- }
- return szBuffer;
+/*****************************************************************************/
+void proj_log_error (PJ *P, const char *fmt, ...) {
+/******************************************************************************
+ For reporting the most severe events.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (pj_get_ctx (P), PJ_LOG_ERROR , fmt, args);
+ va_end( args );
}
-#endif
-// ---------------------------------------------------------------------------
-
-std::string concat(const char *a, const std::string &b) {
- std::string res(a);
- res += b;
- return res;
+/*****************************************************************************/
+void proj_log_debug (PJ *P, const char *fmt, ...) {
+/******************************************************************************
+ For reporting debugging information.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (pj_get_ctx (P), PJ_LOG_DEBUG_MAJOR , fmt, args);
+ va_end( args );
}
-std::string concat(const char *a, const std::string &b, const char *c) {
- std::string res(a);
- res += b;
- res += c;
- return res;
-}
-// ---------------------------------------------------------------------------
+/*****************************************************************************/
+void proj_log_trace (PJ *P, const char *fmt, ...) {
+/******************************************************************************
+ For reporting embarrasingly detailed debugging information.
+******************************************************************************/
+ va_list args;
+ va_start( args, fmt );
+ pj_vlog (pj_get_ctx (P), PJ_LOG_DEBUG_MINOR , fmt, args);
+ va_end( args );
+}
-} // namespace internal
-NS_PROJ_END
+/*****************************************************************************/
+void proj_log_func (PJ_CONTEXT *ctx, void *app_data, PJ_LOG_FUNCTION logf) {
+/******************************************************************************
+ Put a new logging function into P's context. The opaque object app_data is
+ passed as first arg at each call to the logger
+******************************************************************************/
+ if (nullptr==ctx)
+ pj_get_default_ctx ();
+ if (nullptr==ctx)
+ return;
+ ctx->app_data = app_data;
+ if (nullptr!=logf)
+ ctx->logger = logf;
+}
diff --git a/src/pj_inv.c b/src/inv.cpp
index aaa8fea9..ba7e6722 100644
--- a/src/pj_inv.c
+++ b/src/inv.cpp
@@ -114,7 +114,7 @@ static PJ_COORD inv_finalize (PJ *P, PJ_COORD coo) {
return coo;
if (P->hgridshift)
coo = proj_trans (P->hgridshift, PJ_FWD, coo);
- else if (P->helmert || (P->cart_wgs84 != 0 && P->cart != 0)) {
+ else if (P->helmert || (P->cart_wgs84 != nullptr && P->cart != nullptr)) {
coo = proj_trans (P->cart, PJ_FWD, coo); /* Go cartesian in local frame */
if( P->helmert )
coo = proj_trans (P->helmert, PJ_FWD, coo); /* Step into WGS84 */
diff --git a/src/c_api.cpp b/src/iso19111/c_api.cpp
index d0b5d720..d0b5d720 100644
--- a/src/c_api.cpp
+++ b/src/iso19111/c_api.cpp
diff --git a/src/common.cpp b/src/iso19111/common.cpp
index bd690924..bd690924 100644
--- a/src/common.cpp
+++ b/src/iso19111/common.cpp
diff --git a/src/coordinateoperation.cpp b/src/iso19111/coordinateoperation.cpp
index 442a9b78..442a9b78 100644
--- a/src/coordinateoperation.cpp
+++ b/src/iso19111/coordinateoperation.cpp
diff --git a/src/coordinatesystem.cpp b/src/iso19111/coordinatesystem.cpp
index a3ad04e0..a3ad04e0 100644
--- a/src/coordinatesystem.cpp
+++ b/src/iso19111/coordinatesystem.cpp
diff --git a/src/crs.cpp b/src/iso19111/crs.cpp
index a05470ff..a05470ff 100644
--- a/src/crs.cpp
+++ b/src/iso19111/crs.cpp
diff --git a/src/datum.cpp b/src/iso19111/datum.cpp
index 16e86296..16e86296 100644
--- a/src/datum.cpp
+++ b/src/iso19111/datum.cpp
diff --git a/src/factory.cpp b/src/iso19111/factory.cpp
index 47d31db9..47d31db9 100644
--- a/src/factory.cpp
+++ b/src/iso19111/factory.cpp
diff --git a/src/iso19111/internal.cpp b/src/iso19111/internal.cpp
new file mode 100644
index 00000000..c43605d1
--- /dev/null
+++ b/src/iso19111/internal.cpp
@@ -0,0 +1,374 @@
+/******************************************************************************
+ *
+ * Project: PROJ
+ * Purpose: ISO19111:2018 implementation
+ * Author: Even Rouault <even dot rouault at spatialys dot com>
+ *
+ ******************************************************************************
+ * Copyright (c) 2018, Even Rouault <even dot rouault at spatialys dot com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef FROM_PROJ_CPP
+#define FROM_PROJ_CPP
+#endif
+
+#include "proj/internal/internal.hpp"
+
+#include <cstdint>
+#include <cstring>
+#ifdef _MSC_VER
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+#include <exception>
+#include <iomanip> // std::setprecision
+#include <locale>
+#include <sstream> // std::istringstream and std::ostringstream
+#include <string>
+
+#include "sqlite3.h"
+
+NS_PROJ_START
+
+namespace internal {
+
+// ---------------------------------------------------------------------------
+
+/**
+ * Replace all occurrences of before with after.
+ */
+std::string replaceAll(const std::string &str, const std::string &before,
+ const std::string &after) {
+ std::string ret(str);
+ const size_t nBeforeSize = before.size();
+ const size_t nAfterSize = after.size();
+ if (nBeforeSize) {
+ size_t nStartPos = 0;
+ while ((nStartPos = ret.find(before, nStartPos)) != std::string::npos) {
+ ret.replace(nStartPos, nBeforeSize, after);
+ nStartPos += nAfterSize;
+ }
+ }
+ return ret;
+}
+
+// ---------------------------------------------------------------------------
+
+inline static bool EQUALN(const char *a, const char *b, size_t size) {
+#ifdef _MSC_VER
+ return _strnicmp(a, b, size) == 0;
+#else
+ return strncasecmp(a, b, size) == 0;
+#endif
+}
+
+/**
+ * Case-insensitive equality test
+ */
+bool ci_equal(const std::string &a, const std::string &b) noexcept {
+ const auto size = a.size();
+ if (size != b.size()) {
+ return false;
+ }
+ return EQUALN(a.c_str(), b.c_str(), size);
+}
+
+bool ci_equal(const std::string &a, const char *b) noexcept {
+ const auto size = a.size();
+ if (size != strlen(b)) {
+ return false;
+ }
+ return EQUALN(a.c_str(), b, size);
+}
+
+bool ci_equal(const char *a, const char *b) noexcept {
+ const auto size = strlen(a);
+ if (size != strlen(b)) {
+ return false;
+ }
+ return EQUALN(a, b, size);
+}
+
+// ---------------------------------------------------------------------------
+
+bool ci_less(const std::string &a, const std::string &b) noexcept {
+#ifdef _MSC_VER
+ return _stricmp(a.c_str(), b.c_str()) < 0;
+#else
+ return strcasecmp(a.c_str(), b.c_str()) < 0;
+#endif
+}
+
+// ---------------------------------------------------------------------------
+
+/**
+ * Convert to lower case.
+ */
+
+std::string tolower(const std::string &str)
+
+{
+ std::string ret(str);
+ for (size_t i = 0; i < ret.size(); i++)
+ ret[i] = static_cast<char>(::tolower(ret[i]));
+ return ret;
+}
+
+// ---------------------------------------------------------------------------
+
+/**
+ * Convert to upper case.
+ */
+
+std::string toupper(const std::string &str)
+
+{
+ std::string ret(str);
+ for (size_t i = 0; i < ret.size(); i++)
+ ret[i] = static_cast<char>(::toupper(ret[i]));
+ return ret;
+}
+
+// ---------------------------------------------------------------------------
+
+/** Strip leading and trailing double quote characters */
+std::string stripQuotes(const std::string &str) {
+ if (str.size() >= 2 && str[0] == '"' && str.back() == '"') {
+ return str.substr(1, str.size() - 2);
+ }
+ return str;
+}
+
+// ---------------------------------------------------------------------------
+
+size_t ci_find(const std::string &str, const char *needle) noexcept {
+ const size_t needleSize = strlen(needle);
+ for (size_t i = 0; i + needleSize <= str.size(); i++) {
+ if (EQUALN(str.c_str() + i, needle, needleSize)) {
+ return i;
+ }
+ }
+ return std::string::npos;
+}
+
+// ---------------------------------------------------------------------------
+
+size_t ci_find(const std::string &str, const std::string &needle,
+ size_t startPos) noexcept {
+ const size_t needleSize = needle.size();
+ for (size_t i = startPos; i + needleSize <= str.size(); i++) {
+ if (EQUALN(str.c_str() + i, needle.c_str(), needleSize)) {
+ return i;
+ }
+ }
+ return std::string::npos;
+}
+
+// ---------------------------------------------------------------------------
+
+/*
+bool starts_with(const std::string &str, const std::string &prefix) noexcept {
+ if (str.size() < prefix.size()) {
+ return false;
+ }
+ return std::memcmp(str.c_str(), prefix.c_str(), prefix.size()) == 0;
+}
+*/
+
+// ---------------------------------------------------------------------------
+
+/*
+bool starts_with(const std::string &str, const char *prefix) noexcept {
+ const size_t prefixSize = std::strlen(prefix);
+ if (str.size() < prefixSize) {
+ return false;
+ }
+ return std::memcmp(str.c_str(), prefix, prefixSize) == 0;
+}
+*/
+
+// ---------------------------------------------------------------------------
+
+bool ci_starts_with(const char *str, const char *prefix) noexcept {
+ const auto str_size = strlen(str);
+ const auto prefix_size = strlen(prefix);
+ if (str_size < prefix_size) {
+ return false;
+ }
+ return EQUALN(str, prefix, prefix_size);
+}
+
+// ---------------------------------------------------------------------------
+
+bool ci_starts_with(const std::string &str,
+ const std::string &prefix) noexcept {
+ if (str.size() < prefix.size()) {
+ return false;
+ }
+ return EQUALN(str.c_str(), prefix.c_str(), prefix.size());
+}
+
+// ---------------------------------------------------------------------------
+
+bool ends_with(const std::string &str, const std::string &suffix) noexcept {
+ if (str.size() < suffix.size()) {
+ return false;
+ }
+ return std::memcmp(str.c_str() + str.size() - suffix.size(), suffix.c_str(),
+ suffix.size()) == 0;
+}
+
+// ---------------------------------------------------------------------------
+
+double c_locale_stod(const std::string &s) {
+
+ const auto s_size = s.size();
+ // Fast path
+ if (s_size > 0 && s_size < 15) {
+ std::int64_t acc = 0;
+ std::int64_t div = 1;
+ bool afterDot = false;
+ size_t i = 0;
+ if (s[0] == '-') {
+ ++i;
+ div = -1;
+ } else if (s[0] == '+') {
+ ++i;
+ }
+ for (; i < s_size; ++i) {
+ const auto ch = s[i];
+ if (ch >= '0' && ch <= '9') {
+ acc = acc * 10 + ch - '0';
+ if (afterDot) {
+ div *= 10;
+ }
+ } else if (ch == '.') {
+ afterDot = true;
+ } else {
+ div = 0;
+ }
+ }
+ if (div) {
+ return static_cast<double>(acc) / div;
+ }
+ }
+
+ std::istringstream iss(s);
+ iss.imbue(std::locale::classic());
+ double d;
+ iss >> d;
+ if (!iss.eof() || iss.fail()) {
+ throw std::invalid_argument("non double value");
+ }
+ return d;
+}
+
+// ---------------------------------------------------------------------------
+
+std::vector<std::string> split(const std::string &str, char separator) {
+ std::vector<std::string> res;
+ size_t lastPos = 0;
+ size_t newPos = 0;
+ while ((newPos = str.find(separator, lastPos)) != std::string::npos) {
+ res.push_back(str.substr(lastPos, newPos - lastPos));
+ lastPos = newPos + 1;
+ }
+ res.push_back(str.substr(lastPos));
+ return res;
+}
+
+// ---------------------------------------------------------------------------
+
+#ifdef _WIN32
+
+// For some reason, sqlite3_snprintf() in the sqlite3 builds used on AppVeyor
+// doesn't round identically to the Unix builds, and thus breaks a number of
+// unit test. So to avoid this, use the stdlib formatting
+
+std::string toString(int val) {
+ std::ostringstream buffer;
+ buffer.imbue(std::locale::classic());
+ buffer << val;
+ return buffer.str();
+}
+
+std::string toString(double val, int precision) {
+ std::ostringstream buffer;
+ buffer.imbue(std::locale::classic());
+ buffer << std::setprecision(precision);
+ buffer << val;
+ auto str = buffer.str();
+ if (precision == 15 && str.find("9999999999") != std::string::npos) {
+ buffer.str("");
+ buffer.clear();
+ buffer << std::setprecision(14);
+ buffer << val;
+ return buffer.str();
+ }
+ return str;
+}
+
+#else
+
+std::string toString(int val) {
+ // use sqlite3 API that is slighly faster than std::ostringstream
+ // with forcing the C locale. sqlite3_snprintf() emulates a C locale.
+ constexpr int BUF_SIZE = 16;
+ char szBuffer[BUF_SIZE];
+ sqlite3_snprintf(BUF_SIZE, szBuffer, "%d", val);
+ return szBuffer;
+}
+
+std::string toString(double val, int precision) {
+ // use sqlite3 API that is slighly faster than std::ostringstream
+ // with forcing the C locale. sqlite3_snprintf() emulates a C locale.
+ constexpr int BUF_SIZE = 32;
+ char szBuffer[BUF_SIZE];
+ sqlite3_snprintf(BUF_SIZE, szBuffer, "%.*g", precision, val);
+ if (precision == 15 && strstr(szBuffer, "9999999999")) {
+ sqlite3_snprintf(BUF_SIZE, szBuffer, "%.14g", val);
+ }
+ return szBuffer;
+}
+
+#endif
+
+// ---------------------------------------------------------------------------
+
+std::string concat(const char *a, const std::string &b) {
+ std::string res(a);
+ res += b;
+ return res;
+}
+
+std::string concat(const char *a, const std::string &b, const char *c) {
+ std::string res(a);
+ res += b;
+ res += c;
+ return res;
+}
+
+// ---------------------------------------------------------------------------
+
+} // namespace internal
+
+NS_PROJ_END
diff --git a/src/io.cpp b/src/iso19111/io.cpp
index fe3680fb..7f68a579 100644
--- a/src/io.cpp
+++ b/src/iso19111/io.cpp
@@ -60,8 +60,8 @@
#include "proj_constants.h"
-#include "pj_wkt1_parser.h"
-#include "pj_wkt2_parser.h"
+#include "wkt1_parser.h"
+#include "wkt2_parser.h"
// PROJ include order is sensitive
// clang-format off
diff --git a/src/metadata.cpp b/src/iso19111/metadata.cpp
index 2be9dac3..2be9dac3 100644
--- a/src/metadata.cpp
+++ b/src/iso19111/metadata.cpp
diff --git a/src/static.cpp b/src/iso19111/static.cpp
index 5de046f1..5de046f1 100644
--- a/src/static.cpp
+++ b/src/iso19111/static.cpp
diff --git a/src/util.cpp b/src/iso19111/util.cpp
index ac6357a2..ac6357a2 100644
--- a/src/util.cpp
+++ b/src/iso19111/util.cpp
diff --git a/src/jniproj.c b/src/jniproj.cpp
index 67aa2478..67aa2478 100644
--- a/src/jniproj.c
+++ b/src/jniproj.cpp
diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake
index 4f29f4d5..767106e6 100644
--- a/src/lib_proj.cmake
+++ b/src/lib_proj.cmake
@@ -54,217 +54,177 @@ endif()
##############################################
### library source list and include_list ###
##############################################
-SET(SRC_LIBPROJ_PJ
- nad_init.c
- PJ_aea.c
- PJ_aeqd.c
- PJ_affine.c
- PJ_airy.c
- PJ_aitoff.c
- PJ_august.c
- PJ_axisswap.c
- PJ_bacon.c
- PJ_bertin1953.c
- PJ_bipc.c
- PJ_boggs.c
- PJ_bonne.c
- PJ_calcofi.c
- PJ_cart.c
- PJ_cass.c
- PJ_cc.c
- PJ_ccon.c
- PJ_cea.c
- PJ_chamb.c
- PJ_collg.c
- PJ_comill.c
- PJ_crast.c
- PJ_deformation.c
- PJ_denoy.c
- PJ_eck1.c
- PJ_eck2.c
- PJ_eck3.c
- PJ_eck4.c
- PJ_eck5.c
- PJ_eqc.c
- PJ_eqdc.c
- PJ_eqearth.c
- PJ_fahey.c
- PJ_fouc_s.c
- PJ_gall.c
- PJ_geoc.c
- PJ_geos.c
- PJ_gins8.c
- PJ_gnom.c
- PJ_gn_sinu.c
- PJ_goode.c
- PJ_gstmerc.c
- PJ_hammer.c
- PJ_hatano.c
- PJ_helmert.c
- PJ_hgridshift.c
- PJ_horner.c
- PJ_igh.c
- PJ_isea.c
- PJ_imw_p.c
- PJ_krovak.c
- PJ_labrd.c
- PJ_laea.c
- PJ_lagrng.c
- PJ_larr.c
- PJ_lask.c
- PJ_latlong.c
- PJ_lcca.c
- PJ_lcc.c
- PJ_loxim.c
- PJ_lsat.c
- PJ_misrsom.c
- PJ_mbt_fps.c
- PJ_mbtfpp.c
- PJ_mbtfpq.c
- PJ_merc.c
- PJ_mill.c
- PJ_mod_ster.c
- PJ_moll.c
- PJ_molodensky.c
- PJ_natearth.c
- PJ_natearth2.c
- PJ_nell.c
- PJ_nell_h.c
- PJ_nocol.c
- PJ_nsper.c
- PJ_nzmg.c
- PJ_ob_tran.c
- PJ_ocea.c
- PJ_oea.c
- PJ_omerc.c
- PJ_ortho.c
- PJ_patterson.c
- PJ_pipeline.c
- PJ_poly.c
- PJ_putp2.c
- PJ_putp3.c
- PJ_putp4p.c
- PJ_putp5.c
- PJ_putp6.c
- PJ_qsc.c
- PJ_robin.c
- PJ_rpoly.c
- PJ_sch.c
- PJ_sconics.c
- PJ_somerc.c
- PJ_sterea.c
- PJ_stere.c
- PJ_sts.c
- PJ_tcc.c
- PJ_tcea.c
- PJ_times.c
- PJ_tmerc.c
- PJ_tobmerc.c
- PJ_tpeqd.c
- PJ_unitconvert.c
- PJ_urm5.c
- PJ_urmfps.c
- PJ_vandg.c
- PJ_vandg2.c
- PJ_vandg4.c
- PJ_vgridshift.c
- PJ_wag2.c
- PJ_wag3.c
- PJ_wag7.c
- PJ_wink1.c
- PJ_wink2.c
- proj_etmerc.c
+
+SET(SRC_LIBPROJ_PROJECTIONS
+ projections/aeqd.cpp
+ projections/gnom.cpp
+ projections/laea.cpp
+ projections/mod_ster.cpp
+ projections/nsper.cpp
+ projections/nzmg.cpp
+ projections/ortho.cpp
+ projections/stere.cpp
+ projections/sterea.cpp
+ projections/aea.cpp
+ projections/bipc.cpp
+ projections/bonne.cpp
+ projections/eqdc.cpp
+ projections/isea.cpp
+ projections/ccon.cpp
+ projections/imw_p.cpp
+ projections/krovak.cpp
+ projections/lcc.cpp
+ projections/poly.cpp
+ projections/rpoly.cpp
+ projections/sconics.cpp
+ projections/rouss.cpp
+ projections/cass.cpp
+ projections/cc.cpp
+ projections/cea.cpp
+ projections/eqc.cpp
+ projections/gall.cpp
+ projections/labrd.cpp
+ projections/lsat.cpp
+ projections/misrsom.cpp
+ projections/merc.cpp
+ projections/mill.cpp
+ projections/ocea.cpp
+ projections/omerc.cpp
+ projections/somerc.cpp
+ projections/tcc.cpp
+ projections/tcea.cpp
+ projections/times.cpp
+ projections/tmerc.cpp
+ projections/tobmerc.cpp
+ projections/airy.cpp
+ projections/aitoff.cpp
+ projections/august.cpp
+ projections/bacon.cpp
+ projections/bertin1953.cpp
+ projections/chamb.cpp
+ projections/hammer.cpp
+ projections/lagrng.cpp
+ projections/larr.cpp
+ projections/lask.cpp
+ projections/latlong.cpp
+ projections/nicol.cpp
+ projections/ob_tran.cpp
+ projections/oea.cpp
+ projections/tpeqd.cpp
+ projections/vandg.cpp
+ projections/vandg2.cpp
+ projections/vandg4.cpp
+ projections/wag7.cpp
+ projections/lcca.cpp
+ projections/geos.cpp
+ projections/etmerc.cpp
+ projections/boggs.cpp
+ projections/collg.cpp
+ projections/comill.cpp
+ projections/crast.cpp
+ projections/denoy.cpp
+ projections/eck1.cpp
+ projections/eck2.cpp
+ projections/eck3.cpp
+ projections/eck4.cpp
+ projections/eck5.cpp
+ projections/fahey.cpp
+ projections/fouc_s.cpp
+ projections/gins8.cpp
+ projections/gstmerc.cpp
+ projections/gn_sinu.cpp
+ projections/goode.cpp
+ projections/igh.cpp
+ projections/hatano.cpp
+ projections/loxim.cpp
+ projections/mbt_fps.cpp
+ projections/mbtfpp.cpp
+ projections/mbtfpq.cpp
+ projections/moll.cpp
+ projections/nell.cpp
+ projections/nell_h.cpp
+ projections/patterson.cpp
+ projections/putp2.cpp
+ projections/putp3.cpp
+ projections/putp4p.cpp
+ projections/putp5.cpp
+ projections/putp6.cpp
+ projections/qsc.cpp
+ projections/robin.cpp
+ projections/sch.cpp
+ projections/sts.cpp
+ projections/urm5.cpp
+ projections/urmfps.cpp
+ projections/wag2.cpp
+ projections/wag3.cpp
+ projections/wink1.cpp
+ projections/wink2.cpp
+ projections/healpix.cpp
+ projections/natearth.cpp
+ projections/natearth2.cpp
+ projections/calcofi.cpp
+ projections/eqearth.cpp
)
-SET(SRC_LIBPROJ_CORE
- aasincos.c
- adjlon.c
- bch2bps.c
- bchgen.c
- biveval.c
- dmstor.c
- emess.c
- emess.h
- geocent.c
- geocent.h
- geodesic.c
- mk_cheby.c
- nad_cvt.c
- nad_init.c
- nad_intr.c
- pj_apply_gridshift.c
- pj_apply_vgridshift.c
- pj_auth.c
- pj_ctx.c
- pj_fileapi.c
- pj_datum_set.c
- pj_datums.c
- pj_deriv.c
- pj_ell_set.c
- pj_ellps.c
- pj_errno.c
- pj_factors.c
- pj_fwd.c
- pj_gauss.c
- pj_gc_reader.c
- pj_geocent.c
- pj_gridcatalog.c
- pj_gridinfo.c
- pj_gridlist.c
- PJ_healpix.c
- pj_init.c
- pj_initcache.c
- pj_inv.c
- pj_list.c
- pj_list.h
- pj_log.c
- pj_malloc.c
- pj_math.c
- pj_mlfn.c
- pj_msfn.c
- pj_mutex.c
- proj_4D_api.c
- pj_internal.c
- proj_internal.h
- pj_open_lib.c
- pj_param.c
- pj_phi2.c
- pj_pr_list.c
- pj_qsfn.c
- pj_release.c
- pj_strerrno.c
- pj_transform.c
- pj_tsfn.c
- pj_units.c
- pj_utils.c
- pj_zpoly1.c
- proj_mdist.c
- proj_math.h
- proj_rouss.c
- rtodms.c
- vector1.c
- pj_strtod.c
- pj_wkt1_generated_parser.c
- pj_wkt2_generated_parser.c
- ${CMAKE_CURRENT_BINARY_DIR}/proj_config.h
+SET(SRC_LIBPROJ_CONVERSIONS
+ conversions/axisswap.cpp
+ conversions/cart.cpp
+ conversions/geoc.cpp
+ conversions/geocent.cpp
+ conversions/unitconvert.cpp
+)
+
+SET(SRC_LIBPROJ_TRANSFORMATIONS
+ transformations/affine.cpp
+ transformations/deformation.cpp
+ transformations/helmert.cpp
+ transformations/hgridshift.cpp
+ transformations/horner.cpp
+ transformations/molodensky.cpp
+ transformations/vgridshift.cpp
)
-set(SRC_LIBPROJ_CPP
- static.cpp
- common.cpp
- coordinateoperation.cpp
- coordinatesystem.cpp
- crs.cpp
- datum.cpp
- io.cpp
- metadata.cpp
- util.cpp
+SET(SRC_LIBPROJ_ISO19111
+ iso19111/static.cpp
+ iso19111/util.cpp
+ iso19111/metadata.cpp
+ iso19111/common.cpp
+ iso19111/crs.cpp
+ iso19111/datum.cpp
+ iso19111/coordinatesystem.cpp
+ iso19111/coordinateoperation.cpp
+ iso19111/io.cpp
+ iso19111/internal.cpp
+ iso19111/factory.cpp
+ iso19111/c_api.cpp
+)
+
+SET(SRC_LIBPROJ_CORE
+ pj_list.h proj_internal.h proj_math.h projects.h
+ aasincos.cpp adjlon.cpp bch2bps.cpp bchgen.cpp
+ biveval.cpp dmstor.cpp mk_cheby.cpp auth.cpp
+ deriv.cpp ell_set.cpp ellps.cpp errno.cpp
+ factors.cpp fwd.cpp init.cpp inv.cpp
+ list.cpp malloc.cpp mlfn.cpp msfn.cpp proj_mdist.cpp
+ open_lib.cpp param.cpp phi2.cpp pr_list.cpp
+ qsfn.cpp strerrno.cpp
+ tsfn.cpp units.cpp ctx.cpp log.cpp zpoly1.cpp rtodms.cpp
+ vector1.cpp release.cpp gauss.cpp
+ fileapi.cpp
+ gc_reader.cpp gridcatalog.cpp
+ nad_cvt.cpp nad_init.cpp nad_intr.cpp
+ apply_gridshift.cpp datums.cpp datum_set.cpp transform.cpp
+ geocent.cpp geocent.h utils.cpp gridinfo.cpp gridlist.cpp
+ jniproj.cpp mutex.cpp initcache.cpp apply_vgridshift.cpp geodesic.c
+ strtod.cpp math.cpp
+ 4D_api.cpp pipeline.cpp
internal.cpp
- factory.cpp
- c_api.cpp
- pj_wkt_parser.cpp
- pj_wkt1_parser.cpp
- pj_wkt2_parser.cpp
+ wkt_parser.hpp wkt_parser.cpp
+ wkt1_parser.h wkt1_parser.cpp
+ wkt1_generated_parser.h wkt1_generated_parser.c
+ wkt2_parser.h wkt2_parser.cpp
+ wkt2_generated_parser.h wkt2_generated_parser.c
+ ${CMAKE_CURRENT_BINARY_DIR}/proj_config.h
)
set(HEADERS_LIBPROJ
@@ -278,8 +238,10 @@ set(HEADERS_LIBPROJ
# Group source files for IDE source explorers (e.g. Visual Studio)
source_group("Header Files" FILES ${HEADERS_LIBPROJ})
source_group("Source Files\\Core" FILES ${SRC_LIBPROJ_CORE})
-source_group("Source Files\\PJ" FILES ${SRC_LIBPROJ_PJ})
-source_group("Source Files\\C++" FILES ${SRC_LIBPROJ_CPP})
+source_group("Source Files\\Conversions" FILES ${SRC_LIBPROJ_CONVERSIONS})
+source_group("Source Files\\Projections" FILES ${SRC_LIBPROJ_PROJECTIONS})
+source_group("Source Files\\Transformations" FILES ${SRC_LIBPROJ_TRANSFORMATIONS})
+source_group("Source Files\\ISO19111" FILES ${SRC_LIBPROJ_ISO19111})
include_directories(${CMAKE_SOURCE_DIR}/include)
@@ -301,7 +263,7 @@ endif(JNI_SUPPORT AND NOT JNI_FOUND)
boost_report_value(JNI_SUPPORT)
if(JNI_SUPPORT)
set(SRC_LIBPROJ_CORE ${SRC_LIBPROJ_CORE}
- jniproj.c )
+ jniproj.cpp )
set(HEADERS_LIBPROJ ${HEADERS_LIBPROJ}
org_proj4_PJ.h)
source_group("Source Files\\JNI" FILES ${SRC_LIBPROJ_JNI})
@@ -313,7 +275,12 @@ endif(JNI_SUPPORT)
#################################################
## targets: libproj and proj_config.h
#################################################
-set(ALL_LIBPROJ_SOURCES ${SRC_LIBPROJ_PJ} ${SRC_LIBPROJ_CORE} ${SRC_LIBPROJ_CPP})
+set(ALL_LIBPROJ_SOURCES ${SRC_LIBPROJ_CORE}
+ ${SRC_LIBPROJ_CONVERSIONS}
+ ${SRC_LIBPROJ_PROJECTIONS}
+ ${SRC_LIBPROJ_TRANSFORMATIONS}
+ ${SRC_LIBPROJ_ISO19111}
+)
set(ALL_LIBPROJ_HEADERS ${HEADERS_LIBPROJ} )
# Core targets configuration
diff --git a/src/pj_list.c b/src/list.cpp
index 33313875..73ca5f86 100644
--- a/src/pj_list.c
+++ b/src/list.cpp
@@ -9,12 +9,12 @@
/* Generate prototypes for projection functions */
-#define PROJ_HEAD(id, name) struct PJconsts *pj_##id(struct PJconsts*);
+#define PROJ_HEAD(id, name) extern "C" struct PJconsts *pj_##id(struct PJconsts*);
#include "pj_list.h"
#undef PROJ_HEAD
/* Generate extern declarations for description strings */
-#define PROJ_HEAD(id, name) extern const char * const pj_s_##id;
+#define PROJ_HEAD(id, name) extern "C" const char * const pj_s_##id;
#include "pj_list.h"
#undef PROJ_HEAD
@@ -22,7 +22,7 @@
#define PROJ_HEAD(id, name) {#id, pj_##id, &pj_s_##id},
const struct PJ_LIST pj_list[] = {
#include "pj_list.h"
- {0, 0, 0},
+ {nullptr, nullptr, nullptr},
};
#undef PROJ_HEAD
diff --git a/src/pj_log.c b/src/log.cpp
index 6654691c..0f81dc13 100644
--- a/src/pj_log.c
+++ b/src/log.cpp
@@ -68,7 +68,7 @@ void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args )
return;
msg_buf = (char *) malloc(100000);
- if( msg_buf == NULL )
+ if( msg_buf == nullptr )
return;
/* we should use vsnprintf where available once we add configure detect.*/
diff --git a/src/pj_malloc.c b/src/malloc.cpp
index c45da85d..c8681570 100644
--- a/src/pj_malloc.c
+++ b/src/malloc.cpp
@@ -95,8 +95,8 @@ It allocates space for an array of <n> elements of size <size>.
The array is initialized to zeros.
***********************************************************************/
void *res = pj_malloc (n*size);
- if (0==res)
- return 0;
+ if (nullptr==res)
+ return nullptr;
memset (res, 0, n*size);
return res;
}
@@ -128,10 +128,10 @@ pointer" to signal an error in a multi level allocation:
return p; // success
***********************************************************************/
- if (0==ptr)
- return 0;
+ if (nullptr==ptr)
+ return nullptr;
pj_dalloc (ptr);
- return 0;
+ return nullptr;
}
/**********************************************************************/
@@ -139,7 +139,7 @@ char *pj_strdup(const char *str)
/**********************************************************************/
{
size_t len = strlen(str) + 1;
- char *dup = pj_malloc(len);
+ char *dup = static_cast<char*>(pj_malloc(len));
if (dup)
memcpy(dup, str, len);
return dup;
@@ -161,7 +161,7 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
pj_dealloc(t);
}
pj_ctx_set_errno (ctx, errlev);
- return (void *) 0;
+ return (void *) nullptr;
}
@@ -178,7 +178,7 @@ void *pj_dealloc_params (PJ_CONTEXT *ctx, paralist *start, int errlev) {
/************************************************************************/
void pj_free(PJ *P) {
- if (0==P)
+ if (nullptr==P)
return;
/* free projection parameters - all the hard work is done by */
/* pj_default_destructor, which is supposed */
@@ -192,7 +192,7 @@ void pj_free(PJ *P) {
/*****************************************************************************/
-void *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
+PJ *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
/*****************************************************************************
Does memory deallocation for "plain" PJ objects, i.e. that vast majority
of PJs where the opaque object does not contain any additionally
@@ -205,8 +205,8 @@ void *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
if (0!=errlev)
pj_ctx_set_errno (pj_get_ctx(P), errlev);
- if (0==P)
- return 0;
+ if (nullptr==P)
+ return nullptr;
/* free grid lists */
pj_dealloc( P->gridlist );
@@ -234,6 +234,7 @@ void *pj_default_destructor (PJ *P, int errlev) { /* Destructor */
pj_free (P->hgridshift);
pj_free (P->vgridshift);
- pj_dealloc (P->opaque);
- return pj_dealloc(P);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque));
+ pj_dealloc(P);
+ return nullptr;
}
diff --git a/src/pj_math.c b/src/math.cpp
index 540ab9eb..540ab9eb 100644
--- a/src/pj_math.c
+++ b/src/math.cpp
diff --git a/src/mk_cheby.c b/src/mk_cheby.cpp
index a2f90bef..5e6bfef0 100644
--- a/src/mk_cheby.c
+++ b/src/mk_cheby.cpp
@@ -23,36 +23,36 @@ makeT(int nru, int nrv) {
int i;
if (!(T = (Tseries *)pj_malloc(sizeof(Tseries))))
- return 0;
+ return nullptr;
if (!(T->cu = (struct PW_COEF *)pj_malloc(sizeof(struct PW_COEF) * nru))) {
pj_dalloc(T);
- return 0;
+ return nullptr;
}
if (!(T->cv = (struct PW_COEF *)pj_malloc(sizeof(struct PW_COEF) * nrv))) {
pj_dalloc(T->cu);
pj_dalloc(T);
- return 0;
+ return nullptr;
}
for (i = 0; i < nru; ++i)
- T->cu[i].c = 0;
+ T->cu[i].c = nullptr;
for (i = 0; i < nrv; ++i)
- T->cv[i].c = 0;
+ T->cv[i].c = nullptr;
return T;
}
Tseries *
mk_cheby(projUV a, projUV b, double res, projUV *resid, projUV (*func)(projUV),
int nu, int nv, int power) {
int j, i, nru, nrv, *ncu, *ncv;
- Tseries *T = NULL;
+ Tseries *T = nullptr;
projUV **w;
double cutres;
if (!(w = (projUV **)vector2(nu, nv, sizeof(projUV))))
- return 0;
+ return nullptr;
if (!(ncu = (int *)vector1(nu + nv, sizeof(int)))) {
freev2((void **)w, nu);
- return 0;
+ return nullptr;
}
ncv = ncu + nu;
if (!bchgen(a, b, nu, nv, w, func)) {
@@ -106,7 +106,7 @@ mk_cheby(projUV a, projUV b, double res, projUV *resid, projUV (*func)(projUV),
if (ncu[j]) nru = j + 1; /* update row max */
if (ncv[j]) nrv = j + 1;
}
- if ((T = makeT(nru, nrv)) != NULL ) {
+ if ((T = makeT(nru, nrv)) != nullptr ) {
T->a = a;
T->b = b;
T->mu = nru - 1;
@@ -137,7 +137,7 @@ mk_cheby(projUV a, projUV b, double res, projUV *resid, projUV (*func)(projUV),
}
}
}
- } else if ((T = makeT(nru, nrv)) != NULL) {
+ } else if ((T = makeT(nru, nrv)) != nullptr) {
/* else make returned Chebyshev coefficient structure */
T->mu = nru - 1; /* save row degree */
T->mv = nrv - 1;
@@ -184,7 +184,7 @@ mk_cheby(projUV a, projUV b, double res, projUV *resid, projUV (*func)(projUV),
pj_dalloc(T->cv[i].c);
pj_dalloc(T);
}
- T = 0;
+ T = nullptr;
gohome:
freev2((void **) w, nu);
pj_dalloc(ncu);
diff --git a/src/pj_mlfn.c b/src/mlfn.cpp
index 02e05c3a..e032e642 100644
--- a/src/pj_mlfn.c
+++ b/src/mlfn.cpp
@@ -27,8 +27,8 @@ double *pj_enfn(double es) {
double t, *en;
en = (double *) pj_malloc(EN_SIZE * sizeof (double));
- if (0==en)
- return 0;
+ if (nullptr==en)
+ return nullptr;
en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
diff --git a/src/pj_msfn.c b/src/msfn.cpp
index 999e73a7..999e73a7 100644
--- a/src/pj_msfn.c
+++ b/src/msfn.cpp
diff --git a/src/pj_mutex.c b/src/mutex.cpp
index dc4a441b..3752324c 100644
--- a/src/pj_mutex.c
+++ b/src/mutex.cpp
@@ -34,7 +34,9 @@
#endif
/* For PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */
+#ifndef _GNU_SOURCE
#define _GNU_SOURCE
+#endif
#ifndef _WIN32
#include "proj_config.h"
@@ -106,7 +108,14 @@ void pj_cleanup_lock()
#include "pthread.h"
#ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
+#endif
static pthread_mutex_t core_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
#else
static pthread_mutex_t core_lock;
diff --git a/src/nad_cvt.c b/src/nad_cvt.cpp
index ec4a2b47..ec4a2b47 100644
--- a/src/nad_cvt.c
+++ b/src/nad_cvt.cpp
diff --git a/src/nad_init.c b/src/nad_init.cpp
index 8b024ac7..1e2b150d 100644
--- a/src/nad_init.c
+++ b/src/nad_init.cpp
@@ -83,11 +83,11 @@ int nad_ctable_load( projCtx ctx, struct CTABLE *ct, PAFile fid )
/* read all the actual shift values */
a_size = ct->lim.lam * ct->lim.phi;
ct->cvs = (FLP *) pj_malloc(sizeof(FLP) * a_size);
- if( ct->cvs == NULL
+ if( ct->cvs == nullptr
|| pj_ctx_fread(ctx, ct->cvs, sizeof(FLP), a_size, fid) != a_size )
{
pj_dalloc( ct->cvs );
- ct->cvs = NULL;
+ ct->cvs = nullptr;
pj_log( ctx, PJ_LOG_ERROR,
"ctable loading failed on fread() - binary incompatible?" );
@@ -111,12 +111,12 @@ struct CTABLE *nad_ctable_init( projCtx ctx, PAFile fid )
/* read the table header */
ct = (struct CTABLE *) pj_malloc(sizeof(struct CTABLE));
- if( ct == NULL
+ if( ct == nullptr
|| pj_ctx_fread( ctx, ct, sizeof(struct CTABLE), 1, fid ) != 1 )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_dalloc( ct );
- return NULL;
+ return nullptr;
}
/* do some minimal validation to ensure the structure isn't corrupt */
@@ -125,7 +125,7 @@ struct CTABLE *nad_ctable_init( projCtx ctx, PAFile fid )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_dalloc( ct );
- return NULL;
+ return nullptr;
}
/* trim white space and newlines off id */
@@ -137,7 +137,7 @@ struct CTABLE *nad_ctable_init( projCtx ctx, PAFile fid )
break;
}
- ct->cvs = NULL;
+ ct->cvs = nullptr;
return ct;
}
@@ -158,13 +158,13 @@ int nad_ctable2_load( projCtx ctx, struct CTABLE *ct, PAFile fid )
/* read all the actual shift values */
a_size = ct->lim.lam * ct->lim.phi;
ct->cvs = (FLP *) pj_malloc(sizeof(FLP) * a_size);
- if( ct->cvs == NULL
+ if( ct->cvs == nullptr
|| pj_ctx_fread(ctx, ct->cvs, sizeof(FLP), a_size, fid) != a_size )
{
pj_dalloc( ct->cvs );
- ct->cvs = NULL;
+ ct->cvs = nullptr;
- if( getenv("PROJ_DEBUG") != NULL )
+ if( getenv("PROJ_DEBUG") != nullptr )
{
fprintf( stderr,
"ctable2 loading failed on fread() - binary incompatible?\n" );
@@ -197,7 +197,7 @@ struct CTABLE *nad_ctable2_init( projCtx ctx, PAFile fid )
if( pj_ctx_fread( ctx, header, sizeof(header), 1, fid ) != 1 )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
- return NULL;
+ return nullptr;
}
if( !IS_LSB )
@@ -210,15 +210,15 @@ struct CTABLE *nad_ctable2_init( projCtx ctx, PAFile fid )
{
pj_log( ctx, PJ_LOG_ERROR, "ctable2 - wrong header!" );
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
- return NULL;
+ return nullptr;
}
/* read the table header */
ct = (struct CTABLE *) pj_malloc(sizeof(struct CTABLE));
- if( ct == NULL )
+ if( ct == nullptr )
{
pj_ctx_set_errno( ctx, ENOMEM );
- return NULL;
+ return nullptr;
}
memcpy( ct->id, header + 16, 80 );
@@ -235,7 +235,7 @@ struct CTABLE *nad_ctable2_init( projCtx ctx, PAFile fid )
{
pj_ctx_set_errno( ctx, PJD_ERR_FAILED_TO_LOAD_GRID );
pj_dalloc( ct );
- return NULL;
+ return nullptr;
}
/* trim white space and newlines off id */
@@ -247,7 +247,7 @@ struct CTABLE *nad_ctable2_init( projCtx ctx, PAFile fid )
break;
}
- ct->cvs = NULL;
+ ct->cvs = nullptr;
return ct;
}
@@ -271,16 +271,16 @@ struct CTABLE *nad_init(projCtx ctx, char *name)
/* -------------------------------------------------------------------- */
strcpy(fname, name);
if (!(fid = pj_open_lib(ctx, fname, "rb"))) {
- return 0;
+ return nullptr;
}
ct = nad_ctable_init( ctx, fid );
- if( ct != NULL )
+ if( ct != nullptr )
{
if( !nad_ctable_load( ctx, ct, fid ) )
{
nad_free( ct );
- ct = NULL;
+ ct = nullptr;
}
}
@@ -297,7 +297,7 @@ struct CTABLE *nad_init(projCtx ctx, char *name)
void nad_free(struct CTABLE *ct)
{
if (ct) {
- if( ct->cvs != NULL )
+ if( ct->cvs != nullptr )
pj_dalloc(ct->cvs);
pj_dalloc(ct);
diff --git a/src/nad_intr.c b/src/nad_intr.cpp
index 1f9d1e0c..1f9d1e0c 100644
--- a/src/nad_intr.c
+++ b/src/nad_intr.cpp
diff --git a/src/pj_open_lib.c b/src/open_lib.cpp
index 6b908360..c75b4af6 100644
--- a/src/pj_open_lib.c
+++ b/src/open_lib.cpp
@@ -39,14 +39,14 @@
#include "proj_internal.h"
#include "projects.h"
-static const char *(*pj_finder)(const char *) = NULL;
+static const char *(*pj_finder)(const char *) = nullptr;
static int path_count = 0;
-static char **search_path = NULL;
+static char **search_path = nullptr;
static const char * proj_lib_name =
#ifdef PROJ_LIB
PROJ_LIB;
#else
-0;
+nullptr;
#endif
/************************************************************************/
@@ -71,7 +71,7 @@ void pj_set_searchpath ( int count, const char **path )
{
int i;
- if (path_count > 0 && search_path != NULL)
+ if (path_count > 0 && search_path != nullptr)
{
for (i = 0; i < path_count; i++)
{
@@ -79,15 +79,15 @@ void pj_set_searchpath ( int count, const char **path )
}
pj_dalloc(search_path);
path_count = 0;
- search_path = NULL;
+ search_path = nullptr;
}
if( count > 0 )
{
- search_path = pj_malloc(sizeof *search_path * count);
+ search_path = static_cast<char**>(pj_malloc(sizeof *search_path * count));
for (i = 0; i < count; i++)
{
- search_path[i] = pj_malloc(strlen(path[i]) + 1);
+ search_path[i] = static_cast<char*>(pj_malloc(strlen(path[i]) + 1));
strcpy(search_path[i], path[i]);
}
}
@@ -122,15 +122,15 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
static const char dir_chars[] = "/";
#endif
- if( out_full_filename != NULL && out_full_filename_size > 0 )
+ if( out_full_filename != nullptr && out_full_filename_size > 0 )
out_full_filename[0] = '\0';
/* check if ~/name */
if (*name == '~' && strchr(dir_chars,name[1]) )
- if ((sysname = getenv("HOME")) != NULL) {
+ if ((sysname = getenv("HOME")) != nullptr) {
if( strlen(sysname) + 1 + strlen(name) + 1 > sizeof(fname) )
{
- return NULL;
+ return nullptr;
}
(void)strcpy(fname, sysname);
fname[n = (int)strlen(fname)] = DIR_CHAR;
@@ -138,7 +138,7 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
(void)strcpy(fname+n, name + 1);
sysname = fname;
} else
- return NULL;
+ return nullptr;
/* or fixed path: /name, ./name or ../name */
else if (strchr(dir_chars,*name)
@@ -148,14 +148,14 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
sysname = name;
/* or try to use application provided file finder */
- else if( pj_finder != NULL && pj_finder( name ) != NULL )
+ else if( pj_finder != nullptr && pj_finder( name ) != nullptr )
sysname = pj_finder( name );
/* or is environment PROJ_LIB defined */
else if ((sysname = getenv("PROJ_LIB")) || (sysname = proj_lib_name)) {
if( strlen(sysname) + 1 + strlen(name) + 1 > sizeof(fname) )
{
- return NULL;
+ return nullptr;
}
(void)strcpy(fname, sysname);
fname[n = (int)strlen(fname)] = DIR_CHAR;
@@ -165,9 +165,9 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
} else /* just try it bare bones */
sysname = name;
- if ((fid = pj_ctx_fopen(ctx, sysname, mode)) != NULL)
+ if ((fid = pj_ctx_fopen(ctx, sysname, mode)) != nullptr)
{
- if( out_full_filename != NULL && out_full_filename_size > 0 )
+ if( out_full_filename != nullptr && out_full_filename_size > 0 )
{
strncpy(out_full_filename, sysname, out_full_filename_size);
out_full_filename[out_full_filename_size-1] = '\0';
@@ -178,7 +178,7 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
/* If none of those work and we have a search path, try it */
if (!fid && path_count > 0)
{
- for (i = 0; fid == NULL && i < path_count; i++)
+ for (i = 0; fid == nullptr && i < path_count; i++)
{
if( strlen(search_path[i]) + 1 + strlen(name) + 1 <= sizeof(fname) )
{
@@ -189,7 +189,7 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
}
if (fid)
{
- if( out_full_filename != NULL && out_full_filename_size > 0 )
+ if( out_full_filename != nullptr && out_full_filename_size > 0 )
{
strncpy(out_full_filename, sysname, out_full_filename_size);
out_full_filename[out_full_filename_size-1] = '\0';
@@ -204,7 +204,7 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
pj_log( ctx, PJ_LOG_DEBUG_MAJOR,
"pj_open_lib(%s): call fopen(%s) - %s",
name, sysname,
- fid == NULL ? "failed" : "succeeded" );
+ fid == nullptr ? "failed" : "succeeded" );
return(fid);
}
@@ -215,7 +215,7 @@ pj_open_lib_ex(projCtx ctx, const char *name, const char *mode,
PAFile
pj_open_lib(projCtx ctx, const char *name, const char *mode) {
- return pj_open_lib_ex(ctx, name, mode, NULL, 0);
+ return pj_open_lib_ex(ctx, name, mode, nullptr, 0);
}
/************************************************************************/
@@ -238,7 +238,7 @@ int pj_find_file(projCtx ctx, const char *short_filename,
{
PAFile f = pj_open_lib_ex(ctx, short_filename, "rb", out_full_filename,
out_full_filename_size);
- if( f != NULL )
+ if( f != nullptr )
{
pj_ctx_fclose(ctx, f);
return 1;
diff --git a/src/pj_param.c b/src/param.cpp
index 4078dc83..74247b72 100644
--- a/src/pj_param.c
+++ b/src/param.cpp
@@ -12,9 +12,9 @@
paralist *pj_mkparam(const char *str) {
paralist *newitem;
- if((newitem = (paralist *)pj_malloc(sizeof(paralist) + strlen(str))) != NULL) {
+ if((newitem = (paralist *)pj_malloc(sizeof(paralist) + strlen(str))) != nullptr) {
newitem->used = 0;
- newitem->next = 0;
+ newitem->next = nullptr;
if (*str == '+')
++str;
(void)strcpy(newitem->param, str);
@@ -28,8 +28,8 @@ paralist *pj_mkparam_ws (const char *str) {
paralist *newitem;
size_t len = 0;
- if (0==str)
- return 0;
+ if (nullptr==str)
+ return nullptr;
/* Find start and length of string */
while (isspace (*str))
@@ -43,12 +43,12 @@ paralist *pj_mkparam_ws (const char *str) {
/* Use calloc to automagically 0-terminate the copy */
newitem = (paralist *) pj_calloc (1, sizeof(paralist) + len + 1);
- if (0==newitem)
- return 0;
+ if (nullptr==newitem)
+ return nullptr;
memmove(newitem->param, str, len);
newitem->used = 0;
- newitem->next = 0;
+ newitem->next = nullptr;
return newitem;
}
@@ -70,12 +70,12 @@ paralist *pj_param_exists (paralist *list, const char *parameter) {
the t (for compile time known names, this is obviously not an issue).
***************************************************************************************/
paralist *next = list;
- char *c = strchr (parameter, '=');
+ const char *c = strchr (parameter, '=');
size_t len = strlen (parameter);
if (c)
len = c - parameter;
- if (list==0)
- return 0;
+ if (list==nullptr)
+ return nullptr;
for (next = list; next; next = next->next) {
if (0==strncmp (parameter, next->param, len) && (next->param[len]=='=' || next->param[len]==0)) {
@@ -83,10 +83,10 @@ paralist *pj_param_exists (paralist *list, const char *parameter) {
return next;
}
if (0==strcmp (parameter, "step"))
- return 0;
+ return nullptr;
}
- return 0;
+ return nullptr;
}
@@ -116,24 +116,24 @@ PROJVALUE pj_param (projCtx ctx, paralist *pl, const char *opt) {
unsigned l;
PROJVALUE value = {0};
- if ( ctx == NULL )
+ if ( ctx == nullptr )
ctx = pj_get_default_ctx();
type = *opt++;
- if (0==strchr ("tbirds", type)) {
+ if (nullptr==strchr ("tbirds", type)) {
fprintf(stderr, "invalid request to pj_param, fatal\n");
exit(1);
}
pl = pj_param_exists (pl, opt);
if (type == 't') {
- value.i = pl != 0;
+ value.i = pl != nullptr;
return value;
}
/* Not found */
- if (0==pl) {
+ if (nullptr==pl) {
/* Return value after the switch, so that the return path is */
/* taken in all cases */
switch (type) {
@@ -144,7 +144,7 @@ PROJVALUE pj_param (projCtx ctx, paralist *pl, const char *opt) {
value.f = 0.;
break;
case 's':
- value.s = 0;
+ value.s = nullptr;
break;
}
return value;
@@ -165,7 +165,7 @@ PROJVALUE pj_param (projCtx ctx, paralist *pl, const char *opt) {
value.f = pj_atof(opt);
break;
case 'r': /* degrees input */
- value.f = dmstor_ctx(ctx, opt, 0);
+ value.f = dmstor_ctx(ctx, opt, nullptr);
break;
case 's': /* char string */
value.s = (char *) opt;
diff --git a/src/pj_phi2.c b/src/phi2.cpp
index a83302e6..a83302e6 100644
--- a/src/pj_phi2.c
+++ b/src/phi2.cpp
diff --git a/src/PJ_pipeline.c b/src/pipeline.cpp
index 618d4688..76fc58a5 100644
--- a/src/PJ_pipeline.c
+++ b/src/pipeline.cpp
@@ -109,12 +109,14 @@ Thomas Knudsen, thokn@sdfe.dk, 2016-05-20
PROJ_HEAD(pipeline, "Transformation pipeline manager");
/* Projection specific elements for the PJ object */
+namespace { // anonymous namespace
struct pj_opaque {
int steps;
char **argv;
char **current_argv;
PJ **pipeline;
};
+} // anonymous namespace
@@ -132,10 +134,10 @@ static PJ_COORD pipeline_forward_4d (PJ_COORD point, PJ *P) {
int i, first_step, last_step;
first_step = 1;
- last_step = P->opaque->steps + 1;
+ last_step = static_cast<struct pj_opaque*>(P->opaque)->steps + 1;
for (i = first_step; i != last_step; i++)
- point = proj_trans (P->opaque->pipeline[i], 1, point);
+ point = proj_trans (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], PJ_FWD, point);
return point;
}
@@ -144,11 +146,11 @@ static PJ_COORD pipeline_forward_4d (PJ_COORD point, PJ *P) {
static PJ_COORD pipeline_reverse_4d (PJ_COORD point, PJ *P) {
int i, first_step, last_step;
- first_step = P->opaque->steps;
+ first_step = static_cast<struct pj_opaque*>(P->opaque)->steps;
last_step = 0;
for (i = first_step; i != last_step; i--)
- point = proj_trans (P->opaque->pipeline[i], -1, point);
+ point = proj_trans (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], PJ_INV, point);
return point;
}
@@ -161,8 +163,8 @@ static XYZ pipeline_forward_3d (LPZ lpz, PJ *P) {
int i;
point.lpz = lpz;
- for (i = 1; i <= P->opaque->steps; i++)
- point = pj_approx_3D_trans (P->opaque->pipeline[i], 1, point);
+ for (i = 1; i <= static_cast<struct pj_opaque*>(P->opaque)->steps; i++)
+ point = pj_approx_3D_trans (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], PJ_FWD, point);
return point.xyz;
}
@@ -173,8 +175,8 @@ static LPZ pipeline_reverse_3d (XYZ xyz, PJ *P) {
int i;
point.xyz = xyz;
- for (i = P->opaque->steps; i > 0 ; i--)
- point = pj_approx_3D_trans (P->opaque->pipeline[i], -1, point);
+ for (i = static_cast<struct pj_opaque*>(P->opaque)->steps; i > 0 ; i--)
+ point = pj_approx_3D_trans (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], PJ_INV, point);
return point.lpz;
}
@@ -187,8 +189,8 @@ static XY pipeline_forward (LP lp, PJ *P) {
int i;
point.lp = lp;
- for (i = 1; i <= P->opaque->steps; i++)
- point = pj_approx_2D_trans (P->opaque->pipeline[i], 1, point);
+ for (i = 1; i <= static_cast<struct pj_opaque*>(P->opaque)->steps; i++)
+ point = pj_approx_2D_trans (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], PJ_FWD, point);
return point.xy;
}
@@ -198,8 +200,8 @@ static LP pipeline_reverse (XY xy, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
int i;
point.xy = xy;
- for (i = P->opaque->steps; i > 0 ; i--)
- point = pj_approx_2D_trans (P->opaque->pipeline[i], -1, point);
+ for (i = static_cast<struct pj_opaque*>(P->opaque)->steps; i > 0 ; i--)
+ point = pj_approx_2D_trans (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i], PJ_INV, point);
return point.lp;
}
@@ -207,22 +209,22 @@ static LP pipeline_reverse (XY xy, PJ *P) {
-static void *destructor (PJ *P, int errlev) {
+static PJ *destructor (PJ *P, int errlev) {
int i;
- if (0==P)
- return 0;
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
/* Deallocate each pipeine step, then pipeline array */
- if (0!=P->opaque->pipeline)
- for (i = 0; i < P->opaque->steps; i++)
- proj_destroy (P->opaque->pipeline[i+1]);
- pj_dealloc (P->opaque->pipeline);
+ if (nullptr!=static_cast<struct pj_opaque*>(P->opaque)->pipeline)
+ for (i = 0; i < static_cast<struct pj_opaque*>(P->opaque)->steps; i++)
+ proj_destroy (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i+1]);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->pipeline);
- pj_dealloc (P->opaque->argv);
- pj_dealloc (P->opaque->current_argv);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->argv);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->current_argv);
return pj_default_destructor(P, errlev);
}
@@ -231,11 +233,11 @@ static void *destructor (PJ *P, int errlev) {
static PJ *pj_create_pipeline (PJ *P, size_t steps) {
/* Room for the pipeline: An array of PJ * with room for sentinels at both ends */
- P->opaque->pipeline = pj_calloc (steps + 2, sizeof(PJ *));
- if (0==P->opaque->pipeline)
- return 0;
+ static_cast<struct pj_opaque*>(P->opaque)->pipeline = static_cast<PJ**>(pj_calloc (steps + 2, sizeof(PJ *)));
+ if (nullptr==static_cast<struct pj_opaque*>(P->opaque)->pipeline)
+ return nullptr;
- P->opaque->steps = (int)steps;
+ static_cast<struct pj_opaque*>(P->opaque)->steps = (int)steps;
return P;
}
@@ -246,7 +248,7 @@ static PJ *pj_create_pipeline (PJ *P, size_t steps) {
/* count the number of args in pipeline definition, and mark all args as used */
static size_t argc_params (paralist *params) {
size_t argc = 0;
- for (; params != 0; params = params->next) {
+ for (; params != nullptr; params = params->next) {
argc++;
params->used = 1;
}
@@ -254,18 +256,18 @@ static size_t argc_params (paralist *params) {
}
/* Sentinel for argument list */
-static char *argv_sentinel = "step";
+static const char *argv_sentinel = "step";
/* turn paralist into argc/argv style argument list */
static char **argv_params (paralist *params, size_t argc) {
char **argv;
size_t i = 0;
- argv = pj_calloc (argc, sizeof (char *));
- if (0==argv)
- return 0;
- for (; params != 0; params = params->next)
+ argv = static_cast<char**>(pj_calloc (argc, sizeof (char *)));
+ if (nullptr==argv)
+ return nullptr;
+ for (; params != nullptr; params = params->next)
argv[i++] = params->param;
- argv[i++] = argv_sentinel;
+ argv[i++] = const_cast<char*>(argv_sentinel);
return argv;
}
@@ -288,13 +290,13 @@ static void set_ellipsoid(PJ *P) {
int err = proj_errno_reset (P);
/* Break the linked list after the global args */
- attachment = 0;
- for (cur = P->params; cur != 0; cur = cur->next)
+ attachment = nullptr;
+ for (cur = P->params; cur != nullptr; cur = cur->next)
/* cur->next will always be non 0 given argv_sentinel presence, */
/* but this is far from being obvious for a static analyzer */
- if (cur->next != 0 && strcmp(argv_sentinel, cur->next->param) == 0) {
+ if (cur->next != nullptr && strcmp(argv_sentinel, cur->next->param) == 0) {
attachment = cur->next;
- cur->next = 0;
+ cur->next = nullptr;
break;
}
@@ -320,7 +322,7 @@ static void set_ellipsoid(PJ *P) {
/* Re-attach the dangling list */
/* Note: cur will always be non 0 given argv_sentinel presence, */
/* but this is far from being obvious for a static analyzer */
- if( cur != 0 )
+ if( cur != nullptr )
cur->next = attachment;
proj_errno_restore (P, err);
}
@@ -350,17 +352,17 @@ PJ *OPERATION(pipeline,0) {
P->skip_inv_finalize = 1;
- P->opaque = pj_calloc (1, sizeof(struct pj_opaque));
- if (0==P->opaque)
+ P->opaque = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof(struct pj_opaque)));
+ if (nullptr==P->opaque)
return destructor(P, ENOMEM);
argc = (int)argc_params (P->params);
- P->opaque->argv = argv = argv_params (P->params, argc);
- if (0==argv)
+ static_cast<struct pj_opaque*>(P->opaque)->argv = argv = argv_params (P->params, argc);
+ if (nullptr==argv)
return destructor (P, ENOMEM);
- P->opaque->current_argv = current_argv = pj_calloc (argc, sizeof (char *));
- if (0==current_argv)
+ static_cast<struct pj_opaque*>(P->opaque)->current_argv = current_argv = static_cast<char**>(pj_calloc (argc, sizeof (char *)));
+ if (nullptr==current_argv)
return destructor (P, ENOMEM);
/* Do some syntactical sanity checking */
@@ -385,7 +387,7 @@ PJ *OPERATION(pipeline,0) {
}
}
nsteps--; /* Last instance of +step is just a sentinel */
- P->opaque->steps = nsteps;
+ static_cast<struct pj_opaque*>(P->opaque)->steps = nsteps;
if (-1==i_pipeline)
return destructor (P, PJD_ERR_MALFORMED_PIPELINE); /* ERROR: no pipeline def */
@@ -394,7 +396,7 @@ PJ *OPERATION(pipeline,0) {
return destructor (P, PJD_ERR_MALFORMED_PIPELINE); /* ERROR: no pipeline def */
/* Make room for the pipeline and execution indicators */
- if (0==pj_create_pipeline (P, nsteps))
+ if (nullptr==pj_create_pipeline (P, nsteps))
return destructor (P, ENOMEM);
set_ellipsoid(P);
@@ -405,7 +407,7 @@ PJ *OPERATION(pipeline,0) {
int j;
int current_argc = 0;
int err;
- PJ *next_step = 0;
+ PJ *next_step = nullptr;
/* Build a set of setup args for the current step */
proj_log_trace (P, "Pipeline: Building arg list for step no. %d", i);
@@ -429,7 +431,7 @@ PJ *OPERATION(pipeline,0) {
next_step = proj_create_argv (P->ctx, current_argc, current_argv);
proj_log_trace (P, "Pipeline: Step %d (%s) at %p", i, current_argv[0], next_step);
- if (0==next_step) {
+ if (nullptr==next_step) {
/* The step init failed, but possibly without setting errno. If so, we say "malformed" */
int err_to_report = proj_errno(P);
if (0==err_to_report)
@@ -447,14 +449,14 @@ PJ *OPERATION(pipeline,0) {
next_step->inverted = next_step->inverted == 0 ? 1 : 0;
}
- P->opaque->pipeline[i+1] = next_step;
+ static_cast<struct pj_opaque*>(P->opaque)->pipeline[i+1] = next_step;
proj_log_trace (P, "Pipeline at [%p]: step at [%p] (%s) done", P, next_step, current_argv[0]);
}
/* Require a forward path through the pipeline */
for (i = 1; i <= nsteps; i++) {
- PJ *Q = P->opaque->pipeline[i];
+ PJ *Q = static_cast<struct pj_opaque*>(P->opaque)->pipeline[i];
if ( ( Q->inverted && (Q->inv || Q->inv3d || Q->fwd4d) ) ||
(!Q->inverted && (Q->fwd || Q->fwd3d || Q->fwd4d) ) ) {
continue;
@@ -466,21 +468,21 @@ PJ *OPERATION(pipeline,0) {
/* determine if an inverse operation is possible */
for (i = 1; i <= nsteps; i++) {
- PJ *Q = P->opaque->pipeline[i];
+ PJ *Q = static_cast<struct pj_opaque*>(P->opaque)->pipeline[i];
if ( pj_has_inverse(Q) ) {
continue;
} else {
- P->inv = 0;
- P->inv3d = 0;
- P->inv4d = 0;
+ P->inv = nullptr;
+ P->inv3d = nullptr;
+ P->inv4d = nullptr;
break;
}
}
/* Check that output units from step i are compatible with expected units in step i+1 */
for (i = 1; i < nsteps; i++) {
- enum pj_io_units unit_returned = pj_right (P->opaque->pipeline[i]);
- enum pj_io_units unit_expected = pj_left (P->opaque->pipeline[i+1]);
+ enum pj_io_units unit_returned = pj_right (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i]);
+ enum pj_io_units unit_expected = pj_left (static_cast<struct pj_opaque*>(P->opaque)->pipeline[i+1]);
if ( unit_returned == PJ_IO_UNITS_WHATEVER || unit_expected == PJ_IO_UNITS_WHATEVER )
continue;
@@ -493,9 +495,9 @@ PJ *OPERATION(pipeline,0) {
proj_log_trace (P, "Pipeline: %d steps built. Determining i/o characteristics", nsteps);
/* Determine forward input (= reverse output) data type */
- P->left = pj_left (P->opaque->pipeline[1]);
+ P->left = pj_left (static_cast<struct pj_opaque*>(P->opaque)->pipeline[1]);
/* Now, correspondingly determine forward output (= reverse input) data type */
- P->right = pj_right (P->opaque->pipeline[nsteps]);
+ P->right = pj_right (static_cast<struct pj_opaque*>(P->opaque)->pipeline[nsteps]);
return P;
}
diff --git a/src/pj_internal.c b/src/pj_internal.c
deleted file mode 100644
index 7eb917be..00000000
--- a/src/pj_internal.c
+++ /dev/null
@@ -1,445 +0,0 @@
-/******************************************************************************
- * Project: PROJ.4
- * Purpose: This is primarily material originating from pj_obs_api.c
- * (now proj_4D_api.c), that does not fit into the API
- * category. Hence this pile of tubings and fittings for
- * PROJ.4 internal plumbing.
- *
- * Author: Thomas Knudsen, thokn@sdfe.dk, 2017-07-05
- *
- ******************************************************************************
- * Copyright (c) 2016, 2017, 2018, Thomas Knudsen/SDFE
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *****************************************************************************/
-
-#include <ctype.h>
-#include <errno.h>
-#include <math.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "geodesic.h"
-#include "proj_internal.h"
-#include "projects.h"
-
-
-enum pj_io_units pj_left (PJ *P) {
- enum pj_io_units u = P->inverted? P->right: P->left;
- if (u==PJ_IO_UNITS_CLASSIC)
- return PJ_IO_UNITS_PROJECTED;
- return u;
-}
-
-enum pj_io_units pj_right (PJ *P) {
- enum pj_io_units u = P->inverted? P->left: P->right;
- if (u==PJ_IO_UNITS_CLASSIC)
- return PJ_IO_UNITS_PROJECTED;
- return u;
-}
-
-
-/* Work around non-constness of MSVC HUGE_VAL by providing functions rather than constants */
-PJ_COORD proj_coord_error (void) {
- PJ_COORD c;
- c.v[0] = c.v[1] = c.v[2] = c.v[3] = HUGE_VAL;
- return c;
-}
-
-
-
-/**************************************************************************************/
-PJ_COORD pj_approx_2D_trans (PJ *P, PJ_DIRECTION direction, PJ_COORD coo) {
-/***************************************************************************************
-Behave mostly as proj_trans, but attempt to use 2D interfaces only.
-Used in gie.c, to enforce testing 2D code, and by PJ_pipeline.c to implement
-chained calls starting out with a call to its 2D interface.
-***************************************************************************************/
- if (0==P)
- return coo;
- if (P->inverted)
- direction = -direction;
- switch (direction) {
- case PJ_FWD:
- coo.xy = pj_fwd (coo.lp, P);
- return coo;
- case PJ_INV:
- coo.lp = pj_inv (coo.xy, P);
- return coo;
- case PJ_IDENT:
- return coo;
- default:
- break;
- }
- proj_errno_set (P, EINVAL);
- return proj_coord_error ();
-}
-
-
-/**************************************************************************************/
-PJ_COORD pj_approx_3D_trans (PJ *P, PJ_DIRECTION direction, PJ_COORD coo) {
-/***************************************************************************************
-Companion to pj_approx_2D_trans.
-
-Behave mostly as proj_trans, but attempt to use 3D interfaces only.
-Used in gie.c, to enforce testing 3D code, and by PJ_pipeline.c to implement
-chained calls starting out with a call to its 3D interface.
-***************************************************************************************/
- if (0==P)
- return coo;
- if (P->inverted)
- direction = -direction;
- switch (direction) {
- case PJ_FWD:
- coo.xyz = pj_fwd3d (coo.lpz, P);
- return coo;
- case PJ_INV:
- coo.lpz = pj_inv3d (coo.xyz, P);
- return coo;
- case PJ_IDENT:
- return coo;
- default:
- break;
- }
- proj_errno_set (P, EINVAL);
- return proj_coord_error ();
-}
-
-/**************************************************************************************/
-int pj_has_inverse(PJ *P) {
-/***************************************************************************************
-Check if a a PJ has an inverse.
-***************************************************************************************/
- return ( (P->inverted && (P->fwd || P->fwd3d || P->fwd4d) ) ||
- ( P->inv || P->inv3d || P->inv4d) );
-}
-
-
-/* Move P to a new context - or to the default context if 0 is specified */
-void proj_context_set (PJ *P, PJ_CONTEXT *ctx) {
- if (0==ctx)
- ctx = pj_get_default_ctx ();
- pj_set_ctx (P, ctx);
-}
-
-
-void proj_context_inherit (PJ *parent, PJ *child) {
- if (0==parent)
- pj_set_ctx (child, pj_get_default_ctx());
- else
- pj_set_ctx (child, pj_get_ctx(parent));
-}
-
-
-
-/*****************************************************************************/
-char *pj_chomp (char *c) {
-/******************************************************************************
-Strip pre- and postfix whitespace. Inline comments (indicated by '#') are
-considered whitespace.
-******************************************************************************/
- size_t i, n;
- char *comment;
- char *start = c;
-
- if (0==c)
- return 0;
-
- comment = strchr (c, '#');
- if (comment)
- *comment = 0;
-
- n = strlen (c);
- if (0==n)
- return c;
-
- /* Eliminate postfix whitespace */
- for (i = n - 1; (i > 0) && (isspace (c[i]) || ';'==c[i]); i--)
- c[i] = 0;
-
- /* Find start of non-whitespace */
- while (0 != *start && (';'==*start || isspace (*start)))
- start++;
-
- n = strlen (start);
- if (0==n) {
- c[0] = 0;
- return c;
- }
-
- memmove (c, start, n + 1);
- return c;
-}
-
-
-
-/*****************************************************************************/
-char *pj_shrink (char *c) {
-/******************************************************************************
-Collapse repeated whitespace. Remove '+' and ';'. Make ',' and '=' greedy,
-consuming their surrounding whitespace.
-******************************************************************************/
- size_t i, j, n;
-
- /* Flag showing that a whitespace (ws) has been written after last non-ws */
- size_t ws;
-
- if (0==c)
- return 0;
-
- pj_chomp (c);
- n = strlen (c);
-
- /* First collapse repeated whitespace (including +/;) */
- i = 0;
- ws = 0;
- for (j = 0; j < n; j++) {
-
- /* Eliminate prefix '+', only if preceded by whitespace */
- /* (i.e. keep it in 1.23e+08) */
- if ((i > 0) && ('+'==c[j]) && ws)
- c[j] = ' ';
- if ((i==0) && ('+'==c[j]))
- c[j] = ' ';
-
- if (isspace (c[j]) || ';'==c[j]) {
- if (0==ws && (i > 0))
- c[i++] = ' ';
- ws = 1;
- continue;
- }
- else {
- ws = 0;
- c[i++] = c[j];
- }
- }
- c[i] = 0;
- n = strlen(c);
-
- /* Then make ',' and '=' greedy */
- i = 0;
- for (j = 0; j < n; j++) {
- if (i==0) {
- c[i++] = c[j];
- continue;
- }
-
- /* Skip space before '='/',' */
- if ('='==c[j] || ','==c[j]) {
- if (c[i - 1]==' ')
- c[i - 1] = c[j];
- else
- c[i++] = c[j];
- continue;
- }
-
- if (' '==c[j] && ('='==c[i - 1] || ','==c[i - 1]) )
- continue;
-
- c[i++] = c[j];
- }
- c[i] = 0;
- return c;
-}
-
-
-
-/*****************************************************************************/
-size_t pj_trim_argc (char *args) {
-/******************************************************************************
-Trim all unnecessary whitespace (and non-essential syntactic tokens) from the
-argument string, args, and count its number of elements.
-******************************************************************************/
- size_t i, m, n;
- pj_shrink (args);
- n = strlen (args);
- if (n==0)
- return 0;
- for (i = m = 0; i < n; i++) {
- if (' '==args[i]) {
- args[i] = 0;
- m++;
- }
- }
- return m + 1;
-}
-
-
-
-/*****************************************************************************/
-char **pj_trim_argv (size_t argc, char *args) {
-/******************************************************************************
-Create an argv-style array from elements placed in the argument string, args.
-
-args is a trimmed string as returned by pj_trim_argc(), and argc is the number
-of trimmed strings found (i.e. the return value of pj_trim_args()). Hence,
- int argc = pj_trim_argc (args);
- char **argv = pj_trim_argv (argc, args);
-will produce a classic style (argc, argv) pair from a string of whitespace
-separated args. No new memory is allocated for storing the individual args
-(they stay in the args string), but for the pointers to the args a new array
-is allocated and returned.
-
-It is the duty of the caller to free this array.
-******************************************************************************/
- size_t i, j;
- char **argv;
-
- if (0==args)
- return 0;
- if (0==argc)
- return 0;
-
-
- /* turn the input string into an array of strings */
- argv = (char **) calloc (argc, sizeof (char *));
- if (0==argv)
- return 0;
- argv[0] = args;
- j = 1;
- for (i = 0; ; i++) {
- if (0==args[i]) {
- argv[j++] = args + (i + 1);
- }
- if (j==argc)
- break;
- }
- return argv;
-}
-
-
-
-/*****************************************************************************/
-char *pj_make_args (size_t argc, char **argv) {
-/******************************************************************************
-pj_make_args is the inverse of the pj_trim_argc/pj_trim_argv combo: It
-converts free format command line input to something proj_create can consume.
-
-Allocates, and returns, an array of char, large enough to hold a whitespace
-separated copy of the args in argv. It is the duty of the caller to free this
-array.
-******************************************************************************/
- size_t i, n;
- char *p;
-
- for (i = n = 0; i < argc; i++)
- n += strlen (argv[i]);
-
- p = pj_calloc (n + argc + 1, sizeof (char));
- if (0==p)
- return 0;
- if (0==argc)
- return p;
-
- for (i = 0; i < argc; i++) {
- strcat (p, argv[i]);
- strcat (p, " ");
- }
- return pj_shrink (p);
-}
-
-
-
-/*****************************************************************************/
-void proj_context_errno_set (PJ_CONTEXT *ctx, int err) {
-/******************************************************************************
-Raise an error directly on a context, without going through a PJ belonging
-to that context.
-******************************************************************************/
- if (0==ctx)
- ctx = pj_get_default_ctx();
- pj_ctx_set_errno (ctx, err);
-}
-
-/* logging */
-
-/* pj_vlog resides in pj_log.c and relates to pj_log as vsprintf relates to sprintf */
-void pj_vlog( projCtx ctx, int level, const char *fmt, va_list args );
-
-
-/***************************************************************************************/
-PJ_LOG_LEVEL proj_log_level (PJ_CONTEXT *ctx, PJ_LOG_LEVEL log_level) {
-/****************************************************************************************
- Set logging level 0-3. Higher number means more debug info. 0 turns it off
-****************************************************************************************/
- PJ_LOG_LEVEL previous;
- if (0==ctx)
- ctx = pj_get_default_ctx();
- if (0==ctx)
- return PJ_LOG_TELL;
- previous = abs (ctx->debug_level);
- if (PJ_LOG_TELL==log_level)
- return previous;
- ctx->debug_level = log_level;
- return previous;
-}
-
-
-/*****************************************************************************/
-void proj_log_error (PJ *P, const char *fmt, ...) {
-/******************************************************************************
- For reporting the most severe events.
-******************************************************************************/
- va_list args;
- va_start( args, fmt );
- pj_vlog (pj_get_ctx (P), PJ_LOG_ERROR , fmt, args);
- va_end( args );
-}
-
-
-/*****************************************************************************/
-void proj_log_debug (PJ *P, const char *fmt, ...) {
-/******************************************************************************
- For reporting debugging information.
-******************************************************************************/
- va_list args;
- va_start( args, fmt );
- pj_vlog (pj_get_ctx (P), PJ_LOG_DEBUG_MAJOR , fmt, args);
- va_end( args );
-}
-
-
-/*****************************************************************************/
-void proj_log_trace (PJ *P, const char *fmt, ...) {
-/******************************************************************************
- For reporting embarrasingly detailed debugging information.
-******************************************************************************/
- va_list args;
- va_start( args, fmt );
- pj_vlog (pj_get_ctx (P), PJ_LOG_DEBUG_MINOR , fmt, args);
- va_end( args );
-}
-
-
-/*****************************************************************************/
-void proj_log_func (PJ_CONTEXT *ctx, void *app_data, PJ_LOG_FUNCTION logf) {
-/******************************************************************************
- Put a new logging function into P's context. The opaque object app_data is
- passed as first arg at each call to the logger
-******************************************************************************/
- if (0==ctx)
- pj_get_default_ctx ();
- if (0==ctx)
- return;
- ctx->app_data = app_data;
- if (0!=logf)
- ctx->logger = logf;
-}
diff --git a/src/pj_pr_list.c b/src/pr_list.cpp
index 4e71e471..b8ad2c04 100644
--- a/src/pj_pr_list.c
+++ b/src/pr_list.cpp
@@ -67,7 +67,7 @@ char *pj_get_def( PJ *P, int options )
definition = (char *) pj_malloc(def_max);
if (!definition)
- return NULL;
+ return nullptr;
definition[0] = '\0';
for (t = P->params; t; t = t->next)
@@ -91,7 +91,7 @@ char *pj_get_def( PJ *P, int options )
}
else {
pj_dalloc( definition );
- return NULL;
+ return nullptr;
}
}
diff --git a/src/proj.h b/src/proj.h
index 5c0e8fdc..8ec48088 100644
--- a/src/proj.h
+++ b/src/proj.h
@@ -331,7 +331,11 @@ typedef struct projCtx_t PJ_CONTEXT;
/* Functionality for handling thread contexts */
+#ifdef __cplusplus
+#define PJ_DEFAULT_CTX nullptr
+#else
#define PJ_DEFAULT_CTX 0
+#endif
PJ_CONTEXT PROJ_DLL *proj_context_create (void);
PJ_CONTEXT PROJ_DLL *proj_context_destroy (PJ_CONTEXT *ctx);
diff --git a/src/proj_mdist.c b/src/proj_mdist.cpp
index 777f704d..e3f0f5c6 100644
--- a/src/proj_mdist.c
+++ b/src/proj_mdist.cpp
@@ -37,12 +37,14 @@
#define MAX_ITER 20
#define TOL 1e-14
+namespace { // anonymous namespace
struct MDIST {
int nb;
double es;
double E;
double b[1];
};
+} // anonymous namespace
void *
proj_mdist_ini(double es) {
double numf, numfi, twon1, denf, denfi, ens, T, twon;
@@ -71,8 +73,8 @@ proj_mdist_ini(double es) {
El = Es;
}
if ((b = (struct MDIST *)malloc(sizeof(struct MDIST)+
- (i*sizeof(double)))) == NULL)
- return(NULL);
+ (i*sizeof(double)))) == nullptr)
+ return(nullptr);
b->nb = i - 1;
b->es = es;
b->E = Es;
diff --git a/src/PJ_aea.c b/src/projections/aea.cpp
index 640f1013..c4a4a72a 100644
--- a/src/PJ_aea.c
+++ b/src/projections/aea.cpp
@@ -67,6 +67,7 @@ static double phi1_(double qs, double Te, double Tone_es) {
}
+namespace { // anonymous namespace
struct pj_opaque {
double ec;
double n;
@@ -80,16 +81,17 @@ struct pj_opaque {
double *en;
int ellips;
};
+} // anonymous namespace
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -99,7 +101,7 @@ static void *destructor (PJ *P, int errlev) { /* Destruct
static XY e_forward (LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
Q->rho = Q->c - (Q->ellips ? Q->n * pj_qsfn(sin(lp.phi), P->e, P->one_es) : Q->n2 * sin(lp.phi));;
if (Q->rho < 0.) {
proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
@@ -114,7 +116,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoid/spheroid, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if( (Q->rho = hypot(xy.x, xy.y = Q->rho0 - xy.y)) != 0.0 ) {
if (Q->n < 0.) {
Q->rho = -Q->rho;
@@ -148,7 +150,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoid/spheroid, inverse */
static PJ *setup(PJ *P) {
double cosphi, sinphi;
int secant;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
P->inv = e_inverse;
P->fwd = e_forward;
@@ -196,8 +198,8 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(aea) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -209,8 +211,8 @@ PJ *PROJECTION(aea) {
PJ *PROJECTION(leac) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
diff --git a/src/PJ_aeqd.c b/src/projections/aeqd.cpp
index 5d8c3d38..1a350d90 100644
--- a/src/PJ_aeqd.c
+++ b/src/projections/aeqd.cpp
@@ -32,13 +32,16 @@
#include "projects.h"
#include "proj_math.h"
+namespace { // anonymous namespace
enum Mode {
N_POLE = 0,
S_POLE = 1,
EQUIT = 2,
OBLIQ = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double sinph0;
double cosph0;
@@ -51,6 +54,7 @@ struct pj_opaque {
enum Mode mode;
struct geod_geodesic g;
};
+} // anonymous namespace
PROJ_HEAD(aeqd, "Azimuthal Equidistant") "\n\tAzi, Sph&Ell\n\tlat_0 guam";
@@ -58,14 +62,14 @@ PROJ_HEAD(aeqd, "Azimuthal Equidistant") "\n\tAzi, Sph&Ell\n\tlat_0 guam";
#define TOL 1.e-14
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -73,7 +77,7 @@ static void *destructor (PJ *P, int errlev) { /* Destruct
static XY e_guam_fwd(LP lp, PJ *P) { /* Guam elliptical */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosphi, sinphi, t;
cosphi = cos(lp.phi);
@@ -89,7 +93,7 @@ static XY e_guam_fwd(LP lp, PJ *P) { /* Guam elliptical */
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi, rho;
double azi1, azi2, s12;
double lam1, phi1, lam2, phi2;
@@ -128,7 +132,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
sinphi = sin(lp.phi);
@@ -175,7 +179,7 @@ oblcon:
static LP e_guam_inv(XY xy, PJ *P) { /* Guam elliptical */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double x2, t = 0.0;
int i;
@@ -193,7 +197,7 @@ static LP e_guam_inv(XY xy, PJ *P) { /* Guam elliptical */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c;
double azi1, azi2, s12, x2, y2, lat1, lon1, lat2, lon2;
@@ -225,7 +229,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosc, c_rh, sinc;
if ((c_rh = hypot(xy.x, xy.y)) > M_PI) {
@@ -265,8 +269,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(aeqd) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
diff --git a/src/PJ_airy.c b/src/projections/airy.cpp
index 75f95780..0eb5efd7 100644
--- a/src/PJ_airy.c
+++ b/src/projections/airy.cpp
@@ -34,13 +34,16 @@
PROJ_HEAD(airy, "Airy") "\n\tMisc Sph, no inv\n\tno_cut lat_b=";
+namespace { // anonymous namespace
enum Mode {
N_POLE = 0,
S_POLE = 1,
EQUIT = 2,
OBLIQ = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double p_halfpi;
double sinph0;
@@ -49,6 +52,7 @@ struct pj_opaque {
enum Mode mode;
int no_cut; /* do not cut at hemisphere limit */
};
+} // anonymous namespace
# define EPS 1.e-10
@@ -56,7 +60,7 @@ struct pj_opaque {
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinlam, coslam, cosphi, sinphi, t, s, Krho, cosz;
sinlam = sin(lp.lam);
@@ -111,8 +115,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(airy) {
double beta;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_aitoff.c b/src/projections/aitoff.cpp
index 82c981d5..effd2c29 100644
--- a/src/PJ_aitoff.c
+++ b/src/projections/aitoff.cpp
@@ -37,15 +37,19 @@
#include "projects.h"
+namespace { // anonymous namespace
enum Mode {
AITOFF = 0,
WINKEL_TRIPEL = 1
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double cosphi1;
enum Mode mode;
};
+} // anonymous namespace
PROJ_HEAD(aitoff, "Aitoff") "\n\tMisc Sph";
@@ -60,7 +64,7 @@ FORWARD(s_forward); /* spheroid */
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c, d;
if((d = acos(cos(lp.phi) * cos(c = 0.5 * lp.lam))) != 0.0) {/* basic Aitoff */
@@ -98,7 +102,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int iter, MAXITER = 10, round = 0, MAXROUND = 20;
double EPSILON = 1e-12, D, C, f1, f2, f1p, f1l, f2p, f2l, dp, dl, sl, sp, cp, cl, x, y;
@@ -170,8 +174,8 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(aitoff) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -181,8 +185,8 @@ PJ *PROJECTION(aitoff) {
PJ *PROJECTION(wintri) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_august.c b/src/projections/august.cpp
index e891e84e..b5a21ef7 100644
--- a/src/PJ_august.c
+++ b/src/projections/august.cpp
@@ -27,7 +27,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(august) {
- P->inv = 0;
+ P->inv = nullptr;
P->fwd = s_forward;
P->es = 0.;
return P;
diff --git a/src/PJ_bacon.c b/src/projections/bacon.cpp
index f0f11c9d..6c6350fe 100644
--- a/src/PJ_bacon.c
+++ b/src/projections/bacon.cpp
@@ -7,10 +7,12 @@
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
int bacn;
int ortl;
};
+} // anonymous namespace
PROJ_HEAD(apian, "Apian Globular I") "\n\tMisc Sph, no inv";
PROJ_HEAD(ortel, "Ortelius Oval") "\n\tMisc Sph, no inv";
@@ -19,7 +21,7 @@ PROJ_HEAD(bacon, "Bacon Globular") "\n\tMisc Sph, no inv";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double ax, f;
xy.y = Q->bacn ? M_HALFPI * sin(lp.phi) : lp.phi;
@@ -39,8 +41,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(bacon) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -53,8 +55,8 @@ PJ *PROJECTION(bacon) {
PJ *PROJECTION(apian) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -66,8 +68,8 @@ PJ *PROJECTION(apian) {
PJ *PROJECTION(ortel) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_bertin1953.c b/src/projections/bertin1953.cpp
index 5a027da2..2203d6f1 100644
--- a/src/PJ_bertin1953.c
+++ b/src/projections/bertin1953.cpp
@@ -21,14 +21,16 @@
PROJ_HEAD(bertin1953, "Bertin 1953")
"\n\tMisc Sph no inv.";
+namespace { // anonymous namespace
struct pj_opaque {
double cos_delta_phi, sin_delta_phi, cos_delta_gamma, sin_delta_gamma, deltaLambda;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) {
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double fu = 1.4, k = 12., w = 1.68, d;
@@ -74,8 +76,8 @@ static XY s_forward (LP lp, PJ *P) {
PJ *PROJECTION(bertin1953) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_bipc.c b/src/projections/bipc.cpp
index e4a69077..19a6bbe1 100644
--- a/src/PJ_bipc.c
+++ b/src/projections/bipc.cpp
@@ -29,14 +29,16 @@ PROJ_HEAD(bipc, "Bipolar conic of western hemisphere") "\n\tConic Sph";
# define R104 1.81514242207410275904
+namespace { // anonymous namespace
struct pj_opaque {
int noskew;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cphi, sphi, tphi, t, al, Az, z, Av, cdlam, sdlam, r;
int tag;
@@ -113,7 +115,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t, r, rp, rl, al, z = 0.0, fAz, Az, s, c, Av;
int neg, i;
@@ -161,8 +163,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(bipc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_boggs.c b/src/projections/boggs.cpp
index 119357c0..119357c0 100644
--- a/src/PJ_boggs.c
+++ b/src/projections/boggs.cpp
diff --git a/src/PJ_bonne.c b/src/projections/bonne.cpp
index d3d5b757..385c1c4b 100644
--- a/src/PJ_bonne.c
+++ b/src/projections/bonne.cpp
@@ -9,6 +9,7 @@ PROJ_HEAD(bonne, "Bonne (Werner lat_1=90)")
"\n\tConic Sph&Ell\n\tlat_1=";
#define EPS10 1e-10
+namespace { // anonymous namespace
struct pj_opaque {
double phi1;
double cphi1;
@@ -16,11 +17,12 @@ struct pj_opaque {
double m1;
double *en;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, E, c;
rh = Q->am1 + Q->m1 - pj_mlfn(lp.phi, E = sin(lp.phi), c = cos(lp.phi), Q->en);
@@ -33,7 +35,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double E, rh;
rh = Q->cphi1 + Q->phi1 - lp.phi;
@@ -48,7 +50,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh;
rh = hypot(xy.x, xy.y = Q->cphi1 - xy.y);
@@ -67,7 +69,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double s, rh;
rh = hypot(xy.x, xy.y = Q->am1 - xy.y);
@@ -87,22 +89,22 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(bonne) {
double c;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -113,7 +115,7 @@ PJ *PROJECTION(bonne) {
if (P->es != 0.0) {
Q->en = pj_enfn(P->es);
- if (0==Q->en)
+ if (nullptr==Q->en)
return destructor(P, ENOMEM);
Q->m1 = pj_mlfn(Q->phi1, Q->am1 = sin(Q->phi1),
c = cos(Q->phi1), Q->en);
diff --git a/src/PJ_calcofi.c b/src/projections/calcofi.cpp
index ed4cfe86..e81e4d2a 100644
--- a/src/PJ_calcofi.c
+++ b/src/projections/calcofi.cpp
@@ -141,7 +141,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(calcofi) {
- P->opaque = 0;
+ P->opaque = nullptr;
/* if the user has specified +lon_0 or +k0 for some reason,
we're going to ignore it so that xy is consistent with point O */
diff --git a/src/PJ_cass.c b/src/projections/cass.cpp
index 4e3b4251..c831558c 100644
--- a/src/PJ_cass.c
+++ b/src/projections/cass.cpp
@@ -15,17 +15,19 @@ PROJ_HEAD(cass, "Cassini") "\n\tCyl, Sph&Ell";
# define C5 .06666666666666666666
+namespace { // anonymous namespace
struct pj_opaque {
double *en;
double m0;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
double n, t, a1, c, a2, tn;
XY xy = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.y = pj_mlfn (lp.phi, n = sin (lp.phi), c = cos (lp.phi), Q->en);
@@ -55,7 +57,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
double n, t, r, dd, d2, tn, ph1;
LP lp = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
ph1 = pj_inv_mlfn (P->ctx, Q->m0 + xy.y, P->es, Q->en);
tn = tan (ph1); t = tn*tn;
@@ -81,14 +83,14 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
return lp;
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -104,16 +106,16 @@ PJ *PROJECTION(cass) {
}
/* otherwise it's ellipsoidal */
- P->opaque = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==P->opaque)
+ P->opaque = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==P->opaque)
return pj_default_destructor (P, ENOMEM);
P->destructor = destructor;
- P->opaque->en = pj_enfn (P->es);
- if (0==P->opaque->en)
+ static_cast<struct pj_opaque*>(P->opaque)->en = pj_enfn (P->es);
+ if (nullptr==static_cast<struct pj_opaque*>(P->opaque)->en)
return pj_default_destructor (P, ENOMEM);
- P->opaque->m0 = pj_mlfn (P->phi0, sin (P->phi0), cos (P->phi0), P->opaque->en);
+ static_cast<struct pj_opaque*>(P->opaque)->m0 = pj_mlfn (P->phi0, sin (P->phi0), cos (P->phi0), static_cast<struct pj_opaque*>(P->opaque)->en);
P->inv = e_inverse;
P->fwd = e_forward;
diff --git a/src/PJ_cc.c b/src/projections/cc.cpp
index 152e6e4a..152e6e4a 100644
--- a/src/PJ_cc.c
+++ b/src/projections/cc.cpp
diff --git a/src/PJ_ccon.c b/src/projections/ccon.cpp
index 0b8b70cb..4f7dedb4 100644
--- a/src/PJ_ccon.c
+++ b/src/projections/ccon.cpp
@@ -28,6 +28,7 @@
#define EPS10 1e-10
+namespace { // anonymous namespace
struct pj_opaque {
double phi1;
double ctgphi1;
@@ -35,6 +36,7 @@ struct pj_opaque {
double cosphi1;
double *en;
};
+} // anonymous namespace
PROJ_HEAD(ccon, "Central Conic")
"\n\tCentral Conic, Sph\n\tlat_1=";
@@ -43,7 +45,7 @@ PROJ_HEAD(ccon, "Central Conic")
static XY forward (LP lp, PJ *P) {
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r;
r = Q->ctgphi1 - tan(lp.phi - Q->phi1);
@@ -56,7 +58,7 @@ static XY forward (LP lp, PJ *P) {
static LP inverse (XY xy, PJ *P) {
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.y = Q->ctgphi1 - xy.y;
lp.phi = Q->phi1 - atan(hypot(xy.x,xy.y) - Q->ctgphi1);
@@ -66,22 +68,22 @@ static LP inverse (XY xy, PJ *P) {
}
-static void *destructor (PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(ccon) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
diff --git a/src/PJ_cea.c b/src/projections/cea.cpp
index e05e524b..f8275b62 100644
--- a/src/PJ_cea.c
+++ b/src/projections/cea.cpp
@@ -6,10 +6,12 @@
#include "proj.h"
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double qp;
double *apa;
};
+} // anonymous namespace
PROJ_HEAD(cea, "Equal Area Cylindrical") "\n\tCyl, Sph&Ell\n\tlat_ts=";
# define EPS 1e-10
@@ -33,7 +35,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- lp.phi = pj_authlat(asin( 2. * xy.y * P->k0 / P->opaque->qp), P->opaque->apa);
+ lp.phi = pj_authlat(asin( 2. * xy.y * P->k0 / static_cast<struct pj_opaque*>(P->opaque)->qp), static_cast<struct pj_opaque*>(P->opaque)->apa);
lp.lam = xy.x / P->k0;
return lp;
}
@@ -56,22 +58,22 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
return (lp);
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->apa);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(cea) {
double t = 0.0;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
diff --git a/src/PJ_chamb.c b/src/projections/chamb.cpp
index 6951d6a1..a490e817 100644
--- a/src/PJ_chamb.c
+++ b/src/projections/chamb.cpp
@@ -7,6 +7,7 @@
#include "projects.h"
typedef struct { double r, Az; } VECT;
+namespace { // anonymous namespace
struct pj_opaque {
struct { /* control point data */
double phi, lam;
@@ -18,6 +19,7 @@ struct pj_opaque {
XY p;
double beta_0, beta_1, beta_2;
};
+} // anonymous namespace
PROJ_HEAD(chamb, "Chamberlin Trimetric") "\n\tMisc Sph, no inv"
"\n\tlat_1= lon_1= lat_2= lon_2= lat_3= lon_3=";
@@ -54,7 +56,7 @@ static double lc(projCtx ctx, double b,double c,double a) {
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinphi, cosphi, a;
VECT v[3];
int i, j;
@@ -101,8 +103,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(chamb) {
int i, j;
char line[10];
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_collg.c b/src/projections/collg.cpp
index 7904de29..7904de29 100644
--- a/src/PJ_collg.c
+++ b/src/projections/collg.cpp
diff --git a/src/PJ_comill.c b/src/projections/comill.cpp
index b6e0192e..b6e0192e 100644
--- a/src/PJ_comill.c
+++ b/src/projections/comill.cpp
diff --git a/src/PJ_crast.c b/src/projections/crast.cpp
index 4e4dee8b..4e4dee8b 100644
--- a/src/PJ_crast.c
+++ b/src/projections/crast.cpp
diff --git a/src/PJ_denoy.c b/src/projections/denoy.cpp
index 5c337c45..5c337c45 100644
--- a/src/PJ_denoy.c
+++ b/src/projections/denoy.cpp
diff --git a/src/PJ_eck1.c b/src/projections/eck1.cpp
index 88a7430c..88a7430c 100644
--- a/src/PJ_eck1.c
+++ b/src/projections/eck1.cpp
diff --git a/src/PJ_eck2.c b/src/projections/eck2.cpp
index f76ab4ec..f76ab4ec 100644
--- a/src/PJ_eck2.c
+++ b/src/projections/eck2.cpp
diff --git a/src/PJ_eck3.c b/src/projections/eck3.cpp
index 8f91c8bb..90376631 100644
--- a/src/PJ_eck3.c
+++ b/src/projections/eck3.cpp
@@ -10,14 +10,16 @@ PROJ_HEAD(putp1, "Putnins P1") "\n\tPCyl, Sph";
PROJ_HEAD(wag6, "Wagner VI") "\n\tPCyl, Sph";
PROJ_HEAD(kav7, "Kavraisky VII") "\n\tPCyl, Sph";
+namespace { // anonymous namespace
struct pj_opaque {
double C_x, C_y, A, B;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.y = Q->C_y * lp.phi;
xy.x = Q->C_x * lp.lam * (Q->A + asqrt(1. - Q->B * lp.phi * lp.phi));
@@ -27,7 +29,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double denominator;
lp.phi = xy.y / Q->C_y;
@@ -49,8 +51,8 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(eck3) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -64,8 +66,8 @@ PJ *PROJECTION(eck3) {
PJ *PROJECTION(kav7) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -82,8 +84,8 @@ PJ *PROJECTION(kav7) {
PJ *PROJECTION(wag6) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -96,8 +98,8 @@ PJ *PROJECTION(wag6) {
PJ *PROJECTION(putp1) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_eck4.c b/src/projections/eck4.cpp
index 4fa4c21f..4fa4c21f 100644
--- a/src/PJ_eck4.c
+++ b/src/projections/eck4.cpp
diff --git a/src/PJ_eck5.c b/src/projections/eck5.cpp
index f9f28460..f9f28460 100644
--- a/src/PJ_eck5.c
+++ b/src/projections/eck5.cpp
diff --git a/src/PJ_eqc.c b/src/projections/eqc.cpp
index 07d6141c..3fdb6dc0 100644
--- a/src/PJ_eqc.c
+++ b/src/projections/eqc.cpp
@@ -6,9 +6,11 @@
#include "proj.h"
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double rc;
};
+} // anonymous namespace
PROJ_HEAD(eqc, "Equidistant Cylindrical (Plate Carree)")
"\n\tCyl, Sph\n\tlat_ts=[, lat_0=0]";
@@ -16,7 +18,7 @@ PROJ_HEAD(eqc, "Equidistant Cylindrical (Plate Carree)")
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.x = Q->rc * lp.lam;
xy.y = lp.phi - P->phi0;
@@ -27,7 +29,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.lam = xy.x / Q->rc;
lp.phi = xy.y + P->phi0;
@@ -37,8 +39,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(eqc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_eqdc.c b/src/projections/eqdc.cpp
index 8caca87a..0831fca4 100644
--- a/src/PJ_eqdc.c
+++ b/src/projections/eqdc.cpp
@@ -7,6 +7,7 @@
#include "projects.h"
#include "proj_math.h"
+namespace { // anonymous namespace
struct pj_opaque {
double phi1;
double phi2;
@@ -17,6 +18,7 @@ struct pj_opaque {
double *en;
int ellips;
};
+} // anonymous namespace
PROJ_HEAD(eqdc, "Equidistant Conic")
"\n\tConic, Sph&Ell\n\tlat_1= lat_2=";
@@ -25,7 +27,7 @@ PROJ_HEAD(eqdc, "Equidistant Conic")
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
Q->rho = Q->c - (Q->ellips ? pj_mlfn(lp.phi, sin(lp.phi),
cos(lp.phi), Q->en) : lp.phi);
@@ -38,7 +40,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if ((Q->rho = hypot(xy.x, xy.y = Q->rho0 - xy.y)) != 0.0 ) {
if (Q->n < 0.) {
@@ -58,14 +60,14 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -74,8 +76,8 @@ PJ *PROJECTION(eqdc) {
double cosphi, sinphi;
int secant;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
diff --git a/src/PJ_eqearth.c b/src/projections/eqearth.cpp
index a0d4467b..e5c1f974 100644
--- a/src/PJ_eqearth.c
+++ b/src/projections/eqearth.cpp
@@ -31,15 +31,17 @@ PROJ_HEAD(eqearth, "Equal Earth") "\n\tPCyl, Sph&Ell";
#define EPS 1e-11
#define MAX_ITER 12
+namespace { // anonymous namespace
struct pj_opaque {
double qp;
double rqda;
double *apa;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal/spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sbeta;
double psi, psi2, psi6;
@@ -73,7 +75,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal/spheroidal, forwar
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal/spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double yc, y2, y6;
int i;
@@ -127,21 +129,21 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal/spheroidal, invers
return lp;
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->apa);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(eqearth) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -152,7 +154,7 @@ PJ *PROJECTION(eqearth) {
/* Ellipsoidal case */
if (P->es != 0.0) {
Q->apa = pj_authset(P->es); /* For auth_lat(). */
- if (0 == Q->apa)
+ if (nullptr == Q->apa)
return destructor(P, ENOMEM);
Q->qp = pj_qsfn(1.0, P->e, P->one_es); /* For auth_lat(). */
Q->rqda = sqrt(0.5*Q->qp); /* Authalic radius divided by major axis */
diff --git a/src/proj_etmerc.c b/src/projections/etmerc.cpp
index 4d7187e6..05f86f37 100644
--- a/src/proj_etmerc.c
+++ b/src/projections/etmerc.cpp
@@ -47,6 +47,7 @@
#include "proj_math.h"
+namespace { // anonymous namespace
struct pj_opaque {
double Qn; /* Merid. quad., scaled to the projection */ \
double Zb; /* Radius vector in polar coord. systems */ \
@@ -55,6 +56,7 @@ struct pj_opaque {
double utg[6]; /* Constants for transv. merc. -> geo */ \
double gtu[6]; /* Constants for geo -> transv. merc. */
};
+} // anonymous namespace
PROJ_HEAD(etmerc, "Extended Transverse Mercator")
"\n\tCyl, Sph\n\tlat_ts=(0)\nlat_0=(0)";
@@ -145,7 +147,7 @@ static double clens(double *a, int size, double arg_r) {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sin_Cn, cos_Cn, cos_Ce, sin_Ce, dCn, dCe;
double Cn = lp.phi, Ce = lp.lam;
@@ -181,7 +183,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sin_Cn, cos_Cn, cos_Ce, sin_Ce, dCn, dCe;
double Cn = xy.y, Ce = xy.x;
@@ -218,7 +220,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
static PJ *setup(PJ *P) { /* general initialization */
double f, n, np, Z;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (P->es <= 0) {
return pj_default_destructor(P, PJD_ERR_ELLIPSOID_USE_REQUIRED);
@@ -306,8 +308,8 @@ static PJ *setup(PJ *P) { /* general initialization */
PJ *PROJECTION(etmerc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
return setup (P);
@@ -320,8 +322,8 @@ PJ *PROJECTION(etmerc) {
PJ *PROJECTION(utm) {
long zone;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_fahey.c b/src/projections/fahey.cpp
index 85e0ab69..85e0ab69 100644
--- a/src/PJ_fahey.c
+++ b/src/projections/fahey.cpp
diff --git a/src/PJ_fouc_s.c b/src/projections/fouc_s.cpp
index 6efe34bd..c5e711de 100644
--- a/src/PJ_fouc_s.c
+++ b/src/projections/fouc_s.cpp
@@ -11,14 +11,16 @@ PROJ_HEAD(fouc_s, "Foucaut Sinusoidal") "\n\tPCyl, Sph";
#define MAX_ITER 10
#define LOOP_TOL 1e-7
+namespace { // anonymous namespace
struct pj_opaque {
double n, n1;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t;
t = cos(lp.phi);
@@ -30,7 +32,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double V;
int i;
@@ -53,8 +55,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(fouc_s) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_gall.c b/src/projections/gall.cpp
index a8697482..a8697482 100644
--- a/src/PJ_gall.c
+++ b/src/projections/gall.cpp
diff --git a/src/PJ_geos.c b/src/projections/geos.cpp
index 0eb25610..90fb01ab 100644
--- a/src/PJ_geos.c
+++ b/src/projections/geos.cpp
@@ -36,6 +36,7 @@
#include "projects.h"
#include "proj_math.h"
+namespace { // anonymous namespace
struct pj_opaque {
double h;
double radius_p;
@@ -46,13 +47,14 @@ struct pj_opaque {
double C;
int flip_axis;
};
+} // anonymous namespace
PROJ_HEAD(geos, "Geostationary Satellite View") "\n\tAzi, Sph&Ell\n\th=";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Vx, Vy, Vz, tmp;
/* Calculation of the three components of the vector from satellite to
@@ -82,7 +84,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r, Vx, Vy, Vz, tmp;
/* Calculation of geocentric latitude. */
@@ -118,7 +120,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Vx, Vy, Vz, a, b, det, k;
/* Setting three components of vector from satellite to position.*/
@@ -155,7 +157,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Vx, Vy, Vz, a, b, det, k;
/* Setting three components of vector from satellite to position.*/
@@ -195,8 +197,8 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(geos) {
char *sweep_axis;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -204,7 +206,7 @@ PJ *PROJECTION(geos) {
return pj_default_destructor (P, PJD_ERR_H_LESS_THAN_ZERO);
sweep_axis = pj_param(P->ctx, P->params, "ssweep").s;
- if (sweep_axis == NULL)
+ if (sweep_axis == nullptr)
Q->flip_axis = 0;
else {
if ((sweep_axis[0] != 'x' && sweep_axis[0] != 'y') ||
diff --git a/src/PJ_gins8.c b/src/projections/gins8.cpp
index c1a2fff0..cc422437 100644
--- a/src/PJ_gins8.c
+++ b/src/projections/gins8.cpp
@@ -24,7 +24,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(gins8) {
P->es = 0.0;
- P->inv = 0;
+ P->inv = nullptr;
P->fwd = s_forward;
return P;
diff --git a/src/PJ_gn_sinu.c b/src/projections/gn_sinu.cpp
index 2ef0f263..530de229 100644
--- a/src/PJ_gn_sinu.c
+++ b/src/projections/gn_sinu.cpp
@@ -15,17 +15,19 @@ PROJ_HEAD(mbtfps, "McBryde-Thomas Flat-Polar Sinusoidal") "\n\tPCyl, Sph";
#define MAX_ITER 8
#define LOOP_TOL 1e-7
+namespace { // anonymous namespace
struct pj_opaque {
double *en;
double m, n, C_x, C_y;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
double s, c;
- xy.y = pj_mlfn(lp.phi, s = sin(lp.phi), c = cos(lp.phi), P->opaque->en);
+ xy.y = pj_mlfn(lp.phi, s = sin(lp.phi), c = cos(lp.phi), static_cast<struct pj_opaque*>(P->opaque)->en);
xy.x = lp.lam * c / sqrt(1. - P->es * s * s);
return xy;
}
@@ -35,7 +37,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
double s;
- if ((s = fabs(lp.phi = pj_inv_mlfn(P->ctx, xy.y, P->es, P->opaque->en))) < M_HALFPI) {
+ if ((s = fabs(lp.phi = pj_inv_mlfn(P->ctx, xy.y, P->es, static_cast<struct pj_opaque*>(P->opaque)->en))) < M_HALFPI) {
s = sin(lp.phi);
lp.lam = xy.x * sqrt(1. - P->es * s * s) / cos(lp.phi);
} else if ((s - EPS10) < M_HALFPI) {
@@ -50,7 +52,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (Q->m == 0.0)
lp.phi = Q->n != 1. ? aasin(P->ctx,Q->n * sin(lp.phi)): lp.phi;
@@ -80,7 +82,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.y /= Q->C_y;
lp.phi = (Q->m != 0.0) ? aasin(P->ctx,(Q->m * xy.y + sin(xy.y)) / Q->n) :
@@ -90,14 +92,14 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
@@ -105,7 +107,7 @@ static void *destructor (PJ *P, int errlev) { /* Destruct
/* for spheres, only */
static void setup(PJ *P) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
P->es = 0;
P->inv = s_inverse;
P->fwd = s_forward;
@@ -115,8 +117,8 @@ static void setup(PJ *P) {
PJ *PROJECTION(sinu) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -137,8 +139,8 @@ PJ *PROJECTION(sinu) {
PJ *PROJECTION(eck6) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -152,8 +154,8 @@ PJ *PROJECTION(eck6) {
PJ *PROJECTION(mbtfps) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -167,8 +169,8 @@ PJ *PROJECTION(mbtfps) {
PJ *PROJECTION(gn_sinu) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
diff --git a/src/PJ_gnom.c b/src/projections/gnom.cpp
index 635ae49e..a4b5e35d 100644
--- a/src/PJ_gnom.c
+++ b/src/projections/gnom.cpp
@@ -11,23 +11,27 @@ PROJ_HEAD(gnom, "Gnomonic") "\n\tAzi, Sph";
#define EPS10 1.e-10
+namespace { // anonymous namespace
enum Mode {
N_POLE = 0,
S_POLE = 1,
EQUIT = 2,
OBLIQ = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double sinph0;
double cosph0;
enum Mode mode;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
sinphi = sin(lp.phi);
@@ -75,7 +79,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, cosz, sinz;
rh = hypot(xy.x, xy.y);
@@ -120,8 +124,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(gnom) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_goode.c b/src/projections/goode.cpp
index 8d8ac24d..c79d125e 100644
--- a/src/PJ_goode.c
+++ b/src/projections/goode.cpp
@@ -13,15 +13,17 @@ PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph";
C_NAMESPACE PJ *pj_sinu(PJ *), *pj_moll(PJ *);
+namespace { // anonymous namespace
struct pj_opaque {
PJ *sinu;
PJ *moll;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (fabs(lp.phi) <= PHI_LIM)
xy = Q->sinu->fwd(lp, Q->sinu);
@@ -35,7 +37,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (fabs(xy.y) <= PHI_LIM)
lp = Q->sinu->inv(xy, Q->sinu);
@@ -47,27 +49,27 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
- if (0==P->opaque)
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_free (P->opaque->sinu);
- pj_free (P->opaque->moll);
+ pj_free (static_cast<struct pj_opaque*>(P->opaque)->sinu);
+ pj_free (static_cast<struct pj_opaque*>(P->opaque)->moll);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(goode) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
P->es = 0.;
- if (!(Q->sinu = pj_sinu(0)) || !(Q->moll = pj_moll(0)))
+ if (!(Q->sinu = pj_sinu(nullptr)) || !(Q->moll = pj_moll(nullptr)))
return destructor (P, ENOMEM);
Q->sinu->es = 0.;
Q->sinu->ctx = P->ctx;
diff --git a/src/PJ_gstmerc.c b/src/projections/gstmerc.cpp
index 5b5109b0..9b819bac 100644
--- a/src/PJ_gstmerc.c
+++ b/src/projections/gstmerc.cpp
@@ -8,6 +8,7 @@
PROJ_HEAD(gstmerc, "Gauss-Schreiber Transverse Mercator (aka Gauss-Laborde Reunion)")
"\n\tCyl, Sph&Ell\n\tlat_0= lon_0= k_0=";
+namespace { // anonymous namespace
struct pj_opaque {
double lamc;
double phic;
@@ -17,11 +18,12 @@ struct pj_opaque {
double XS;
double YS;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double L, Ls, sinLs1, Ls1;
L = Q->n1*lp.lam;
@@ -37,7 +39,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double L, LC, sinC;
L = atan(sinh((xy.x * P->a - Q->XS) / Q->n2) / cos((xy.y * P->a - Q->YS) / Q->n2));
@@ -51,8 +53,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(gstmerc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_hammer.c b/src/projections/hammer.cpp
index f3e0d64e..d4caa656 100644
--- a/src/PJ_hammer.c
+++ b/src/projections/hammer.cpp
@@ -11,15 +11,17 @@ PROJ_HEAD(hammer, "Hammer & Eckert-Greifendorff")
#define EPS 1.0e-10
+namespace { // anonymous namespace
struct pj_opaque {
double w;
double m, rm;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosphi, d;
d = sqrt(2./(1. + (cosphi = cos(lp.phi)) * cos(lp.lam *= Q->w)));
@@ -31,7 +33,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double z;
z = sqrt(1. - 0.25*Q->w*Q->w*xy.x*xy.x - 0.25*xy.y*xy.y);
@@ -48,8 +50,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(hammer) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_hatano.c b/src/projections/hatano.cpp
index 019671cc..019671cc 100644
--- a/src/PJ_hatano.c
+++ b/src/projections/hatano.cpp
diff --git a/src/PJ_healpix.c b/src/projections/healpix.cpp
index 3a88695f..7f0b3e83 100644
--- a/src/PJ_healpix.c
+++ b/src/projections/healpix.cpp
@@ -53,12 +53,14 @@ PROJ_HEAD(rhealpix, "rHEALPix") "\n\tSph&Ell\n\tnorth_square= south_square=";
/* Fuzz to handle rounding errors: */
# define EPS 1e-15
+namespace { // anonymous namespace
struct pj_opaque {
int north_square;
int south_square;
double qp;
double *apa;
};
+} // anonymous namespace
typedef struct {
int cn; /* An integer 0--3 indicating the position of the polar cap. */
@@ -229,7 +231,7 @@ static int in_image(double x, double y, int proj, int north_square,
* P contains the relevant ellipsoid parameters.
**/
static double auth_lat(PJ *P, double alpha, int inverse) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (inverse == 0) {
/* Authalic latitude. */
double q = pj_qsfn(sin(alpha), P->e, 1.0 - P->es);
@@ -366,13 +368,13 @@ static CapMap get_cap(double x, double y, int north_square, int south_square,
capmap.y = y;
if (inverse == 0) {
if (y > M_FORTPI) {
- capmap.region = north;
+ capmap.region = CapMap::north;
c = M_HALFPI;
} else if (y < -M_FORTPI) {
- capmap.region = south;
+ capmap.region = CapMap::south;
c = -M_HALFPI;
} else {
- capmap.region = equatorial;
+ capmap.region = CapMap::equatorial;
capmap.cn = 0;
return capmap;
}
@@ -396,23 +398,23 @@ static CapMap get_cap(double x, double y, int north_square, int south_square,
}
} else {
if (y > M_FORTPI) {
- capmap.region = north;
+ capmap.region = CapMap::north;
capmap.x = -3*M_FORTPI + north_square*M_HALFPI;
capmap.y = M_HALFPI;
x = x - north_square*M_HALFPI;
} else if (y < -M_FORTPI) {
- capmap.region = south;
+ capmap.region = CapMap::south;
capmap.x = -3*M_FORTPI + south_square*M_HALFPI;
capmap.y = -M_HALFPI;
x = x - south_square*M_HALFPI;
} else {
- capmap.region = equatorial;
+ capmap.region = CapMap::equatorial;
capmap.cn = 0;
return capmap;
}
/* Polar Region, find the HEALPix polar cap number that
x, y moves to when rHEALPix polar square is disassembled. */
- if (capmap.region == north) {
+ if (capmap.region == CapMap::north) {
if (y >= -x - M_FORTPI - EPS && y < x + 5*M_FORTPI - EPS) {
capmap.cn = (north_square + 1) % 4;
} else if (y > -x -M_FORTPI + EPS && y >= x + 5*M_FORTPI - EPS) {
@@ -422,7 +424,7 @@ static CapMap get_cap(double x, double y, int north_square, int south_square,
} else {
capmap.cn = north_square;
}
- } else if (capmap.region == south) {
+ } else if (capmap.region == CapMap::south) {
if (y <= x + M_FORTPI + EPS && y > -x - 5*M_FORTPI + EPS) {
capmap.cn = (south_square + 1) % 4;
} else if (y < x + M_FORTPI - EPS && y <= -x - 5*M_FORTPI + EPS) {
@@ -459,7 +461,7 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
int pole = 0;
CapMap capmap = get_cap(x, y, north_square, south_square, inverse);
- if (capmap.region == equatorial) {
+ if (capmap.region == CapMap::equatorial) {
xy.x = capmap.x;
xy.y = capmap.y;
return xy;
@@ -472,7 +474,7 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
/* Rotate (x, y) about its polar cap tip and then translate it to
north_square or south_square. */
- if (capmap.region == north) {
+ if (capmap.region == CapMap::north) {
pole = north_square;
tmpRot = rot[get_rotate_index(capmap.cn - pole)];
} else {
@@ -484,7 +486,7 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
Unrotate (x, y) and then translate it back. */
/* disassemble */
- if (capmap.region == north) {
+ if (capmap.region == CapMap::north) {
pole = north_square;
tmpRot = rot[get_rotate_index(-1*(capmap.cn - pole))];
} else {
@@ -500,7 +502,7 @@ static XY combine_caps(double x, double y, int north_square, int south_square,
/* Workaround cppcheck git issue */
double* pa = a;
pa[0] = -3*M_FORTPI + ((inverse == 0) ? pole : capmap.cn) *M_HALFPI;
- pa[1] = ((capmap.region == north) ? 1 : -1) *M_HALFPI;
+ pa[1] = ((capmap.region == CapMap::north) ? 1 : -1) *M_HALFPI;
vector_add(ret_dot, a, vector);
}
@@ -552,7 +554,7 @@ static LP e_healpix_inverse(XY xy, PJ *P) { /* ellipsoid */
static XY s_rhealpix_forward(LP lp, PJ *P) { /* sphere */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
XY xy = healpix_sphere(lp);
return combine_caps(xy.x, xy.y, Q->north_square, Q->south_square, 0);
@@ -560,7 +562,7 @@ static XY s_rhealpix_forward(LP lp, PJ *P) { /* sphere */
static XY e_rhealpix_forward(LP lp, PJ *P) { /* ellipsoid */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
XY xy;
lp.phi = auth_lat(P, lp.phi, 0);
xy = healpix_sphere(lp);
@@ -569,7 +571,7 @@ static XY e_rhealpix_forward(LP lp, PJ *P) { /* ellipsoid */
static LP s_rhealpix_inverse(XY xy, PJ *P) { /* sphere */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
/* Check whether (x, y) lies in the rHEALPix image. */
if (in_image(xy.x, xy.y, 1, Q->north_square, Q->south_square) == 0) {
@@ -585,7 +587,7 @@ static LP s_rhealpix_inverse(XY xy, PJ *P) { /* sphere */
static LP e_rhealpix_inverse(XY xy, PJ *P) { /* ellipsoid */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
LP lp = {0.0,0.0};
/* Check whether (x, y) lies in the rHEALPix image. */
@@ -602,28 +604,28 @@ static LP e_rhealpix_inverse(XY xy, PJ *P) { /* ellipsoid */
}
-static void *destructor (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->apa);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(healpix) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
if (P->es != 0.0) {
Q->apa = pj_authset(P->es); /* For auth_lat(). */
- if (0==Q->apa)
+ if (nullptr==Q->apa)
return destructor(P, ENOMEM);
Q->qp = pj_qsfn(1.0, P->e, P->one_es); /* For auth_lat(). */
P->a = P->a*sqrt(0.5*Q->qp); /* Set P->a to authalic radius. */
@@ -640,8 +642,8 @@ PJ *PROJECTION(healpix) {
PJ *PROJECTION(rhealpix) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -656,7 +658,7 @@ PJ *PROJECTION(rhealpix) {
return destructor (P, PJD_ERR_AXIS);
if (P->es != 0.0) {
Q->apa = pj_authset(P->es); /* For auth_lat(). */
- if (0==Q->apa)
+ if (nullptr==Q->apa)
return destructor(P, ENOMEM);
Q->qp = pj_qsfn(1.0, P->e, P->one_es); /* For auth_lat(). */
P->a = P->a*sqrt(0.5*Q->qp); /* Set P->a to authalic radius. */
diff --git a/src/PJ_igh.c b/src/projections/igh.cpp
index c991649a..e3576861 100644
--- a/src/PJ_igh.c
+++ b/src/projections/igh.cpp
@@ -32,15 +32,17 @@ static const double d180 = 180 * DEG_TO_RAD;
static const double EPSLN = 1.e-10; /* allow a little 'slack' on zone edge positions */
+namespace { // anonymous namespace
struct pj_opaque {
struct PJconsts* pj[12]; \
double dy0;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int z;
if (lp.phi >= d4044118) { /* 1|2 */
@@ -73,7 +75,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
const double y90 = Q->dy0 + sqrt(2); /* lt=90 corresponds to y=y0+sqrt(2) */
int z = 0;
@@ -134,17 +136,17 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static void *destructor (PJ *P, int errlev) {
+static PJ *destructor (PJ *P, int errlev) {
int i;
- if (0==P)
- return 0;
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
for (i = 0; i < 12; ++i) {
- if (P->opaque->pj[i])
- P->opaque->pj[i]->destructor(P->opaque->pj[i], errlev);
+ if (static_cast<struct pj_opaque*>(P->opaque)->pj[i])
+ static_cast<struct pj_opaque*>(P->opaque)->pj[i]->destructor(static_cast<struct pj_opaque*>(P->opaque)->pj[i], errlev);
}
return pj_default_destructor(P, errlev);
@@ -173,7 +175,7 @@ static void *destructor (PJ *P, int errlev) {
*/
#define SETUP(n, proj, x_0, y_0, lon_0) \
- if (!(Q->pj[n-1] = pj_##proj(0))) return destructor(P, ENOMEM); \
+ if (!(Q->pj[n-1] = pj_##proj(nullptr))) return destructor(P, ENOMEM); \
if (!(Q->pj[n-1] = pj_##proj(Q->pj[n-1]))) return destructor(P, ENOMEM); \
Q->pj[n-1]->ctx = P->ctx; \
Q->pj[n-1]->x0 = x_0; \
@@ -184,8 +186,8 @@ static void *destructor (PJ *P, int errlev) {
PJ *PROJECTION(igh) {
XY xy1, xy3;
LP lp = { 0, d4044118 };
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_imw_p.c b/src/projections/imw_p.cpp
index abed5006..012c5caa 100644
--- a/src/PJ_imw_p.c
+++ b/src/projections/imw_p.cpp
@@ -12,22 +12,26 @@ PROJ_HEAD(imw_p, "International Map of the World Polyconic")
#define TOL 1e-10
#define EPS 1e-10
+namespace { // anonymous namespace
enum Mode {
NONE_IS_ZERO = 0, /* phi_1 and phi_2 != 0 */
PHI_1_IS_ZERO = 1, /* phi_1 = 0 */
PHI_2_IS_ZERO = -1 /* phi_2 = 0 */
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double P, Pp, Q, Qp, R_1, R_2, sphi_1, sphi_2, C2;
double phi_1, phi_2, lam_1;
double *en;
enum Mode mode;
};
+} // anonymous namespace
static int phi12(PJ *P, double *del, double *sig) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int err = 0;
if (!pj_param(P->ctx, P->params, "tlat_1").i ||
@@ -45,7 +49,7 @@ static int phi12(PJ *P, double *del, double *sig) {
static XY loc_for(LP lp, PJ *P, double *yc) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
XY xy;
if (lp.phi == 0.0) {
@@ -102,7 +106,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
XY t;
double yc = 0.0;
int i = 0;
@@ -132,21 +136,21 @@ static void xy(PJ *P, double phi, double *x, double *y, double *sp, double *R) {
*sp = sin(phi);
*R = 1./(tan(phi) * sqrt(1. - P->es * *sp * *sp ));
- F = P->opaque->lam_1 * *sp;
+ F = static_cast<struct pj_opaque*>(P->opaque)->lam_1 * *sp;
*y = *R * (1 - cos(F));
*x = *R * sin(F);
}
-static void *destructor (PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- if( P->opaque->en )
- pj_dealloc (P->opaque->en);
+ if( static_cast<struct pj_opaque*>(P->opaque)->en )
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor(P, errlev);
}
@@ -155,8 +159,8 @@ static void *destructor (PJ *P, int errlev) {
PJ *PROJECTION(imw_p) {
double del, sig, s, t, x1, x2, T2, y1, m1, m2, y2;
int err;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_isea.c b/src/projections/isea.cpp
index 4ffd2983..522e6813 100644
--- a/src/PJ_isea.c
+++ b/src/projections/isea.cpp
@@ -46,10 +46,12 @@
#define ISEA_STD_LAT 1.01722196792335072101
#define ISEA_STD_LON .19634954084936207740
+namespace { // anonymous namespace
struct hex {
int iso;
long x, y, z;
};
+} // anonymous namespace
/* y *must* be positive down as the xy /iso conversion assumes this */
static void hex_xy(struct hex *h) {
@@ -124,12 +126,15 @@ static void hexbin2(double width, double x, double y, long *i, long *j) {
*j = h.y;
}
+namespace { // anonymous namespace
enum isea_poly { ISEA_NONE, ISEA_ICOSAHEDRON = 20 };
enum isea_topology { ISEA_HEXAGON=6, ISEA_TRIANGLE=3, ISEA_DIAMOND=4 };
enum isea_address_form { ISEA_GEO, ISEA_Q2DI, ISEA_SEQNUM, ISEA_INTERLEAVE,
ISEA_PLANE, ISEA_Q2DD, ISEA_PROJTRI, ISEA_VERTEX2DD, ISEA_HEX
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct isea_dgg {
int polyhedron; /* ignored, icosahedron */
double o_lat, o_lon, o_az; /* orientation, radians */
@@ -143,29 +148,38 @@ struct isea_dgg {
int quad; /* quad of last transformed point */
unsigned long serial;
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct isea_pt {
double x, y;
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct isea_geo {
double lon, lat;
};
+} // anonymous namespace
/* ENDINC */
+namespace { // anonymous namespace
enum snyder_polyhedron {
SNYDER_POLY_HEXAGON, SNYDER_POLY_PENTAGON,
SNYDER_POLY_TETRAHEDRON, SNYDER_POLY_CUBE,
SNYDER_POLY_OCTAHEDRON, SNYDER_POLY_DODECAHEDRON,
SNYDER_POLY_ICOSAHEDRON
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct snyder_constants {
double g, G, theta;
/* cppcheck-suppress unusedStructMember */
double ea_w, ea_a, ea_b, g_w, g_a, g_b;
};
+} // anonymous namespace
/* TODO put these in radians to avoid a later conversion */
static const struct snyder_constants constants[] = {
@@ -974,14 +988,16 @@ static struct isea_pt isea_forward(struct isea_dgg *g, struct isea_geo *in)
PROJ_HEAD(isea, "Icosahedral Snyder Equal Area") "\n\tSph";
+namespace { // anonymous namespace
struct pj_opaque {
struct isea_dgg dgg;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
struct isea_pt out;
struct isea_geo in;
@@ -999,8 +1015,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(isea) {
char *opt;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_krovak.c b/src/projections/krovak.cpp
index 5ca21214..9ecffb89 100644
--- a/src/PJ_krovak.c
+++ b/src/projections/krovak.cpp
@@ -90,6 +90,7 @@ PROJ_HEAD(krovak, "Krovak") "\n\tPCyl, Ell";
/* Not sure at all of the appropriate number for MAX_ITER... */
#define MAX_ITER 100
+namespace { // anonymous namespace
struct pj_opaque {
double alpha;
double k;
@@ -98,10 +99,11 @@ struct pj_opaque {
double ad;
int czech;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
XY xy = {0.0,0.0};
double gfi, u, deltav, s, d, eps, rho;
@@ -128,7 +130,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
LP lp = {0.0,0.0};
double u, deltav, s, d, eps, rho, fi1, xy0;
@@ -176,8 +178,8 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(krovak) {
double u0, n0, g;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_labrd.c b/src/projections/labrd.cpp
index 769dc620..d3930243 100644
--- a/src/PJ_labrd.c
+++ b/src/projections/labrd.cpp
@@ -8,14 +8,16 @@
PROJ_HEAD(labrd, "Laborde") "\n\tCyl, Sph\n\tSpecial for Madagascar";
#define EPS 1.e-10
+namespace { // anonymous namespace
struct pj_opaque {
double kRg, p0s, A, C, Ca, Cb, Cc, Cd;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double V1, V2, ps, sinps, cosps, sinps2, cosps2;
double I1, I2, I3, I4, I5, I6, x2, y2, t;
@@ -48,7 +50,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
/* t = 0.0 optimization is to avoid a false positive cppcheck warning */
/* (cppcheck git beaf29c15867984aa3c2a15cf15bd7576ccde2b3). Might no */
/* longer be necessary with later versions. */
@@ -100,8 +102,8 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(labrd) {
double Az, sinp, R, N, t;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_laea.c b/src/projections/laea.cpp
index bcf9c44d..dd02c75a 100644
--- a/src/PJ_laea.c
+++ b/src/projections/laea.cpp
@@ -6,13 +6,16 @@
PROJ_HEAD(laea, "Lambert Azimuthal Equal Area") "\n\tAzi, Sph&Ell";
+namespace { // anonymous namespace
enum Mode {
N_POLE = 0,
S_POLE = 1,
EQUIT = 2,
OBLIQ = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double sinb1;
double cosb1;
@@ -25,12 +28,13 @@ struct pj_opaque {
double *apa;
enum Mode mode;
};
+} // anonymous namespace
#define EPS10 1.e-10
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, sinlam, sinphi, q, sinb=0.0, cosb=0.0, b=0.0;
coslam = cos(lp.lam);
@@ -92,7 +96,7 @@ eqcon:
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
sinphi = sin(lp.phi);
@@ -134,7 +138,7 @@ oblcon:
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cCe, sCe, q, rho, ab=0.0;
switch (Q->mode) {
@@ -183,7 +187,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosz=0.0, rh, sinz=0.0;
rh = hypot(xy.x, xy.y);
@@ -222,14 +226,14 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static void *destructor (PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->apa);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->apa);
return pj_default_destructor(P, errlev);
}
@@ -237,8 +241,8 @@ static void *destructor (PJ *P, int errlev) {
PJ *PROJECTION(laea) {
double t;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
P->destructor = destructor;
@@ -257,7 +261,7 @@ PJ *PROJECTION(laea) {
Q->qp = pj_qsfn(1., P->e, P->one_es);
Q->mmf = .5 / (1. - P->es);
Q->apa = pj_authset(P->es);
- if (0==Q->apa)
+ if (nullptr==Q->apa)
return destructor(P, ENOMEM);
switch (Q->mode) {
case N_POLE:
diff --git a/src/PJ_lagrng.c b/src/projections/lagrng.cpp
index 3856fcdc..8c0150aa 100644
--- a/src/PJ_lagrng.c
+++ b/src/projections/lagrng.cpp
@@ -9,6 +9,7 @@ PROJ_HEAD(lagrng, "Lagrange") "\n\tMisc Sph\n\tW=";
#define TOL 1e-10
+namespace { // anonymous namespace
struct pj_opaque {
double a1;
double a2;
@@ -17,11 +18,12 @@ struct pj_opaque {
double rw;
double w;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double v, c;
if (fabs(fabs(lp.phi) - M_HALFPI) < TOL) {
@@ -45,7 +47,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c, x2, y2p, y2m;
if (fabs(fabs(xy.y) - 2.) < TOL) {
@@ -69,8 +71,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(lagrng) {
double phi1;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_larr.c b/src/projections/larr.cpp
index e4d5d240..e4d5d240 100644
--- a/src/PJ_larr.c
+++ b/src/projections/larr.cpp
diff --git a/src/PJ_lask.c b/src/projections/lask.cpp
index 46f23edb..46f23edb 100644
--- a/src/PJ_lask.c
+++ b/src/projections/lask.cpp
diff --git a/src/PJ_latlong.c b/src/projections/latlong.cpp
index 1331d59a..1331d59a 100644
--- a/src/PJ_latlong.c
+++ b/src/projections/latlong.cpp
diff --git a/src/PJ_lcc.c b/src/projections/lcc.cpp
index 96aa3f2a..7d6e3f57 100644
--- a/src/PJ_lcc.c
+++ b/src/projections/lcc.cpp
@@ -9,6 +9,7 @@ PROJ_HEAD(lcc, "Lambert Conformal Conic")
#define EPS10 1.e-10
+namespace { // anonymous namespace
struct pj_opaque {
double phi1;
double phi2;
@@ -16,11 +17,12 @@ struct pj_opaque {
double rho0;
double c;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0., 0.};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
if (fabs(fabs(lp.phi) - M_HALFPI) < EPS10) {
@@ -43,7 +45,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0., 0.};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
xy.x /= P->k0;
@@ -78,9 +80,9 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(lcc) {
double cosphi, sinphi;
int secant;
- struct pj_opaque *Q = pj_calloc(1, sizeof (struct pj_opaque));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc(1, sizeof (struct pj_opaque)));
- if (0 == Q)
+ if (nullptr == Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_lcca.c b/src/projections/lcca.cpp
index f0f256b1..70b5dff9 100644
--- a/src/PJ_lcca.c
+++ b/src/projections/lcca.cpp
@@ -59,11 +59,13 @@ PROJ_HEAD(lcca, "Lambert Conformal Conic Alternative")
#define MAX_ITER 10
#define DEL_TOL 1e-12
+namespace { // anonymous namespace
struct pj_opaque {
double *en;
double r0, l, M0;
double C;
};
+} // anonymous namespace
static double fS(double S, double C) { /* func to compute dr */
@@ -80,7 +82,7 @@ static double fSp(double S, double C) { /* deriv of fs */
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double S, r, dr;
S = pj_mlfn(lp.phi, sin(lp.phi), cos(lp.phi), Q->en) - Q->M0;
@@ -94,7 +96,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double theta, dr, S, dif;
int i;
@@ -118,22 +120,22 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static void *destructor (PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(lcca) {
double s2p0, N0, R0, tan0;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_loxim.c b/src/projections/loxim.cpp
index 512bfc23..f68e844a 100644
--- a/src/PJ_loxim.c
+++ b/src/projections/loxim.cpp
@@ -10,16 +10,18 @@ PROJ_HEAD(loxim, "Loximuthal") "\n\tPCyl Sph";
#define EPS 1e-8
+namespace { // anonymous namespace
struct pj_opaque {
double phi1;
double cosphi1;
double tanphi1;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.y = lp.phi - Q->phi1;
if (fabs(xy.y) < EPS)
@@ -37,7 +39,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.phi = xy.y + Q->phi1;
if (fabs(xy.y) < EPS) {
@@ -54,8 +56,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(loxim) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_lsat.c b/src/projections/lsat.cpp
index 810a1cba..a0eca1bd 100644
--- a/src/PJ_lsat.c
+++ b/src/projections/lsat.cpp
@@ -12,13 +12,15 @@ PROJ_HEAD(lsat, "Space oblique for LANDSAT")
#define TOL 1e-7
+namespace { // anonymous namespace
struct pj_opaque {
double a2, a4, b, c1, c3;
double q, t, u, w, p22, sa, ca, xj, rlm, rlm2;
};
+} // anonymous namespace
static void seraz0(double lam, double mult, PJ *P) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sdsq, h, s, fc, sd, sq, d__1 = 0;
lam *= DEG_TO_RAD;
@@ -44,7 +46,7 @@ static void seraz0(double lam, double mult, PJ *P) {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int l, nn;
double lamt = 0.0, xlam, sdsq, c, d, s, lamdp = 0.0, phidp, lampp, tanph;
double lamtp, cl, sd, sp, sav, tanphi;
@@ -107,7 +109,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
double lamt, sdsq, s, lamdp, phidp, sppsq, dd, sd, sl, fac, scl, sav, spp;
@@ -153,8 +155,8 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(lsat) {
int land, path;
double lam, alf, esc, ess;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_mbt_fps.c b/src/projections/mbt_fps.cpp
index 66ed9458..66ed9458 100644
--- a/src/PJ_mbt_fps.c
+++ b/src/projections/mbt_fps.cpp
diff --git a/src/PJ_mbtfpp.c b/src/projections/mbtfpp.cpp
index 276a43eb..276a43eb 100644
--- a/src/PJ_mbtfpp.c
+++ b/src/projections/mbtfpp.cpp
diff --git a/src/PJ_mbtfpq.c b/src/projections/mbtfpq.cpp
index b7c0eb16..b7c0eb16 100644
--- a/src/PJ_mbtfpq.c
+++ b/src/projections/mbtfpq.cpp
diff --git a/src/PJ_merc.c b/src/projections/merc.cpp
index 1998234e..1998234e 100644
--- a/src/PJ_merc.c
+++ b/src/projections/merc.cpp
diff --git a/src/PJ_mill.c b/src/projections/mill.cpp
index 3ea9636f..3ea9636f 100644
--- a/src/PJ_mill.c
+++ b/src/projections/mill.cpp
diff --git a/src/PJ_misrsom.c b/src/projections/misrsom.cpp
index 0308fc42..c84b96e3 100644
--- a/src/PJ_misrsom.c
+++ b/src/projections/misrsom.cpp
@@ -33,13 +33,15 @@ PROJ_HEAD(misrsom, "Space oblique for MISR")
#define TOL 1e-7
+namespace { // anonymous namespace
struct pj_opaque {
double a2, a4, b, c1, c3;
double q, t, u, w, p22, sa, ca, xj, rlm, rlm2;
};
+} // anonymous namespace
static void seraz0(double lam, double mult, PJ *P) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sdsq, h, s, fc, sd, sq, d__1;
lam *= DEG_TO_RAD;
@@ -62,7 +64,7 @@ static void seraz0(double lam, double mult, PJ *P) {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int l, nn;
double lamt = 0.0, xlam, sdsq, c, d, s, lamdp = 0.0, phidp, lampp, tanph;
double lamtp, cl, sd, sp, sav, tanphi;
@@ -123,7 +125,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
double lamt, sdsq, s, lamdp, phidp, sppsq, dd, sd, sl, fac, scl, sav, spp;
@@ -170,8 +172,8 @@ PJ *PROJECTION(misrsom) {
int path;
double lam, alf, esc, ess;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_mod_ster.c b/src/projections/mod_ster.cpp
index 5e6ce136..7c4f363b 100644
--- a/src/PJ_mod_ster.c
+++ b/src/projections/mod_ster.cpp
@@ -12,16 +12,18 @@ PROJ_HEAD(gs50, "Mod. Stereographic of 50 U.S.") "\n\tAzi(mod)";
#define EPSLN 1e-12
+namespace { // anonymous namespace
struct pj_opaque {
const COMPLEX *zcoeff; \
double cchio, schio; \
int n;
};
+} // anonymous namespace
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinlon, coslon, esphi, chi, schi, cchi, s;
COMPLEX p;
@@ -45,7 +47,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
int nn;
COMPLEX p, fxy, fpxy, dp;
double den, rh = 0.0, z, sinz = 0.0, cosz = 0.0, chi, phi = 0.0, esphi;
@@ -101,7 +103,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
static PJ *setup(PJ *P) { /* general initialization */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double esphi, chio;
if (P->es != 0.0) {
@@ -127,8 +129,8 @@ PJ *PROJECTION(mil_os) {
{0.019430, 0.}
};
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -150,8 +152,8 @@ PJ *PROJECTION(lee_os) {
{-0.0088162, -0.00617325}
};
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -175,8 +177,8 @@ PJ *PROJECTION(gs48) {
{0.075528, 0.}
};
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -210,8 +212,8 @@ PJ *PROJECTION(alsk) {
{ .3660976, -.2937382}
};
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -258,8 +260,8 @@ PJ *PROJECTION(gs50) {
{-.0225161, .0853673}
};
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_moll.c b/src/projections/moll.cpp
index 4ac73841..c877a1bb 100644
--- a/src/PJ_moll.c
+++ b/src/projections/moll.cpp
@@ -12,14 +12,16 @@ PROJ_HEAD(wag5, "Wagner V") "\n\tPCyl, Sph";
#define MAX_ITER 10
#define LOOP_TOL 1e-7
+namespace { // anonymous namespace
struct pj_opaque {
double C_x, C_y, C_p;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double k, V;
int i;
@@ -42,7 +44,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.phi = aasin(P->ctx, xy.y / Q->C_y);
lp.lam = xy.x / (Q->C_x * cos(lp.phi));
if (fabs(lp.lam) < M_PI) {
@@ -56,7 +58,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ * setup(PJ *P, double p) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r, sp, p2 = p + p;
P->es = 0;
@@ -74,8 +76,8 @@ static PJ * setup(PJ *P, double p) {
PJ *PROJECTION(moll) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -84,8 +86,8 @@ PJ *PROJECTION(moll) {
PJ *PROJECTION(wag4) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -93,8 +95,8 @@ PJ *PROJECTION(wag4) {
}
PJ *PROJECTION(wag5) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_natearth.c b/src/projections/natearth.cpp
index 27a6b137..27a6b137 100644
--- a/src/PJ_natearth.c
+++ b/src/projections/natearth.cpp
diff --git a/src/PJ_natearth2.c b/src/projections/natearth2.cpp
index f6aba671..f6aba671 100644
--- a/src/PJ_natearth2.c
+++ b/src/projections/natearth2.cpp
diff --git a/src/PJ_nell.c b/src/projections/nell.cpp
index 2a7ea32c..2a7ea32c 100644
--- a/src/PJ_nell.c
+++ b/src/projections/nell.cpp
diff --git a/src/PJ_nell_h.c b/src/projections/nell_h.cpp
index 28c3ace7..28c3ace7 100644
--- a/src/PJ_nell_h.c
+++ b/src/projections/nell_h.cpp
diff --git a/src/PJ_nocol.c b/src/projections/nicol.cpp
index 541d08b2..541d08b2 100644
--- a/src/PJ_nocol.c
+++ b/src/projections/nicol.cpp
diff --git a/src/PJ_nsper.c b/src/projections/nsper.cpp
index 223cd75b..f93010f8 100644
--- a/src/PJ_nsper.c
+++ b/src/projections/nsper.cpp
@@ -4,13 +4,16 @@
#include "projects.h"
#include "proj_math.h"
+namespace { // anonymous namespace
enum Mode {
N_POLE = 0,
S_POLE = 1,
EQUIT = 2,
OBLIQ = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double height;
double sinph0;
@@ -27,6 +30,7 @@ struct pj_opaque {
enum Mode mode;
int tilt;
};
+} // anonymous namespace
PROJ_HEAD(nsper, "Near-sided perspective") "\n\tAzi, Sph\n\th=";
PROJ_HEAD(tpers, "Tilted perspective") "\n\tAzi, Sph\n\ttilt= azi= h=";
@@ -36,7 +40,7 @@ PROJ_HEAD(tpers, "Tilted perspective") "\n\tAzi, Sph\n\ttilt= azi= h=";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
sinphi = sin(lp.phi);
@@ -91,7 +95,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, cosz, sinz;
if (Q->tilt) {
@@ -140,7 +144,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ *setup(PJ *P) {
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if ((Q->height = pj_param(P->ctx, P->params, "dh").f) <= 0.)
return pj_default_destructor(P, PJD_ERR_H_LESS_THAN_ZERO);
@@ -168,8 +172,8 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(nsper) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -182,8 +186,8 @@ PJ *PROJECTION(nsper) {
PJ *PROJECTION(tpers) {
double omega, gamma;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_nzmg.c b/src/projections/nzmg.cpp
index bf0862fb..bf0862fb 100644
--- a/src/PJ_nzmg.c
+++ b/src/projections/nzmg.cpp
diff --git a/src/PJ_ob_tran.c b/src/projections/ob_tran.cpp
index f5a05cf9..d34059a9 100644
--- a/src/PJ_ob_tran.c
+++ b/src/projections/ob_tran.cpp
@@ -7,11 +7,13 @@
#include "proj.h"
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
struct PJconsts *link;
double lamp;
double cphip, sphip;
};
+} // anonymous namespace
PROJ_HEAD(ob_tran, "General Oblique Transformation") "\n\tMisc Sph"
"\n\to_proj= plus parameters for projection"
@@ -23,7 +25,7 @@ PROJ_HEAD(ob_tran, "General Oblique Transformation") "\n\tMisc Sph"
static XY o_forward(LP lp, PJ *P) { /* spheroid */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, sinphi, cosphi;
coslam = cos(lp.lam);
@@ -38,7 +40,7 @@ static XY o_forward(LP lp, PJ *P) { /* spheroid */
static XY t_forward(LP lp, PJ *P) { /* spheroid */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosphi, coslam;
cosphi = cos(lp.phi);
@@ -52,7 +54,7 @@ static XY t_forward(LP lp, PJ *P) { /* spheroid */
static LP o_inverse(XY xy, PJ *P) { /* spheroid */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, sinphi, cosphi;
LP lp = Q->link->inv(xy, Q->link);
@@ -70,7 +72,7 @@ static LP o_inverse(XY xy, PJ *P) { /* spheroid */
static LP t_inverse(XY xy, PJ *P) { /* spheroid */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosphi, t;
LP lp = Q->link->inv(xy, Q->link);
@@ -84,14 +86,14 @@ static LP t_inverse(XY xy, PJ *P) { /* spheroid */
}
-static void *destructor(PJ *P, int errlev) {
- if (0==P)
- return 0;
- if (0==P->opaque)
+static PJ *destructor(PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- if (P->opaque->link)
- P->opaque->link->destructor (P->opaque->link, errlev);
+ if (static_cast<struct pj_opaque*>(P->opaque)->link)
+ static_cast<struct pj_opaque*>(P->opaque)->link->destructor (static_cast<struct pj_opaque*>(P->opaque)->link, errlev);
return pj_default_destructor(P, errlev);
}
@@ -120,7 +122,7 @@ typedef struct {int argc; char **argv;} ARGS;
/* count the number of args in the linked list <params> */
static size_t paralist_params_argc (paralist *params) {
size_t argc = 0;
- for (; params != 0; params = params->next)
+ for (; params != nullptr; params = params->next)
argc++;
return argc;
}
@@ -129,18 +131,18 @@ static size_t paralist_params_argc (paralist *params) {
/* turn paralist into argc/argv style argument list */
static ARGS ob_tran_target_params (paralist *params) {
int i = 0;
- ARGS args = {0, 0};
+ ARGS args = {0, nullptr};
size_t argc = paralist_params_argc (params);
if (argc < 2)
return args;
/* all args except the proj_ob_tran */
- args.argv = pj_calloc (argc - 1, sizeof (char *));
- if (0==args.argv)
+ args.argv = static_cast<char**>(pj_calloc (argc - 1, sizeof (char *)));
+ if (nullptr==args.argv)
return args;
/* Copy all args *except* the proj=ob_tran arg to the argv array */
- for (i = 0; params != 0; params = params->next) {
+ for (i = 0; params != nullptr; params = params->next) {
if (0==strcmp (params->param, "proj=ob_tran"))
continue;
args.argv[i++] = params->param;
@@ -166,8 +168,8 @@ PJ *PROJECTION(ob_tran) {
ARGS args;
PJ *R; /* projection to rotate */
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return destructor(P, ENOMEM);
P->opaque = Q;
@@ -186,7 +188,7 @@ PJ *PROJECTION(ob_tran) {
R = pj_init_ctx (pj_get_ctx(P), args.argc, args.argv);
pj_dealloc (args.argv);
- if (0==R)
+ if (nullptr==R)
return destructor (P, PJD_ERR_UNKNOWN_PROJECTION_ID);
Q->link = R;
@@ -226,11 +228,11 @@ PJ *PROJECTION(ob_tran) {
if (fabs(phip) > TOL) { /* oblique */
Q->cphip = cos(phip);
Q->sphip = sin(phip);
- P->fwd = Q->link->fwd ? o_forward : 0;
- P->inv = Q->link->inv ? o_inverse : 0;
+ P->fwd = Q->link->fwd ? o_forward : nullptr;
+ P->inv = Q->link->inv ? o_inverse : nullptr;
} else { /* transverse */
- P->fwd = Q->link->fwd ? t_forward : 0;
- P->inv = Q->link->inv ? t_inverse : 0;
+ P->fwd = Q->link->fwd ? t_forward : nullptr;
+ P->inv = Q->link->inv ? t_inverse : nullptr;
}
/* Support some rather speculative test cases, where the rotated projection */
diff --git a/src/PJ_ocea.c b/src/projections/ocea.cpp
index 7a9353a6..0576ace7 100644
--- a/src/PJ_ocea.c
+++ b/src/projections/ocea.cpp
@@ -8,6 +8,7 @@
PROJ_HEAD(ocea, "Oblique Cylindrical Equal Area") "\n\tCyl, Sph"
"lonc= alpha= or\n\tlat_1= lat_2= lon_1= lon_2=";
+namespace { // anonymous namespace
struct pj_opaque {
double rok;
double rtk;
@@ -16,11 +17,12 @@ struct pj_opaque {
double singam;
double cosgam;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t;
xy.y = sin(lp.lam);
t = cos(lp.lam);
@@ -35,7 +37,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t, s;
xy.y /= Q->rok;
@@ -51,8 +53,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(ocea) {
double phi_0=0.0, phi_1, phi_2, lam_1, lam_2, lonz, alpha;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_oea.c b/src/projections/oea.cpp
index 2bfeffa8..0c401b2f 100644
--- a/src/PJ_oea.c
+++ b/src/projections/oea.cpp
@@ -6,17 +6,19 @@
PROJ_HEAD(oea, "Oblated Equal Area") "\n\tMisc Sph\n\tn= m= theta=";
+namespace { // anonymous namespace
struct pj_opaque {
double theta;
double m, n;
double two_r_m, two_r_n, rm, rn, hm, hn;
double cp0, sp0;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double Az, M, N, cp, sp, cl, shz;
cp = cos(lp.phi);
@@ -35,7 +37,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double N, M, xp, yp, z, Az, cz, sz, cAz;
N = Q->hn * aasin(P->ctx,xy.y * Q->rn);
@@ -57,8 +59,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(oea) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_omerc.c b/src/projections/omerc.cpp
index 70c12e27..ead07128 100644
--- a/src/PJ_omerc.c
+++ b/src/projections/omerc.cpp
@@ -33,11 +33,13 @@ PROJ_HEAD(omerc, "Oblique Mercator")
"\n\tCyl, Sph&Ell no_rot\n\t"
"alpha= [gamma=] [no_off] lonc= or\n\t lon_1= lat_1= lon_2= lat_2=";
+namespace { // anonymous namespace
struct pj_opaque {
double A, B, E, AB, ArB, BrA, rB, singam, cosgam, sinrot, cosrot;
double v_pole_n, v_pole_s, u_0;
int no_rot;
};
+} // anonymous namespace
#define TOL 1.e-7
#define EPS 1.e-10
@@ -45,7 +47,7 @@ struct pj_opaque {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double S, T, U, V, W, temp, u, v;
if (fabs(fabs(lp.phi) - M_HALFPI) > EPS) {
@@ -84,7 +86,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double u, v, Qp, Sp, Tp, Vp, Up;
if (Q->no_rot) {
@@ -120,8 +122,8 @@ PJ *PROJECTION(omerc) {
gamma0, lamc=0, lam1=0, lam2=0, phi1=0, phi2=0, alpha_c=0;
int alp, gam, no_off = 0;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_ortho.c b/src/projections/ortho.cpp
index d442aa8a..6ea55248 100644
--- a/src/PJ_ortho.c
+++ b/src/projections/ortho.cpp
@@ -7,18 +7,22 @@
PROJ_HEAD(ortho, "Orthographic") "\n\tAzi, Sph";
+namespace { // anonymous namespace
enum Mode {
N_POLE = 0,
S_POLE = 1,
EQUIT = 2,
OBLIQ = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double sinph0;
double cosph0;
enum Mode mode;
};
+} // anonymous namespace
#define EPS10 1.e-10
@@ -31,7 +35,7 @@ static XY forward_error(PJ *P, LP lp, XY xy) {
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, cosphi, sinphi;
xy.x = HUGE_VAL; xy.y = HUGE_VAL;
@@ -65,7 +69,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rh, cosc, sinc;
lp.lam = HUGE_VAL; lp.phi = HUGE_VAL;
@@ -117,8 +121,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(ortho) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_patterson.c b/src/projections/patterson.cpp
index 0d19414e..0d19414e 100644
--- a/src/PJ_patterson.c
+++ b/src/projections/patterson.cpp
diff --git a/src/PJ_poly.c b/src/projections/poly.cpp
index b5f78fdf..a970fdb1 100644
--- a/src/PJ_poly.c
+++ b/src/projections/poly.cpp
@@ -9,10 +9,12 @@
PROJ_HEAD(poly, "Polyconic (American)")
"\n\tConic, Sph&Ell";
+namespace { // anonymous namespace
struct pj_opaque {
double ml0; \
double *en;
};
+} // anonymous namespace
#define TOL 1e-10
#define CONV 1e-10
@@ -23,7 +25,7 @@ struct pj_opaque {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double ms, sp, cp;
if (fabs(lp.phi) <= TOL) {
@@ -42,7 +44,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cot, E;
if (fabs(lp.phi) <= TOL) {
@@ -60,7 +62,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.y += Q->ml0;
if (fabs(xy.y) <= TOL) {
@@ -131,23 +133,23 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static void *destructor(PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor(PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- if (P->opaque->en)
- pj_dealloc (P->opaque->en);
+ if (static_cast<struct pj_opaque*>(P->opaque)->en)
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor(P, errlev);
}
PJ *PROJECTION(poly) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_putp2.c b/src/projections/putp2.cpp
index d7a847c8..d7a847c8 100644
--- a/src/PJ_putp2.c
+++ b/src/projections/putp2.cpp
diff --git a/src/PJ_putp3.c b/src/projections/putp3.cpp
index 695ea877..98bb2ff0 100644
--- a/src/PJ_putp3.c
+++ b/src/projections/putp3.cpp
@@ -2,9 +2,11 @@
#include <errno.h>
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double A;
};
+} // anonymous namespace
PROJ_HEAD(putp3, "Putnins P3") "\n\tPCyl, Sph";
PROJ_HEAD(putp3p, "Putnins P3'") "\n\tPCyl, Sph";
@@ -16,7 +18,7 @@ PROJ_HEAD(putp3p, "Putnins P3'") "\n\tPCyl, Sph";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- xy.x = C * lp.lam * (1. - P->opaque->A * lp.phi * lp.phi);
+ xy.x = C * lp.lam * (1. - static_cast<struct pj_opaque*>(P->opaque)->A * lp.phi * lp.phi);
xy.y = C * lp.phi;
return xy;
@@ -27,15 +29,15 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
lp.phi = xy.y / C;
- lp.lam = xy.x / (C * (1. - P->opaque->A * lp.phi * lp.phi));
+ lp.lam = xy.x / (C * (1. - static_cast<struct pj_opaque*>(P->opaque)->A * lp.phi * lp.phi));
return lp;
}
PJ *PROJECTION(putp3) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -49,8 +51,8 @@ PJ *PROJECTION(putp3) {
}
PJ *PROJECTION(putp3p) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_putp4p.c b/src/projections/putp4p.cpp
index 6448dc19..608fc76e 100644
--- a/src/PJ_putp4p.c
+++ b/src/projections/putp4p.cpp
@@ -5,9 +5,11 @@
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double C_x, C_y;
};
+} // anonymous namespace
PROJ_HEAD(putp4p, "Putnins P4'") "\n\tPCyl, Sph";
PROJ_HEAD(weren, "Werenskiold I") "\n\tPCyl, Sph";
@@ -15,7 +17,7 @@ PROJ_HEAD(weren, "Werenskiold I") "\n\tPCyl, Sph";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.phi = aasin(P->ctx,0.883883476 * sin(lp.phi));
xy.x = Q->C_x * lp.lam * cos(lp.phi);
@@ -28,7 +30,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.phi = aasin(P->ctx,xy.y / Q->C_y);
lp.lam = xy.x * cos(lp.phi) / Q->C_x;
@@ -41,8 +43,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(putp4p) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -58,8 +60,8 @@ PJ *PROJECTION(putp4p) {
PJ *PROJECTION(weren) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_putp5.c b/src/projections/putp5.cpp
index 96b0670d..79e2ad15 100644
--- a/src/PJ_putp5.c
+++ b/src/projections/putp5.cpp
@@ -5,9 +5,11 @@
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double A, B;
};
+} // anonymous namespace
PROJ_HEAD(putp5, "Putnins P5") "\n\tPCyl, Sph";
PROJ_HEAD(putp5p, "Putnins P5'") "\n\tPCyl, Sph";
@@ -18,7 +20,7 @@ PROJ_HEAD(putp5p, "Putnins P5'") "\n\tPCyl, Sph";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
xy.x = C * lp.lam * (Q->A - Q->B * sqrt(1. + D * lp.phi * lp.phi));
xy.y = C * lp.phi;
@@ -29,7 +31,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
lp.phi = xy.y / C;
lp.lam = xy.x / (C * (Q->A - Q->B * sqrt(1. + D * lp.phi * lp.phi)));
@@ -40,8 +42,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(putp5) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -57,8 +59,8 @@ PJ *PROJECTION(putp5) {
PJ *PROJECTION(putp5p) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_putp6.c b/src/projections/putp6.cpp
index fa9290b4..1186b18b 100644
--- a/src/PJ_putp6.c
+++ b/src/projections/putp6.cpp
@@ -5,9 +5,11 @@
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double C_x, C_y, A, B, D;
};
+} // anonymous namespace
PROJ_HEAD(putp6, "Putnins P6") "\n\tPCyl, Sph";
PROJ_HEAD(putp6p, "Putnins P6'") "\n\tPCyl, Sph";
@@ -19,7 +21,7 @@ PROJ_HEAD(putp6p, "Putnins P6'") "\n\tPCyl, Sph";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double p, r, V;
int i;
@@ -43,7 +45,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double r;
lp.phi = xy.y / Q->C_y;
@@ -56,8 +58,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(putp6) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -76,8 +78,8 @@ PJ *PROJECTION(putp6) {
PJ *PROJECTION(putp6p) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_qsc.c b/src/projections/qsc.cpp
index 3b8b7fe2..b50a7c95 100644
--- a/src/PJ_qsc.c
+++ b/src/projections/qsc.cpp
@@ -46,6 +46,7 @@
#include "projects.h"
/* The six cube faces. */
+namespace { // anonymous namespace
enum Face {
FACE_FRONT = 0,
FACE_RIGHT = 1,
@@ -54,7 +55,9 @@ enum Face {
FACE_TOP = 4,
FACE_BOTTOM = 5
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
enum Face face;
double a_squared;
@@ -62,18 +65,21 @@ struct pj_opaque {
double one_minus_f;
double one_minus_f_squared;
};
+} // anonymous namespace
PROJ_HEAD(qsc, "Quadrilateralized Spherical Cube") "\n\tAzi, Sph";
#define EPS10 1.e-10
/* The four areas on a cube face. AREA_0 is the area of definition,
* the other three areas are counted counterclockwise. */
+namespace { // anonymous namespace
enum Area {
AREA_0 = 0,
AREA_1 = 1,
AREA_2 = 2,
AREA_3 = 3
};
+} // anonymous namespace
/* Helper function for forward projection: compute the theta angle
* and determine the area number. */
@@ -114,7 +120,7 @@ static double qsc_shift_lon_origin(double lon, double offset) {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double lat, lon;
double theta, phi;
double t, mu; /* nu; */
@@ -230,7 +236,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double mu, nu, cosmu, tannu;
double tantheta, theta, cosphi, phi;
double t;
@@ -370,8 +376,8 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(qsc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_robin.c b/src/projections/robin.cpp
index 19bdc2dc..987977ae 100644
--- a/src/PJ_robin.c
+++ b/src/projections/robin.cpp
@@ -18,9 +18,11 @@ http://article.gmane.org/gmane.comp.gis.proj-4.devel/6039
http://trac.osgeo.org/proj/ticket/113
*/
+namespace { // anonymous namespace
struct COEFS {
float c0, c1, c2, c3;
};
+} // anonymous namespace
static const struct COEFS X[] = {
{1.0f, 2.2199e-17f, -7.15515e-05f, 3.1103e-06f},
diff --git a/src/proj_rouss.c b/src/projections/rouss.cpp
index 0e0f9982..3b4428bc 100644
--- a/src/proj_rouss.c
+++ b/src/projections/rouss.cpp
@@ -31,6 +31,7 @@
#include "proj.h"
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double s0;
double A1, A2, A3, A4, A5, A6;
@@ -39,12 +40,13 @@ struct pj_opaque {
double D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11;
void *en;
};
+} // anonymous namespace
PROJ_HEAD(rouss, "Roussilhe Stereographic") "\n\tAzi, Ell";
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double s, al, cp, sp, al2, s2;
cp = cos(lp.phi);
@@ -65,7 +67,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double s, al, x = xy.x / P->k0, y = xy.y / P->k0, x2, y2;;
x2 = x * x;
@@ -83,15 +85,15 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static void *destructor (PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- if (P->opaque->en)
- pj_dealloc (P->opaque->en);
+ if (static_cast<struct pj_opaque*>(P->opaque)->en)
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, ENOMEM);
}
@@ -100,8 +102,8 @@ static void *destructor (PJ *P, int errlev) {
PJ *PROJECTION(rouss) {
double N0, es2, t, t2, R_R0_2, R_R0_4;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_rpoly.c b/src/projections/rpoly.cpp
index 03c2b161..a34f6171 100644
--- a/src/PJ_rpoly.c
+++ b/src/projections/rpoly.cpp
@@ -5,12 +5,14 @@
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
double phi1;
double fxa;
double fxb;
int mode;
};
+} // anonymous namespace
PROJ_HEAD(rpoly, "Rectangular Polyconic")
"\n\tConic, Sph, no inv\n\tlat_ts=";
@@ -19,7 +21,7 @@ PROJ_HEAD(rpoly, "Rectangular Polyconic")
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double fa;
if (Q->mode)
@@ -40,8 +42,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(rpoly) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_sch.c b/src/projections/sch.cpp
index 64e5cdb8..5a2f944b 100644
--- a/src/PJ_sch.c
+++ b/src/projections/sch.cpp
@@ -39,6 +39,7 @@
#include "projects.h"
#include "geocent.h"
+namespace { // anonymous namespace
struct pj_opaque {
double plat; /*Peg Latitude */
double plon; /*Peg Longitude*/
@@ -50,12 +51,13 @@ struct pj_opaque {
GeocentricInfo sph;
GeocentricInfo elp_0;
};
+} // anonymous namespace
PROJ_HEAD(sch, "Spherical Cross-track Height") "\n\tMisc\n\tplat_0= plon_0= phdg_0= [h_0=]";
static LPZ inverse3d(XYZ xyz, PJ *P) {
LPZ lpz = {0.0, 0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double temp[3];
double pxyz[3];
@@ -93,7 +95,7 @@ static LPZ inverse3d(XYZ xyz, PJ *P) {
static XYZ forward3d(LPZ lpz, PJ *P) {
XYZ xyz = {0.0, 0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double temp[3];
double pxyz[3];
@@ -131,7 +133,7 @@ static XYZ forward3d(LPZ lpz, PJ *P) {
static PJ *setup(PJ *P) { /* general initialization */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double reast, rnorth;
double chdg, shdg;
double clt, slt;
@@ -192,8 +194,8 @@ static PJ *setup(PJ *P) { /* general initialization */
PJ *PROJECTION(sch) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_sconics.c b/src/projections/sconics.cpp
index ce044c24..1d19a13d 100644
--- a/src/PJ_sconics.c
+++ b/src/projections/sconics.cpp
@@ -5,6 +5,7 @@
#include "proj_math.h"
+namespace { // anonymous namespace
enum Type {
EULER = 0,
MURD1 = 1,
@@ -14,7 +15,9 @@ enum Type {
TISSOT = 5,
VITK1 = 6
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double n;
double rho_c;
@@ -23,6 +26,7 @@ struct pj_opaque {
double c1, c2;
enum Type type;
};
+} // anonymous namespace
#define EPS10 1.e-10
@@ -51,8 +55,8 @@ static int phi12(PJ *P, double *del) {
p1 = pj_param(P->ctx, P->params, "rlat_1").f;
p2 = pj_param(P->ctx, P->params, "rlat_2").f;
*del = 0.5 * (p2 - p1);
- P->opaque->sig = 0.5 * (p2 + p1);
- err = (fabs(*del) < EPS || fabs(P->opaque->sig) < EPS) ? PJD_ERR_ABS_LAT1_EQ_ABS_LAT2 : 0;
+ static_cast<struct pj_opaque*>(P->opaque)->sig = 0.5 * (p2 + p1);
+ err = (fabs(*del) < EPS || fabs(static_cast<struct pj_opaque*>(P->opaque)->sig) < EPS) ? PJD_ERR_ABS_LAT1_EQ_ABS_LAT2 : 0;
}
return err;
}
@@ -60,7 +64,7 @@ static int phi12(PJ *P, double *del) {
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
switch (Q->type) {
@@ -83,7 +87,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, (and ellipsoidal?) inverse */
LP lp = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho;
rho = hypot (xy.x, xy.y = Q->rho_0 - xy.y);
@@ -112,8 +116,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, (and ellipsoidal?) inverse
static PJ *setup(PJ *P, enum Type type) {
double del, cs;
int err;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
Q->type = type;
diff --git a/src/PJ_somerc.c b/src/projections/somerc.cpp
index c6c3ff21..15d2e765 100644
--- a/src/PJ_somerc.c
+++ b/src/projections/somerc.cpp
@@ -8,9 +8,11 @@
PROJ_HEAD(somerc, "Swiss. Obl. Mercator") "\n\tCyl, Ell\n\tFor CH1903";
+namespace { // anonymous namespace
struct pj_opaque {
double K, c, hlf_e, kR, cosp0, sinp0;
};
+} // anonymous namespace
#define EPS 1.e-10
#define NITER 6
@@ -19,7 +21,7 @@ struct pj_opaque {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0, 0.0};
double phip, lamp, phipp, lampp, sp, cp;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
sp = P->e * sin (lp.phi);
phip = 2.* atan ( exp ( Q->c * (
@@ -37,7 +39,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double phip, lamp, phipp, lampp, cp, esp, con, delp;
int i;
@@ -69,8 +71,8 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
PJ *PROJECTION(somerc) {
double cp, phip0, sp;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_stere.c b/src/projections/stere.cpp
index 82fd5c07..1502b2a6 100644
--- a/src/PJ_stere.c
+++ b/src/projections/stere.cpp
@@ -8,13 +8,16 @@ PROJ_HEAD(stere, "Stereographic") "\n\tAzi, Sph&Ell\n\tlat_ts=";
PROJ_HEAD(ups, "Universal Polar Stereographic") "\n\tAzi, Sph&Ell\n\tsouth";
+namespace { // anonymous namespace
enum Mode {
S_POLE = 0,
N_POLE = 1,
OBLIQ = 2,
EQUIT = 3
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque {
double phits;
double sinX1;
@@ -22,9 +25,10 @@ struct pj_opaque {
double akm1;
enum Mode mode;
};
+} // anonymous namespace
-#define sinph0 P->opaque->sinX1
-#define cosph0 P->opaque->cosX1
+#define sinph0 static_cast<struct pj_opaque*>(P->opaque)->sinX1
+#define cosph0 static_cast<struct pj_opaque*>(P->opaque)->cosX1
#define EPS10 1.e-10
#define TOL 1.e-8
#define NITER 8
@@ -39,7 +43,7 @@ static double ssfn_ (double phit, double sinphi, double eccen) {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double coslam, sinlam, sinX = 0.0, cosX = 0.0, X, A = 0.0, sinphi;
coslam = cos (lp.lam);
@@ -87,7 +91,7 @@ xmul:
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double sinphi, cosphi, coslam, sinlam;
sinphi = sin(lp.phi);
@@ -129,7 +133,7 @@ oblcon:
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosphi, sinphi, tp=0.0, phi_l=0.0, rho, halfe=0.0, halfpi=0.0;
int i;
@@ -179,7 +183,7 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c, rh, sinc, cosc;
sinc = sin (c = 2. * atan ((rh = hypot (xy.x, xy.y)) / Q->akm1));
@@ -220,7 +224,7 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
static PJ *setup(PJ *P) { /* general initialization */
double t;
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (fabs ((t = fabs (P->phi0)) - M_HALFPI) < EPS10)
Q->mode = P->phi0 < 0. ? S_POLE : N_POLE;
@@ -281,8 +285,8 @@ static PJ *setup(PJ *P) { /* general initialization */
PJ *PROJECTION(stere) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -294,8 +298,8 @@ PJ *PROJECTION(stere) {
PJ *PROJECTION(ups) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_sterea.c b/src/projections/sterea.cpp
index eb4c9f2c..bb498068 100644
--- a/src/PJ_sterea.c
+++ b/src/projections/sterea.cpp
@@ -29,12 +29,14 @@
#include "proj_math.h"
+namespace { // anonymous namespace
struct pj_opaque {
double phic0;
double cosc0, sinc0;
double R2;
void *en;
};
+} // anonymous namespace
PROJ_HEAD(sterea, "Oblique Stereographic Alternative") "\n\tAzimuthal, Sph&Ell";
@@ -43,7 +45,7 @@ PROJ_HEAD(sterea, "Oblique Stereographic Alternative") "\n\tAzimuthal, Sph&Ell";
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cosc, sinc, cosl, k;
lp = pj_gauss(P->ctx, lp, Q->en);
@@ -59,7 +61,7 @@ static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double rho, c, sinc, cosc;
xy.x /= P->k0;
@@ -78,28 +80,28 @@ static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
}
-static void *destructor (PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor (PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor (P, errlev);
}
PJ *PROJECTION(sterea) {
double R;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
- if (0==Q)
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
Q->en = pj_gauss_ini(P->e, P->phi0, &(Q->phic0), &R);
- if (0==Q->en)
+ if (nullptr==Q->en)
return pj_default_destructor (P, ENOMEM);
Q->sinc0 = sin (Q->phic0);
diff --git a/src/PJ_sts.c b/src/projections/sts.cpp
index 66094178..9f889611 100644
--- a/src/PJ_sts.c
+++ b/src/projections/sts.cpp
@@ -11,15 +11,17 @@ PROJ_HEAD(fouc, "Foucaut") "\n\tPCyl, Sph";
PROJ_HEAD(mbt_s, "McBryde-Thomas Flat-Polar Sine (No. 1)") "\n\tPCyl, Sph";
+namespace { // anonymous namespace
struct pj_opaque {
double C_x, C_y, C_p;
int tan_mode;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c;
xy.x = Q->C_x * lp.lam * cos(lp.phi);
@@ -39,7 +41,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double c;
xy.y /= Q->C_y;
@@ -58,18 +60,18 @@ static PJ *setup(PJ *P, double p, double q, int mode) {
P->es = 0.;
P->inv = s_inverse;
P->fwd = s_forward;
- P->opaque->C_x = q / p;
- P->opaque->C_y = p;
- P->opaque->C_p = 1/ q;
- P->opaque->tan_mode = mode;
+ static_cast<struct pj_opaque*>(P->opaque)->C_x = q / p;
+ static_cast<struct pj_opaque*>(P->opaque)->C_y = p;
+ static_cast<struct pj_opaque*>(P->opaque)->C_p = 1/ q;
+ static_cast<struct pj_opaque*>(P->opaque)->tan_mode = mode;
return P;
}
PJ *PROJECTION(fouc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
return setup(P, 2., 2., 1);
@@ -78,8 +80,8 @@ PJ *PROJECTION(fouc) {
PJ *PROJECTION(kav5) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -89,8 +91,8 @@ PJ *PROJECTION(kav5) {
PJ *PROJECTION(qua_aut) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
return setup(P, 2., 2., 0);
@@ -99,8 +101,8 @@ PJ *PROJECTION(qua_aut) {
PJ *PROJECTION(mbt_s) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
return setup(P, 1.48875, 1.36509, 0);
diff --git a/src/PJ_tcc.c b/src/projections/tcc.cpp
index 60ded63e..64fdc182 100644
--- a/src/PJ_tcc.c
+++ b/src/projections/tcc.cpp
@@ -28,7 +28,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(tcc) {
P->es = 0.;
P->fwd = s_forward;
- P->inv = 0;
+ P->inv = nullptr;
return P;
}
diff --git a/src/PJ_tcea.c b/src/projections/tcea.cpp
index d30f3df0..d30f3df0 100644
--- a/src/PJ_tcea.c
+++ b/src/projections/tcea.cpp
diff --git a/src/PJ_times.c b/src/projections/times.cpp
index e8b4499f..e8b4499f 100644
--- a/src/PJ_times.c
+++ b/src/projections/times.cpp
diff --git a/src/PJ_tmerc.c b/src/projections/tmerc.cpp
index 069cdc2c..5a2dacbd 100644
--- a/src/PJ_tmerc.c
+++ b/src/projections/tmerc.cpp
@@ -9,11 +9,13 @@
PROJ_HEAD(tmerc, "Transverse Mercator") "\n\tCyl, Sph&Ell";
+namespace { // anonymous namespace
struct pj_opaque {
double esp;
double ml0;
double *en;
};
+} // anonymous namespace
#define EPS10 1.e-10
#define FC1 1.
@@ -28,7 +30,7 @@ struct pj_opaque {
static XY e_forward (LP lp, PJ *P) { /* Ellipsoidal, forward */
XY xy = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double al, als, n, cosphi, sinphi, t;
/*
@@ -93,7 +95,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
return xy;
}
- xy.x = P->opaque->ml0 * log ((1. + b) / (1. - b));
+ xy.x = static_cast<struct pj_opaque*>(P->opaque)->ml0 * log ((1. + b) / (1. - b));
xy.y = cosphi * cos (lp.lam) / sqrt (1. - b * b);
b = fabs ( xy.y );
@@ -108,14 +110,14 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
if (lp.phi < 0.)
xy.y = -xy.y;
- xy.y = P->opaque->esp * (xy.y - P->phi0);
+ xy.y = static_cast<struct pj_opaque*>(P->opaque)->esp * (xy.y - P->phi0);
return xy;
}
static LP e_inverse (XY xy, PJ *P) { /* Ellipsoidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double n, con, cosphi, d, ds, sinphi, t;
lp.phi = pj_inv_mlfn(P->ctx, Q->ml0 + xy.y / P->k0, P->es, Q->en);
@@ -151,9 +153,9 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0, 0.0};
double h, g;
- h = exp(xy.x / P->opaque->esp);
+ h = exp(xy.x / static_cast<struct pj_opaque*>(P->opaque)->esp);
g = .5 * (h - 1. / h);
- h = cos (P->phi0 + xy.y / P->opaque->esp);
+ h = cos (P->phi0 + xy.y / static_cast<struct pj_opaque*>(P->opaque)->esp);
lp.phi = asin(sqrt((1. - h * h) / (1. + g * g)));
/* Make sure that phi is on the correct hemisphere when false northing is used */
@@ -164,20 +166,20 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
}
-static void *destructor(PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
+static PJ *destructor(PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor(P, errlev);
- pj_dealloc (P->opaque->en);
+ pj_dealloc (static_cast<struct pj_opaque*>(P->opaque)->en);
return pj_default_destructor(P, errlev);
}
static PJ *setup(PJ *P) { /* general initialization */
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
if (P->es != 0.0) {
if (!(Q->en = pj_enfn(P->es)))
return pj_default_destructor(P, ENOMEM);
@@ -197,8 +199,8 @@ static PJ *setup(PJ *P) { /* general initialization */
PJ *PROJECTION(tmerc) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_tobmerc.c b/src/projections/tobmerc.cpp
index 9c939f0b..9c939f0b 100644
--- a/src/PJ_tobmerc.c
+++ b/src/projections/tobmerc.cpp
diff --git a/src/PJ_tpeqd.c b/src/projections/tpeqd.cpp
index 87877ec1..2720327a 100644
--- a/src/PJ_tpeqd.c
+++ b/src/projections/tpeqd.cpp
@@ -8,15 +8,17 @@
PROJ_HEAD(tpeqd, "Two Point Equidistant")
"\n\tMisc Sph\n\tlat_1= lon_1= lat_2= lon_2=";
+namespace { // anonymous namespace
struct pj_opaque {
double cp1, sp1, cp2, sp2, ccs, cs, sc, r2z0, z02, dlam2;
double hz0, thz0, rhshz0, ca, sa, lp, lamc;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t, z1, z2, dl1, dl2, sp, cp;
sp = sin(lp.phi);
@@ -37,7 +39,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double cz1, cz2, s, d, cp, sp;
cz1 = cos (hypot(xy.y, xy.x + Q->hz0));
@@ -59,8 +61,8 @@ static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
PJ *PROJECTION(tpeqd) {
double lam_1, lam_2, phi_1, phi_2, A12, pp;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_urm5.c b/src/projections/urm5.cpp
index 293de8cf..0e3c7e3c 100644
--- a/src/PJ_urm5.c
+++ b/src/projections/urm5.cpp
@@ -8,14 +8,16 @@
PROJ_HEAD(urm5, "Urmaev V") "\n\tPCyl, Sph, no inv\n\tn= q= alpha=";
+namespace { // anonymous namespace
struct pj_opaque {
double m, rmn, q3, n;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0, 0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double t;
t = lp.phi = aasin (P->ctx, Q->n * sin (lp.phi));
@@ -28,8 +30,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(urm5) {
double alpha, t;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
@@ -47,7 +49,7 @@ PJ *PROJECTION(urm5) {
Q->rmn = 1. / (Q->m * Q->n);
P->es = 0.;
- P->inv = 0;
+ P->inv = nullptr;
P->fwd = s_forward;
return P;
diff --git a/src/PJ_urmfps.c b/src/projections/urmfps.cpp
index 467fc9bc..7103222a 100644
--- a/src/PJ_urmfps.c
+++ b/src/projections/urmfps.cpp
@@ -9,9 +9,11 @@
PROJ_HEAD(urmfps, "Urmaev Flat-Polar Sinusoidal") "\n\tPCyl, Sph\n\tn=";
PROJ_HEAD(wag1, "Wagner I (Kavraisky VI)") "\n\tPCyl, Sph";
+namespace { // anonymous namespace
struct pj_opaque {
double n, C_y;
};
+} // anonymous namespace
#define C_x 0.8773826753
#define Cy 1.139753528477
@@ -19,24 +21,24 @@ struct pj_opaque {
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0, 0.0};
- lp.phi = aasin (P->ctx,P->opaque->n * sin (lp.phi));
+ lp.phi = aasin (P->ctx,static_cast<struct pj_opaque*>(P->opaque)->n * sin (lp.phi));
xy.x = C_x * lp.lam * cos (lp.phi);
- xy.y = P->opaque->C_y * lp.phi;
+ xy.y = static_cast<struct pj_opaque*>(P->opaque)->C_y * lp.phi;
return xy;
}
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0, 0.0};
- xy.y /= P->opaque->C_y;
- lp.phi = aasin(P->ctx, sin (xy.y) / P->opaque->n);
+ xy.y /= static_cast<struct pj_opaque*>(P->opaque)->C_y;
+ lp.phi = aasin(P->ctx, sin (xy.y) / static_cast<struct pj_opaque*>(P->opaque)->n);
lp.lam = xy.x / (C_x * cos (xy.y));
return lp;
}
static PJ *setup(PJ *P) {
- P->opaque->C_y = Cy / P->opaque->n;
+ static_cast<struct pj_opaque*>(P->opaque)->C_y = Cy / static_cast<struct pj_opaque*>(P->opaque)->n;
P->es = 0.;
P->inv = s_inverse;
P->fwd = s_forward;
@@ -45,15 +47,15 @@ static PJ *setup(PJ *P) {
PJ *PROJECTION(urmfps) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
if (pj_param(P->ctx, P->params, "tn").i) {
- P->opaque->n = pj_param(P->ctx, P->params, "dn").f;
- if (P->opaque->n <= 0. || P->opaque->n > 1.)
+ static_cast<struct pj_opaque*>(P->opaque)->n = pj_param(P->ctx, P->params, "dn").f;
+ if (static_cast<struct pj_opaque*>(P->opaque)->n <= 0. || static_cast<struct pj_opaque*>(P->opaque)->n > 1.)
return pj_default_destructor(P, PJD_ERR_N_OUT_OF_RANGE);
} else {
return pj_default_destructor(P, PJD_ERR_N_OUT_OF_RANGE);
@@ -64,11 +66,11 @@ PJ *PROJECTION(urmfps) {
PJ *PROJECTION(wag1) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
- P->opaque->n = 0.8660254037844386467637231707;
+ static_cast<struct pj_opaque*>(P->opaque)->n = 0.8660254037844386467637231707;
return setup(P);
}
diff --git a/src/PJ_vandg.c b/src/projections/vandg.cpp
index d148e210..d148e210 100644
--- a/src/PJ_vandg.c
+++ b/src/projections/vandg.cpp
diff --git a/src/PJ_vandg2.c b/src/projections/vandg2.cpp
index 447cb782..61d50044 100644
--- a/src/PJ_vandg2.c
+++ b/src/projections/vandg2.cpp
@@ -5,9 +5,11 @@
#include "projects.h"
+namespace { // anonymous namespace
struct pj_opaque {
int vdg3;
};
+} // anonymous namespace
PROJ_HEAD(vandg2, "van der Grinten II") "\n\tMisc Sph, no inv";
PROJ_HEAD(vandg3, "van der Grinten III") "\n\tMisc Sph, no inv";
@@ -17,7 +19,7 @@ PROJ_HEAD(vandg3, "van der Grinten III") "\n\tMisc Sph, no inv";
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- struct pj_opaque *Q = P->opaque;
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(P->opaque);
double x1, at, bt, ct;
bt = fabs(M_TWO_D_PI * lp.phi);
@@ -49,8 +51,8 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(vandg2) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
@@ -61,8 +63,8 @@ PJ *PROJECTION(vandg2) {
}
PJ *PROJECTION(vandg3) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = Q;
diff --git a/src/PJ_vandg4.c b/src/projections/vandg4.cpp
index d9a53c87..d9a53c87 100644
--- a/src/PJ_vandg4.c
+++ b/src/projections/vandg4.cpp
diff --git a/src/PJ_wag2.c b/src/projections/wag2.cpp
index 1bee737a..1bee737a 100644
--- a/src/PJ_wag2.c
+++ b/src/projections/wag2.cpp
diff --git a/src/PJ_wag3.c b/src/projections/wag3.cpp
index ccd19d4d..bb1b4d49 100644
--- a/src/PJ_wag3.c
+++ b/src/projections/wag3.cpp
@@ -9,14 +9,16 @@ PROJ_HEAD(wag3, "Wagner III") "\n\tPCyl, Sph\n\tlat_ts=";
#define TWOTHIRD 0.6666666666666666666667
+namespace { // anonymous namespace
struct pj_opaque {
double C_x;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- xy.x = P->opaque->C_x * lp.lam * cos(TWOTHIRD * lp.phi);
+ xy.x = static_cast<struct pj_opaque*>(P->opaque)->C_x * lp.lam * cos(TWOTHIRD * lp.phi);
xy.y = lp.phi;
return xy;
}
@@ -25,21 +27,21 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
lp.phi = xy.y;
- lp.lam = xy.x / (P->opaque->C_x * cos(TWOTHIRD * lp.phi));
+ lp.lam = xy.x / (static_cast<struct pj_opaque*>(P->opaque)->C_x * cos(TWOTHIRD * lp.phi));
return lp;
}
PJ *PROJECTION(wag3) {
double ts;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
ts = pj_param (P->ctx, P->params, "rlat_ts").f;
- P->opaque->C_x = cos (ts) / cos (2.*ts/3.);
+ static_cast<struct pj_opaque*>(P->opaque)->C_x = cos (ts) / cos (2.*ts/3.);
P->es = 0.;
P->inv = s_inverse;
P->fwd = s_forward;
diff --git a/src/PJ_wag7.c b/src/projections/wag7.cpp
index 2009e672..c8807f12 100644
--- a/src/PJ_wag7.c
+++ b/src/projections/wag7.cpp
@@ -24,7 +24,7 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
PJ *PROJECTION(wag7) {
P->fwd = s_forward;
- P->inv = 0;
+ P->inv = nullptr;
P->es = 0.;
return P;
}
diff --git a/src/PJ_wink1.c b/src/projections/wink1.cpp
index 865cc6ac..de2f55ee 100644
--- a/src/PJ_wink1.c
+++ b/src/projections/wink1.cpp
@@ -7,15 +7,17 @@
PROJ_HEAD(wink1, "Winkel I") "\n\tPCyl, Sph\n\tlat_ts=";
+namespace { // anonymous namespace
struct pj_opaque {
double cosphi1;
};
+} // anonymous namespace
static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
XY xy = {0.0,0.0};
- xy.x = .5 * lp.lam * (P->opaque->cosphi1 + cos(lp.phi));
+ xy.x = .5 * lp.lam * (static_cast<struct pj_opaque*>(P->opaque)->cosphi1 + cos(lp.phi));
xy.y = lp.phi;
return (xy);
}
@@ -24,18 +26,18 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */
LP lp = {0.0,0.0};
lp.phi = xy.y;
- lp.lam = 2. * xy.x / (P->opaque->cosphi1 + cos(lp.phi));
+ lp.lam = 2. * xy.x / (static_cast<struct pj_opaque*>(P->opaque)->cosphi1 + cos(lp.phi));
return (lp);
}
PJ *PROJECTION(wink1) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
- P->opaque->cosphi1 = cos (pj_param(P->ctx, P->params, "rlat_ts").f);
+ static_cast<struct pj_opaque*>(P->opaque)->cosphi1 = cos (pj_param(P->ctx, P->params, "rlat_ts").f);
P->es = 0.;
P->inv = s_inverse;
P->fwd = s_forward;
diff --git a/src/PJ_wink2.c b/src/projections/wink2.cpp
index f8e9af09..74a47283 100644
--- a/src/PJ_wink2.c
+++ b/src/projections/wink2.cpp
@@ -7,7 +7,11 @@
PROJ_HEAD(wink2, "Winkel II") "\n\tPCyl, Sph, no inv\n\tlat_1=";
-struct pj_opaque { double cosphi1; };
+namespace { // anonymous namespace
+struct pj_opaque {
+ double cosphi1;
+};
+} // anonymous namespace
#define MAX_ITER 10
#define LOOP_TOL 1e-7
@@ -31,21 +35,21 @@ static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */
lp.phi = (lp.phi < 0.) ? -M_HALFPI : M_HALFPI;
else
lp.phi *= 0.5;
- xy.x = 0.5 * lp.lam * (cos (lp.phi) + P->opaque->cosphi1);
+ xy.x = 0.5 * lp.lam * (cos (lp.phi) + static_cast<struct pj_opaque*>(P->opaque)->cosphi1);
xy.y = M_FORTPI * (sin (lp.phi) + xy.y);
return xy;
}
PJ *PROJECTION(wink2) {
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = Q;
- P->opaque->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_1").f);
+ static_cast<struct pj_opaque*>(P->opaque)->cosphi1 = cos(pj_param(P->ctx, P->params, "rlat_1").f);
P->es = 0.;
- P->inv = 0;
+ P->inv = nullptr;
P->fwd = s_forward;
return P;
diff --git a/src/projects.h b/src/projects.h
index 11467d56..b76205a5 100644
--- a/src/projects.h
+++ b/src/projects.h
@@ -197,7 +197,6 @@ struct PJconsts;
union PJ_COORD;
struct geod_geodesic;
-struct pj_opaque;
struct ARG_list;
struct PJ_REGION_S;
typedef struct PJ_REGION_S PJ_Region;
@@ -260,7 +259,7 @@ PJ_OPERATOR:
*****************************************************************************/
typedef PJ *(* PJ_CONSTRUCTOR) (PJ *);
-typedef void *(* PJ_DESTRUCTOR) (PJ *, int);
+typedef PJ *(* PJ_DESTRUCTOR) (PJ *, int);
typedef PJ_COORD (* PJ_OPERATOR) (PJ_COORD, PJ *);
/****************************************************************************/
@@ -290,7 +289,7 @@ struct PJconsts {
char *def_ellps;
struct geod_geodesic *geod; /* For geodesic computations */
- struct pj_opaque *opaque; /* Projection specific parameters, Defined in PJ_*.c */
+ void *opaque; /* Projection specific parameters, Defined in PJ_*.c */
int inverted; /* Tell high level API functions to swap inv/fwd */
@@ -493,10 +492,10 @@ typedef union { double f; int i; char *s; } PROJVALUE;
struct PJ_DATUMS {
- char *id; /* datum keyword */
- char *defn; /* ie. "to_wgs84=..." */
- char *ellipse_id; /* ie from ellipse table */
- char *comments; /* EPSG code, etc */
+ const char *id; /* datum keyword */
+ const char *defn; /* ie. "to_wgs84=..." */
+ const char *ellipse_id; /* ie from ellipse table */
+ const char *comments; /* EPSG code, etc */
};
@@ -628,8 +627,8 @@ C_NAMESPACE PJ *pj_##name (PJ *P) { \
if (P) \
return pj_projection_specific_setup_##name (P); \
P = (PJ*) pj_calloc (1, sizeof(PJ)); \
- if (0==P) \
- return 0; \
+ if (nullptr==P) \
+ return nullptr; \
P->destructor = pj_default_destructor; \
P->descr = des_##name; \
P->need_ellps = NEED_ELLPS; \
@@ -828,7 +827,7 @@ extern char const PROJ_DLL pj_release[];
struct PJ_DATUMS PROJ_DLL *pj_get_datums_ref( void );
-void *pj_default_destructor (PJ *P, int errlev);
+PJ *pj_default_destructor (PJ *P, int errlev);
double PROJ_DLL pj_atof( const char* nptr );
double pj_strtod( const char *nptr, char **endptr );
diff --git a/src/pj_qsfn.c b/src/qsfn.cpp
index c18a7b95..c18a7b95 100644
--- a/src/pj_qsfn.c
+++ b/src/qsfn.cpp
diff --git a/src/pj_release.c b/src/release.cpp
index 9beb45ef..9beb45ef 100644
--- a/src/pj_release.c
+++ b/src/release.cpp
diff --git a/src/rtodms.c b/src/rtodms.cpp
index 674cebdf..674cebdf 100644
--- a/src/rtodms.c
+++ b/src/rtodms.cpp
diff --git a/src/pj_strerrno.c b/src/strerrno.cpp
index 16042f79..18ed0d33 100644
--- a/src/pj_strerrno.c
+++ b/src/strerrno.cpp
@@ -79,7 +79,7 @@ char *pj_strerrno(int err) {
size_t adjusted_err;
if (0==err)
- return 0;
+ return nullptr;
/* System error codes are positive */
if (err > 0) {
diff --git a/src/pj_strtod.c b/src/strtod.cpp
index f604a013..5a360c2e 100644
--- a/src/pj_strtod.c
+++ b/src/strtod.cpp
@@ -65,7 +65,7 @@
*/
double pj_atof( const char* nptr )
{
- return pj_strtod(nptr, NULL);
+ return pj_strtod(nptr, nullptr);
}
@@ -134,7 +134,7 @@ static char* replace_point_by_locale_point(const char* pszNumber, char point,
else {
pszNew = pj_strdup(pszNumber);
if (!pszNew)
- return NULL;
+ return nullptr;
}
if( pszLocalePoint )
pszNew[pszLocalePoint - pszNumber] = ' ';
diff --git a/src/geodtest.c b/src/tests/geodtest.cpp
index 0ee86d5c..6b3ea8b2 100644
--- a/src/geodtest.c
+++ b/src/tests/geodtest.cpp
@@ -157,7 +157,7 @@ static int testdirect() {
s12 = testcases[i][6]; a12 = testcases[i][7]; m12 = testcases[i][8];
M12 = testcases[i][9]; M21 = testcases[i][10]; S12 = testcases[i][11];
a12a = geod_gendirect(&g, lat1, lon1, azi1, flags, s12,
- &lat2a, &lon2a, &azi2a, 0,
+ &lat2a, &lon2a, &azi2a, nullptr,
&m12a, &M12a, &M21a, &S12a);
result += checkEquals(lat2, lat2a, 1e-13);
result += checkEquals(lon2, lon2a, 1e-13);
@@ -246,7 +246,7 @@ static int GeodSolve4() {
int result = 0;
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, 36.493349428792, 0, 36.49334942879201, .0000008,
- &s12, 0, 0);
+ &s12, nullptr, nullptr);
result += checkEquals(s12, 0.072, 0.5e-3);
return result;
}
@@ -277,13 +277,13 @@ static int GeodSolve6() {
int result = 0;
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, 88.202499451857, 0,
- -88.202499451857, 179.981022032992859592, &s12, 0, 0);
+ -88.202499451857, 179.981022032992859592, &s12, nullptr, nullptr);
result += checkEquals(s12, 20003898.214, 0.5e-3);
geod_inverse(&g, 89.262080389218, 0,
- -89.262080389218, 179.992207982775375662, &s12, 0, 0);
+ -89.262080389218, 179.992207982775375662, &s12, nullptr, nullptr);
result += checkEquals(s12, 20003925.854, 0.5e-3);
geod_inverse(&g, 89.333123580033, 0,
- -89.333123580032997687, 179.99295812360148422, &s12, 0, 0);
+ -89.333123580032997687, 179.99295812360148422, &s12, nullptr, nullptr);
result += checkEquals(s12, 20003926.881, 0.5e-3);
return result;
}
@@ -295,7 +295,7 @@ static int GeodSolve9() {
int result = 0;
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, 56.320923501171, 0,
- -56.320923501171, 179.664747671772880215, &s12, 0, 0);
+ -56.320923501171, 179.664747671772880215, &s12, nullptr, nullptr);
result += checkEquals(s12, 19993558.287, 0.5e-3);
return result;
}
@@ -308,7 +308,7 @@ static int GeodSolve10() {
int result = 0;
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, 52.784459512564, 0,
- -52.784459512563990912, 179.634407464943777557, &s12, 0, 0);
+ -52.784459512563990912, 179.634407464943777557, &s12, nullptr, nullptr);
result += checkEquals(s12, 19991596.095, 0.5e-3);
return result;
}
@@ -321,7 +321,7 @@ static int GeodSolve11() {
int result = 0;
geod_init(&g, wgs84_a, wgs84_f);
geod_inverse(&g, 48.522876735459, 0,
- -48.52287673545898293, 179.599720456223079643, &s12, 0, 0);
+ -48.52287673545898293, 179.599720456223079643, &s12, nullptr, nullptr);
result += checkEquals(s12, 19989144.774, 0.5e-3);
return result;
}
@@ -367,7 +367,7 @@ static int GeodSolve15() {
int result = 0;
geod_init(&g, 6.4e6, -1/150.0);
geod_gendirect(&g, 1, 2, 3, 0, 4,
- 0, 0, 0, 0, 0, 0, 0, &S12);
+ nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &S12);
result += checkEquals(S12, 23700, 0.5);
return result;
}
@@ -381,12 +381,12 @@ static int GeodSolve17() {
unsigned flags = GEOD_LONG_UNROLL;
geod_init(&g, wgs84_a, wgs84_f);
geod_gendirect(&g, 40, -75, -10, flags, 2e7,
- &lat2, &lon2, &azi2, 0, 0, 0, 0, 0);
+ &lat2, &lon2, &azi2, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(lat2, -39, 1);
result += checkEquals(lon2, -254, 1);
result += checkEquals(azi2, -170, 1);
geod_lineinit(&l, &g, 40, -75, -10, 0);
- geod_genposition(&l, flags, 2e7, &lat2, &lon2, &azi2, 0, 0, 0, 0, 0);
+ geod_genposition(&l, flags, 2e7, &lat2, &lon2, &azi2, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(lat2, -39, 1);
result += checkEquals(lon2, -254, 1);
result += checkEquals(azi2, -170, 1);
@@ -407,7 +407,7 @@ static int GeodSolve26() {
struct geod_geodesic g;
int result = 0;
geod_init(&g, 6.4e6, 0);
- geod_geninverse(&g, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, &S12);
+ geod_geninverse(&g, 1, 2, 3, 4, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &S12);
result += checkEquals(S12, 49911046115.0, 0.5);
return result;
}
@@ -419,7 +419,7 @@ static int GeodSolve28() {
struct geod_geodesic g;
int result = 0;
geod_init(&g, 6.4e6, 0.1);
- a12 = geod_gendirect(&g, 1, 2, 10, 0, 5e6, 0, 0, 0, 0, 0, 0, 0, 0);
+ a12 = geod_gendirect(&g, 1, 2, 10, 0, 5e6, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(a12, 48.55570690, 0.5e-8);
return result;
}
@@ -527,12 +527,12 @@ static int GeodSolve61() {
unsigned flags = GEOD_LONG_UNROLL;
geod_init(&g, wgs84_a, wgs84_f);
geod_gendirect(&g, 45, 0, -0.000000000000000003, flags, 1e7,
- &lat2, &lon2, &azi2, 0, 0, 0, 0, 0);
+ &lat2, &lon2, &azi2, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(lat2, 45.30632, 0.5e-5);
result += checkEquals(lon2, -180, 0.5e-5);
result += checkEquals(fabs(azi2), 180, 0.5e-5);
geod_inverseline(&l, &g, 45, 0, 80, -0.000000000000000003, 0);
- geod_genposition(&l, flags, 1e7, &lat2, &lon2, &azi2, 0, 0, 0, 0, 0);
+ geod_genposition(&l, flags, 1e7, &lat2, &lon2, &azi2, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(lat2, 45.30632, 0.5e-5);
result += checkEquals(lon2, -180, 0.5e-5);
result += checkEquals(fabs(azi2), 180, 0.5e-5);
@@ -585,11 +585,11 @@ static int GeodSolve67() {
unsigned flags = GEOD_LONG_UNROLL;
geod_init(&g, wgs84_a, wgs84_f);
geod_inverseline(&l, &g, -5, -0.000000000000002, -10, 180, 0);
- geod_genposition(&l, flags, 2e7, &lat2, &lon2, &azi2, 0, 0, 0, 0, 0);
+ geod_genposition(&l, flags, 2e7, &lat2, &lon2, &azi2, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(lat2, 4.96445, 0.5e-5);
result += checkEquals(lon2, -180.00000, 0.5e-5);
result += checkEquals(azi2, -0.00000, 0.5e-5);
- geod_genposition(&l, flags, 0.5 * l.s13, &lat2, &lon2, &azi2, 0, 0, 0, 0, 0);
+ geod_genposition(&l, flags, 0.5 * l.s13, &lat2, &lon2, &azi2, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkEquals(lat2, -87.52461, 0.5e-5);
result += checkEquals(lon2, -0.00000, 0.5e-5);
result += checkEquals(azi2, -180.00000, 0.5e-5);
@@ -647,7 +647,7 @@ static void polylength(const struct geod_geodesic* g,
geod_polygon_init(&p, 1);
for (i = 0; i < N; ++i)
geod_polygon_addpoint(g, &p, points[i][0], points[i][1]);
- geod_polygon_compute(g, &p, 0, 1, 0, perimeter);
+ geod_polygon_compute(g, &p, 0, 1, nullptr, perimeter);
}
static int GeodSolve74() {
@@ -707,10 +707,10 @@ static int GeodSolve80() {
struct geod_geodesicline l;
int result = 0;
geod_init(&g, wgs84_a, wgs84_f);
- geod_geninverse(&g, 0, 0, 0, 90, 0, 0, 0, 0, &M12, &M21, 0);
+ geod_geninverse(&g, 0, 0, 0, 90, nullptr, nullptr, nullptr, nullptr, &M12, &M21, nullptr);
result += checkEquals(M12, -0.00528427534, 0.5e-10);
result += checkEquals(M21, -0.00528427534, 0.5e-10);
- geod_geninverse(&g, 0, 0, 1e-6, 1e-6, 0, 0, 0, 0, &M12, &M21, 0);
+ geod_geninverse(&g, 0, 0, 1e-6, 1e-6, nullptr, nullptr, nullptr, nullptr, &M12, &M21, nullptr);
result += checkEquals(M12, 1, 0.5e-10);
result += checkEquals(M21, 1, 0.5e-10);
a12 = geod_geninverse(&g, 20.001, 0, 20.001, 0,
@@ -735,7 +735,7 @@ static int GeodSolve80() {
result += checkEquals(S12, 127516405431022, 0.5);
/* An incapable line which can't take distance as input */
geod_lineinit(&l, &g, 1, 2, 90, GEOD_LATITUDE);
- a12 = geod_genposition(&l, 0, 1000, 0, 0, 0, 0, 0, 0, 0, 0);
+ a12 = geod_genposition(&l, 0, 1000, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
result += checkNaN(a12);
return result;
}
@@ -853,33 +853,33 @@ static int Planimeter15() {
geod_polygon_init(&p, 0);
geod_polygon_addpoint(&g, &p, lat[0], lon[0]);
geod_polygon_addpoint(&g, &p, lat[1], lon[1]);
- geod_polygon_testpoint(&g, &p, lat[2], lon[2], 0, 1, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat[2], lon[2], 0, 1, &area, nullptr);
result += checkEquals(area, r, 0.5);
- geod_polygon_testpoint(&g, &p, lat[2], lon[2], 0, 0, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat[2], lon[2], 0, 0, &area, nullptr);
result += checkEquals(area, r, 0.5);
- geod_polygon_testpoint(&g, &p, lat[2], lon[2], 1, 1, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat[2], lon[2], 1, 1, &area, nullptr);
result += checkEquals(area, -r, 0.5);
- geod_polygon_testpoint(&g, &p, lat[2], lon[2], 1, 0, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat[2], lon[2], 1, 0, &area, nullptr);
result += checkEquals(area, a0-r, 0.5);
- geod_inverse(&g, lat[1], lon[1], lat[2], lon[2], &s12, &azi1, 0);
- geod_polygon_testedge(&g, &p, azi1, s12, 0, 1, &area, 0);
+ geod_inverse(&g, lat[1], lon[1], lat[2], lon[2], &s12, &azi1, nullptr);
+ geod_polygon_testedge(&g, &p, azi1, s12, 0, 1, &area, nullptr);
result += checkEquals(area, r, 0.5);
- geod_polygon_testedge(&g, &p, azi1, s12, 0, 0, &area, 0);
+ geod_polygon_testedge(&g, &p, azi1, s12, 0, 0, &area, nullptr);
result += checkEquals(area, r, 0.5);
- geod_polygon_testedge(&g, &p, azi1, s12, 1, 1, &area, 0);
+ geod_polygon_testedge(&g, &p, azi1, s12, 1, 1, &area, nullptr);
result += checkEquals(area, -r, 0.5);
- geod_polygon_testedge(&g, &p, azi1, s12, 1, 0, &area, 0);
+ geod_polygon_testedge(&g, &p, azi1, s12, 1, 0, &area, nullptr);
result += checkEquals(area, a0-r, 0.5);
geod_polygon_addpoint(&g, &p, lat[2], lon[2]);
- geod_polygon_compute(&g, &p, 0, 1, &area, 0);
+ geod_polygon_compute(&g, &p, 0, 1, &area, nullptr);
result += checkEquals(area, r, 0.5);
- geod_polygon_compute(&g, &p, 0, 0, &area, 0);
+ geod_polygon_compute(&g, &p, 0, 0, &area, nullptr);
result += checkEquals(area, r, 0.5);
- geod_polygon_compute(&g, &p, 1, 1, &area, 0);
+ geod_polygon_compute(&g, &p, 1, 1, &area, nullptr);
result += checkEquals(area, -r, 0.5);
- geod_polygon_compute(&g, &p, 1, 0, &area, 0);
+ geod_polygon_compute(&g, &p, 1, 0, &area, nullptr);
result += checkEquals(area, a0-r, 0.5);
- geod_polygonarea(&g, lat, lon, 3, &area, 0);
+ geod_polygonarea(&g, lat, lon, 3, &area, nullptr);
result += checkEquals(area, r, 0.5);
return result;
}
@@ -907,14 +907,14 @@ static int Planimeter19() {
result += area == 0 ? 0 : 1;
result += perim == 0 ? 0 : 1;
geod_polygon_init(&p, 1);
- geod_polygon_compute(&g, &p, 0, 1, 0, &perim);
+ geod_polygon_compute(&g, &p, 0, 1, nullptr, &perim);
result += perim == 0 ? 0 : 1;
- geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, 0, &perim);
+ geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, nullptr, &perim);
result += perim == 0 ? 0 : 1;
- geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, 0, &perim);
+ geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, nullptr, &perim);
result += checkNaN(perim);
geod_polygon_addpoint(&g, &p, 1, 1);
- geod_polygon_compute(&g, &p, 0, 1, 0, &perim);
+ geod_polygon_compute(&g, &p, 0, 1, nullptr, &perim);
result += perim == 0 ? 0 : 1;
return result;
}
@@ -944,30 +944,30 @@ static int Planimeter21() {
for (i = 3; i <= 4; ++i) {
geod_polygon_addpoint(&g, &p, lat, 60);
geod_polygon_addpoint(&g, &p, lat, 180);
- geod_polygon_testpoint(&g, &p, lat, -60, 0, 1, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat, -60, 0, 1, &area, nullptr);
if (i != 4) result += checkEquals(area, i*r, 0.5);
- geod_polygon_testpoint(&g, &p, lat, -60, 0, 0, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat, -60, 0, 0, &area, nullptr);
if (i != 4) result += checkEquals(area, i*r, 0.5);
- geod_polygon_testpoint(&g, &p, lat, -60, 1, 1, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat, -60, 1, 1, &area, nullptr);
if (i != 4) result += checkEquals(area, -i*r, 0.5);
- geod_polygon_testpoint(&g, &p, lat, -60, 1, 0, &area, 0);
+ geod_polygon_testpoint(&g, &p, lat, -60, 1, 0, &area, nullptr);
result += checkEquals(area, -i*r + a0, 0.5);
- geod_polygon_testedge(&g, &p, a, s, 0, 1, &area, 0);
+ geod_polygon_testedge(&g, &p, a, s, 0, 1, &area, nullptr);
if (i != 4) result += checkEquals(area, i*r, 0.5);
- geod_polygon_testedge(&g, &p, a, s, 0, 0, &area, 0);
+ geod_polygon_testedge(&g, &p, a, s, 0, 0, &area, nullptr);
if (i != 4) result += checkEquals(area, i*r, 0.5);
- geod_polygon_testedge(&g, &p, a, s, 1, 1, &area, 0);
+ geod_polygon_testedge(&g, &p, a, s, 1, 1, &area, nullptr);
if (i != 4) result += checkEquals(area, -i*r, 0.5);
- geod_polygon_testedge(&g, &p, a, s, 1, 0, &area, 0);
+ geod_polygon_testedge(&g, &p, a, s, 1, 0, &area, nullptr);
result += checkEquals(area, -i*r + a0, 0.5);
geod_polygon_addpoint(&g, &p, lat, -60);
- geod_polygon_compute(&g, &p, 0, 1, &area, 0);
+ geod_polygon_compute(&g, &p, 0, 1, &area, nullptr);
if (i != 4) result += checkEquals(area, i*r, 0.5);
- geod_polygon_compute(&g, &p, 0, 0, &area, 0);
+ geod_polygon_compute(&g, &p, 0, 0, &area, nullptr);
if (i != 4) result += checkEquals(area, i*r, 0.5);
- geod_polygon_compute(&g, &p, 1, 1, &area, 0);
+ geod_polygon_compute(&g, &p, 1, 1, &area, nullptr);
if (i != 4) result += checkEquals(area, -i*r, 0.5);
- geod_polygon_compute(&g, &p, 1, 0, &area, 0);
+ geod_polygon_compute(&g, &p, 1, 0, &area, nullptr);
result += checkEquals(area, -i*r + a0, 0.5);
}
return result;
@@ -985,7 +985,7 @@ static int AddEdge1() {
geod_polygon_addedge(&g, &p, 90, 1000);
geod_polygon_addedge(&g, &p, 0, 1000);
geod_polygon_addedge(&g, &p, -90, 1000);
- geod_polygon_compute(&g, &p, 0, 1, &area, 0);
+ geod_polygon_compute(&g, &p, 0, 1, &area, nullptr);
result += checkEquals(area, 1000000.0, 0.01);
return result;
}
@@ -1007,16 +1007,16 @@ static int EmptyPoly() {
result += area == 0 ? 0 : 1;
result += perim == 0 ? 0 : 1;
geod_polygon_init(&p, 1);
- geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, 0, &perim);
+ geod_polygon_testpoint(&g, &p, 1, 1, 0, 1, nullptr, &perim);
result += perim == 0 ? 0 : 1;
- geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, 0, &perim);
+ geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, nullptr, &perim);
result += checkNaN(perim);
- geod_polygon_compute(&g, &p, 0, 1, 0, &perim);
+ geod_polygon_compute(&g, &p, 0, 1, nullptr, &perim);
result += perim == 0 ? 0 : 1;
geod_polygon_addpoint(&g, &p, 1, 1);
- geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, 0, &perim);
+ geod_polygon_testedge(&g, &p, 90, 1000, 0, 1, nullptr, &perim);
result += checkEquals(perim, 1000, 1e-10);
- geod_polygon_testpoint(&g, &p, 2, 2, 0, 1, 0, &perim);
+ geod_polygon_testpoint(&g, &p, 2, 2, 0, 1, nullptr, &perim);
result += checkEquals(perim, 156876.149, 0.5e-3);
return result;
}
diff --git a/src/multistresstest.c b/src/tests/multistresstest.cpp
index b0bd5c9c..234783b3 100644
--- a/src/multistresstest.c
+++ b/src/tests/multistresstest.cpp
@@ -177,7 +177,7 @@ static TestItem test_list[] = {
static volatile int active_thread_count = 0;
-static projPJ* custom_pj_init_plus_ctx(projCtx ctx, const char* def)
+static projPJ custom_pj_init_plus_ctx(projCtx ctx, const char* def)
{
if( add_no_defs )
{
@@ -243,7 +243,7 @@ static void TestThread()
dst_pj_list[i] = custom_pj_init_plus_ctx( ctx, test->dst_def );
{
- int skipTest = (src_pj_list[i] == NULL || dst_pj_list[i] == NULL);
+ int skipTest = (src_pj_list[i] == nullptr || dst_pj_list[i] == nullptr);
if ( skipTest != test->skip )
fprintf( stderr, "Threaded projection initialization does not match unthreaded initialization\n" );
@@ -335,7 +335,7 @@ static void *PosixTestThread( void *pData )
{
(void)pData;
TestThread();
- return NULL;
+ return nullptr;
}
#endif
@@ -363,7 +363,7 @@ static int do_main(void)
src_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->src_def );
dst_pj = custom_pj_init_plus_ctx( pj_get_default_ctx(), test->dst_def );
- if( src_pj == NULL )
+ if( src_pj == nullptr )
{
printf( "Unable to translate:\n%s\n", test->src_def );
test->skip = 1;
@@ -371,7 +371,7 @@ static int do_main(void)
continue;
}
- if( dst_pj == NULL )
+ if( dst_pj == nullptr )
{
printf( "Unable to translate:\n%s\n", test->dst_def );
test->skip = 1;
@@ -439,7 +439,7 @@ static int do_main(void)
active_thread_count++;
pthread_create( &(ahThread[i]), &hThreadAttr,
- PosixTestThread, NULL );
+ PosixTestThread, nullptr );
}
printf( "%d test threads launched.\n", num_threads );
diff --git a/src/test228.c b/src/tests/test228.cpp
index 83d29f8f..fcacd7c9 100644
--- a/src/test228.c
+++ b/src/tests/test228.cpp
@@ -49,7 +49,7 @@ static void* thread_main(void* unused)
x = -5.2*DEG_TO_RAD;
y = 50*DEG_TO_RAD;
proj_ret = pj_transform(p_WGS84_proj,
- p_OSGB36_proj, 1, 1, &x, &y, NULL );
+ p_OSGB36_proj, 1, 1, &x, &y, nullptr );
x *= RAD_TO_DEG;
y *= RAD_TO_DEG;
/*printf("%.18f %.18f\n", x, y); */
@@ -60,7 +60,7 @@ static void* thread_main(void* unused)
pj_free (p_OSGB36_proj);
pj_free (p_WGS84_proj);
- return NULL;
+ return nullptr;
}
int main()
@@ -73,8 +73,8 @@ int main()
pthread_attr_init(&attr1);
pthread_attr_init(&attr2);
- pthread_create(&tid1, &attr1, thread_main, NULL);
- pthread_create(&tid2, &attr2, thread_main, NULL);
+ pthread_create(&tid1, &attr1, thread_main, nullptr);
+ pthread_create(&tid2, &attr2, thread_main, nullptr);
while(started != 2);
run = 1;
for(i=0;i<2;i++)
diff --git a/src/pj_transform.c b/src/transform.cpp
index 6982676e..433fc017 100644
--- a/src/pj_transform.c
+++ b/src/transform.cpp
@@ -31,23 +31,10 @@
#include <math.h>
#include <string.h>
+#include "proj.h"
#include "projects.h"
#include "geocent.h"
-
-/* Apply transformation to observation - in forward or inverse direction */
-/* Copied from proj.h */
-enum PJ_DIRECTION {
- PJ_FWD = 1, /* Forward */
- PJ_IDENT = 0, /* Do nothing */
- PJ_INV = -1 /* Inverse */
-};
-typedef enum PJ_DIRECTION PJ_DIRECTION;
-
-/* Copied from proj.h FIXME */
-int proj_errno_reset (const PJ *P);
-
-
static int adjust_axis( projCtx ctx, const char *axis, int denormalize_flag,
long point_count, int point_offset,
double *x, double *y, double *z );
@@ -140,7 +127,7 @@ static int geographic_to_cartesian (PJ *P, PJ_DIRECTION dir, long n, int dist, d
if (!P->is_geocent)
return 0;
- if ( z == NULL ) {
+ if ( z == nullptr ) {
pj_ctx_set_errno( pj_get_ctx(P), PJD_ERR_GEOCENTRIC);
return PJD_ERR_GEOCENTRIC;
}
@@ -195,10 +182,10 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double *
if (P->is_geocent)
return 0;
- if(P->fwd3d != NULL && !(z == NULL && P->is_latlong))
+ if(P->fwd3d != nullptr && !(z == nullptr && P->is_latlong))
{
/* Three dimensions must be defined */
- if ( z == NULL)
+ if ( z == nullptr)
{
pj_ctx_set_errno( pj_get_ctx(P), PJD_ERR_GEOCENTRIC);
return PJD_ERR_GEOCENTRIC;
@@ -209,11 +196,11 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double *
XYZ projected_loc;
LPZ geodetic_loc;
- geodetic_loc.u = x[dist*i];
- geodetic_loc.v = y[dist*i];
- geodetic_loc.w = z[dist*i];
+ geodetic_loc.lam = x[dist*i];
+ geodetic_loc.phi = y[dist*i];
+ geodetic_loc.z = z[dist*i];
- if (geodetic_loc.u == HUGE_VAL)
+ if (geodetic_loc.lam == HUGE_VAL)
continue;
proj_errno_reset( P );
@@ -230,15 +217,15 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double *
}
else
{
- projected_loc.u = HUGE_VAL;
- projected_loc.v = HUGE_VAL;
- projected_loc.w = HUGE_VAL;
+ projected_loc.x = HUGE_VAL;
+ projected_loc.y = HUGE_VAL;
+ projected_loc.z = HUGE_VAL;
}
}
- x[dist*i] = projected_loc.u;
- y[dist*i] = projected_loc.v;
- z[dist*i] = projected_loc.w;
+ x[dist*i] = projected_loc.x;
+ y[dist*i] = projected_loc.y;
+ z[dist*i] = projected_loc.z;
}
return 0;
}
@@ -248,10 +235,10 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double *
XY projected_loc;
LP geodetic_loc;
- geodetic_loc.u = x[dist*i];
- geodetic_loc.v = y[dist*i];
+ geodetic_loc.lam = x[dist*i];
+ geodetic_loc.phi = y[dist*i];
- if( geodetic_loc.u == HUGE_VAL )
+ if( geodetic_loc.lam == HUGE_VAL )
continue;
proj_errno_reset( P );
@@ -268,13 +255,13 @@ static int geographic_to_projected (PJ *P, long n, int dist, double *x, double *
}
else
{
- projected_loc.u = HUGE_VAL;
- projected_loc.v = HUGE_VAL;
+ projected_loc.x = HUGE_VAL;
+ projected_loc.y = HUGE_VAL;
}
}
- x[dist*i] = projected_loc.u;
- y[dist*i] = projected_loc.v;
+ x[dist*i] = projected_loc.x;
+ y[dist*i] = projected_loc.y;
}
return 0;
}
@@ -296,7 +283,7 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *
return 0;
/* Check first if projection is invertible. */
- if( (P->inv3d == NULL) && (P->inv == NULL))
+ if( (P->inv3d == nullptr) && (P->inv == nullptr))
{
pj_ctx_set_errno(pj_get_ctx(P), PJD_ERR_NON_CONV_INV_MERI_DIST);
pj_log( pj_get_ctx(P), PJ_LOG_ERROR,
@@ -305,10 +292,10 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *
}
/* If invertible - First try inv3d if defined */
- if (P->inv3d != NULL && !(z == NULL && P->is_latlong))
+ if (P->inv3d != nullptr && !(z == nullptr && P->is_latlong))
{
/* Three dimensions must be defined */
- if ( z == NULL)
+ if ( z == nullptr)
{
pj_ctx_set_errno( pj_get_ctx(P), PJD_ERR_GEOCENTRIC);
return PJD_ERR_GEOCENTRIC;
@@ -317,13 +304,13 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *
for (i=0; i < n; i++)
{
XYZ projected_loc;
- XYZ geodetic_loc;
+ LPZ geodetic_loc;
- projected_loc.u = x[dist*i];
- projected_loc.v = y[dist*i];
- projected_loc.w = z[dist*i];
+ projected_loc.x = x[dist*i];
+ projected_loc.y = y[dist*i];
+ projected_loc.z = z[dist*i];
- if (projected_loc.u == HUGE_VAL)
+ if (projected_loc.x == HUGE_VAL)
continue;
proj_errno_reset( P );
@@ -340,15 +327,15 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *
}
else
{
- geodetic_loc.u = HUGE_VAL;
- geodetic_loc.v = HUGE_VAL;
- geodetic_loc.w = HUGE_VAL;
+ geodetic_loc.lam = HUGE_VAL;
+ geodetic_loc.phi = HUGE_VAL;
+ geodetic_loc.z = HUGE_VAL;
}
}
- x[dist*i] = geodetic_loc.u;
- y[dist*i] = geodetic_loc.v;
- z[dist*i] = geodetic_loc.w;
+ x[dist*i] = geodetic_loc.lam;
+ y[dist*i] = geodetic_loc.phi;
+ z[dist*i] = geodetic_loc.z;
}
return 0;
@@ -359,10 +346,10 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *
XY projected_loc;
LP geodetic_loc;
- projected_loc.u = x[dist*i];
- projected_loc.v = y[dist*i];
+ projected_loc.x = x[dist*i];
+ projected_loc.y = y[dist*i];
- if( projected_loc.u == HUGE_VAL )
+ if( projected_loc.x == HUGE_VAL )
continue;
proj_errno_reset( P );
@@ -379,13 +366,13 @@ static int projected_to_geographic (PJ *P, long n, int dist, double *x, double *
}
else
{
- geodetic_loc.u = HUGE_VAL;
- geodetic_loc.v = HUGE_VAL;
+ geodetic_loc.lam = HUGE_VAL;
+ geodetic_loc.phi = HUGE_VAL;
}
}
- x[dist*i] = geodetic_loc.u;
- y[dist*i] = geodetic_loc.v;
+ x[dist*i] = geodetic_loc.lam;
+ y[dist*i] = geodetic_loc.phi;
}
return 0;
}
@@ -430,7 +417,7 @@ static int height_unit (PJ *P, PJ_DIRECTION dir, long n, int dist, double *z) {
/* Nothing to do? */
if (fac==1.0)
return 0;
- if (0==z)
+ if (nullptr==z)
return 0;
if (P->is_latlong)
return 0; /* done in pj_inv3d() / pj_fwd3d() */
@@ -451,7 +438,7 @@ static int geometric_to_orthometric (PJ *P, PJ_DIRECTION dir, long n, int dist,
int err;
if (0==P->has_geoid_vgrids)
return 0;
- if (z==0)
+ if (z==nullptr)
return PJD_ERR_GEOCENTRIC;
err = pj_apply_vgridshift (P, "sgeoidgrids",
&(P->vgridlist_geoid),
@@ -713,7 +700,7 @@ int pj_compare_datums( PJ *srcdefn, PJ *dstdefn )
pj_param(srcdefn->ctx, srcdefn->params,"snadgrids").s;
const char* dstnadgrids =
pj_param(dstdefn->ctx, dstdefn->params,"snadgrids").s;
- return srcnadgrids != 0 && dstnadgrids != 0 &&
+ return srcnadgrids != nullptr && dstnadgrids != nullptr &&
strcmp( srcnadgrids, dstnadgrids ) == 0;
}
else
@@ -859,7 +846,7 @@ int pj_datum_transform( PJ *src, PJ *dst,
/* -------------------------------------------------------------------- */
/* Create a temporary Z array if one is not provided. */
/* -------------------------------------------------------------------- */
- if( z == NULL )
+ if( z == nullptr )
{
size_t bytes = sizeof(double) * point_count * point_offset;
z = (double *) pj_malloc(bytes);
@@ -1024,7 +1011,7 @@ static int adjust_axis( projCtx ctx,
{
double *target;
- if( i_axis == 2 && z == NULL )
+ if( i_axis == 2 && z == nullptr )
continue;
if( i_axis == 0 )
diff --git a/src/PJ_affine.c b/src/transformations/affine.cpp
index 0d8b6374..e2b668d3 100644
--- a/src/PJ_affine.c
+++ b/src/transformations/affine.cpp
@@ -32,6 +32,7 @@
PROJ_HEAD(affine, "Affine transformation");
PROJ_HEAD(geogoffset, "Geographic Offset");
+namespace { // anonymous namespace
struct pj_affine_coeffs {
double s11;
double s12;
@@ -44,7 +45,9 @@ struct pj_affine_coeffs {
double s33;
double tscale;
};
+} // anonymous namespace
+namespace { // anonymous namespace
struct pj_opaque_affine {
double xoff;
double yoff;
@@ -53,6 +56,7 @@ struct pj_opaque_affine {
struct pj_affine_coeffs forward;
struct pj_affine_coeffs reverse;
};
+} // anonymous namespace
static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) {
@@ -107,9 +111,9 @@ static LP reverse_2d(XY xy, PJ *P) {
}
static struct pj_opaque_affine * initQ() {
- struct pj_opaque_affine *Q = pj_calloc(1, sizeof(struct pj_opaque_affine));
- if (0==Q)
- return 0;
+ struct pj_opaque_affine *Q = static_cast<struct pj_opaque_affine *>(pj_calloc(1, sizeof(struct pj_opaque_affine)));
+ if (nullptr==Q)
+ return nullptr;
/* default values */
Q->forward.s11 = 1.0;
@@ -153,9 +157,9 @@ static void computeReverseParameters(PJ* P)
if (proj_log_level(P->ctx, PJ_LOG_TELL) >= PJ_LOG_DEBUG) {
proj_log_debug(P, "Affine: matrix non invertible");
}
- P->inv4d = NULL;
- P->inv3d = NULL;
- P->inv = NULL;
+ P->inv4d = nullptr;
+ P->inv3d = nullptr;
+ P->inv = nullptr;
} else {
Q->reverse.s11 = A / det;
Q->reverse.s12 = D / det;
@@ -172,7 +176,7 @@ static void computeReverseParameters(PJ* P)
PJ *TRANSFORMATION(affine,0 /* no need for ellipsoid */) {
struct pj_opaque_affine *Q = initQ();
- if (0==Q)
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = (void *) Q;
@@ -223,7 +227,7 @@ PJ *TRANSFORMATION(affine,0 /* no need for ellipsoid */) {
PJ *TRANSFORMATION(geogoffset,0 /* no need for ellipsoid */) {
struct pj_opaque_affine *Q = initQ();
- if (0==Q)
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = (void *) Q;
diff --git a/src/PJ_deformation.c b/src/transformations/deformation.cpp
index 5511eed4..6c30f21c 100644
--- a/src/PJ_deformation.c
+++ b/src/transformations/deformation.cpp
@@ -63,11 +63,13 @@ PROJ_HEAD(deformation, "Kinematic grid shift");
#define TOL 1e-8
#define MAX_ITERATIONS 10
+namespace { // anonymous namespace
struct pj_opaque {
double t_obs;
double t_epoch;
PJ *cart;
};
+} // anonymous namespace
/********************************************************************************/
static XYZ get_grid_shift(PJ* P, XYZ cartesian) {
@@ -86,7 +88,7 @@ static XYZ get_grid_shift(PJ* P, XYZ cartesian) {
int previous_errno = proj_errno_reset(P);
/* cartesian to geodetic */
- geodetic.lpz = pj_inv3d(cartesian, P->opaque->cart);
+ geodetic.lpz = pj_inv3d(cartesian, static_cast<struct pj_opaque*>(P->opaque)->cart);
/* look up correction values in grids */
shift.lp = proj_hgrid_value(P, geodetic.lp);
@@ -245,15 +247,15 @@ static PJ_COORD reverse_4d(PJ_COORD in, PJ *P) {
return out;
}
-static void *destructor(PJ *P, int errlev) {
- if (0==P)
- return 0;
+static PJ *destructor(PJ *P, int errlev) {
+ if (nullptr==P)
+ return nullptr;
- if (0==P->opaque)
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
- if (P->opaque->cart)
- P->opaque->cart->destructor (P->opaque->cart, errlev);
+ if (static_cast<struct pj_opaque*>(P->opaque)->cart)
+ static_cast<struct pj_opaque*>(P->opaque)->cart->destructor (static_cast<struct pj_opaque*>(P->opaque)->cart, errlev);
return pj_default_destructor(P, errlev);
}
@@ -262,13 +264,13 @@ static void *destructor(PJ *P, int errlev) {
PJ *TRANSFORMATION(deformation,1) {
int has_xy_grids = 0;
int has_z_grids = 0;
- struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque));
- if (0==Q)
+ struct pj_opaque *Q = static_cast<struct pj_opaque*>(pj_calloc (1, sizeof (struct pj_opaque)));
+ if (nullptr==Q)
return destructor(P, ENOMEM);
P->opaque = (void *) Q;
Q->cart = proj_create(P->ctx, "+proj=cart");
- if (Q->cart == 0)
+ if (Q->cart == nullptr)
return destructor(P, ENOMEM);
/* inherit ellipsoid definition from P to Q->cart */
@@ -311,8 +313,8 @@ PJ *TRANSFORMATION(deformation,1) {
P->inv4d = reverse_4d;
P->fwd3d = forward_3d;
P->inv3d = reverse_3d;
- P->fwd = 0;
- P->inv = 0;
+ P->fwd = nullptr;
+ P->inv = nullptr;
P->left = PJ_IO_UNITS_CARTESIAN;
P->right = PJ_IO_UNITS_CARTESIAN;
diff --git a/src/PJ_helmert.c b/src/transformations/helmert.cpp
index 757cf950..4a3abf4e 100644
--- a/src/PJ_helmert.c
+++ b/src/transformations/helmert.cpp
@@ -65,6 +65,7 @@ static LPZ helmert_reverse_3d (XYZ xyz, PJ *P);
/***********************************************************************/
+namespace { // anonymous namespace
struct pj_opaque_helmert {
/************************************************************************
Projection specific elements for the "helmert" PJ object
@@ -87,6 +88,7 @@ struct pj_opaque_helmert {
int no_rotation, exact, fourparam;
int is_position_vector; /* 1 = position_vector, 0 = coordinate_frame */
};
+} // anonymous namespace
/* Make the maths of the rotation operations somewhat more readable and textbook like */
@@ -476,8 +478,8 @@ static PJ_COORD helmert_reverse_4d (PJ_COORD point, PJ *P) {
static PJ* init_helmert_six_parameters(PJ* P) {
- struct pj_opaque_helmert *Q = pj_calloc (1, sizeof (struct pj_opaque_helmert));
- if (0==Q)
+ struct pj_opaque_helmert *Q = static_cast<struct pj_opaque_helmert*>(pj_calloc (1, sizeof (struct pj_opaque_helmert)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;
@@ -558,7 +560,7 @@ PJ *TRANSFORMATION(helmert, 0) {
struct pj_opaque_helmert *Q;
if( !init_helmert_six_parameters(P) ) {
- return 0;
+ return nullptr;
}
/* In the 2D case, the coordinates are projected */
@@ -661,7 +663,7 @@ PJ *TRANSFORMATION(helmert, 0) {
}
if( !read_convention(P) ) {
- return 0;
+ return nullptr;
}
/* Let's help with debugging */
@@ -697,7 +699,7 @@ PJ *TRANSFORMATION(molobadekas, 0) {
struct pj_opaque_helmert *Q;
if( !init_helmert_six_parameters(P) ) {
- return 0;
+ return nullptr;
}
P->fwd3d = helmert_forward_3d;
@@ -714,7 +716,7 @@ PJ *TRANSFORMATION(molobadekas, 0) {
Q->scale = Q->scale_0;
if( !read_convention(P) ) {
- return 0;
+ return nullptr;
}
/* Reference point */
diff --git a/src/PJ_hgridshift.c b/src/transformations/hgridshift.cpp
index 2919a85c..f0e57251 100644
--- a/src/PJ_hgridshift.c
+++ b/src/transformations/hgridshift.cpp
@@ -10,16 +10,18 @@
PROJ_HEAD(hgridshift, "Horizontal grid shift");
+namespace { // anonymous namespace
struct pj_opaque_hgridshift {
double t_final;
double t_epoch;
};
+} // anonymous namespace
static XYZ forward_3d(LPZ lpz, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
point.lpz = lpz;
- if (P->gridlist != NULL) {
+ if (P->gridlist != nullptr) {
/* Only try the gridshift if at least one grid is loaded,
* otherwise just pass the coordinate through unchanged. */
point.lp = proj_hgrid_apply(P, point.lp, PJ_FWD);
@@ -33,7 +35,7 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
point.xyz = xyz;
- if (P->gridlist != NULL) {
+ if (P->gridlist != nullptr) {
/* Only try the gridshift if at least one grid is loaded,
* otherwise just pass the coordinate through unchanged. */
point.lp = proj_hgrid_apply(P, point.lp, PJ_INV);
@@ -79,8 +81,8 @@ static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
PJ *TRANSFORMATION(hgridshift,0) {
- struct pj_opaque_hgridshift *Q = pj_calloc (1, sizeof (struct pj_opaque_hgridshift));
- if (0==Q)
+ struct pj_opaque_hgridshift *Q = static_cast<struct pj_opaque_hgridshift*>(pj_calloc (1, sizeof (struct pj_opaque_hgridshift)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;
@@ -88,8 +90,8 @@ PJ *TRANSFORMATION(hgridshift,0) {
P->inv4d = reverse_4d;
P->fwd3d = forward_3d;
P->inv3d = reverse_3d;
- P->fwd = 0;
- P->inv = 0;
+ P->fwd = nullptr;
+ P->inv = nullptr;
P->left = PJ_IO_UNITS_ANGULAR;
P->right = PJ_IO_UNITS_ANGULAR;
diff --git a/src/PJ_horner.c b/src/transformations/horner.cpp
index a6a26e52..73977de6 100644
--- a/src/PJ_horner.c
+++ b/src/transformations/horner.cpp
@@ -92,13 +92,7 @@ PROJ_HEAD(horner, "Horner polynomial evaluation");
#define horner_dealloc(x) pj_dealloc(x)
#define horner_calloc(n,x) pj_calloc(n,x)
-
-struct horner;
-typedef struct horner HORNER;
-static UV horner (const HORNER *transformation, PJ_DIRECTION direction, UV position);
-static HORNER *horner_alloc (size_t order, int complex_polynomia);
-static void horner_free (HORNER *h);
-
+namespace { // anonymous namespace
struct horner {
int uneg; /* u axis negated? */
int vneg; /* v axis negated? */
@@ -118,6 +112,12 @@ struct horner {
UV *fwd_origin; /* False longitude/latitude */
UV *inv_origin; /* False easting/northing */
};
+} // anonymous namespace
+
+typedef struct horner HORNER;
+static UV horner_func (const HORNER *transformation, PJ_DIRECTION direction, UV position);
+static HORNER *horner_alloc (size_t order, int complex_polynomia);
+static void horner_free (HORNER *h);
/* e.g. degree = 2: a + bx + cy + dxx + eyy + fxy, i.e. 6 coefficients */
#define horner_number_of_coefficients(order) \
@@ -141,10 +141,10 @@ static HORNER *horner_alloc (size_t order, int complex_polynomia) {
/* size_t is unsigned, so we need not check for order > 0 */
int n = (int)horner_number_of_coefficients(order);
int polynomia_ok = 0;
- HORNER *h = horner_calloc (1, sizeof (HORNER));
+ HORNER *h = static_cast<HORNER*>(horner_calloc (1, sizeof (HORNER)));
- if (0==h)
- return 0;
+ if (nullptr==h)
+ return nullptr;
if (complex_polynomia)
n = 2*(int)order + 2;
@@ -152,36 +152,36 @@ static HORNER *horner_alloc (size_t order, int complex_polynomia) {
h->coefs = n;
if (complex_polynomia) {
- h->fwd_c = horner_calloc (n, sizeof(double));
- h->inv_c = horner_calloc (n, sizeof(double));
+ h->fwd_c = static_cast<double*>(horner_calloc (n, sizeof(double)));
+ h->inv_c = static_cast<double*>(horner_calloc (n, sizeof(double)));
if (h->fwd_c && h->inv_c)
polynomia_ok = 1;
}
else {
- h->fwd_u = horner_calloc (n, sizeof(double));
- h->fwd_v = horner_calloc (n, sizeof(double));
- h->inv_u = horner_calloc (n, sizeof(double));
- h->inv_v = horner_calloc (n, sizeof(double));
+ h->fwd_u = static_cast<double*>(horner_calloc (n, sizeof(double)));
+ h->fwd_v = static_cast<double*>(horner_calloc (n, sizeof(double)));
+ h->inv_u = static_cast<double*>(horner_calloc (n, sizeof(double)));
+ h->inv_v = static_cast<double*>(horner_calloc (n, sizeof(double)));
if (h->fwd_u && h->fwd_v && h->inv_u && h->inv_v)
polynomia_ok = 1;
}
- h->fwd_origin = horner_calloc (1, sizeof(UV));
- h->inv_origin = horner_calloc (1, sizeof(UV));
+ h->fwd_origin = static_cast<UV*>(horner_calloc (1, sizeof(UV)));
+ h->inv_origin = static_cast<UV*>(horner_calloc (1, sizeof(UV)));
if (polynomia_ok && h->fwd_origin && h->inv_origin)
return h;
/* safe, since all pointers are null-initialized (by calloc) */
horner_free (h);
- return 0;
+ return nullptr;
}
/**********************************************************************/
-static UV horner (const HORNER *transformation, PJ_DIRECTION direction, UV position) {
+static UV horner_func (const HORNER *transformation, PJ_DIRECTION direction, UV position) {
/***********************************************************************
A reimplementation of the classic Engsager/Poder 2D Horner polynomial
@@ -226,7 +226,7 @@ summing the tiny high order elements first.
UV uv_error;
uv_error.u = uv_error.v = HUGE_VAL;
- if (0==transformation)
+ if (nullptr==transformation)
return uv_error;
/* Check for valid value of direction (-1, 0, 1) */
@@ -297,12 +297,12 @@ summing the tiny high order elements first.
static PJ_COORD horner_forward_4d (PJ_COORD point, PJ *P) {
- point.uv = horner ((HORNER *) P->opaque, 1, point.uv);
+ point.uv = horner_func ((HORNER *) P->opaque, PJ_FWD, point.uv);
return point;
}
static PJ_COORD horner_reverse_4d (PJ_COORD point, PJ *P) {
- point.uv = horner ((HORNER *) P->opaque, -1, point.uv);
+ point.uv = horner_func ((HORNER *) P->opaque, PJ_INV, point.uv);
return point;
}
@@ -326,7 +326,7 @@ polynomial evaluation engine.
UV uv_error;
uv_error.u = uv_error.v = HUGE_VAL;
- if (0==transformation)
+ if (nullptr==transformation)
return uv_error;
/* Check for valid value of direction (-1, 0, 1) */
@@ -397,23 +397,23 @@ static PJ_COORD complex_horner_reverse_4d (PJ_COORD point, PJ *P) {
}
-static void *horner_freeup (PJ *P, int errlev) { /* Destructor */
- if (0==P)
- return 0;
- if (0==P->opaque)
+static PJ *horner_freeup (PJ *P, int errlev) { /* Destructor */
+ if (nullptr==P)
+ return nullptr;
+ if (nullptr==P->opaque)
return pj_default_destructor (P, errlev);
horner_free ((HORNER *) P->opaque);
- P->opaque = 0;
+ P->opaque = nullptr;
return pj_default_destructor (P, errlev);
}
-static int parse_coefs (PJ *P, double *coefs, char *param, int ncoefs) {
- char *buf, *init, *next = 0;
+static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) {
+ char *buf, *init, *next = nullptr;
int i;
- buf = pj_calloc (strlen (param) + 2, sizeof(char));
- if (0==buf) {
+ buf = static_cast<char*>(pj_calloc (strlen (param) + 2, sizeof(char)));
+ if (nullptr==buf) {
proj_log_error (P, "Horner: No memory left");
return 0;
}
@@ -429,7 +429,7 @@ static int parse_coefs (PJ *P, double *coefs, char *param, int ncoefs) {
for (i = 0; i < ncoefs; i++) {
if (i > 0) {
- if ( next == 0 || ','!=*next) {
+ if ( next == nullptr || ','!=*next) {
proj_log_error (P, "Horner: Malformed polynomium set %s. need %d coefs", param, ncoefs);
return 0;
}
@@ -448,10 +448,10 @@ PJ *PROJECTION(horner) {
HORNER *Q;
P->fwd4d = horner_forward_4d;
P->inv4d = horner_reverse_4d;
- P->fwd3d = 0;
- P->inv3d = 0;
- P->fwd = 0;
- P->inv = 0;
+ P->fwd3d = nullptr;
+ P->inv3d = nullptr;
+ P->fwd = nullptr;
+ P->inv = nullptr;
P->left = P->right = PJ_IO_UNITS_PROJECTED;
P->destructor = horner_freeup;
@@ -472,9 +472,9 @@ PJ *PROJECTION(horner) {
complex_polynomia = 1;
Q = horner_alloc (degree, complex_polynomia);
- if (Q == 0)
+ if (Q == nullptr)
return horner_freeup (P, ENOMEM);
- P->opaque = (void *) Q;
+ P->opaque = Q;
if (complex_polynomia) {
/* Westings and/or southings? */
diff --git a/src/PJ_molodensky.c b/src/transformations/molodensky.cpp
index dbc83768..91743fda 100644
--- a/src/PJ_molodensky.c
+++ b/src/transformations/molodensky.cpp
@@ -56,6 +56,7 @@ PROJ_HEAD(molodensky, "Molodensky transform");
static XYZ forward_3d(LPZ lpz, PJ *P);
static LPZ reverse_3d(XYZ xyz, PJ *P);
+namespace { // anonymous namespace
struct pj_opaque_molodensky {
double dx;
double dy;
@@ -64,6 +65,7 @@ struct pj_opaque_molodensky {
double df;
int abridged;
};
+} // anonymous namespace
static double RN (double a, double es, double phi) {
@@ -273,8 +275,8 @@ static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
PJ *TRANSFORMATION(molodensky,1) {
int count_required_params = 0;
- struct pj_opaque_molodensky *Q = pj_calloc(1, sizeof(struct pj_opaque_molodensky));
- if (0==Q)
+ struct pj_opaque_molodensky *Q = static_cast<struct pj_opaque_molodensky*>(pj_calloc(1, sizeof(struct pj_opaque_molodensky)));
+ if (nullptr==Q)
return pj_default_destructor(P, ENOMEM);
P->opaque = (void *) Q;
diff --git a/src/PJ_vgridshift.c b/src/transformations/vgridshift.cpp
index ac5d26ef..b3da906d 100644
--- a/src/PJ_vgridshift.c
+++ b/src/transformations/vgridshift.cpp
@@ -10,18 +10,20 @@
PROJ_HEAD(vgridshift, "Vertical grid shift");
+namespace { // anonymous namespace
struct pj_opaque_vgridshift {
double t_final;
double t_epoch;
double forward_multiplier;
};
+} // anonymous namespace
static XYZ forward_3d(LPZ lpz, PJ *P) {
struct pj_opaque_vgridshift *Q = (struct pj_opaque_vgridshift *) P->opaque;
PJ_COORD point = {{0,0,0,0}};
point.lpz = lpz;
- if (P->vgridlist_geoid != NULL) {
+ if (P->vgridlist_geoid != nullptr) {
/* Only try the gridshift if at least one grid is loaded,
* otherwise just pass the coordinate through unchanged. */
point.xyz.z += Q->forward_multiplier * proj_vgrid_value(P, point.lp);
@@ -36,7 +38,7 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
PJ_COORD point = {{0,0,0,0}};
point.xyz = xyz;
- if (P->vgridlist_geoid != NULL) {
+ if (P->vgridlist_geoid != nullptr) {
/* Only try the gridshift if at least one grid is loaded,
* otherwise just pass the coordinate through unchanged. */
point.xyz.z -= Q->forward_multiplier * proj_vgrid_value(P, point.lp);
@@ -83,8 +85,8 @@ static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
PJ *TRANSFORMATION(vgridshift,0) {
- struct pj_opaque_vgridshift *Q = pj_calloc (1, sizeof (struct pj_opaque_vgridshift));
- if (0==Q)
+ struct pj_opaque_vgridshift *Q = static_cast<struct pj_opaque_vgridshift*>(pj_calloc (1, sizeof (struct pj_opaque_vgridshift)));
+ if (nullptr==Q)
return pj_default_destructor (P, ENOMEM);
P->opaque = (void *) Q;
@@ -132,8 +134,8 @@ PJ *TRANSFORMATION(vgridshift,0) {
P->inv4d = reverse_4d;
P->fwd3d = forward_3d;
P->inv3d = reverse_3d;
- P->fwd = 0;
- P->inv = 0;
+ P->fwd = nullptr;
+ P->inv = nullptr;
P->left = PJ_IO_UNITS_ANGULAR;
P->right = PJ_IO_UNITS_ANGULAR;
diff --git a/src/pj_tsfn.c b/src/tsfn.cpp
index ea3b896d..ea3b896d 100644
--- a/src/pj_tsfn.c
+++ b/src/tsfn.cpp
diff --git a/src/pj_units.c b/src/units.cpp
index 877758a3..50f11396 100644
--- a/src/pj_units.c
+++ b/src/units.cpp
@@ -33,7 +33,7 @@ pj_units[] = {
{"ind-yd", "0.91439523", "Indian Yard", 0.91439523},
{"ind-ft", "0.30479841", "Indian Foot", 0.30479841},
{"ind-ch", "20.11669506", "Indian Chain", 20.11669506},
- {NULL, NULL, NULL, 0.0}
+ {nullptr, nullptr, nullptr, 0.0}
};
const PJ_UNITS *proj_list_units()
@@ -49,7 +49,7 @@ pj_angular_units[] = {
{"rad", "1.0", "Radian", 1.0},
{"deg", "0.017453292519943296", "Degree", DEG_TO_RAD},
{"grad", "0.015707963267948967", "Grad", GRAD_TO_RAD},
- {NULL, NULL, NULL, 0.0}
+ {nullptr, nullptr, nullptr, 0.0}
};
const PJ_UNITS *proj_list_angular_units()
diff --git a/src/pj_utils.c b/src/utils.cpp
index 81a80b45..8587dc30 100644
--- a/src/pj_utils.c
+++ b/src/utils.cpp
@@ -43,7 +43,7 @@
int pj_is_latlong( PJ *pj )
{
- return pj == NULL || pj->is_latlong;
+ return pj == nullptr || pj->is_latlong;
}
/************************************************************************/
@@ -55,7 +55,7 @@ int pj_is_latlong( PJ *pj )
int pj_is_geocent( PJ *pj )
{
- return pj != NULL && pj->is_geocent;
+ return pj != nullptr && pj->is_geocent;
}
/************************************************************************/
@@ -118,7 +118,7 @@ PJ *pj_latlong_from_proj( PJ *pj_in )
{
pj_ctx_set_errno( pj_in->ctx, PJD_ERR_MAJOR_AXIS_NOT_GIVEN );
- return NULL;
+ return nullptr;
}
if( !got_datum )
diff --git a/src/vector1.c b/src/vector1.cpp
index 22e1f5d0..869dd76a 100644
--- a/src/vector1.c
+++ b/src/vector1.cpp
@@ -15,14 +15,14 @@ freev2(void **v, int nrows) {
vector2(int nrows, int ncols, int size) {
void **s;
- if ((s = (void **)pj_malloc(sizeof(void *) * nrows)) != NULL) {
+ if ((s = (void **)pj_malloc(sizeof(void *) * nrows)) != nullptr) {
int rsize, i;
rsize = size * ncols;
for (i = 0; i < nrows; ++i)
if (!(s[i] = pj_malloc(rsize))) {
freev2(s, i);
- return (void **)0;
+ return (void **)nullptr;
}
}
return s;
diff --git a/src/pj_wkt1_generated_parser.c b/src/wkt1_generated_parser.c
index 91d5e60d..7a590f80 100644
--- a/src/pj_wkt1_generated_parser.c
+++ b/src/wkt1_generated_parser.c
@@ -97,7 +97,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#include "pj_wkt1_parser.h"
+#include "wkt1_parser.h"
@@ -119,9 +119,9 @@
#endif
/* In a future release of Bison, this section will be replaced
- by #include "pj_wkt1_generated_parser.h". */
-#ifndef YY_PJ_WKT1_SRC_PJ_WKT1_GENERATED_PARSER_H_INCLUDED
-# define YY_PJ_WKT1_SRC_PJ_WKT1_GENERATED_PARSER_H_INCLUDED
+ by #include "wkt1_generated_parser.h". */
+#ifndef YY_PJ_WKT1_SRC_WKT1_GENERATED_PARSER_H_INCLUDED
+# define YY_PJ_WKT1_SRC_WKT1_GENERATED_PARSER_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -176,7 +176,7 @@ typedef int YYSTYPE;
int pj_wkt1_parse (pj_wkt1_parse_context *context);
-#endif /* !YY_PJ_WKT1_SRC_PJ_WKT1_GENERATED_PARSER_H_INCLUDED */
+#endif /* !YY_PJ_WKT1_SRC_WKT1_GENERATED_PARSER_H_INCLUDED */
/* Copy the second part of user declarations. */
diff --git a/src/pj_wkt1_generated_parser.h b/src/wkt1_generated_parser.h
index 7bdec61f..989f1f32 100644
--- a/src/pj_wkt1_generated_parser.h
+++ b/src/wkt1_generated_parser.h
@@ -30,8 +30,8 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
-#ifndef YY_PJ_WKT1_SRC_PJ_WKT1_GENERATED_PARSER_H_INCLUDED
-# define YY_PJ_WKT1_SRC_PJ_WKT1_GENERATED_PARSER_H_INCLUDED
+#ifndef YY_PJ_WKT1_SRC_WKT1_GENERATED_PARSER_H_INCLUDED
+# define YY_PJ_WKT1_SRC_WKT1_GENERATED_PARSER_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -86,4 +86,4 @@ typedef int YYSTYPE;
int pj_wkt1_parse (pj_wkt1_parse_context *context);
-#endif /* !YY_PJ_WKT1_SRC_PJ_WKT1_GENERATED_PARSER_H_INCLUDED */
+#endif /* !YY_PJ_WKT1_SRC_WKT1_GENERATED_PARSER_H_INCLUDED */
diff --git a/src/pj_wkt1_grammar.y b/src/wkt1_grammar.y
index 05ae792a..28ff7a6e 100644
--- a/src/pj_wkt1_grammar.y
+++ b/src/wkt1_grammar.y
@@ -26,7 +26,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#include "pj_wkt1_parser.h"
+#include "wkt1_parser.h"
%}
diff --git a/src/pj_wkt1_parser.cpp b/src/wkt1_parser.cpp
index cdeb6b87..9db7d4bd 100644
--- a/src/pj_wkt1_parser.cpp
+++ b/src/wkt1_parser.cpp
@@ -35,8 +35,8 @@
#include <cstring>
#include <string>
-#include "pj_wkt1_parser.h"
-#include "pj_wkt_parser.hpp"
+#include "wkt1_parser.h"
+#include "wkt_parser.hpp"
using namespace NS_PROJ::internal;
diff --git a/src/pj_wkt1_parser.h b/src/wkt1_parser.h
index f8f7c841..f04ee67f 100644
--- a/src/pj_wkt1_parser.h
+++ b/src/wkt1_parser.h
@@ -36,7 +36,7 @@ extern "C" {
typedef struct pj_wkt1_parse_context pj_wkt1_parse_context;
-#include "pj_wkt1_generated_parser.h"
+#include "wkt1_generated_parser.h"
void pj_wkt1_error( pj_wkt1_parse_context *context, const char *msg );
int pj_wkt1_lex(YYSTYPE* pNode, pj_wkt1_parse_context *context);
diff --git a/src/pj_wkt2_generated_parser.c b/src/wkt2_generated_parser.c
index 759ad052..6d816135 100644
--- a/src/pj_wkt2_generated_parser.c
+++ b/src/wkt2_generated_parser.c
@@ -97,7 +97,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#include "pj_wkt2_parser.h"
+#include "wkt2_parser.h"
@@ -119,9 +119,9 @@
#endif
/* In a future release of Bison, this section will be replaced
- by #include "pj_wkt2_generated_parser.h". */
-#ifndef YY_PJ_WKT2_SRC_PJ_WKT2_GENERATED_PARSER_H_INCLUDED
-# define YY_PJ_WKT2_SRC_PJ_WKT2_GENERATED_PARSER_H_INCLUDED
+ by #include "wkt2_generated_parser.h". */
+#ifndef YY_PJ_WKT2_SRC_WKT2_GENERATED_PARSER_H_INCLUDED
+# define YY_PJ_WKT2_SRC_WKT2_GENERATED_PARSER_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -295,7 +295,7 @@ typedef int YYSTYPE;
int pj_wkt2_parse (pj_wkt2_parse_context *context);
-#endif /* !YY_PJ_WKT2_SRC_PJ_WKT2_GENERATED_PARSER_H_INCLUDED */
+#endif /* !YY_PJ_WKT2_SRC_WKT2_GENERATED_PARSER_H_INCLUDED */
/* Copy the second part of user declarations. */
diff --git a/src/pj_wkt2_generated_parser.h b/src/wkt2_generated_parser.h
index f9d17ea0..baeb0b4f 100644
--- a/src/pj_wkt2_generated_parser.h
+++ b/src/wkt2_generated_parser.h
@@ -30,8 +30,8 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
-#ifndef YY_PJ_WKT2_SRC_PJ_WKT2_GENERATED_PARSER_H_INCLUDED
-# define YY_PJ_WKT2_SRC_PJ_WKT2_GENERATED_PARSER_H_INCLUDED
+#ifndef YY_PJ_WKT2_SRC_WKT2_GENERATED_PARSER_H_INCLUDED
+# define YY_PJ_WKT2_SRC_WKT2_GENERATED_PARSER_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
@@ -205,4 +205,4 @@ typedef int YYSTYPE;
int pj_wkt2_parse (pj_wkt2_parse_context *context);
-#endif /* !YY_PJ_WKT2_SRC_PJ_WKT2_GENERATED_PARSER_H_INCLUDED */
+#endif /* !YY_PJ_WKT2_SRC_WKT2_GENERATED_PARSER_H_INCLUDED */
diff --git a/src/pj_wkt2_grammar.y b/src/wkt2_grammar.y
index 2c8393e2..f028eb5b 100644
--- a/src/pj_wkt2_grammar.y
+++ b/src/wkt2_grammar.y
@@ -26,7 +26,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#include "pj_wkt2_parser.h"
+#include "wkt2_parser.h"
%}
diff --git a/src/pj_wkt2_parser.cpp b/src/wkt2_parser.cpp
index 0e898436..f77c7ceb 100644
--- a/src/pj_wkt2_parser.cpp
+++ b/src/wkt2_parser.cpp
@@ -36,8 +36,8 @@
#include <cstring>
#include <string>
-#include "pj_wkt2_parser.h"
-#include "pj_wkt_parser.hpp"
+#include "wkt2_parser.h"
+#include "wkt_parser.hpp"
using namespace NS_PROJ::internal;
diff --git a/src/pj_wkt2_parser.h b/src/wkt2_parser.h
index 9229f2ff..1eaadab6 100644
--- a/src/pj_wkt2_parser.h
+++ b/src/wkt2_parser.h
@@ -36,7 +36,7 @@ extern "C" {
typedef struct pj_wkt2_parse_context pj_wkt2_parse_context;
-#include "pj_wkt2_generated_parser.h"
+#include "wkt2_generated_parser.h"
void pj_wkt2_error( pj_wkt2_parse_context *context, const char *msg );
int pj_wkt2_lex(YYSTYPE* pNode, pj_wkt2_parse_context *context);
diff --git a/src/pj_wkt_parser.cpp b/src/wkt_parser.cpp
index ea8d2a29..32fc4e34 100644
--- a/src/pj_wkt_parser.cpp
+++ b/src/wkt_parser.cpp
@@ -25,7 +25,7 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
-#include "pj_wkt_parser.hpp"
+#include "wkt_parser.hpp"
#include <algorithm>
#include <string>
diff --git a/src/pj_wkt_parser.hpp b/src/wkt_parser.hpp
index 0e7e9e8b..0e7e9e8b 100644
--- a/src/pj_wkt_parser.hpp
+++ b/src/wkt_parser.hpp
diff --git a/src/pj_zpoly1.c b/src/zpoly1.cpp
index bacb62ce..bacb62ce 100644
--- a/src/pj_zpoly1.c
+++ b/src/zpoly1.cpp