aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Knudsen <thokn@sdfe.dk>2018-02-11 17:29:17 +0100
committerThomas Knudsen <thokn@sdfe.dk>2018-02-12 11:19:32 +0100
commitcc26b288fe0a208468068726bc4b38f4cf05ba47 (patch)
treed19742da6d82541aecb2e3384cd7dca969be3cce
parente1a213b2d9a29d86b89547781a2e27d5fd01f111 (diff)
downloadPROJ-cc26b288fe0a208468068726bc4b38f4cf05ba47.tar.gz
PROJ-cc26b288fe0a208468068726bc4b38f4cf05ba47.zip
typedef some recurring function signatures
-rw-r--r--src/pj_init.c10
-rw-r--r--src/projects.h37
2 files changed, 38 insertions, 9 deletions
diff --git a/src/pj_init.c b/src/pj_init.c
index f54a2a92..3c36fc3a 100644
--- a/src/pj_init.c
+++ b/src/pj_init.c
@@ -470,22 +470,20 @@ pj_init(int argc, char **argv) {
}
-typedef PJ *(constructor)(PJ *);
-
-static constructor *pj_constructor (const char *name) {
+static PJ_CONSTRUCTOR pj_locate_constructor (const char *name) {
int i;
char *s;
for (i = 0; (s = pj_list[i].id) && strcmp(name, s) ; ++i) ;
if (0==s)
return 0;
- return (constructor *) pj_list[i].proj;
+ return (PJ_CONSTRUCTOR) pj_list[i].proj;
}
PJ *
pj_init_ctx(projCtx ctx, int argc, char **argv) {
char *s, *name;
- constructor *proj;
+ PJ_CONSTRUCTOR proj;
paralist *curr, *init, *start;
int i;
int err;
@@ -559,7 +557,7 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
return pj_dealloc_params (ctx, start, PJD_ERR_PROJ_NOT_NAMED);
name += 5;
- proj = pj_constructor (name);
+ proj = pj_locate_constructor (name);
if (0==proj)
return pj_dealloc_params (ctx, start, PJD_ERR_UNKNOWN_PROJECTION_ID);
diff --git a/src/projects.h b/src/projects.h
index bfbe08cb..25ff82a4 100644
--- a/src/projects.h
+++ b/src/projects.h
@@ -218,6 +218,37 @@ struct PJ_AREA {
struct projCtx_t;
typedef struct projCtx_t projCtx_t;
+/*****************************************************************************
+
+ Some function types that are especially useful when working with PJs
+
+******************************************************************************
+
+PJ_CONSTRUCTOR:
+
+ A function taking a pointer-to-PJ as arg, and returning a pointer-to-PJ.
+ Historically called twice: First with a 0 argument, to allocate memory,
+ second with the first return value as argument, for actual setup.
+
+PJ_DESTRUCTOR:
+
+ A function taking a pointer-to-PJ and an integer as args, then first
+ handling the deallocation of the PJ, afterwards handing the integer over
+ to the error reporting subsystem, and finally returning a null pointer in
+ support of the "return free (P)" (aka "get the hell out of here") idiom.
+
+PJ_OPERATOR:
+
+ A function taking a PJ_COORD and a pointer-to-PJ as args, applying the
+ PJ to the PJ_COORD, and returning the resulting PJ_COORD.
+
+*****************************************************************************/
+typedef PJ *(* PJ_CONSTRUCTOR) (PJ *);
+typedef void *(* PJ_DESTRUCTOR) (PJ *, int);
+typedef PJ_COORD (* PJ_OPERATOR) (PJ_COORD, PJ *);
+/****************************************************************************/
+
+
/* base projection data structure */
struct PJconsts {
@@ -267,10 +298,10 @@ struct PJconsts {
LP (*inv)(XY, PJ *);
XYZ (*fwd3d)(LPZ, PJ *);
LPZ (*inv3d)(XYZ, PJ *);
- PJ_COORD (*fwd4d)(PJ_COORD, PJ *);
- PJ_COORD (*inv4d)(PJ_COORD, PJ *);
+ PJ_OPERATOR fwd4d;
+ PJ_OPERATOR inv4d;
- void *(*destructor)(PJ *, int);
+ PJ_DESTRUCTOR destructor;
/*************************************************************************************