32 #ifndef CPL_BASE_H_INCLUDED
33 #define CPL_BASE_H_INCLUDED
45 #if defined(_WIN32) && !defined(WIN32)
49 #if defined(_WINDOWS) && !defined(WIN32)
58 # ifndef _CRT_SECURE_NO_DEPRECATE
59 # define _CRT_SECURE_NO_DEPRECATE
61 # ifndef _CRT_NONSTDC_NO_DEPRECATE
62 # define _CRT_NONSTDC_NO_DEPRECATE
66 #include "cpl_config.h"
73 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4
74 #error "Unexpected value for SIZEOF_INT"
77 #if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
78 #error "Unexpected value for SIZEOF_UNSIGNED_LONG"
81 #if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8)
82 #error "Unexpected value for SIZEOF_VOIDP"
95 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
96 # define _LARGEFILE64_SOURCE 1
105 #if defined(HAVE_ICONV)
106 # define CPL_RECODE_ICONV
109 #define CPL_RECODE_STUB
119 #if defined(__MINGW32__)
120 #ifndef __MSVCRT_VERSION__
121 #define __MSVCRT_VERSION__ 0x0700
126 #if defined(GDAL_COMPILATION) && defined(__sun__) && (__STDC_VERSION__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600
130 #define _XOPEN_SOURCE 600
147 #if defined(HAVE_ERRNO_H)
160 # include <strings.h>
163 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
165 # include <dbmalloc.h>
168 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
170 # include <dmalloc.h>
185 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
186 # if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))
187 # error Must have C++11 or newer.
189 # if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
190 # define HAVE_CXX14 1
192 # if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
193 # define HAVE_CXX17 1
200 #if UINT_MAX == 65535
218 #ifndef CPL_GBOOL_DEFINED
220 #define CPL_GBOOL_DEFINED
228 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
229 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
231 #define CPL_STATIC_CAST(type, expr) ((type)(expr))
232 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
250 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
252 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
254 #define GUINTBIG_MAX ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
257 #define CPL_HAS_GINT64 1
268 #define GINT64_MIN GINTBIG_MIN
270 #define GINT64_MAX GINTBIG_MAX
272 #define GUINT64_MAX GUINTBIG_MAX
276 #error "64bit integer support required"
280 #if SIZEOF_VOIDP == 8
288 #ifdef GDAL_COMPILATION
291 typedef uintptr_t GUIntptr_t;
292 #elif SIZEOF_VOIDP == 8
295 typedef unsigned int GUIntptr_t;
298 #define CPL_IS_ALIGNED(ptr, quant) ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void*, ptr)) % (quant)) == 0)
302 #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER))
303 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
306 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
308 #define CPL_FRMT_GB_WITHOUT_PREFIX "l"
312 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
314 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
317 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
318 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
320 #define CPL_INT64_FITS_ON_INT32(x) (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
329 # define CPL_C_START extern "C" {
338 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
339 # ifdef GDAL_COMPILATION
340 # define CPL_DLL __declspec(dllexport)
344 # define CPL_INTERNAL
346 # if defined(USE_GCC_VISIBILITY_FLAG)
347 # define CPL_DLL __attribute__ ((visibility("default")))
348 # if !defined(__MINGW32__)
349 # define CPL_INTERNAL __attribute__((visibility("hidden")))
351 # define CPL_INTERNAL
355 # define CPL_INTERNAL
360 #define CPL_UNSTABLE_API CPL_DLL
366 #ifdef CPL_OPTIONAL_APIS
367 # define CPL_ODLL CPL_DLL
374 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
375 # define CPL_STDCALL __stdcall
383 # define FORCE_CDECL __cdecl
391 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
392 #define HAS_CPL_INLINE 1
393 #define CPL_INLINE __inline
394 #elif defined(__SUNPRO_CC)
395 #define HAS_CPL_INLINE 1
396 #define CPL_INLINE inline
404 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
406 # define MAX(a,b) (((a)>(b)) ? (a) : (b))
411 # define ABS(x) (((x)<0) ? (-1*(x)) : (x))
416 # define M_PI 3.14159265358979323846
427 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
436 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
438 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
439 __attribute__((always_inline));
441 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
443 const unsigned char* bptr1 = (
const unsigned char*)ptr1;
444 const unsigned char* bptr2 = (
const unsigned char*)ptr2;
447 unsigned char b1 = *(bptr1++);
448 unsigned char b2 = *(bptr2++);
449 if( b1 != b2 )
return b1 - b2;
454 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
455 __attribute__((always_inline));
457 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
459 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
460 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
463 unsigned char ch1 = *(usptr1++);
464 unsigned char ch2 = *(usptr2++);
465 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
469 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
470 __attribute__((always_inline));
472 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
474 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
475 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
478 unsigned char ch1 = *(usptr1++);
479 unsigned char ch2 = *(usptr2++);
480 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
485 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
486 __attribute__((always_inline));
488 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
490 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
491 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
494 unsigned char ch1 = *(usptr1++);
495 unsigned char ch2 = *(usptr2++);
496 ch1 = (
unsigned char)toupper(ch1);
497 ch2 = (
unsigned char)toupper(ch2);
498 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
502 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
503 __attribute__((always_inline));
505 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
507 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
508 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
511 unsigned char ch1 = *(usptr1++);
512 unsigned char ch2 = *(usptr2++);
513 ch1 = (
unsigned char)toupper(ch1);
514 ch2 = (
unsigned char)toupper(ch2);
515 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
520 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
521 __attribute__((always_inline));
523 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
525 const char* ptr_haystack = haystack;
528 const char* ptr_haystack2 = ptr_haystack;
529 const char* ptr_needle = needle;
532 char ch1 = *(ptr_haystack2++);
533 char ch2 = *(ptr_needle++);
535 return (
char*)ptr_haystack;
539 if( *ptr_haystack == 0 )
547 #define memcmp CPL_afl_friendly_memcmp
548 #define strcmp CPL_afl_friendly_strcmp
549 #define strncmp CPL_afl_friendly_strncmp
550 #define strcasecmp CPL_afl_friendly_strcasecmp
551 #define strncasecmp CPL_afl_friendly_strncasecmp
552 #define strstr CPL_afl_friendly_strstr
557 # define STRCASECMP(a,b) (_stricmp(a,b))
558 # define STRNCASECMP(a,b,n) (_strnicmp(a,b,n))
561 # define STRCASECMP(a,b) (strcasecmp(a,b))
563 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n))
566 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0)
568 # define EQUAL(a,b) (STRCASECMP(a,b)==0)
575 #ifndef STARTS_WITH_CI
577 #define STARTS_WITH(a,b) (strncmp(a,b,strlen(b)) == 0)
579 #define STARTS_WITH_CI(a,b) EQUALN(a,b,strlen(b))
583 #ifndef CPL_THREADLOCAL
584 # define CPL_THREADLOCAL
599 # define CPLIsNan(x) _isnan(x)
600 # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
601 # define CPLIsFinite(x) _finite(x)
602 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) )
605 # define CPLIsNan(x) __builtin_isnan(x)
606 # define CPLIsInf(x) __builtin_isinf(x)
607 # define CPLIsFinite(x) __builtin_isfinite(x)
608 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
613 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
614 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
615 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
616 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
617 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
618 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
622 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
626 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
627 static inline int CPLIsNan(
double f) {
return __isnan(f); }
628 static inline int CPLIsInf(
float f) {
return __isinff(f); }
629 static inline int CPLIsInf(
double f) {
return __isinf(f); }
630 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
631 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
634 # define CPLIsNan(x) isnan(x)
635 # if defined(isinf) || defined(__FreeBSD__)
637 # define CPLIsInf(x) isinf(x)
639 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
640 # elif defined(__sun__)
642 # define CPLIsInf(x) (!finite(x) && !isnan(x))
643 # define CPLIsFinite(x) finite(x)
645 # define CPLIsInf(x) (0)
646 # define CPLIsFinite(x) (!isnan(x))
659 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
663 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
668 # define CPL_IS_LSB 1
670 # define CPL_IS_LSB 0
674 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
679 template <
bool b>
struct CPLStaticAssert {};
680 template<>
struct CPLStaticAssert<true>
682 static void my_function() {}
687 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
688 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
692 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
702 #define CPL_SWAP16(x) CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | (CPL_STATIC_CAST(GUInt16, x) >> 8) )
704 #if defined(HAVE_GCC_BSWAP)
706 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
708 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
709 #elif defined(_MSC_VER)
710 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
711 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
714 #define CPL_SWAP32(x) \
715 CPL_STATIC_CAST(GUInt32, \
716 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
717 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
718 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
719 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24) )
722 #define CPL_SWAP64(x) \
723 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) << 32) | \
724 (CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
729 #define CPL_SWAP16PTR(x) \
733 memcpy(&_n16, _lx, 2); \
734 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \
735 _n16 = CPL_SWAP16(_n16); \
736 memcpy(_lx, &_n16, 2); \
740 #define CPL_SWAP32PTR(x) \
744 memcpy(&_n32, _lx, 4); \
745 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \
746 _n32 = CPL_SWAP32(_n32); \
747 memcpy(_lx, &_n32, 4); \
751 #define CPL_SWAP64PTR(x) \
755 memcpy(&_n64, _lx, 8); \
756 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \
757 _n64 = CPL_SWAP64(_n64); \
758 memcpy(_lx, &_n64, 8); \
762 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
765 # define CPL_MSBWORD16(x) (x)
766 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
767 # define CPL_MSBWORD32(x) (x)
768 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
769 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
770 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
771 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
772 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
773 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
774 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
777 # define CPL_LSBWORD16(x) (x)
779 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
781 # define CPL_LSBWORD32(x) (x)
783 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
785 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
787 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
789 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
791 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
793 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
795 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
801 #define CPL_LSBINT16PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8))
806 #define CPL_LSBINT32PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8) | \
807 (*((CPL_REINTERPRET_CAST(const GByte*, x))+2) << 16) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+3) << 24))
810 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16,CPL_LSBINT16PTR(x))
813 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
816 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
819 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
823 #ifndef UNREFERENCED_PARAM
824 # ifdef UNREFERENCED_PARAMETER
825 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
827 # define UNREFERENCED_PARAM(param) ((void)param)
841 #ifndef DISABLE_CVSID
842 #if defined(__GNUC__) && __GNUC__ >= 4
843 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string;
845 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \
846 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); }
849 # define CPL_CVSID(string)
854 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
856 # define CPL_NULL_TERMINATED __attribute__((__sentinel__))
859 # define CPL_NULL_TERMINATED
862 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
864 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
866 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
869 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
871 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx )
874 #if defined(_MSC_VER) && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
878 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
881 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
884 # define CPL_FORMAT_STRING(arg) arg
886 # define CPL_SCANF_FORMAT_STRING(arg) arg
889 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
891 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
894 #define CPL_WARN_UNUSED_RESULT
897 #if defined(__GNUC__) && __GNUC__ >= 4
899 # define CPL_UNUSED __attribute((__unused__))
906 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
908 #define CPL_NO_RETURN __attribute__((noreturn))
911 #define CPL_NO_RETURN
916 #ifndef __has_attribute
917 #define __has_attribute(x) 0
922 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
924 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
927 # define CPL_RETURNS_NONNULL
930 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
932 #define CPL_RESTRICT __restrict__
938 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
942 # define CPL_OVERRIDE override
945 # define CPL_FINAL final
948 # define CPL_NON_FINAL
955 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
956 ClassName( const ClassName & ) = delete; \
957 ClassName &operator=( const ClassName & ) = delete;
961 #if !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
962 #if defined(__has_extension)
963 #if __has_extension(attribute_deprecated_with_message)
965 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x)))
967 #define CPL_WARN_DEPRECATED(x)
969 #elif defined(__GNUC__)
970 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated))
972 #define CPL_WARN_DEPRECATED(x)
976 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
978 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
979 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
980 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
981 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
984 int sprintf(
char *str, const
char* fmt, ...)
987 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
988 int sprintf(
char *str,
const char* fmt, ...)
990 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
995 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64))
997 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS
1001 #if defined(__cplusplus)
1004 #define CPL_ARRAYSIZE(array) \
1005 ((sizeof(array) / sizeof(*(array))) / \
1006 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1009 #define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
1013 template<
class T>
static void CPL_IGNORE_RET_VAL(
const T&) {}
1014 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
1019 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER))
1020 #define HAVE_GCC_DIAGNOSTIC_PUSH
1023 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER))
1024 #define HAVE_GCC_SYSTEM_HEADER
1027 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7)
1029 # define CPL_FALLTHROUGH [[clang::fallthrough]];
1032 # define CPL_FALLTHROUGH
1040 #if defined(__cplusplus) && defined(DEBUG_BOOL) && !defined(DO_NOT_USE_DEBUG_BOOL) && !defined(CPL_SUPRESS_CPLUSPLUS)
1042 class MSVCPedanticBool
1045 friend bool operator== (
const bool& one,
const MSVCPedanticBool& other);
1046 friend bool operator!= (
const bool& one,
const MSVCPedanticBool& other);
1049 MSVCPedanticBool(
int bIn);
1054 MSVCPedanticBool() {}
1055 MSVCPedanticBool(
bool bIn) : b(bIn) {}
1056 MSVCPedanticBool(
const MSVCPedanticBool& other) : b(other.b) {}
1058 MSVCPedanticBool& operator= (
const MSVCPedanticBool& other) { b = other.b;
return *
this; }
1059 MSVCPedanticBool& operator&= (
const MSVCPedanticBool& other) { b &= other.b;
return *
this; }
1060 MSVCPedanticBool& operator|= (
const MSVCPedanticBool& other) { b |= other.b;
return *
this; }
1062 bool operator== (
const bool& other)
const {
return b == other; }
1063 bool operator!= (
const bool& other)
const {
return b != other; }
1064 bool operator< (
const bool& other)
const {
return b < other; }
1065 bool operator== (
const MSVCPedanticBool& other)
const {
return b == other.b; }
1066 bool operator!= (
const MSVCPedanticBool& other)
const {
return b != other.b; }
1067 bool operator< (
const MSVCPedanticBool& other)
const {
return b < other.b; }
1069 bool operator! ()
const {
return !b; }
1070 operator bool()
const {
return b; }
1071 operator int()
const {
return b; }
1072 operator GIntBig()
const {
return b; }
1075 inline bool operator== (
const bool& one,
const MSVCPedanticBool& other) {
return one == other.b; }
1076 inline bool operator!= (
const bool& one,
const MSVCPedanticBool& other) {
return one != other.b; }
1087 #include <algorithm>
1088 #include <functional>
1092 #include <unordered_map>
1094 #include <unordered_set>
1106 #define EMULATED_BOOL int
1109 #define bool MSVCPedanticBool
1113 #define VOLATILE_BOOL bool
1125 #define EMULATED_BOOL bool
1126 #define VOLATILE_BOOL volatile bool
1130 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1131 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
1133 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1136 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && defined(GDAL_COMPILATION)
1138 template<
class C,
class A,
class B>
1139 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1140 inline C CPLUnsanitizedAdd(A a, B b)
1150 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1151 #define CPL_NULLPTR nullptr
1153 #define CPL_NULLPTR NULL
1162 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP)
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:247
short GInt16
Int16 type.
Definition: cpl_port.h:211
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:331
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:329
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:263
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:223
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:207
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:869
GIntBig GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:282
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1169
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:265
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:213
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
int GInt32
Int32 type.
Definition: cpl_port.h:205
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:244
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1339