Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
constants.hxx File Reference
#include <stddef.h>

Go to the source code of this file.

Macros

#define EXTERNC
 Allows both C and C++ compilation.
 
#define EXTERNCEND
 Allows both C and C++ compilation.
 
#define DECLARE_CONST(name)
 Declares a constant value.
 
#define DEFAULT_CONST(name, value)   DEFAULT_CONST_(name, value)
 Defines the default value of a constant.
 
#define DEFAULT_CONST_(name, value)
 
#define OVERRIDE_CONST(name, value)   OVERRIDE_CONST_(name, value)
 Overrides the value of a constant.
 
#define OVERRIDE_CONST_(name, value)
 
#define CONSTANT_TRUE   1
 We cannot compare constants to zero, so we use 1 and 2 as constant values for booleans.
 
#define CONSTANT_FALSE   2
 We cannot compare constants to zero, so we use 1 and 2 as constant values for booleans.
 
#define DEFAULT_CONST_TRUE(name)   DEFAULT_CONST(name, 1)
 Sets the default value of a boolean constant to true.
 
#define DEFAULT_CONST_FALSE(name)   DEFAULT_CONST(name, 2)
 Sets the default value of a boolean constant to false.
 
#define OVERRIDE_CONST_TRUE(name)   OVERRIDE_CONST(name, 1)
 Overrides the value of a boolean constant to true.
 
#define OVERRIDE_CONST_FALSE(name)   OVERRIDE_CONST(name, 2)
 Overrides the value of a boolean constant to false.
 

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.

Utility to specify linking-time constants and overrides for them.

Author
Balazs Racz
Date
30 Apr 2014

Definition in file constants.hxx.

Macro Definition Documentation

◆ CONSTANT_FALSE

#define CONSTANT_FALSE   2

We cannot compare constants to zero, so we use 1 and 2 as constant values for booleans.

Definition at line 160 of file constants.hxx.

◆ CONSTANT_TRUE

#define CONSTANT_TRUE   1

We cannot compare constants to zero, so we use 1 and 2 as constant values for booleans.

Definition at line 157 of file constants.hxx.

◆ DECLARE_CONST

#define DECLARE_CONST (   name)
Value:
EXTERNC extern const int _sym_##name; \
EXTERNCEND \
static inline int config_##name(void) \
{ \
return _sym_##name; \
} \
\
typedef unsigned char \
_do_not_add_declare_and_default_const_to_the_same_file_for_##name;
#define EXTERNC
Allows both C and C++ compilation.
Definition constants.hxx:44

Declares a constant value.

Put this into a header and include that header to the code which has to access that constant.

Parameters
namename of the constant. For a name NNN Creates a function called config_NNN() that returns the configured value.

Definition at line 60 of file constants.hxx.

◆ DEFAULT_CONST

#define DEFAULT_CONST (   name,
  value 
)    DEFAULT_CONST_(name, value)

Defines the default value of a constant.

Use this in a single .cxx file and make sure NOT to include the header that has the respective DECLARE_CONST macros. Best not to incude anything at all.

Parameters
namename of the constant.
valueis what the default value should be.

Definition at line 77 of file constants.hxx.

◆ DEFAULT_CONST_

#define DEFAULT_CONST_ (   name,
  value 
)
Value:
EXTERNC extern const int __attribute__((__weak__)) _sym_##name = value; \
\
typedef signed char \
_do_not_add_declare_and_default_const_to_the_same_file_for_##name;
#define EXTERNCEND
Allows both C and C++ compilation.
Definition constants.hxx:46

Definition at line 79 of file constants.hxx.

◆ DEFAULT_CONST_FALSE

#define DEFAULT_CONST_FALSE (   name)    DEFAULT_CONST(name, 2)

Sets the default value of a boolean constant to false.

Parameters
nameis the name of the constant to set.

Definition at line 167 of file constants.hxx.

◆ DEFAULT_CONST_TRUE

#define DEFAULT_CONST_TRUE (   name)    DEFAULT_CONST(name, 1)

Sets the default value of a boolean constant to true.

Parameters
nameis the name of the constant to set.

Definition at line 164 of file constants.hxx.

◆ EXTERNC

#define EXTERNC

Allows both C and C++ compilation.

Definition at line 44 of file constants.hxx.

◆ EXTERNCEND

#define EXTERNCEND

Allows both C and C++ compilation.

Definition at line 46 of file constants.hxx.

◆ OVERRIDE_CONST

#define OVERRIDE_CONST (   name,
  value 
)    OVERRIDE_CONST_(name, value)

Overrides the value of a constant.

Use this is a single .cxx file (usually main.cxx).

Parameters
namename of the constant.
valueis what the actual value should be.

Definition at line 91 of file constants.hxx.

◆ OVERRIDE_CONST_

#define OVERRIDE_CONST_ (   name,
  value 
)
Value:
EXTERNC extern const int _sym_##name; \
const int _sym_##name = value; \

Definition at line 93 of file constants.hxx.

◆ OVERRIDE_CONST_FALSE

#define OVERRIDE_CONST_FALSE (   name)    OVERRIDE_CONST(name, 2)

Overrides the value of a boolean constant to false.

Parameters
nameis the name of the constant to set.

Definition at line 174 of file constants.hxx.

◆ OVERRIDE_CONST_TRUE

#define OVERRIDE_CONST_TRUE (   name)    OVERRIDE_CONST(name, 1)

Overrides the value of a boolean constant to true.

Parameters
nameis the name of the constant to set.

Definition at line 171 of file constants.hxx.