Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
OptionalArgs.hxx File Reference

Go to the source code of this file.

Classes

class  Fetcher< DATA_TYPE, N >
 Used as an argument to the get(Fetcher) function in the OptionalArg implementation to select which entry to retrieve. More...
 
class  Specifier< DATA_TYPE, N, defval >
 Used as an argument to the constructor of the OptionalArg implementation to represent that a specific argument has to be overridden with a given value. More...
 
class  OptionalArg< Decl >
 Terminates the class recursion template. More...
 
class  OptionalArg< Decl, Specifier, TArgs... >
 Template recursion entry. More...
 

Macros

#define DECLARE_OPTIONALARG(SpecName, function_name, DataType, N, DEF)
 Use this macro in the Defs structure of an optional args instance to add an optional argument.
 
#define DEFINE_OPTIONALARG(SpecName, function_name, DataType)
 Use this macro in the final optionalargs structure.
 

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.

Constexpr structure for storing a list of optional arguments to a function that needs to be optimized at compile time.

Author
Balazs Racz
Date
24 November 2015

Definition in file OptionalArgs.hxx.

Macro Definition Documentation

◆ DECLARE_OPTIONALARG

#define DECLARE_OPTIONALARG (   SpecName,
  function_name,
  DataType,
  N,
  DEF 
)
Value:
using SpecName = Specifier<DataType, N, (DEF)>; \
using SpecName##Get = Fetcher<DataType, N>; \
static constexpr int check_arguments_are_valid(const SpecName s) \
{ \
return 0; \
}
Used as an argument to the get(Fetcher) function in the OptionalArg implementation to select which en...
Used as an argument to the constructor of the OptionalArg implementation to represent that a specific...

Use this macro in the Defs structure of an optional args instance to add an optional argument.

Parameters
SpecNameName by which the user will specify the given argument. Usually capitalized like a class.
function_namefunction name by which to access the argument in the final structure. Usually lower_case like a function name.
DataTypeC++ data type of the argument
NA unique integer assigned to this argument in the current optionalargs instance (and its base classes).
DEFDefault value that should be returned from the structure if the user does not specify it.

Definition at line 86 of file OptionalArgs.hxx.

◆ DEFINE_OPTIONALARG

#define DEFINE_OPTIONALARG (   SpecName,
  function_name,
  DataType 
)
Value:
constexpr DataType function_name() const \
{ \
return get(SpecName##Get()); \
} \
constexpr bool has_##function_name() const \
{ \
return has(SpecName##Get()); \
}

Use this macro in the final optionalargs structure.

Each entry in the Defs structure should have a definition with matching options.

Parameters
SpecNamesame as in DECLARE_OPTIONALARG
function_namesame as in DECLARE_OPTIONALARG
DataTypesame as in DECLARE_OPTIONALARG

Definition at line 100 of file OptionalArgs.hxx.