40 #define NCBI_USE_ERRCODE_X Corelib_Config
67 bool s_StringToBool(
const string&
value)
77 string s_GetEnvVarName(
const char* section,
79 const char* env_var_name)
82 if ( env_var_name && *env_var_name ) {
83 env_var = env_var_name;
87 if ( section && *section ) {
99 const TXChar* s_GetEnv(
const char* section,
100 const char* variable,
101 const char* env_var_name)
104 s_GetEnvVarName(section, variable, env_var_name).c_str() ));
107 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
108 static const char*
const CONFIG_DUMP_SECTION =
"NCBI";
109 static const char*
const CONFIG_DUMP_VARIABLE =
"CONFIG_DUMP_VARIABLES";
111 CONFIG_DUMP_VARIABLE,
115 static volatile bool s_InConfigDump =
false;
117 inline bool s_CanDumpConfig(
void)
126 #define DUMP_CONFIG(code, data) \
127 if ( !s_InConfigDump ) { \
128 s_InConfigDump = true; \
129 ERR_POST_X(code, Note << data); \
130 s_InConfigDump = false; \
134 const char* variable,
135 const char* env_var_name,
138 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
139 bool is_config_dump =
NStr::Equal(section, CONFIG_DUMP_SECTION) &&
145 const TXChar*
str = s_GetEnv(section, variable, env_var_name);
149 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
150 if ( is_config_dump ) {
151 s_ConfigDump =
value;
153 if ( s_CanDumpConfig() ) {
154 if ( section && *section ) {
156 " [" << section <<
"]"
160 s_GetEnvVarName(section, variable, env_var_name));
177 if ( section && *section ) {
180 const string& s = app->
GetConfig().
Get(section, variable);
183 bool value = s_StringToBool(s);
184 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
185 if ( is_config_dump ) {
186 s_ConfigDump =
value;
188 if ( s_CanDumpConfig() ) {
190 " [" << section <<
"]"
204 bool value = default_value;
205 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
206 if ( is_config_dump ) {
207 s_ConfigDump =
value;
209 if ( s_CanDumpConfig() ) {
210 if ( section && *section ) {
212 " [" << section <<
"]"
230 const char* variable,
231 const char* env_var_name,
236 const TXChar*
str = s_GetEnv(section, variable, env_var_name);
240 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
241 if ( s_CanDumpConfig() ) {
242 if ( section && *section ) {
244 " [" << section <<
"]"
248 s_GetEnvVarName(section, variable, env_var_name));
265 if ( section && *section ) {
268 const string& s = app->
GetConfig().
Get(section, variable);
272 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
273 if ( s_CanDumpConfig() ) {
275 " [" << section <<
"]"
289 int value = default_value;
290 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
291 if ( s_CanDumpConfig() ) {
292 if ( section && *section ) {
294 " [" << section <<
"]"
312 const char* variable,
313 const char* env_var_name,
314 double default_value)
318 const TXChar*
str = s_GetEnv(section, variable, env_var_name);
324 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
325 if ( s_CanDumpConfig() ) {
326 if ( section && *section ) {
328 " [" << section <<
"]"
332 s_GetEnvVarName(section, variable, env_var_name));
349 if ( section && *section ) {
352 const string& s = app->
GetConfig().
Get(section, variable);
358 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
359 if ( s_CanDumpConfig() ) {
361 " [" << section <<
"]"
375 double value = default_value;
376 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
377 if ( s_CanDumpConfig() ) {
378 if ( section && *section ) {
380 " [" << section <<
"]"
398 const char* variable,
399 const char* env_var_name,
400 const char* default_value,
405 const TXChar*
value = s_GetEnv(section, variable, env_var_name);
407 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
408 if ( s_CanDumpConfig() ) {
409 if ( section && *section ) {
411 " [" << section <<
"]"
413 " = \"" <<
value <<
"\""
415 s_GetEnvVarName(section, variable, env_var_name));
420 " = \"" <<
value <<
"\""
429 if ( section && *section ) {
432 const string& v = app->
GetConfig().
Get(section, variable);
434 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
435 if ( s_CanDumpConfig() ) {
437 " [" << section <<
"]"
439 " = \"" <<
value <<
"\""
448 const char* dvalue = default_value? default_value:
"";
450 #ifdef NCBI_PARAM_ENABLE_CONFIG_DUMP
451 if ( s_CanDumpConfig() ) {
452 if ( section && *section ) {
454 " [" << section <<
"]"
456 " = \"" << dvalue <<
"\""
462 " = \"" << dvalue <<
"\""
CAtomicCounter_WithAutoInit –.
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
bool FinishedLoadingConfig(void) const
Check if the application has finished loading config file (successfully or not).
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
TValue Get(void) const THROWS_NONE
Get atomic counter value.
static bool IsMainThreadDataInitialized(void)
TErrCode GetErrCode(void) const
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
int g_GetConfigInt(const char *section, const char *variable, const char *env_var_name, int default_value)
Get integer configuration value.
double g_GetConfigDouble(const char *section, const char *variable, const char *env_var_name, double default_value)
Get double configuration value.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
static void EnableConfigDump(bool enable)
string g_GetConfigString(const char *section, const char *variable, const char *env_var_name, const char *default_value, CParamBase::EParamSource *src)
Helper functions for getting values from registry/environment.
EParamSource
Source of the value returned by CParam::GetDefault().
bool g_GetConfigFlag(const char *section, const char *variable, const char *env_var_name, bool default_value)
Get boolean configuration value.
@ eNoThreadValue
Per-thread value is prohibited by flags.
@ eRecursion
Recursion while initializing param.
@ eParserError
Can not convert string to value.
@ eBadValue
Unexpected parameter value.
@ eSource_EnvVar
Environment.
@ eSource_Config
The app. config file.
@ eSource_NotSet
Not fully initialized.
@ eSource_Default
Hardcoded default.
virtual const string & Get(const string §ion, const string &name, TFlags flags=0) const
Get the parameter value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static bool StringToBool(const CTempString str)
Convert string to bool.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
static string & ToUpper(string &str)
Convert string to upper case – string& version.
@ fAllowTrailingSpaces
Ignore trailing space characters.
@ fAllowLeadingSpaces
Ignore leading spaces in converted string.
@ fDecimalPosixOrLocal
StringToDouble*(): For decimal point, try both C and current locale.
#define NCBI_XNCBI_EXPORT
Definition of all error codes used in corelib (xncbi.lib).
static CAtomicCounter_WithAutoInit s_ConfigDumpDisabled(0)
Helper functions for getting values from registry/environment.
#define DUMP_CONFIG(code, data)
const char * kNcbiConfigPrefix
static const char * str(char *buf, int n)