stub_analytics_plugin  1.6
Network Optix Video Analytics SDK
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
nx::kit::IniConfig Class Reference

#include <ini_config.h>

Inheritance diagram for nx::kit::IniConfig:
nx::vms_server_plugins::analytics::stub::Ini

Classes

class  Impl
 

Public Member Functions

 IniConfig (const char *iniFile)
 
 IniConfig (const IniConfig &)=delete
 
IniConfigoperator= (const IniConfig &)=delete
 
const char * iniFile () const
 
const char * iniFilePath () const
 
void reload ()
 

Static Public Member Functions

static bool isEnabled ()
 
static void setOutput (std::ostream *output)
 
static const char * iniFilesDir ()
 
static void setIniFilesDir (const char *iniFilesDir)
 

Protected Member Functions

bool regBoolParam (const bool *pValue, bool defaultValue, const char *paramName, const char *description)
 
int regIntParam (const int *pValue, int defaultValue, const char *paramName, const char *description)
 
const char * regStringParam (const char *const *pValue, const char *defaultValue, const char *paramName, const char *description)
 
float regFloatParam (const float *pValue, float defaultValue, const char *paramName, const char *description)
 
double regDoubleParam (const double *pValue, double defaultValue, const char *paramName, const char *description)
 

Detailed Description

Mechanism for configuration variables that can alter the behavior of the code for the purpose of debugging and experimenting, with very little performance overhead. The default (initial) values are defined in the code and lead to the nominal behavior, which can be overridden by creating .ini files (with name=value lines) in the directory determined by the platform:

This unit can be compiled in the context of any C++ project.

Each derived class represents a dedicated .ini file. If, on attempt to load a file, it is found empty, the file is filled with default values and descriptions. The names of .ini files and their values are printed to stderr (configurable), overridden values marked with "*".

Usage example:

    struct Ini: nx::kit::IniConfig
    {
        // NOTE: Omit "reload();" if load-on-start is not needed.
        Ini(): IniConfig("my_module.ini") { reload(); }
        NX_INI_FLAG(0, myFlag, "Here 0 stands for 'false' as the default value.");
        NX_INI_INT(7, myInt, "Here 7 is the default value.");
        NX_INI_STRING("Default value", myStr, "Description.");
        NX_INI_FLOAT(1.0, myFloat, "Here 1.0 is the default value.");
        NX_INI_DOUBLE(1.0, myDouble, "Here 1.0 is the default value.");
    };
    inline Ini& ini()
    {
        static Ini ini;
        return ini;
    }

In the code, use ini().<param-name> to access the values. Call ini().reload() when needed, e.g. when certain activity starts or at regular intervals.

Constructor & Destructor Documentation

◆ IniConfig()

nx::kit::IniConfig::IniConfig ( const char *  iniFile)
explicit
Parameters
iniFileName of .ini file without a path but including ".ini" suffix.

Member Function Documentation

◆ iniFile()

const char * nx::kit::IniConfig::iniFile ( ) const
Returns
Stored copy of the string supplied to the ctor.

◆ iniFilePath()

const char * nx::kit::IniConfig::iniFilePath ( ) const

◆ iniFilesDir()

const char * nx::kit::IniConfig::iniFilesDir ( )
static
Returns
Currently used path to .ini files, including the trailing slash or backslash.

◆ isEnabled()

bool nx::kit::IniConfig::isEnabled ( )
static

If needed, reading .ini files can be disabled defining a macro at compiling ini_config.cpp: -DNX_INI_CONFIG_DISABLED - minimizes performance overhead and freezes values at defaults.

Returns
Whether the macro NX_INI_CONFIG_DISABLED was defined.

◆ reload()

void nx::kit::IniConfig::reload ( )

Reload values from .ini file, logging the values first time, or if changed.

◆ setIniFilesDir()

void nx::kit::IniConfig::setIniFilesDir ( const char *  iniFilesDir)
static

Use the specified directory for .ini files. If iniFilesDir is null or empty, and also before this call, a platform-dependent directory is used (described in this class comment), which can be changed defining a macro at compiling ini_config.cpp: -DNX_INI_CONFIG_DEFAULT_INI_FILES_DIR=<enquoted-path-with-trailing-slash-or-backslash>

Parameters
iniFilesDirShould include the trailing slash or backslash.

◆ setOutput()

void nx::kit::IniConfig::setOutput ( std::ostream *  output)
static

Change the output stream, affecting all instances, null means silent. Before this call, all output goes to std::cerr, which can be changed defining a macro at compiling ini_config.cpp: -DNX_INI_CONFIG_DEFAULT_OUTPUT=<stream-address>, where <stream-address> can be e.g. '&std::cout', or 'nullptr' for no output.


The documentation for this class was generated from the following files: