Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Added proj_context_clone #2383

Merged
merged 3 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ m4/lt~obsolete.m4
/test/unit/proj_errno_string_test
/test/unit/test_defmodel
/test/unit/test_network
/test/unit/test_tinshift
/tmp_alias/

# jniwrap
Expand Down
8 changes: 8 additions & 0 deletions docs/source/development/reference/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ Threading contexts

:returns: a new context

.. c:function:: PJ_CONTEXT* proj_context_clone(PJ_CONTEXT *ctx)

.. versionadded:: 7.2

Create a new threading-context based on an existing context.

:returns: a new context

.. c:function:: void proj_context_destroy(PJ_CONTEXT *ctx)

Deallocate a threading-context.
Expand Down
2 changes: 2 additions & 0 deletions scripts/reference_exported_symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ pj_compare_datums
pj_context_get_grid_cache_filename(projCtx_t*)
pj_context_set_user_writable_directory(projCtx_t*, std::string const&)
pj_ctx_alloc
pj_ctx_clone
snowman2 marked this conversation as resolved.
Show resolved Hide resolved
pj_ctx_fclose
pj_ctx_fgets
pj_ctx_fopen
Expand Down Expand Up @@ -830,6 +831,7 @@ proj_cleanup
proj_clone
proj_concatoperation_get_step
proj_concatoperation_get_step_count
proj_context_clone
proj_context_create
proj_context_delete_cpp_context(projCppContext*)
proj_context_destroy
Expand Down
9 changes: 8 additions & 1 deletion src/4D_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,11 +1448,18 @@ int proj_errno_reset (const PJ *P) {
}


/* Create a new context */
/* Create a new context based on the default context */
PJ_CONTEXT *proj_context_create (void) {
return pj_ctx_alloc ();
}

/* Create a new context based on a custom context */
PJ_CONTEXT *proj_context_clone (PJ_CONTEXT *ctx) {
if (nullptr==ctx)
return pj_ctx_alloc ();

return pj_ctx_clone (ctx);
snowman2 marked this conversation as resolved.
Show resolved Hide resolved
}

PJ_CONTEXT *proj_context_destroy (PJ_CONTEXT *ctx) {
if (nullptr==ctx)
Expand Down
10 changes: 10 additions & 0 deletions src/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ projCtx pj_ctx_alloc()
return new (std::nothrow) projCtx_t(*pj_get_default_ctx());
}

/************************************************************************/
/* pj_ctx_clone() */
/************************************************************************/

projCtx pj_ctx_clone( projCtx ctx )
snowman2 marked this conversation as resolved.
Show resolved Hide resolved

{
return new (std::nothrow) projCtx_t(*ctx);
}

/************************************************************************/
/* pj_ctx_free() */
/************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/proj.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ typedef struct projCtx_t PJ_CONTEXT;
#endif
PJ_CONTEXT PROJ_DLL *proj_context_create (void);
PJ_CONTEXT PROJ_DLL *proj_context_destroy (PJ_CONTEXT *ctx);
PJ_CONTEXT PROJ_DLL *proj_context_clone (PJ_CONTEXT *ctx);

/** Callback to resolve a filename to a full path */
typedef const char* (*proj_file_finder) (PJ_CONTEXT *ctx, const char*, void* user_data);
Expand Down
1 change: 1 addition & 0 deletions src/proj_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void PROJ_DLL pj_cleanup_lock(void);

void PROJ_DLL pj_set_ctx( projPJ, projCtx );
projCtx PROJ_DLL pj_ctx_alloc(void);
projCtx PROJ_DLL pj_ctx_clone( projCtx );
snowman2 marked this conversation as resolved.
Show resolved Hide resolved
void PROJ_DLL pj_ctx_free( projCtx );
int PROJ_DLL pj_ctx_get_errno( projCtx );
void PROJ_DLL pj_ctx_set_errno( projCtx, int );
Expand Down
8 changes: 8 additions & 0 deletions src/proj_symbol_rename.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define pj_clear_initcache internal_pj_clear_initcache
#define pj_compare_datums internal_pj_compare_datums
#define pj_ctx_alloc internal_pj_ctx_alloc
#define pj_ctx_clone internal_pj_ctx_clone
snowman2 marked this conversation as resolved.
Show resolved Hide resolved
#define pj_ctx_fclose internal_pj_ctx_fclose
#define pj_ctx_fgets internal_pj_ctx_fgets
#define pj_ctx_fopen internal_pj_ctx_fopen
Expand Down Expand Up @@ -97,6 +98,7 @@
#define proj_clone internal_proj_clone
#define proj_concatoperation_get_step internal_proj_concatoperation_get_step
#define proj_concatoperation_get_step_count internal_proj_concatoperation_get_step_count
#define proj_context_clone internal_proj_context_clone
#define proj_context_create internal_proj_context_create
#define proj_context_destroy internal_proj_context_destroy
#define proj_context_errno internal_proj_context_errno
Expand Down Expand Up @@ -235,6 +237,8 @@
#define proj_crs_get_coordinate_system internal_proj_crs_get_coordinate_system
#define proj_crs_get_coordoperation internal_proj_crs_get_coordoperation
#define proj_crs_get_datum internal_proj_crs_get_datum
#define proj_crs_get_datum_ensemble internal_proj_crs_get_datum_ensemble
#define proj_crs_get_datum_forced internal_proj_crs_get_datum_forced
#define proj_crs_get_geodetic_crs internal_proj_crs_get_geodetic_crs
#define proj_crs_get_horizontal_datum internal_proj_crs_get_horizontal_datum
#define proj_crs_get_sub_crs internal_proj_crs_get_sub_crs
Expand All @@ -243,11 +247,15 @@
#define proj_cs_get_axis_count internal_proj_cs_get_axis_count
#define proj_cs_get_axis_info internal_proj_cs_get_axis_info
#define proj_cs_get_type internal_proj_cs_get_type
#define proj_datum_ensemble_get_accuracy internal_proj_datum_ensemble_get_accuracy
#define proj_datum_ensemble_get_member internal_proj_datum_ensemble_get_member
#define proj_datum_ensemble_get_member_count internal_proj_datum_ensemble_get_member_count
#define proj_degree_input internal_proj_degree_input
#define proj_degree_output internal_proj_degree_output
#define proj_destroy internal_proj_destroy
#define proj_dmstor internal_proj_dmstor
#define proj_download_file internal_proj_download_file
#define proj_dynamic_datum_get_frame_reference_epoch internal_proj_dynamic_datum_get_frame_reference_epoch
#define proj_ellipsoid_get_parameters internal_proj_ellipsoid_get_parameters
#define proj_errno internal_proj_errno
#define proj_errno_reset internal_proj_errno_reset
Expand Down
24 changes: 23 additions & 1 deletion test/unit/test_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,7 @@ TEST_F(Fixture_proj_context_set_autoclose_database,

// ---------------------------------------------------------------------------

TEST_F(CApi, proj_context_clone) {
TEST_F(CApi, proj_context_copy_from_default) {
auto c_path = proj_context_get_database_path(m_ctxt);
ASSERT_TRUE(c_path != nullptr);
std::string path(c_path);
Expand Down Expand Up @@ -4123,6 +4123,28 @@ TEST_F(CApi, proj_context_clone) {
ASSERT_EQ(new_db_path, tmp_filename);
}


// ---------------------------------------------------------------------------

TEST_F(CApi, proj_context_clone) {
int new_init_rules = proj_context_get_use_proj4_init_rules(NULL, 0) > 0 ? 0 : 1;
PJ_CONTEXT *new_ctx = proj_context_create();
EXPECT_NE(new_ctx, nullptr);
PjContextKeeper keeper_ctxt(new_ctx);
proj_context_use_proj4_init_rules(new_ctx, new_init_rules);
PJ_CONTEXT *clone_ctx = proj_context_clone(new_ctx);
EXPECT_NE(clone_ctx, nullptr);
PjContextKeeper keeper_clone_ctxt(clone_ctx);
ASSERT_EQ(
proj_context_get_use_proj4_init_rules(new_ctx, 0),
proj_context_get_use_proj4_init_rules(clone_ctx, 0)
);
EXPECT_NE(
proj_context_get_use_proj4_init_rules(NULL, 0),
proj_context_get_use_proj4_init_rules(clone_ctx, 0)
);
}

// ---------------------------------------------------------------------------

TEST_F(CApi, proj_create_crs_to_crs_from_pj) {
Expand Down