nx_metadata_sdk 1.0 Metadata SDK

ini_config_c_impl.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <nx/kit/ini_config.h>
6
7 #include <ini_config_c.h> //< Needed for IDE convenience, since already included from "ini.h".
8
9 using nx::kit::IniConfig;
10
11 struct Ini ini; //< Definition of Ini instance global variable.
12
13 namespace {
14
15 struct CppIni: public IniConfig
16 {
17 CppIni(): IniConfig(NX_INI_FILE)
18 {
19 // Call reg...Param() for each param, and assign default values.
20
21 #undef NX_INI_FLAG
22 #undef NX_INI_INT
23 #undef NX_INI_STRING
24 #undef NX_INI_FLOAT
25
26 #define NX_INI_FLAG(DEFAULT, PARAM, DESCR) \
27 pIni->PARAM = regBoolParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
28 #define NX_INI_INT(DEFAULT, PARAM, DESCR) \
29 pIni->PARAM = regIntParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
30 #define NX_INI_STRING(DEFAULT, PARAM, DESCR) \
31 pIni->PARAM = regStringParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
32 #define NX_INI_FLOAT(DEFAULT, PARAM, DESCR) \
33 pIni->PARAM = regFloatParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
34
35 NX_INI_STRUCT //< Fields initialization: expands using the macros defined above.
36 }
37
38 Ini* const pIni = &ini;
39 };
40
41 static CppIni cppIni;
42
43 } // namespace
44
45 bool nx_ini_isEnabled()
46 {
47 return IniConfig::isEnabled();
48 }
49
50 void nx_ini_setOutput(NxIniOutput output)
51 {
52 switch (output)
53 {
54 case NX_INI_OUTPUT_NONE: IniConfig::setOutput(nullptr); break;
55 case NX_INI_OUTPUT_STDOUT: IniConfig::setOutput(&std::cout); break;
56 case NX_INI_OUTPUT_STDERR: IniConfig::setOutput(&std::cerr); break;
57 default:
58 std::cerr << "nx_ini_setOutput(): INTERNAL ERROR: Invalid NxIniOutput: "
59 << output << std::endl;
60 }
61 }
62
63 void nx_ini_reload()
64 {
65 cppIni.reload();
66 }
67
68 const char* nx_ini_iniFile()
69 {
70 return cppIni.iniFile();
71 }
72
73 void nx_ini_setIniFilesDir(const char* value)
74 {
75 IniConfig::setIniFilesDir(value);
76 }
77
78 const char* nx_ini_iniFilesDir()
79 {
80 return IniConfig::iniFilesDir();
81 }
82
83 const char* nx_ini_iniFilePath()
84 {
85 return cppIni.iniFilePath();
86 }
nx::kit::IniConfig
Definition: ini_config.h:77
ini_config_c.h
ini
static TestIni & ini()
Definition: ini_config_ut.cpp:69