TSDuck Version 3.22-1925 (TSDuck - The MPEG Transport Stream Toolkit)
tsPlatform.h File Reference

Cross-platforms portable base definitions for the TSDuck project. More...

Namespaces

 ts
 TSDuck namespace, containing all TSDuck classes and functions.
 

Macros

#define TS_ADDRESS_BITS   16, 32, 64, etc.
 Number of bits in an address (or a pointer or a size_t).
 
#define TS_AIX
 Defined when compiled for an IBM AIX target platform.
 
#define TS_ALPHA
 Defined when the target processor architecture is Digital Alpha architecture.
 
#define TS_ARM
 Defined when the target processor architecture is ARM.
 
#define TS_ARM64
 Defined when the target processor architecture is ARM64.
 
#define TS_BIG_ENDIAN
 Defined when compiled for a big-endian or MSB-first target platform.
 
#define TS_CONST64(n)
 Portable definition of a 64-bit signed literal. More...
 
#define TS_CXX11
 Defined when the compiler is compliant with C++11.
 
#define TS_CXX11_STRING
 Defined when the STL basic_string is compliant with C++11. More...
 
#define TS_CXX14
 Defined when the compiler is compliant with C++14.
 
#define TS_CXX17
 Defined when the compiler is compliant with C++17.
 
#define TS_CYGWIN
 Defined when compiled for a Cygwin target platform.
 
#define TS_DLL_EXPORT
 On Windows, this attribute exports a symbol out of a DLL.
 
#define TS_DVB_API_VERSION
 On Linux systems, identify the Linux DVB API version in one value. More...
 
#define TS_FALLTHROUGH   [[clang::fallthrough]];
 This macro should preceed an intentional fallthrough in a switch expression.
 
#define TS_FUNCTION
 Definition of the name of the current function. More...
 
#define TS_GCC
 Defined when the compiler is GCC, also known as "GNU C", or a GCC-compatible compiler.
 
#define TS_GCC_NOWARNING(name)
 Disable a warning with the GCC compiler (does nothing on other compilers). More...
 
#define TS_GCC_ONLY
 Defined when the compiler is exactly GCC, also known as "GNU C", not a GCC-compatible compiler.
 
#define TS_GCC_VERSION
 GCC version, encoded as an integer. More...
 
#define TS_I386
 Defined when the target processor architecture is Intel IA-32, also known as x86.
 
#define TS_IA64
 Defined when the target processor architecture is Intel IA-64 architecture, also known as Itanium.
 
#define TS_LINUX
 Defined when compiled for a Linux target platform.
 
#define TS_LITTLE_ENDIAN
 Defined when compiled for a little-endian or LSB-first target platform.
 
#define TS_LLVM
 Defined when the compiler is LLVM (clang). More...
 
#define TS_LLVM_NOWARNING(name)
 Disable a warning with the LLVM/clang compiler (does nothing on other compilers). More...
 
#define TS_MAC
 Defined when compiled for a macOS target platform.
 
#define TS_MIPS
 Defined when the target processor architecture is MIPS architecture.
 
#define TS_MSC
 Defined when the compiler is Microsoft C/C++, the default compiler in the Microsoft Visual Studio environment. More...
 
#define TS_MSC_NOWARNING(num)
 Disable a warning with the Microsoft Visual C++ compiler (does nothing on other compilers). More...
 
#define TS_NEED_STATIC_CONST_DEFINITIONS
 Compilation of definitions of C++ constants. More...
 
#define TS_NO_MEMORY_BARRIER
 To be defined to implement memory barrier as a no-operation. More...
 
#define TS_NOBUILD_NOCOPY(classname)
 A macro to disable default constructor and object copy in the definition of a class. More...
 
#define TS_NOCOPY(classname)
 A macro to disable object copy in the definition of a class. More...
 
#define TS_POP_WARNING()
 Restore the compiler's warnings reporting from a previous TS_PUSH_WARNING(). More...
 
#define TS_POWERPC
 Defined when the target processor architecture is 32-bit Power PC.
 
#define TS_POWERPC64
 Defined when the target processor architecture is 64-bit Power PC.
 
#define TS_PRAGMA(directive)
 Helper macro for the C++11 keyword _Pragma. More...
 
#define TS_PUSH_WARNING()
 Save the compiler's warnings reporting. More...
 
#define TS_RECVBUF_T(x)   platform_specific
 Type conversion macro for the address of the data buffer for a recv() system call. More...
 
#define TS_SENDBUF_T(x)   platform_specific
 Type conversion macro for the address of the data buffer for a send() system call. More...
 
#define TS_SIZE_T_IS_STDINT
 Defined is size_t is an exact overload of some predefined uintXX_t. More...
 
#define TS_SLINE   TS_STRINGIFY(__LINE__)
 String version of LINE
 
#define TS_SOCKET_CLOSE   platform_specific
 Name of the close() system call which applies to socket devices. More...
 
#define TS_SOCKET_ERR_NOTCONN   platform_specific
 System error code value meaning "peer socket not connected".
 
#define TS_SOCKET_ERR_RESET   platform_specific
 System error code value meaning "connection reset by peer".
 
#define TS_SOCKET_IOCTL   platform_specific
 Name of the ioctl() system call which applies to socket devices. More...
 
#define TS_SOCKET_L_LINGER_T(x)   platform_specific
 Type conversion macro for the field l_linger in the struct linger socket option. More...
 
#define TS_SOCKET_SHUT_RD   platform_specific
 Name of the option for the shutdown() system call which means "close on receive side". More...
 
#define TS_SOCKET_SHUT_RDWR   platform_specific
 Name of the option for the shutdown() system call which means "close on both directions". More...
 
#define TS_SOCKET_SHUT_WR   platform_specific
 Name of the option for the shutdown() system call which means "close on send side". More...
 
#define TS_SOCKET_T_INVALID   platform_specific
 Value of type TS_SOCKET_T which is returned by the socket() system call in case of failure. More...
 
#define TS_SOCKOPT_T(x)   platform_specific
 Type conversion macro for the address of a socket option value. More...
 
#define TS_SOLARIS
 Defined when compiled for a Sun Solaris target platform.
 
#define TS_SPARC
 Defined when the target processor architecture is Sun SPARC architecture.
 
#define TS_STRICT_MEMORY_ALIGN   1
 Defined when the CPU requires strict memory alignment (address must be a multiple of the data size).
 
#define TS_STRINGIFY(x)
 This macro transforms the value of a macro parameter into the equivalent string literal. More...
 
#define TS_STXP70
 Defined when the target processor architecture is STxP70.
 
#define TS_UCONST64(n)
 Portable definition of a 64-bit unsigned literal. More...
 
#define TS_UNIQUE_NAME(prefix)
 This macro generates a unique name based on the source line number. More...
 
#define TS_UNIX
 Defined when compiled for any flavor of UNIX target platforms. More...
 
#define TS_UNUSED   platform_specific
 Attribute for explicitly unused variables. More...
 
#define TS_USTRINGIFY(x)
 This macro transforms the value of a macro parameter into the equivalent 16-bit Unicode string literal. More...
 
#define TS_WINDOWS
 Defined when compiled for a Microsoft Windows target platform.
 
#define TS_X86_64
 Defined when the target processor architecture is the 64-bit extension of the IA-32 architecture, also known as AMD-64 or Intel x86-64.
 
#define TSDUCK_SOURCE
 This macro inserts a build mark in the source code, identifying it as part or TSDuck. More...
 
#define TSDUCK_STATIC
 User-defined macro to enable full static linking. More...
 
#define TSDUCK_STATIC_LIBRARY
 Applications which link against the TSDuck static library. More...
 
#define TSDUCK_STATIC_PLUGINS
 User-defined macro to enable static linking of plugins. More...
 
#define TSDUCKDLL
 Attribute to declare a class or function from tsduck.dll on Windows. More...
 

Typedefs

typedef char * ts::char_ptr
 Pointer to char.
 
typedef const char * ts::const_char_ptr
 Pointer to const char.
 
typedef const int16_t * ts::const_int16_ptr
 Pointer to const int16_t.
 
typedef const int32_t * ts::const_int32_ptr
 Pointer to const int32_t.
 
typedef const int64_t * ts::const_int64_ptr
 Pointer to const int64_t.
 
typedef const int8_t * ts::const_int8_ptr
 Pointer to const int8_t.
 
typedef const uint16_t * ts::const_uint16_ptr
 Pointer to const uint16_t.
 
typedef const uint32_t * ts::const_uint32_ptr
 Pointer to const uint32_t.
 
typedef const uint64_t * ts::const_uint64_ptr
 Pointer to const uint64_t.
 
typedef const uint8_t * ts::const_uint8_ptr
 Pointer to const uint8_t.
 
typedef platform_specific ts::ErrorCode
 Integer type for operating system error codes.
 
typedef int16_t * ts::int16_ptr
 Pointer to int16_t.
 
typedef int32_t * ts::int32_ptr
 Pointer to int32_t.
 
typedef int64_t * ts::int64_ptr
 Pointer to int64_t.
 
typedef int8_t * ts::int8_ptr
 Pointer to int8_t.
 
typedef platform dependent ts::ioctl_request_t
 Portable type for ioctl() request parameter.
 
typedef SubSecond ts::MicroSecond
 This integer type is used to represent a number of microseconds. More...
 
typedef SubSecond ts::MilliSecond
 This integer type is used to represent a number of milliseconds. More...
 
typedef SubSecond ts::NanoSecond
 This integer type is used to represent a number of nanoseconds. More...
 
typedef SubSecond ts::Second
 This integer type is used to represent a number of seconds. More...
 
typedef int64_t ts::SubSecond
 This integer type is used to represent any sub-quantity of seconds. More...
 
typedef platform_specific TS_SOCKET_MC_TTL_T
 Integer data type for the multicast Time To Live (TTL) socket option. More...
 
typedef platform_specific TS_SOCKET_PKTINFO_T
 Integer data type for the IP_PKTINFO socket option. More...
 
typedef platform_specific TS_SOCKET_SOCKLEN_T
 Integer data type which receives the length of a struct sockaddr. More...
 
typedef platform_specific TS_SOCKET_SSIZE_T
 Integer data type for a "signed size" returned from send() or recv() system calls. More...
 
typedef platform_specific TS_SOCKET_T
 Data type for socket descriptors as returned by the socket() system call.
 
typedef platform_specific TS_SOCKET_TOS_T
 Integer data type for the TOS socket option.
 
typedef platform_specific TS_SOCKET_TTL_T
 Integer data type for the Time To Live (TTL) socket option. More...
 
typedef uint16_t * ts::uint16_ptr
 Pointer to uint16_t.
 
typedef uint32_t * ts::uint32_ptr
 Pointer to uint32_t.
 
typedef uint64_t * ts::uint64_ptr
 Pointer to uint64_t.
 
typedef uint8_t * ts::uint8_ptr
 Pointer to uint8_t.
 

Enumerations

enum  ts::ShareMode {
  ts::ShareMode::COPY,
  ts::ShareMode::SHARE
}
 Enumeration type used to indicate if the data referenced by a pointer shall be copied or shared. More...
 
enum  ts::Tristate {
  MAYBE = -1,
  ts::Tristate::FALSE = 0,
  ts::Tristate::TRUE = 1
}
 Tristate boolean. More...
 

Functions

uint16_t ts::ByteSwap16 (uint16_t x)
 Inlined function performing byte swap on 16-bit integer data. More...
 
uint32_t ts::ByteSwap24 (uint32_t x)
 Inlined function performing byte swap on 24-bit integer data. More...
 
uint32_t ts::ByteSwap32 (uint32_t x)
 Inlined function performing byte swap on 32-bit integer data. More...
 
uint64_t ts::ByteSwap64 (uint64_t x)
 Inlined function performing byte swap on 64-bit integer data. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
INT ts::CondByteSwap (INT x)
 Template function performing conditional byte swap on integer data to obtain the data in big endian representation. More...
 
uint16_t ts::CondByteSwap16 (uint16_t x)
 Inlined function performing conditional byte swap on 16-bit integer data to obtain the data in big endian representation. More...
 
uint16_t ts::CondByteSwap16BE (uint16_t x)
 Inlined function performing conditional byte swap on 16-bit integer data to obtain the data in big endian representation. More...
 
uint16_t ts::CondByteSwap16LE (uint16_t x)
 Inlined function performing conditional byte swap on 16-bit integer data to obtain the data in little endian representation. More...
 
uint32_t ts::CondByteSwap24 (uint32_t x)
 Inlined function performing conditional byte swap on 24-bit integer data to obtain the data in big endian representation. More...
 
uint32_t ts::CondByteSwap24BE (uint32_t x)
 Inlined function performing conditional byte swap on 24-bit integer data to obtain the data in big endian representation. More...
 
uint32_t ts::CondByteSwap24LE (uint32_t x)
 Inlined function performing conditional byte swap on 24-bit integer data to obtain the data in little endian representation. More...
 
uint32_t ts::CondByteSwap32 (uint32_t x)
 Inlined function performing conditional byte swap on 32-bit integer data to obtain the data in big endian representation. More...
 
uint32_t ts::CondByteSwap32BE (uint32_t x)
 Inlined function performing conditional byte swap on 32-bit integer data to obtain the data in big endian representation. More...
 
uint32_t ts::CondByteSwap32LE (uint32_t x)
 Inlined function performing conditional byte swap on 32-bit integer data to obtain the data in little endian representation. More...
 
uint64_t ts::CondByteSwap64 (uint64_t x)
 Inlined function performing conditional byte swap on 64-bit integer data to obtain the data in big endian representation. More...
 
uint64_t ts::CondByteSwap64BE (uint64_t x)
 Inlined function performing conditional byte swap on 64-bit integer data to obtain the data in big endian representation. More...
 
uint64_t ts::CondByteSwap64LE (uint64_t x)
 Inlined function performing conditional byte swap on 64-bit integer data to obtain the data in little endian representation. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
INT ts::CondByteSwapBE (INT x)
 Template function performing conditional byte swap on integer data to obtain the data in big endian representation. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
INT ts::CondByteSwapLE (INT x)
 Template function performing conditional byte swap on integer data to obtain the data in little endian representation. More...
 
ErrorCode ts::LastErrorCode ()
 Get the error code of the last operating system call. More...
 
void ts::MemoryBarrier (void)
 Inlined C function performing a CPU/compiler dependent memory barrier.
 
uint32_t ts::ROL (uint32_t word, int i)
 Inlined function performing 32-bit left-rotate. More...
 
uint64_t ts::ROL64 (uint64_t word, int i)
 Inlined function performing 64-bit left-rotate. More...
 
uint64_t ts::ROL64c (uint64_t word, const int i)
 Inlined function performing 64-bit left-rotate with a constant value in the range 0..63 for index. More...
 
uint32_t ts::ROLc (uint32_t word, const int i)
 Inlined function performing 32-bit left-rotate with a constant value in the range 0..31 for index. More...
 
uint32_t ts::ROR (uint32_t word, int i)
 Inlined function performing 32-bit right-rotate. More...
 
uint64_t ts::ROR64 (uint64_t word, int i)
 Inlined function performing 64-bit right-rotate. More...
 
uint64_t ts::ROR64c (uint64_t word, const int i)
 Inlined function performing 64-bit right-rotate with a constant value in the range 0..63 for index. More...
 
uint32_t ts::RORc (uint32_t word, const int i)
 Inlined function performing 32-bit right-rotate with a constant value in the range 0..31 for index. More...
 
int32_t ts::SignExtend24 (int32_t x)
 Perform a sign extension on 24 bit integers. More...
 
int64_t ts::SignExtend40 (int64_t x)
 Perform a sign extension on 40 bit integers. More...
 
int64_t ts::SignExtend48 (int64_t x)
 Perform a sign extension on 48 bit integers. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
Tristate ts::ToTristate (INT i)
 Normalize any integer value in the range of a Tristate value. More...
 

Variables

constexpr SubSecond ts::Infinite =
 This constant shall be used by convention to express an infinite number of sub-quantities of seconds.
 
constexpr MicroSecond ts::MicroSecPerMilliSec = 1000
 Number of microseconds per millisecond.
 
constexpr MicroSecond ts::MicroSecPerSec = 1000000
 Number of microseconds per second.
 
constexpr MilliSecond ts::MilliSecPerDay = 1000 * 60 * 60 * 24
 Number of milliseconds per day.
 
constexpr MilliSecond ts::MilliSecPerHour = 1000 * 60 * 60
 Number of milliseconds per hour.
 
constexpr MilliSecond ts::MilliSecPerMin = 1000 * 60
 Number of milliseconds per minute.
 
constexpr MilliSecond ts::MilliSecPerSec = 1000
 Number of milliseconds per second.
 
constexpr NanoSecond ts::NanoSecPerMicroSec = 1000
 Number of nanoseconds per microsecond.
 
constexpr NanoSecond ts::NanoSecPerMilliSec = 1000000
 Number of nanoseconds per millisecond.
 
constexpr NanoSecond ts::NanoSecPerSec = 1000000000
 Number of nanoseconds per second.
 
const size_t ts::NPOS
 Constant meaning "no size", "not found" or "do not resize". More...
 
const ErrorCode ts::SYS_DATA_ERROR = platform_specific
 An ErrorCode value indicating a generic data error. More...
 
const ErrorCode ts::SYS_SUCCESS = platform_specific
 An ErrorCode value indicating success. More...
 

Detailed Description

Cross-platforms portable base definitions for the TSDuck project.

This header file shall be included by all C++ compilation units in the TSDuck project. It provides common portable definitions. This file shall always be included first, before system headers and other TSDuck headers.

Important: This file shall be updated each time a new platform is used (processor, compiler, operating system). When recompiling this header on a new platform, many errors are generated (explicit #error directives). These errors will guide you on the required additions for the new platform.

Platform definitions

This header file conditionally defines several symbols (macros) which describe the platform (processor, compiler, operating system). These symbols can be used for conditional compilation.

The following environments are described:

Solving various compilation issues

This header file defines some macros which can be used to solve various C/C++ compilation issues.

Macro Definition Documentation

◆ TS_LLVM

#define TS_LLVM

Defined when the compiler is LLVM (clang).

In that case, TS_GCC is also defined since LLVM is reasonably compatible with GCC.

◆ TS_MSC

#define TS_MSC

Defined when the compiler is Microsoft C/C++, the default compiler in the Microsoft Visual Studio environment.

Also used on command line and batch file as the cl command.

◆ TS_GCC_VERSION

#define TS_GCC_VERSION

GCC version, encoded as an integer.

Example: 40801 for GCC 4.8.1. Undefined when the compiler is not GCC or its version is unknown.

◆ TS_CXX11_STRING

#define TS_CXX11_STRING

Defined when the STL basic_string is compliant with C++11.

The class basic_string from the C++ STL has more features starting with C++11. However, GCC does not support them with old versions, even if –std=c++11 or 14 is specified. The level of language is increased but not the level of STL.

◆ TS_UNIX

#define TS_UNIX

Defined when compiled for any flavor of UNIX target platforms.

This symbol comes in addition to the specific symbol for the target platform (TS_LINUX, etc.)

◆ TSDUCK_STATIC_PLUGINS

#define TSDUCK_STATIC_PLUGINS

User-defined macro to enable static linking of plugins.

If TSDUCK_STATIC_PLUGINS is defined, typically on the compilation command line, all plugins are linked statically. Dynamic loading of plugins is disabled.

◆ TSDUCK_STATIC_LIBRARY

#define TSDUCK_STATIC_LIBRARY

Applications which link against the TSDuck static library.

Applications which link against the TSDuck static library should define TSDUCK_STATIC_LIBRARY. This symbol can be used to force external references.

TSDUCK_STATIC_LIBRARY enforces TSDUCK_STATIC_PLUGINS.

◆ TSDUCK_STATIC

#define TSDUCK_STATIC

User-defined macro to enable full static linking.

If TSDUCK_STATIC is defined, typically on the compilation command line, the code is compiled and linked statically, including system libraries. On Linux, this is not recommended since a few features such as IP address resolution are disabled.

TSDUCK_STATIC enforces TSDUCK_STATIC_LIBRARY and TSDUCK_STATIC_PLUGINS.

◆ TS_STRINGIFY

#define TS_STRINGIFY (   x)

This macro transforms the value of a macro parameter into the equivalent string literal.

This is a very specific macro. It is typically used only inside the definition of another macro. It is similar to the # token in the preprocessor but has a slightly different effect. The # token transforms the text of a macro parameter into a string while TS_STRINGIFY transforms the value of a macro parameter into a string, after all preprocessing substitutions.

The following example illustrates the difference between the # token and TS_STRINGIFY:

#define P1(v) printf("#parameter: %s = %d\n", #v, v)
#define P2(v) printf("TS_STRINGIFY: %s = %d\n", TS_STRINGIFY(v), v)
....
#define X 1
P1(X);
P2(X);

This will print:

#parameter: X = 1
TS_STRINGIFY: 1 = 1

◆ TS_USTRINGIFY

#define TS_USTRINGIFY (   x)

This macro transforms the value of a macro parameter into the equivalent 16-bit Unicode string literal.

This macro is equivalent to TS_STRINGIFY() except that the string literal is of the for u"..." instead of "..."

See also
TS_STRINGIFY()

◆ TS_UNIQUE_NAME

#define TS_UNIQUE_NAME (   prefix)

This macro generates a unique name based on the source line number.

It is typically used in more complex macro definitions. These complex macros should be defined on one single line. All invocations of TS_UNIQUE_NAME generate the same symbol when placed one the same source line.

Parameters
prefixPrefix for the symbol. Using different prefixes, several distinct unique identifiers can be used on the same line.

◆ TS_PRAGMA

#define TS_PRAGMA (   directive)

Helper macro for the C++11 keyword _Pragma.

With the C++11 standard, the keywork _Pragma uses a string literal. However, Visual C++ does not support it as of Visual Studio 2019. Instead, it uses the non-standard keyword __pragma with a plain directive (not a string).

Parameters
directiveThe directive for the pragma. Plain directive, not a string literal.

Examples (depending on compilers):

TS_PRAGMA(clang diagnostic push)
TS_PRAGMA(GCC diagnostic push)
TS_PRAGMA(warning(push))

◆ TS_PUSH_WARNING

#define TS_PUSH_WARNING ( )

Save the compiler's warnings reporting.

See also
TS_POP_WARNING

◆ TS_POP_WARNING

#define TS_POP_WARNING ( )

Restore the compiler's warnings reporting from a previous TS_PUSH_WARNING().

See also
TS_PUSH_WARNING

◆ TS_LLVM_NOWARNING

#define TS_LLVM_NOWARNING (   name)

Disable a warning with the LLVM/clang compiler (does nothing on other compilers).

Parameters
nameWarning name, as used after command line option -W

◆ TS_GCC_NOWARNING

#define TS_GCC_NOWARNING (   name)

Disable a warning with the GCC compiler (does nothing on other compilers).

Parameters
nameWarning name, as used after command line option -W

◆ TS_MSC_NOWARNING

#define TS_MSC_NOWARNING (   num)

Disable a warning with the Microsoft Visual C++ compiler (does nothing on other compilers).

Parameters
numWarning number.

◆ TS_DVB_API_VERSION

#define TS_DVB_API_VERSION

On Linux systems, identify the Linux DVB API version in one value.

Example: TS_DVB_API_VERSION is 503 for DVB API version 5.3.

◆ TS_UNUSED

#define TS_UNUSED   platform_specific

Attribute for explicitly unused variables.

It is sometimes required to declare unused variables. This may be temporary, before completing the code and using the variable later, or for any other reason. When the compiler is used in "paranoid" warning mode, declaring unused variables may trigger a warning or an error.

When you know that you need to declare an unused variable, the special macro TS_UNUSED shall be used as an attribute of the variable. Using this attribute, the compiler will no longer complain that the variable is unused.

Example:

TS_UNUSED int i;

◆ TS_FUNCTION

#define TS_FUNCTION

Definition of the name of the current function.

This is typically func but recent compilers have "pretty" names for C++.

◆ TSDUCKDLL

#define TSDUCKDLL

Attribute to declare a class or function from tsduck.dll on Windows.

When building tsduck.dll on Windows, define _TSDUCKDLL_IMPL in the project options. When building a project which references tsduck.dll, define _TSDUCKDLL_USE. All API located inside tsduck.dll shall be prefixed by TSDUCKDLL in headers. This prefix exports the API when building the DLL and imports the API when used in an application.

◆ TS_NEED_STATIC_CONST_DEFINITIONS

#define TS_NEED_STATIC_CONST_DEFINITIONS

Compilation of definitions of C++ constants.

It is a well-known pattern in C++ to define constants in header files as static const. Example:

static const int FOO = 1;

According to Stroustrup 10.4.6.2, this is only a declaration, which needs a definition somewhere else, without initialization. Example:

const int classname::FOO;

This is a really stupid oddity of C++ which is handled differently by compilers:

  • GCC, with optimization: The declaration alone is fine. The definition is accepted.
  • GCC, without optimization: Sometimes, depending on the way the constants are used, the definition is required. Without definition, the linker complains about an undefined symbol.
  • Microsoft C: The definition must not be used. Otherwise, the linker complains about a multiply defined symbol.

As a consequence, there are situations where the definition is required and situations where the definition is forbidden. The presence of the definition shall be conditioned to the macro TS_NEED_STATIC_CONST_DEFINITIONS.

Example: In tsFoo.h, the constant is declared as:

namespace ts {
class Foo
{
public:
static const size_t MAX_ENTRIES = 10;
...

In tsFoo.cpp, the definition of the constant shall be conditionally compiled since all compilers do not behave identically:

#if defined(TS_NEED_STATIC_CONST_DEFINITIONS)
const size_t ts::Foo::MAX_ENTRIES;
#endif

◆ TS_NOCOPY

#define TS_NOCOPY (   classname)
Value:
private: \
classname(classname&&) = delete; \
classname(const classname&) = delete; \
classname& operator=(classname&&) = delete; \
classname& operator=(const classname&) = delete

A macro to disable object copy in the definition of a class.

The copy and move constructors and assignments are explicitly deleted.

Parameters
classnameName of the enclosing class.

◆ TS_NOBUILD_NOCOPY

#define TS_NOBUILD_NOCOPY (   classname)
Value:
private: \
classname() = delete; \
classname(classname&&) = delete; \
classname(const classname&) = delete; \
classname& operator=(classname&&) = delete; \
classname& operator=(const classname&) = delete

A macro to disable default constructor and object copy in the definition of a class.

The default, copy and move constructors and assignments are explicitly deleted.

Parameters
classnameName of the enclosing class.

◆ TS_SIZE_T_IS_STDINT

#define TS_SIZE_T_IS_STDINT

Defined is size_t is an exact overload of some predefined uintXX_t.

In that case, it is not possible to declare distinct overloads of a function with size_t and uint32_t or uint64_t for instance.

◆ TS_CONST64

#define TS_CONST64 (   n)

Portable definition of a 64-bit signed literal.

The C/C++ languages define the syntax for integer literals. An integer literal is always typed. Without suffix such as in 0, the literal has type int. With an L suffix, such as in 0L, the literal has type long. But there is no standard suffix or syntax for 64-bit literals; different compilers have different syntaxes.

This macro is a portable way to write 64-bit signed literals.

Example:

const int64_t aBigOne = TS_CONST64(0x7FFFFFFFFFFFFFFF);

◆ TS_UCONST64

#define TS_UCONST64 (   n)

Portable definition of a 64-bit unsigned literal.

The C/C++ languages define the syntax for integer literals. An integer literal is always typed. Without suffix such as in 0, the literal has type int. With an L suffix, such as in 0L, the literal has type long. But there is no standard suffix or syntax for 64-bit literals; different compilers have different syntaxes.

This macro is a portable way to write 64-bit unsigned literals.

Example:

const uint64_t aBigOne = TS_UCONST64(0xFFFFFFFFFFFFFFFF);

◆ TS_NO_MEMORY_BARRIER

#define TS_NO_MEMORY_BARRIER

To be defined to implement memory barrier as a no-operation.

This symbol shall be defined by the developer on the command line to ensure that no specific memory barrier instruction is generated.

This can be useful in some environments (for instance using valgrind on the ARM architecture) when the memory barrier causes some trouble.

Note that not using memory barrier instructions can cause some extremely rare race conditions.

◆ TS_SOCKET_T_INVALID

#define TS_SOCKET_T_INVALID   platform_specific

Value of type TS_SOCKET_T which is returned by the socket() system call in case of failure.

Example:

TS_SOCKET_T sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == TS_SOCKET_T_INVALID) {
... error processing ...
}

◆ TS_SOCKET_L_LINGER_T

#define TS_SOCKET_L_LINGER_T (   x)    platform_specific

Type conversion macro for the field l_linger in the struct linger socket option.

All systems do not use the same type size and this may generate some warnings. Example:

struct linger lin;
lin.l_linger = TS_SOCKET_L_LINGER_T(seconds);

◆ TS_SOCKOPT_T

#define TS_SOCKOPT_T (   x)    platform_specific

Type conversion macro for the address of a socket option value.

The "standard" parameter type is void* but some systems use other exotic values. Example:

TS_SOCKET_TTL_T ttl = 10;
if (setsockopt(sock, IPPROTO_IP, IP_TTL, TS_SOCKOPT_T(&ttl), sizeof(ttl)) != 0) {
... error processing ...
}

◆ TS_RECVBUF_T

#define TS_RECVBUF_T (   x)    platform_specific

Type conversion macro for the address of the data buffer for a recv() system call.

The "standard" parameter type is void* but some systems use other exotic values. Example:

TS_SOCKET_SSIZE_T got = recv(sock, TS_RECVBUF_T(&data), max_size, 0);

◆ TS_SENDBUF_T

#define TS_SENDBUF_T (   x)    platform_specific

Type conversion macro for the address of the data buffer for a send() system call.

The "standard" parameter type is void* but some systems use other exotic values. Example:

TS_SOCKET_SSIZE_T gone = send(sock, TS_SENDBUF_T(&data), size, 0);

◆ TS_SOCKET_IOCTL

#define TS_SOCKET_IOCTL   platform_specific

Name of the ioctl() system call which applies to socket devices.

The "standard" name is ioctl but some systems use other exotic names. Note that the ioctl() system call is rarely used on sockets. Most options are accessed through getsockopt() and setsockopt().

◆ TS_SOCKET_CLOSE

#define TS_SOCKET_CLOSE   platform_specific

Name of the close() system call which applies to socket devices.

The "standard" name is close but some systems use other exotic names. Example:

◆ TS_SOCKET_SHUT_RDWR

#define TS_SOCKET_SHUT_RDWR   platform_specific

Name of the option for the shutdown() system call which means "close on both directions".

Example:

shutdown(sock, TS_SOCKET_SHUT_RDWR);

◆ TS_SOCKET_SHUT_RD

#define TS_SOCKET_SHUT_RD   platform_specific

Name of the option for the shutdown() system call which means "close on receive side".

Example:

shutdown(sock, TS_SOCKET_SHUT_RD);

◆ TS_SOCKET_SHUT_WR

#define TS_SOCKET_SHUT_WR   platform_specific

Name of the option for the shutdown() system call which means "close on send side".

Example:

shutdown(sock, TS_SOCKET_SHUT_WR);

◆ TSDUCK_SOURCE

#define TSDUCK_SOURCE

This macro inserts a build mark in the source code, identifying it as part or TSDuck.

The string is built from fields, separated by '|'. The list of fields is:

  • Marker prefix: @($%)
  • String literal "tsduck"
  • TSDuck version number.
  • Compilation date. According to the C11 and C++11 standards, the value of the macro DATE is a character string literal of the form "Mmm dd yyyy", where the names of the months are the same as those generated by the asctime function, and the first character of dd is a space character if the value is less than 10.
  • Compilation time. According to the C11 and C++11 standards, the value of the macro TIME is a character string literal of the form "hh:mm:ss" as in the time generated by the asctime function.
  • Name of the source file which invokes the macro.

Typedef Documentation

◆ TS_SOCKET_SOCKLEN_T

typedef platform_specific TS_SOCKET_SOCKLEN_T

Integer data type which receives the length of a struct sockaddr.

Example:

struct sockaddr sock_addr;
TS_SOCKET_SOCKLEN_T len = sizeof(sock_addr);
if (getsockname(sock, &sock_addr, &len) != 0) {
... error processing ...
}

◆ TS_SOCKET_SSIZE_T

typedef platform_specific TS_SOCKET_SSIZE_T

Integer data type for a "signed size" returned from send() or recv() system calls.

Example:

TS_SOCKET_SSIZE_T got = recv(sock, TS_RECVBUF_T(&data), max_size, 0);

◆ TS_SOCKET_TTL_T

typedef platform_specific TS_SOCKET_TTL_T

Integer data type for the Time To Live (TTL) socket option.

Example:

TS_SOCKET_TTL_T ttl = 10;
if (setsockopt(sock, IPPROTO_IP, IP_TTL, TS_SOCKOPT_T(&ttl), sizeof(ttl)) != 0) {
... error processing ...
}

◆ TS_SOCKET_MC_TTL_T

typedef platform_specific TS_SOCKET_MC_TTL_T

Integer data type for the multicast Time To Live (TTL) socket option.

Example:

if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, TS_SOCKOPT_T(&mttl), sizeof(mttl)) != 0) {
... error processing ...
}

◆ TS_SOCKET_PKTINFO_T

typedef platform_specific TS_SOCKET_PKTINFO_T

Integer data type for the IP_PKTINFO socket option.

Example:

if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, TS_SOCKOPT_T(&state), sizeof(state)) != 0) {
... error processing ...
}