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 #undef NX_INI_DOUBLE
26
27 #define NX_INI_FLAG(DEFAULT, PARAM, DESCR) \
28 pIni->PARAM = regBoolParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
29 #define NX_INI_INT(DEFAULT, PARAM, DESCR) \
30 pIni->PARAM = regIntParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
31 #define NX_INI_STRING(DEFAULT, PARAM, DESCR) \
32 pIni->PARAM = regStringParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
33 #define NX_INI_FLOAT(DEFAULT, PARAM, DESCR) \
34 pIni->PARAM = regFloatParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
35 #define NX_INI_DOUBLE(DEFAULT, PARAM, DESCR) \
36 pIni->PARAM = regDoubleParam(&pIni->PARAM, (DEFAULT), #PARAM, (DESCR))
37
38 NX_INI_STRUCT //< Fields initialization: expands using the macros defined above.
39 }
40
41 Ini* const pIni = &ini;
42 };
43
44 static CppIni cppIni;
45
46 } // namespace
47
48 bool nx_ini_isEnabled()
49 {
50 return IniConfig::isEnabled();
51 }
52
53 void nx_ini_setOutput(NxIniOutput output)
54 {
55 switch (output)
56 {
57 case NX_INI_OUTPUT_NONE: IniConfig::setOutput(nullptr); break;
58 case NX_INI_OUTPUT_STDOUT: IniConfig::setOutput(&std::cout); break;
59 case NX_INI_OUTPUT_STDERR: IniConfig::setOutput(&std::cerr); break;
60 default:
61 std::cerr << "nx_ini_setOutput(): INTERNAL ERROR: Invalid NxIniOutput: "
62 << output << std::endl;
63 }
64 }
65
66 void nx_ini_reload()
67 {
68 cppIni.reload();
69 }
70
71 const char* nx_ini_iniFile()
72 {
73 return cppIni.iniFile();
74 }
75
76 void nx_ini_setIniFilesDir(const char* value)
77 {
78 IniConfig::setIniFilesDir(value);
79 }
80
81 const char* nx_ini_iniFilesDir()
82 {
83 return IniConfig::iniFilesDir();
84 }
85
86 const char* nx_ini_iniFilePath()
87 {
88 return cppIni.iniFilePath();
89 }
nx::kit::IniConfig
Definition: ini_config.h:62
ini_config_c.h