aboutsummaryrefslogtreecommitdiff
path: root/src/ctx.cpp
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2020-12-13 15:30:47 +0100
committerKristian Evers <kristianevers@gmail.com>2020-12-13 15:30:47 +0100
commitc3efbd23a5bf26f1dfd5bc55ae3488d5665ace98 (patch)
treea204df79f7057d7d420bf7c5358791347617b9cd /src/ctx.cpp
parent126445148d3b742c7f4e31f5f65857be59c48340 (diff)
parent6857d1a4a8eb6fcb7b88b0339413913ba2c3351a (diff)
downloadPROJ-c3efbd23a5bf26f1dfd5bc55ae3488d5665ace98.tar.gz
PROJ-c3efbd23a5bf26f1dfd5bc55ae3488d5665ace98.zip
Merge remote-tracking branch 'osgeo/master'
Diffstat (limited to 'src/ctx.cpp')
-rw-r--r--src/ctx.cpp163
1 files changed, 27 insertions, 136 deletions
diff --git a/src/ctx.cpp b/src/ctx.cpp
index 6dbe0de5..2093950b 100644
--- a/src/ctx.cpp
+++ b/src/ctx.cpp
@@ -1,6 +1,6 @@
/******************************************************************************
* Project: PROJ.4
- * Purpose: Implementation of the projCtx thread context object.
+ * Purpose: Implementation of the PJ_CONTEXT thread context object.
* Author: Frank Warmerdam, warmerdam@pobox.com
*
******************************************************************************
@@ -43,7 +43,7 @@
/* pj_get_ctx() */
/************************************************************************/
-projCtx pj_get_ctx( projPJ pj )
+PJ_CONTEXT* pj_get_ctx( PJ *pj )
{
if (nullptr==pj)
@@ -54,13 +54,17 @@ projCtx pj_get_ctx( projPJ pj )
}
/************************************************************************/
-/* pj_set_ctx() */
-/* */
-/* Note we do not deallocate the old context! */
+/* proj_assign_context() */
/************************************************************************/
-void pj_set_ctx( projPJ pj, projCtx ctx )
-
+/** \brief Re-assign a context to a PJ* object.
+ *
+ * This may be useful if the PJ* has been created with a context that is
+ * thread-specific, and is later used in another thread. In that case,
+ * the user may want to assign another thread-specific context to the
+ * object.
+ */
+void proj_assign_context( PJ* pj, PJ_CONTEXT *ctx )
{
if (pj==nullptr)
return;
@@ -71,36 +75,20 @@ void pj_set_ctx( projPJ pj, projCtx ctx )
}
for( const auto &alt: pj->alternativeCoordinateOperations )
{
- pj_set_ctx(alt.pj, ctx);
+ proj_assign_context(alt.pj, ctx);
}
-}
-
-/************************************************************************/
-/* proj_assign_context() */
-/************************************************************************/
-/** \brief Re-assign a context to a PJ* object.
- *
- * This may be useful if the PJ* has been created with a context that is
- * thread-specific, and is later used in another thread. In that case,
- * the user may want to assign another thread-specific context to the
- * object.
- */
-void proj_assign_context( PJ* pj, PJ_CONTEXT* ctx )
-{
- pj_set_ctx( pj, ctx );
}
/************************************************************************/
/* createDefault() */
/************************************************************************/
-projCtx_t projCtx_t::createDefault()
+pj_ctx pj_ctx::createDefault()
{
- projCtx_t ctx;
+ pj_ctx ctx;
ctx.debug_level = PJ_LOG_NONE;
ctx.logger = pj_stderr_logger;
- ctx.fileapi_legacy = pj_get_default_fileapi();
NS_PROJ::FileManager::fillDefaultNetworkInterface(&ctx);
if( getenv("PROJ_DEBUG") != nullptr )
@@ -117,7 +105,7 @@ projCtx_t projCtx_t::createDefault()
/* get_cpp_context() */
/**************************************************************************/
-projCppContext* projCtx_t::get_cpp_context()
+projCppContext* pj_ctx::get_cpp_context()
{
if (cpp_context == nullptr) {
cpp_context = new projCppContext(this);
@@ -125,12 +113,11 @@ projCppContext* projCtx_t::get_cpp_context()
return cpp_context;
}
-
/**************************************************************************/
/* safeAutoCloseDbIfNeeded() */
/**************************************************************************/
-void projCtx_t::safeAutoCloseDbIfNeeded()
+void pj_ctx::safeAutoCloseDbIfNeeded()
{
if (cpp_context) {
cpp_context->autoCloseDbIfNeeded();
@@ -141,7 +128,7 @@ void projCtx_t::safeAutoCloseDbIfNeeded()
/* set_search_paths() */
/************************************************************************/
-void projCtx_t::set_search_paths(const std::vector<std::string>& search_paths_in )
+void pj_ctx::set_search_paths(const std::vector<std::string>& search_paths_in )
{
search_paths = search_paths_in;
delete[] c_compat_paths;
@@ -158,26 +145,24 @@ void projCtx_t::set_search_paths(const std::vector<std::string>& search_paths_in
/* set_ca_bundle_path() */
/**************************************************************************/
-void projCtx_t::set_ca_bundle_path(const std::string& ca_bundle_path_in)
+void pj_ctx::set_ca_bundle_path(const std::string& ca_bundle_path_in)
{
ca_bundle_path = ca_bundle_path_in;
}
/************************************************************************/
-/* projCtx_t(const projCtx_t& other) */
+/* pj_ctx(const pj_ctx& other) */
/************************************************************************/
-projCtx_t::projCtx_t(const projCtx_t& other) :
+pj_ctx::pj_ctx(const pj_ctx& other) :
debug_level(other.debug_level),
logger(other.logger),
logger_app_data(other.logger_app_data),
- fileapi_legacy(other.fileapi_legacy),
cpp_context(other.cpp_context ? other.cpp_context->clone(this) : nullptr),
use_proj4_init_rules(other.use_proj4_init_rules),
epsg_file_exists(other.epsg_file_exists),
ca_bundle_path(other.ca_bundle_path),
env_var_proj_lib(other.env_var_proj_lib),
- file_finder_legacy(other.file_finder_legacy),
file_finder(other.file_finder),
file_finder_user_data(other.file_finder_user_data),
custom_sqlite3_vfs_name(other.custom_sqlite3_vfs_name),
@@ -197,129 +182,35 @@ projCtx_t::projCtx_t(const projCtx_t& other) :
/* pj_get_default_ctx() */
/************************************************************************/
-projCtx pj_get_default_ctx()
+PJ_CONTEXT* pj_get_default_ctx()
{
// C++11 rules guarantee a thread-safe instantiation.
- static projCtx_t default_context(projCtx_t::createDefault());
+ static pj_ctx default_context(pj_ctx::createDefault());
return &default_context;
}
/************************************************************************/
-/* ~projCtx_t() */
+/* ~pj_ctx() */
/************************************************************************/
-projCtx_t::~projCtx_t()
+pj_ctx::~pj_ctx()
{
delete[] c_compat_paths;
proj_context_delete_cpp_context(cpp_context);
}
/************************************************************************/
-/* pj_ctx_alloc() */
-/************************************************************************/
-
-projCtx pj_ctx_alloc()
-
-{
- return new (std::nothrow) projCtx_t(*pj_get_default_ctx());
-}
-
-/************************************************************************/
/* proj_context_clone() */
/* 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 new (std::nothrow) projCtx_t(*ctx);
-}
-
-/************************************************************************/
-/* pj_ctx_free() */
-/************************************************************************/
-
-void pj_ctx_free( projCtx ctx )
-
-{
- delete ctx;
-}
-
-/************************************************************************/
-/* pj_ctx_get_errno() */
-/************************************************************************/
-
-int pj_ctx_get_errno( projCtx ctx )
-
+PJ_CONTEXT* proj_context_clone (PJ_CONTEXT *ctx)
{
if (nullptr==ctx)
- return pj_get_default_ctx ()->last_errno;
- return ctx->last_errno;
-}
-
-/************************************************************************/
-/* pj_ctx_set_errno() */
-/* */
-/* Also sets the global errno */
-/************************************************************************/
-
-void pj_ctx_set_errno( projCtx ctx, int new_errno )
-
-{
- ctx->last_errno = new_errno;
- if( new_errno == 0 )
- return;
- errno = new_errno;
- pj_errno = new_errno;
-}
-
-/************************************************************************/
-/* pj_ctx_set_debug() */
-/************************************************************************/
-
-void pj_ctx_set_debug( projCtx ctx, int new_debug )
+ return proj_context_create();
-{
- if (nullptr==ctx)
- return;
- ctx->debug_level = new_debug;
+ return new (std::nothrow) pj_ctx(*ctx);
}
-/************************************************************************/
-/* pj_ctx_set_logger() */
-/************************************************************************/
-
-void pj_ctx_set_logger( projCtx ctx, void (*new_logger)(void*,int,const char*) )
-{
- if (nullptr==ctx)
- return;
- ctx->logger = new_logger;
-}
-
-/************************************************************************/
-/* pj_ctx_set_app_data() */
-/************************************************************************/
-
-void pj_ctx_set_app_data( projCtx ctx, void *new_app_data )
-
-{
- if (nullptr==ctx)
- return;
- ctx->logger_app_data = new_app_data;
-}
-
-/************************************************************************/
-/* pj_ctx_get_app_data() */
-/************************************************************************/
-
-void *pj_ctx_get_app_data( projCtx ctx )
-
-{
- if (nullptr==ctx)
- return nullptr;
- return ctx->logger_app_data;
-}