Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
macros.h File Reference
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define HASSERT(x)   do { assert(x); } while(0)
 Checks that the value of expression x is true, else terminates the current process.
 
#define DIE(MSG)   do { fprintf(stderr, "Crashed in file " __FILE__ " line %d: " MSG "\n", __LINE__); g_death_file = __FILE__; g_death_lineno = __LINE__; abort(); } while(0)
 Unconditionally terminates the current process with a message.
 
#define DASSERT(x)   HASSERT(x)
 Debug assertion facility.
 
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
 Removes default copy-constructor and assignment added by C++.
 
#define OVERRIDE   override
 Function attribute for virtual functions declaring that this funciton is overriding a funciton that should be virtual in the base class.
 
#define ARRAYSIZE(a)   (sizeof(a) / sizeof(a[0]))
 Returns the number of elements in a statically defined array (of static size)
 
#define INHERIT_CONSTRUCTOR(CURRENT_CLASS, BASE_CLASS)
 Adds a constructor to the current class that proxies every argument to the base constructor.
 
#define INHERIT_CONSTEXPR_CONSTRUCTOR(CURRENT_CLASS, BASE_CLASS)
 Adds a constexpr constructor to the current class that proxies every argument to the base constructor.
 
#define C_STATIC_ASSERT(expr, name)    typedef unsigned char __attribute__((unused)) __static_assert_##name[expr ? 0 : -1]
 Static (aka compile-time) assertion for C implementation files.
 
#define ICACHE_FLASH_ATTR
 Declares (on the ESP8266) that the current function is not executed too often and should be placed in the SPI flash.
 
#define ICACHE_RAM_ATTR
 Declares (on the ESP8266) that the current function is executed often and should be placed in the instruction RAM.
 
#define GET_PARENT_PTR(ParentClass, variable)
 Retrieve a parent pointer from a member class variable.
 
#define FAKELLP(x)   static_cast<unsigned>((x) >> 32), static_cast<unsigned>((x) & 0xffffffffu)
 Helper macro for printing a node ID on printf that does not support llx.
 
#define MUST_USE_RESULT   __attribute__((__warn_unused_result__))
 Macro to signal a function that the result must be used.
 

Variables

int g_death_lineno
 Captures point of death (line).
 
const char * g_death_file
 Captures point of death (file).
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Useful macros shared across the entire codebase.

Author
Balazs Racz
Date
19 July 2013

Definition in file macros.h.

Macro Definition Documentation

◆ ARRAYSIZE

#define ARRAYSIZE (   a)    (sizeof(a) / sizeof(a[0]))

Returns the number of elements in a statically defined array (of static size)

Definition at line 185 of file macros.h.

◆ C_STATIC_ASSERT

#define C_STATIC_ASSERT (   expr,
  name 
)     typedef unsigned char __attribute__((unused)) __static_assert_##name[expr ? 0 : -1]

Static (aka compile-time) assertion for C implementation files.

For C++ use the language's builtin static_assert functionality.

Definition at line 214 of file macros.h.

◆ DASSERT

#define DASSERT (   x)    HASSERT(x)

Debug assertion facility.

Will terminate the program if the program was compiled without NDEBUG symbol.

Definition at line 159 of file macros.h.

◆ DIE

#define DIE (   MSG)    do { fprintf(stderr, "Crashed in file " __FILE__ " line %d: " MSG "\n", __LINE__); g_death_file = __FILE__; g_death_lineno = __LINE__; abort(); } while(0)

Unconditionally terminates the current process with a message.

Parameters
MSGis the message to print as cause of death.

Definition at line 143 of file macros.h.

◆ DISALLOW_COPY_AND_ASSIGN

#define DISALLOW_COPY_AND_ASSIGN (   TypeName)
Value:
\
TypeName(const TypeName &); \
\
void operator=(const TypeName &)

Removes default copy-constructor and assignment added by C++.

This macro should be used in the private part of all classes that are not meant to be copied (which is almost all classes), to avoid bugs resulting from unintended passing of the objects by value.

Definition at line 171 of file macros.h.

◆ FAKELLP

#define FAKELLP (   x)    static_cast<unsigned>((x) >> 32), static_cast<unsigned>((x) & 0xffffffffu)

Helper macro for printing a node ID on printf that does not support llx.

Definition at line 245 of file macros.h.

◆ GET_PARENT_PTR

#define GET_PARENT_PTR (   ParentClass,
  variable 
)
Value:
reinterpret_cast<ParentClass *>( \
reinterpret_cast<char *>(this) - offsetof(ParentClass, variable));

Retrieve a parent pointer from a member class variable.

UNSAFE. Usage: class Parent { ... class Inner { void dosth() { Parent* p = GET_PARENT_PTR(Parent, innerVar_); p->call(); } } innerVar_; };

Definition at line 239 of file macros.h.

◆ HASSERT

#define HASSERT (   x)    do { assert(x); } while(0)

Checks that the value of expression x is true, else terminates the current process.

Parameters
xis the assertion expression that should evaluate to true.

Definition at line 138 of file macros.h.

◆ ICACHE_FLASH_ATTR

#define ICACHE_FLASH_ATTR

Declares (on the ESP8266) that the current function is not executed too often and should be placed in the SPI flash.

Definition at line 222 of file macros.h.

◆ ICACHE_RAM_ATTR

#define ICACHE_RAM_ATTR

Declares (on the ESP8266) that the current function is executed often and should be placed in the instruction RAM.

Definition at line 225 of file macros.h.

◆ INHERIT_CONSTEXPR_CONSTRUCTOR

#define INHERIT_CONSTEXPR_CONSTRUCTOR (   CURRENT_CLASS,
  BASE_CLASS 
)
Value:
template <typename... Args> \
explicit constexpr CURRENT_CLASS(Args... args) \
: BASE_CLASS(args...) \
{ \
}
#define BASE_CLASS
Define StlMap as the base class for Map.
Definition Map.hxx:47

Adds a constexpr constructor to the current class that proxies every argument to the base constructor.

Parameters
CURRENT_CLASSthe name of the current class
BASE_CLASSthe name of the immediate base class

Definition at line 205 of file macros.h.

◆ INHERIT_CONSTRUCTOR

#define INHERIT_CONSTRUCTOR (   CURRENT_CLASS,
  BASE_CLASS 
)
Value:
template <typename... Args> \
explicit CURRENT_CLASS(Args... args) \
: BASE_CLASS(args...) \
{ \
}

Adds a constructor to the current class that proxies every argument to the base constructor.

Parameters
CURRENT_CLASSthe name of the current class
BASE_CLASSthe name of the immediate base class

Definition at line 193 of file macros.h.

◆ MUST_USE_RESULT

#define MUST_USE_RESULT   __attribute__((__warn_unused_result__))

Macro to signal a function that the result must be used.

Definition at line 248 of file macros.h.

◆ OVERRIDE

#define OVERRIDE   override

Function attribute for virtual functions declaring that this funciton is overriding a funciton that should be virtual in the base class.

Supported by GCC >= 4.7

Definition at line 180 of file macros.h.

Variable Documentation

◆ g_death_file

const char* g_death_file
extern

Captures point of death (file).

Definition at line 95 of file os.c.

◆ g_death_lineno

int g_death_lineno
extern

Captures point of death (line).

Definition at line 93 of file os.c.