Any++
Loading...
Searching...
No Matches
ANY_SINGLETON macros

Macros to reduce boilerplate for declaring/defining static runtime data. More...

Macros

#define ANY_SINGLETON_DECLARE(export_, name, ...)
 Declare access to a singleton object in a header file.
#define ANY_SINGLETON(namespace_, name, ...)
 Define a singleton object in a source file.

Detailed Description

Macros to reduce boilerplate for declaring/defining static runtime data.

To enable some dynamic functionality (crosscast, open dispatch) there must be some static data holding information to perform these operations. Extra care must be taken in a DLL scenario.

To reduce boilerplate code, Any++ supplies these macros.

Macro Definition Documentation

◆ ANY_SINGLETON

#define ANY_SINGLETON ( namespace_,
name,
... )
Value:
namespace_::name##_t& namespace_::get_##name() { \
static name##_t singleton_{__VA_ARGS__}; \
return singleton_; \
};

Define a singleton object in a source file.

Parameters
namespace_The namespace for the singleton.
nameName of the singleton.
__VA_ARGS__Parameters for the singleton constructor.

See also ANY_SINGLETON_DECLARE.

Examples
21_Tree_any_borrow_as.cpp.

◆ ANY_SINGLETON_DECLARE

#define ANY_SINGLETON_DECLARE ( export_,
name,
... )
Value:
using name##_t = __VA_ARGS__; \
export_ extern name##_t& get_##name(); \
static inline name##_t& name = get_##name();

Declare access to a singleton object in a header file.

Parameters
export_To supply an export macro in a DLL scenario.
nameName of the singleton.
__VA_ARGS__Type of the singleton object.

This macro should reside inside the namespace you wish the singleton to reside. See also ANY_SINGLETON.

Examples
21_Tree_any_borrow_as.cpp.