GDAL

Macros | Typedefs
cpl_port.h File Reference

Core portability definitions for CPL. More...

`#include "cpl_config.h"`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <math.h>`
`#include <stdarg.h>`
`#include <string.h>`
`#include <ctype.h>`
`#include <limits.h>`
`#include <time.h>`
`#include <errno.h>`
`#include <strings.h>`

Go to the source code of this file.

## Macros
#define | GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
| Minimum GIntBig value.
#define | GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
| Maximum GIntBig value.
#define | GUINTBIG_MAX ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
| Maximum GUIntBig value.
#define | GINT64_MIN GINTBIG_MIN
| Minimum GInt64 value.
#define | GINT64_MAX GINTBIG_MAX
| Maximum GInt64 value.
#define | GUINT64_MAX GUINTBIG_MAX
| Minimum GUInt64 value.
#define | CPL_FRMT_GB_WITHOUT_PREFIX "ll"
| Printf formatting suffix for GIntBig.
#define | CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
| Printf formatting for GIntBig.
#define | CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
| Printf formatting for GUIntBig.
#define | CPL_C_START
| Macro to start a block of C symbols. More...
#define | CPL_C_END }
| Macro to end a block of C symbols.
#define | MIN(a, b) (((a) < (b)) ? (a) : (b))
| Macro to compute the minimum of 2 values.
#define | MAX(a, b) (((a) > (b)) ? (a) : (b))
| Macro to compute the maximum of 2 values.
#define | ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
| Macro to compute the absolute value.
#define | M_PI 3.14159265358979323846
| PI definition.
#define | STRCASECMP(a, b) (strcasecmp(a, b))
| Alias for strcasecmp()
#define | STRNCASECMP(a, b, n) (strncasecmp(a, b, n))
| Alias for strncasecmp()
#define | EQUALN(a, b, n) (STRNCASECMP(a, b, n) == 0)
| Alias for strncasecmp() == 0.
#define | EQUAL(a, b) (STRCASECMP(a, b) == 0)
| Alias for strcasecmp() == 0.
#define | STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
| Returns whether a starts with b.
#define | STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
| Returns whether a starts with b (case insensitive comparison)
#define | CPLIsNan(x) isnan(x)
| Return whether a floating-pointer number is NaN.
#define | CPLIsInf(x) isinf(x)
| Return whether a floating-pointer number is +/- infinity.
#define | CPLIsFinite(x) (!isnan(x) && !isinf(x))
| Return whether a floating-pointer number is finite.
#define | CPL_SWAP16(x)
| Byte-swap a 16bit unsigned integer. More...
#define | CPL_SWAP32(x)
| Byte-swap a 32bit unsigned integer. More...
#define | CPL_SWAP64(x)
| Byte-swap a 64bit unsigned integer. More...
#define | CPL_SWAP16PTR(x)
| Byte-swap a 16 bit pointer. More...
#define | CPL_SWAP32PTR(x)
| Byte-swap a 32 bit pointer. More...
#define | CPL_SWAP64PTR(x)
| Byte-swap a 64 bit pointer. More...
#define | CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
| Byte-swap a 64 bit pointer.
#define | CPL_LSBWORD16(x) (x)
| Return a 16bit word from a originally LSB ordered word.
#define | CPL_MSBWORD16(x) CPL_SWAP16(x)
| Return a 16bit word from a originally MSB ordered word.
#define | CPL_LSBWORD32(x) (x)
| Return a 32bit word from a originally LSB ordered word.
#define | CPL_MSBWORD32(x) CPL_SWAP32(x)
| Return a 32bit word from a originally MSB ordered word.
#define | CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
| Byte-swap if necessary a 16bit word at the location pointed from a originally LSB ordered pointer.
#define | CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
| Byte-swap if necessary a 16bit word at the location pointed from a originally MSB ordered pointer.
#define | CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
| Byte-swap if necessary a 32bit word at the location pointed from a originally LSB ordered pointer.
#define | CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
| Byte-swap if necessary a 32bit word at the location pointed from a originally MSB ordered pointer.
#define | CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
| Byte-swap if necessary a 64bit word at the location pointed from a originally LSB ordered pointer.
#define | CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
| Byte-swap if necessary a 64bit word at the location pointed from a originally MSB ordered pointer.
#define | CPL_LSBINT16PTR(x)
| Return a Int16 from the 2 bytes ordered in LSB order at address x. More...
#define | CPL_LSBINT32PTR(x)
| Return a Int32 from the 4 bytes ordered in LSB order at address x. More...
#define | CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16, CPL_LSBINT16PTR(x))
| Return a signed Int16 from the 2 bytes ordered in LSB order at address x.
#define | CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
| Return a unsigned Int16 from the 2 bytes ordered in LSB order at address x.
#define | CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
| Return a signed Int32 from the 4 bytes ordered in LSB order at address x.
#define | CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
| Return a unsigned Int32 from the 4 bytes ordered in LSB order at address x.
#define | CPL_NULL_TERMINATED
| Null terminated variadic.
#define | CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
| Tag a function to have printf() formatting.
#define | CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
| Tag a function to have scanf() formatting.
#define | CPL_FORMAT_STRING(arg) arg
| Macro into which to wrap the format argument of a printf-like function.
#define | CPL_SCANF_FORMAT_STRING(arg) arg
| Macro into which to wrap the format argument of a sscanf-like function.
#define | CPL_WARN_UNUSED_RESULT
| Qualifier to warn when the return value of a function is not used.
#define | CPL_UNUSED
| Qualifier for an argument that is unused.
#define | CPL_NO_RETURN
| Qualifier for a function that does not return at all (terminates the process)
#define | CPL_RETURNS_NONNULL
| Qualifier for a function that does not return NULL.
#define | CPL_RESTRICT
| restrict keyword to declare that pointers do not alias
#define | CPL_OVERRIDE override
| To be used in public headers only. More...
#define | CPL_FINAL final
| C++11 final qualifier.
#define | CPL_NON_FINAL
| Mark that a class is explicitly recognized as non-final.
#define | CPL_DISALLOW_COPY_ASSIGN(ClassName)
| Helper to remove the copy and assignment constructors so that the compiler will not generate the default versions. More...
#define | CPL_ARRAYSIZE(array)
| Returns the size of C style arrays. More...

## Typedefs
typedef int | GInt32
| Int32 type.
typedef unsigned int | GUInt32
| Unsigned int32 type.
typedef short | GInt16
| Int16 type.
typedef unsigned short | GUInt16
| Unsigned int16 type.
typedef unsigned char | GByte
| Unsigned byte type.
typedef signed char | GInt8
| Signed int8 type.
typedef int | GBool
| Type for boolean values (alias to int)
typedef long long | GIntBig
| Large signed integer type (generally 64-bit integer type). More...
typedef unsigned long long | GUIntBig
| Large unsigned integer type (generally 64-bit unsigned integer type). More...
typedef GIntBig | GInt64
| Signed 64 bit integer type.
typedef GUIntBig | GUInt64
| Unsigned 64 bit integer type.
typedef int | GPtrDiff_t
| Integer type large enough to hold the difference between 2 addresses.
typedef char ** | CSLConstList
| Type of a constant null-terminated list of nul terminated strings. More...

## Detailed Description

Core portability definitions for CPL.

## Macro Definition Documentation

## ◆ CPL_ARRAYSIZE

#define CPL_ARRAYSIZE | ( |  | array | ) |

Value:
((sizeof(array) / sizeof(*(array))) / \
static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))

Returns the size of C style arrays.

## ◆ CPL_C_START

#define CPL_C_START

Value:
extern "C" \
{

Macro to start a block of C symbols.

## ◆ CPL_DISALLOW_COPY_ASSIGN

#define CPL_DISALLOW_COPY_ASSIGN | ( |  | ClassName | ) |

Value:
ClassName(const ClassName &) = delete; \
ClassName &operator=(const ClassName &) = delete;

Helper to remove the copy and assignment constructors so that the compiler will not generate the default versions.

Must be placed in the private section of a class and should be at the end.

## ◆ CPL_LSBINT16PTR

#define CPL_LSBINT16PTR | ( |  | x | ) |

Value:
((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
(*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8))
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:185

Return a Int16 from the 2 bytes ordered in LSB order at address x.

Deprecated:
  Use rather CPL_LSBSINT16PTR or CPL_LSBUINT16PTR for explicit signedness.

## ◆ CPL_LSBINT32PTR

#define CPL_LSBINT32PTR | ( |  | x | ) |

Value:
((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
(*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8) | \
(*((CPL_REINTERPRET_CAST(const GByte *, x)) + 2) << 16) | \
(*((CPL_REINTERPRET_CAST(const GByte *, x)) + 3) << 24))

Return a Int32 from the 4 bytes ordered in LSB order at address x.

Deprecated:
  Use rather CPL_LSBSINT32PTR or CPL_LSBUINT32PTR for explicit signedness.

## ◆ CPL_OVERRIDE

#define CPL_OVERRIDE override

To be used in public headers only.

For non-public headers or .cpp files, use override directly.

## ◆ CPL_SWAP16

#define CPL_SWAP16 | ( |  | x | ) |

Value:
CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | \
(CPL_STATIC_CAST(GUInt16, x) >> 8))
GUInt16
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:183

Byte-swap a 16bit unsigned integer.

## ◆ CPL_SWAP16PTR

#define CPL_SWAP16PTR | ( |  | x | ) |

Value:
do \
{ \
GUInt16 _n16; \
void *_lx = x; \
memcpy(&_n16, _lx, 2); \
CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
sizeof(*(x)) == 2); \
_n16 = CPL_SWAP16(_n16); \
memcpy(_lx, &_n16, 2); \
} while (0)
CPL_SWAP16
#define CPL_SWAP16(x)
Byte-swap a 16bit unsigned integer.
Definition: cpl_port.h:741

Byte-swap a 16 bit pointer.

## ◆ CPL_SWAP32

#define CPL_SWAP32 | ( |  | x | ) |

Value:
CPL_STATIC_CAST(GUInt32, \
((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24))
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:177

Byte-swap a 32bit unsigned integer.

## ◆ CPL_SWAP32PTR

#define CPL_SWAP32PTR | ( |  | x | ) |

Value:
do \
{ \
GUInt32 _n32; \
void *_lx = x; \
memcpy(&_n32, _lx, 4); \
CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
sizeof(*(x)) == 4); \
_n32 = CPL_SWAP32(_n32); \
memcpy(_lx, &_n32, 4); \
} while (0)
CPL_SWAP32
#define CPL_SWAP32(x)
Byte-swap a 32bit unsigned integer.
Definition: cpl_port.h:759

Byte-swap a 32 bit pointer.

## ◆ CPL_SWAP64

#define CPL_SWAP64 | ( |  | x | ) |

Value:
((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) \
<< 32) | \
(CPL_STATIC_CAST(GUInt64, \
CPL_SWAP32(CPL_STATIC_CAST( \
GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
GUInt64
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:238

Byte-swap a 64bit unsigned integer.

## ◆ CPL_SWAP64PTR

#define CPL_SWAP64PTR | ( |  | x | ) |

Value:
do \
{ \
GUInt64 _n64; \
void *_lx = x; \
memcpy(&_n64, _lx, 8); \
CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
sizeof(*(x)) == 8); \
_n64 = CPL_SWAP64(_n64); \
memcpy(_lx, &_n64, 8); \
} while (0)
CPL_SWAP64
#define CPL_SWAP64(x)
Byte-swap a 64bit unsigned integer.
Definition: cpl_port.h:767

Byte-swap a 64 bit pointer.

## Typedef Documentation

## ◆ CSLConstList

typedef char** CSLConstList

Type of a constant null-terminated list of nul terminated strings.

Seen as char** from C and const char* const* from C++

## ◆ GIntBig

typedef long long GIntBig

Large signed integer type (generally 64-bit integer type).

Use GInt64 when exactly 64 bit is needed

## ◆ GUIntBig

typedef unsigned long long GUIntBig

Large unsigned integer type (generally 64-bit unsigned integer type).

Use GUInt64 when exactly 64 bit is needed