NCBI C++ ToolKit
ncbi_param.hpp
Go to the documentation of this file.

Go to the repository for this file.

1 #ifndef CORELIB___NCBI_PARAM__HPP
2 #define CORELIB___NCBI_PARAM__HPP
3 
4 /* $Id: ncbi_param.hpp 107449 2026-09-21 14:27:34Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Eugene Vasilchenko, Aleksey Grichenko
30  *
31  * File Description:
32  * Parameters storage interface
33  *
34  */
35 
36 /// @file ncbiparam.hpp
37 /// Classes for storing parameters.
38 ///
39 
40 
41 #include <corelib/ncbiapp_api.hpp>
42 #include <corelib/ncbithr.hpp>
43 #include <atomic>
44 
45 
46 /** @addtogroup Param
47  *
48  * @{
49  */
50 
51 
53 
54 
55 /////////////////////////////////////////////////////////////////////////////
56 ///
57 /// Usage of the parameters:
58 ///
59 /// - Declare the parameter with NCBI_PARAM_DECL (NCBI_PARAM_ENUM_DECL for
60 /// enums):
61 /// NCBI_PARAM_DECL(int, MySection, MyIntParam);
62 /// NCBI_PARAM_DECL(string, MySection, MyStrParam);
63 /// NCBI_PARAM_ENUM_DECL(EMyEnum, MySection, MyEnumParam);
64 ///
65 /// - Add parameter definition (this will also generate static data):
66 /// NCBI_PARAM_DEF(int, MySection, MyIntParam, 12345);
67 /// NCBI_PARAM_DEF(string, MySection, MyStrParam, "Default string value");
68 ///
69 /// - For enum parameters define mappings between strings and values
70 /// before defining the parameter:
71 /// NCBI_PARAM_ENUM_ARRAY(EMyEnum, MySection, MyEnumParam)
72 /// {
73 /// {"My_A", eMyEnum_A},
74 /// {"My_B", eMyEnum_B},
75 /// {"My_C", eMyEnum_C}
76 /// };
77 ///
78 /// NCBI_PARAM_ENUM_DEF(EMyEnum, MySection, MyEnumParam, eMyEnum_B);
79 ///
80 /// - Use NCBI_PARAM_TYPE() as parameter type:
81 /// NCBI_PARAM_TYPE(MySection, MyIntParam)::GetDefault();
82 /// typedef NCBI_PARAM_TYPE(MySection, MyStrParam) TMyStrParam;
83 /// TMyStrParam str_param; str_param.Set("Local string value");
84 ///
85 
86 
87 /////////////////////////////////////////////////////////////////////////////
88 ///
89 /// Parameter declaration and definition macros
90 ///
91 /// Each parameter must be declared and defined using the macros
92 ///
93 
94 
95 // Internal definitions
96 #define X_NCBI_PARAM_DECLNAME(section, name) \
97  SNcbiParamDesc_##section##_##name
98 
99 #define X_NCBI_PARAM_DECLNAME_SCOPE(scope, section, name) \
100  scope::SNcbiParamDesc_##section##_##name
101 
102 #define X_NCBI_PARAM_ENUMNAME(section, name) \
103  s_EnumData_##section##_##name
104 
105 // Common part of the param description structure. 'desctype' can be
106 // SParamDescription or SParamEnumDescription.
107 #define X_NCBI_PARAM_DESC_DECL(type, desctype, tagtype) \
108  { \
109  typedef tagtype TTagType; \
110  typedef type TValueType; \
111  typedef desctype<TValueType> TDescription; \
112  typedef TDescription::TStaticValue TStaticValue; \
113  typedef CStaticTls< type > TTls; \
114  static TDescription sm_ParamDescription; \
115  static TStaticValue sm_Default; \
116  static bool sm_DefaultInitialized; \
117  static TTls sm_ValueTls; \
118  static CParamBase::EParamState sm_State; \
119  static CParamBase::EParamSource sm_Source; \
120  }
121 
122 // Common definitions related to enum parser.
123 // 'ptype' is the final parameter type used to make the parser unique even
124 // if the same enum is used by another parameter.
125 #define X_NCBI_PARAM_ENUM_PARSER_DECL(type, ptype) \
126  template<> inline \
127  CParamParser< SParamEnumDescription< type >, ptype >::TValueType \
128  CParamParser< SParamEnumDescription< type >, ptype >:: \
129  StringToValue(const string& str, \
130  const TParamDesc& descr) \
131  { return CEnumParser< type, ptype >::StringToEnum(str, descr); } \
132  template<> inline string \
133  CParamParser< SParamEnumDescription< type >, ptype >:: \
134  ValueToString(const TValueType& val, \
135  const TParamDesc& descr) \
136  { return CEnumParser< type, ptype >::EnumToString(val, descr); }
137 
138 // Definition of SNcbiParamDesc_XXXX static members common for normal
139 // and enum parameters.
140 #define X_NCBI_PARAM_STATIC_DEF(descname, defval) \
141  descname::TStaticValue descname::sm_Default = defval; \
142  bool descname::sm_DefaultInitialized = false; \
143  descname::TTls descname::sm_ValueTls; \
144  CParamBase::EParamState descname::sm_State = CParamBase::eState_NotSet; \
145  CParamBase::EParamSource descname::sm_Source = CParamBase::eSource_NotSet
146 
147 
148 /// Generate typename for a parameter from its {section, name} attributes
149 #define NCBI_PARAM_TYPE(section, name) \
150  CParam< X_NCBI_PARAM_DECLNAME(section, name) >
151 
152 
153 /// Parameter declaration. Generates struct for storing the parameter.
154 /// Section and name may be used to set default value through a
155 /// registry or environment variable section_name.
156 /// @sa NCBI_PARAM_DEF
157 #define NCBI_PARAM_DECL(type, section, name) \
158  struct X_NCBI_PARAM_DECLNAME(section, name) \
159  X_NCBI_PARAM_DESC_DECL(type, SParamDescription, type)
160 
161 
162 /// Same as NCBI_PARAM_DECL but with export specifier (e.g. NCBI_XNCBI_EXPORT)
163 /// @sa NCBI_PARAM_DECL
164 #define NCBI_PARAM_DECL_EXPORT(expname, type, section, name) \
165  struct expname X_NCBI_PARAM_DECLNAME(section, name) \
166  X_NCBI_PARAM_DESC_DECL(type, SParamDescription, type)
167 
168 
169 /// Enum parameter declaration. In addition to NCBI_PARAM_DECL also
170 /// specializes CParamParser<type, ptype> to convert between strings and
171 /// enum values.
172 /// @attention
173 /// Only use this macro in the global or "ncbi" namespace, otherwise you will
174 /// get compilation errors. Using this macro in the said namespaces will not
175 /// affect usability of a created CParamParser<type, ptype> specialization
176 /// from other namespaces.
177 /// @sa NCBI_PARAM_ENUM_ARRAY
178 /// @sa NCBI_PARAM_ENUM_DEF
179 #define NCBI_PARAM_ENUM_DECL(type, section, name) \
180  struct X_NCBI_PARAM_DECLNAME(section, name); \
181  X_NCBI_PARAM_ENUM_PARSER_DECL(type, X_NCBI_PARAM_DECLNAME(section, name)) \
182  struct X_NCBI_PARAM_DECLNAME(section, name) \
183  X_NCBI_PARAM_DESC_DECL(type, SParamEnumDescription, \
184  X_NCBI_PARAM_DECLNAME(section, name))
185 
186 
187 /// Same as NCBI_PARAM_ENUM_DECL but with export specifier (e.g. NCBI_XNCBI_EXPORT)
188 /// @attention
189 /// Only use this macro in the global or "ncbi" namespace, otherwise you will
190 /// get compilation errors. Using this macro in the said namespaces will not
191 /// affect usability of a created CParamParser<type, ptype> specialization
192 /// from other namespaces.
193 /// @sa NCBI_PARAM_ENUM_DECL
194 #define NCBI_PARAM_ENUM_DECL_EXPORT(expname, type, section, name) \
195  struct expname X_NCBI_PARAM_DECLNAME(section, name); \
196  X_NCBI_PARAM_ENUM_PARSER_DECL(type, X_NCBI_PARAM_DECLNAME(section, name)) \
197  struct expname X_NCBI_PARAM_DECLNAME(section, name) \
198  X_NCBI_PARAM_DESC_DECL(type, SParamEnumDescription, \
199  X_NCBI_PARAM_DECLNAME(section, name))
200 
201 
202 /// Parameter definition. "default_value" is used to set the initial parameter
203 /// value, which may be overriden by registry or environment. The default value
204 /// must be a scalar literal for the default value to be initialized statically.
205 /// @sa NCBI_PARAM_DECL
206 #define NCBI_PARAM_DEF(type, section, name, default_value) \
207  SParamDescription< type > \
208  X_NCBI_PARAM_DECLNAME(section, name)::sm_ParamDescription = \
209  { #section, #name, 0, default_value, NULL, eParam_Default }; \
210  X_NCBI_PARAM_STATIC_DEF(X_NCBI_PARAM_DECLNAME(section, name), \
211  default_value)
212 
213 
214 /// Parameter definition. The same as NCBI_PARAM_DEF, but with a callback
215 /// used to initialize the default value.
216 /// @sa NCBI_PARAM_DEF
217 #define NCBI_PARAM_DEF_WITH_INIT(type, section, name, default_value, init) \
218  SParamDescription< type > \
219  X_NCBI_PARAM_DECLNAME(section, name)::sm_ParamDescription = \
220  { #section, #name, 0, default_value, init, eParam_Default }; \
221  X_NCBI_PARAM_STATIC_DEF(X_NCBI_PARAM_DECLNAME(section, name), \
222  default_value)
223 
224 
225 /// Definition of a parameter with additional flags.
226 /// @sa NCBI_PARAM_DEF
227 /// @sa ENcbiParamFlags
228 #define NCBI_PARAM_DEF_EX(type, section, name, default_value, flags, env) \
229  SParamDescription< type > \
230  X_NCBI_PARAM_DECLNAME(section, name)::sm_ParamDescription = \
231  { #section, #name, #env, default_value, NULL, flags }; \
232  X_NCBI_PARAM_STATIC_DEF(X_NCBI_PARAM_DECLNAME(section, name), \
233  default_value)
234 
235 
236 /// Definition of a parameter with additional flags and initialization
237 /// callback.
238 /// @sa NCBI_PARAM_DEF_WITH_INIT
239 /// @sa ENcbiParamFlags
240 #define NCBI_PARAM_DEF_EX_WITH_INIT(type, section, name, def_value, init, flags, env) \
241  SParamDescription< type > \
242  X_NCBI_PARAM_DECLNAME(section, name)::sm_ParamDescription = \
243  { #section, #name, #env, def_value, init, flags }; \
244  X_NCBI_PARAM_STATIC_DEF(X_NCBI_PARAM_DECLNAME(section, name), \
245  def_value)
246 
247 
248 /// Similar to NCBI_PARAM_DEF except it adds "scope" (class name or
249 /// namespace) to the parameter's type.
250 /// @sa NCBI_PARAM_DECL, NCBI_PARAM_DEF
251 #define NCBI_PARAM_DEF_IN_SCOPE(type, section, name, default_value, scope) \
252  SParamDescription< type > \
253  X_NCBI_PARAM_DECLNAME_SCOPE(scope, section, name)::sm_ParamDescription = \
254  { #section, #name, 0, default_value, NULL, eParam_Default }; \
255  X_NCBI_PARAM_STATIC_DEF( \
256  X_NCBI_PARAM_DECLNAME_SCOPE(scope, section, name), \
257  default_value)
258 
259 
260 // Static array of enum name+value pairs.
261 #define NCBI_PARAM_ENUM_ARRAY(type, section, name) \
262  static SEnumDescription< type > X_NCBI_PARAM_ENUMNAME(section, name)[] =
263 
264 /// Enum parameter definition. Additional 'enums' argument should provide
265 /// static array of SEnumDescription<type>.
266 /// @sa NCBI_PARAM_ENUM_ARRAY
267 #define NCBI_PARAM_ENUM_DEF(type, section, name, default_value) \
268  SParamEnumDescription< type > \
269  X_NCBI_PARAM_DECLNAME(section, name)::sm_ParamDescription = \
270  { #section, #name, 0, default_value, NULL, eParam_Default, \
271  X_NCBI_PARAM_ENUMNAME(section, name), \
272  ArraySize(X_NCBI_PARAM_ENUMNAME(section, name)) }; \
273  X_NCBI_PARAM_STATIC_DEF(X_NCBI_PARAM_DECLNAME(section, name), \
274  default_value)
275 
276 
277 /// Definition of an enum parameter with additional flags.
278 /// @sa NCBI_PARAM_ENUM_DEF
279 /// @sa ENcbiParamFlags
280 #define NCBI_PARAM_ENUM_DEF_EX(type, section, name, \
281  default_value, flags, env) \
282  SParamEnumDescription< type > \
283  X_NCBI_PARAM_DECLNAME(section, name)::sm_ParamDescription = \
284  { #section, #name, #env, default_value, NULL, flags, \
285  X_NCBI_PARAM_ENUMNAME(section, name), \
286  ArraySize(X_NCBI_PARAM_ENUMNAME(section, name)) }; \
287  X_NCBI_PARAM_STATIC_DEF(X_NCBI_PARAM_DECLNAME(section, name), \
288  default_value)
289 
290 
291 /// Define CSafeStatic_Proxy for a non-POD type using the provided POD type
292 /// to store the default value.
293 /// NOTE: The proxy specialization must be defined in 'ncbi' namespace.
294 #define NCBI_PARAM_STATIC_PROXY(user_type, pod_type) \
295  template<> class CSafeStatic_Proxy<user_type> { \
296  public: \
297  typedef user_type TValue; \
298  typedef pod_type TStaticInit; \
299  CSafeStatic_Proxy(void) {} \
300  CSafeStatic_Proxy(TStaticInit init) : m_Value(init) {} \
301  CSafeStatic_Proxy(TValue value) : m_Value(value) {} \
302  CSafeStatic_Proxy& operator=(TStaticInit init) { \
303  m_Value = init; \
304  return *this; \
305  } \
306  CSafeStatic_Proxy& operator=(TValue value) { \
307  m_Value = value; \
308  return *this; \
309  } \
310  operator TValue& (void) { return m_Value; } \
311  private: \
312  mutable TValue m_Value; \
313  }
314 
315 
316 /////////////////////////////////////////////////////////////////////////////
317 ///
318 /// CParamException
319 ///
320 /// Exception generated by param parser
321 
323 {
324 public:
325  enum EErrCode {
326  eParserError, ///< Can not convert string to value
327  eBadValue, ///< Unexpected parameter value
328  eNoThreadValue, ///< Per-thread value is prohibited by flags
329  eRecursion ///< Recursion while initializing param
330  };
331 
332  /// Translate from the error code value to its string representation.
333  virtual const char* GetErrCodeString(void) const override;
334 
335  // Standard exception boilerplate code.
337 };
338 
339 
340 
341 /////////////////////////////////////////////////////////////////////////////
342 ///
343 /// CParamParser
344 ///
345 /// Parameter parser template.
346 ///
347 /// Used to read parameter value from registry/environment.
348 /// Default implementation requires TValue to be readable from and writable
349 /// to a stream. Optimized specializations exist for string and bool types.
350 /// The template is also specialized for each enum parameter.
351 ///
352 
353 
354 template<class TDescription, class TParam>
356 {
357 public:
358  typedef TDescription TParamDesc;
359  typedef typename TDescription::TValueType TValueType;
360 
361  static TValueType StringToValue(const string& str,
362  const TParamDesc& descr);
363  static string ValueToString(const TValueType& val,
364  const TParamDesc& descr);
365 };
366 
367 
368 /////////////////////////////////////////////////////////////////////////////
369 ///
370 /// CParamBase
371 ///
372 /// Base class to provide single static mutex for parameters.
373 ///
374 
376 {
377 public:
378  /// Current param state flag - indicates which possible sources for
379  /// the param have been checked. This flag does not indicate where
380  /// does the current value originate from. It just shows the stage
381  /// of parameter loading process.
382  /// @sa EParamSource
383  enum EParamState {
384  eState_NotSet = 0, ///< The param's value has not been set yet
385  eState_InFunc = 1, ///< The initialization function is being executed
386  eState_Func = 2, ///< Initialized using FParamInit function
387  eState_User = 3, ///< Value has been set by user
388  eState_EnvVar = 4, ///< The environment variable has been checked
389  eState_Config = 5, ///< The app. config file has been checked
390  eState_Error = 99 ///< Error reading param value, do not try to re-read
391  };
392 
393  /// Source of the value returned by CParam::GetDefault().
394  /// @sa EParamState
396  eSource_NotSet, ///< Not fully initialized
397  eSource_Default, ///< Hardcoded default
398  eSource_Func, ///< Initialization function
399  eSource_User, ///< User code
400  eSource_EnvVar, ///< Environment
401  eSource_Config ///< The app. config file
402  };
403 
404  // Allow to disable config dump to avoid recursions/deadlocks (e.g. from SetupDiag).
405  static void EnableConfigDump(bool enable);
406 };
407 
408 
409 /////////////////////////////////////////////////////////////////////////////
410 ///
411 /// ENcbiParamFlags
412 ///
413 /// CParam flags
414 
416  eParam_Default = 0, ///< Default flags
417  eParam_NoLoad = 1 << 0, ///< Do not load from registry or environment
418  eParam_NoThread = 1 << 1 ///< Do not use per-thread values
419 };
420 
421 typedef int TNcbiParamFlags;
422 
423 /// Caching default value on construction of a param
425  eParamCache_Force, ///< Force caching currently set default value.
426  eParamCache_Try, ///< Cache the default value if the application
427  ///< registry is already initialized.
428  eParamCache_Defer ///< Do not try to cache the default value.
429 };
430 
431 /////////////////////////////////////////////////////////////////////////////
432 ///
433 /// CParam
434 ///
435 /// Parameter template.
436 ///
437 /// Used to store parameters with per-object values, thread-wide and
438 /// application-wide defaults. Global default value may be set through
439 /// application registry or environment.
440 ///
441 /// Do not use the class directly. Create parameters through NCBI_PARAM_DECL
442 /// and NCBI_PARAM_DEF macros.
443 ///
444 
445 template<class TDescription>
446 class CParam : public CParamBase
447 {
448 public:
450  typedef typename TDescription::TTagType TTagType;
451  typedef typename TDescription::TDescription TParamDescription;
452  typedef typename TParamDescription::TValueType TValueType;
454  typedef typename TDescription::TTls TTls;
455 
456  /// Create parameter with the thread default or global default value.
457  /// Changing defaults does not affect the existing parameter objects.
458  CParam(EParamCacheFlag cache_flag = eParamCache_Try);
459 
460  /// Create parameter with a given value, ignore defaults.
462 
463  /// Load parameter value from registry or environment.
464  /// Overrides section and name set in the parameter description.
465  /// Does not affect the existing default values.
466  CParam(const string& section, const string& name);
467 
468  ~CParam(void) {}
469 
470  /// Get current state of the param.
471  static EParamState GetState(bool* sourcing_complete = nullptr, EParamSource* param_source = nullptr);
472 
473  /// Get current parameter value. It is safe to get value from
474  /// multiple threads, but setting a new value is not MT-safe.
475  TValueType Get(void) const;
476  /// Set new parameter value (this instance only).
477  /// @note The method is not MT-safe. Use an additional external lock
478  /// if it's necessary for multiple threads to use the same variable.
479  void Set(const TValueType& val);
480  /// Reset value as if it has not been initialized yet. Next call to
481  /// Get() will cache the thread default (or global default) value.
482  /// @note The method is not MT-safe. Use an additional external lock
483  /// if it's necessary for multiple threads to use the same variable.
484  void Reset(void);
485 
486  /// Get global default value. If not yet set, attempts to load the value
487  /// from application registry or environment.
488  static TValueType GetDefault(void);
489  /// Set new global default value. Does not affect values of existing
490  /// CParam<> objects or thread-local default values.
491  static void SetDefault(const TValueType& val);
492  /// Reload the global default value from the environment/registry
493  /// or reset it to the initial value specified in NCBI_PARAM_DEF.
494  static void ResetDefault(void);
495 
496  /// Get thread-local default value if set or global default value.
497  static TValueType GetThreadDefault(void);
498  /// Set new thread-local default value.
499  static void SetThreadDefault(const TValueType& val);
500  /// Reset thread default value as if it has not been set. Unless
501  /// SetThreadDefault() is called, GetThreadDefault() will return
502  /// global default value.
503  static void ResetThreadDefault(void);
504 
505 private:
506  static SSystemMutex& s_GetLock(void);
507 
508  static TValueType& sx_GetDefault(bool force_reset = false);
509  static TTls& sx_GetTls (void);
510  static EParamState& sx_GetState(void);
511  static EParamSource& sx_GetSource(void);
512 
513  static bool sx_IsSetFlag(ENcbiParamFlags flag);
514  static bool sx_CanGetDefault(void);
515 
516  mutable atomic<bool> m_ValueSet;
518 };
519 
520 
521 /////////////////////////////////////////////////////////////////////////////
522 ///
523 /// Helper functions for getting values from registry/environment
524 ///
525 
526 /// Get string configuration value.
527 ///
528 /// @param section
529 /// Check application configuration named section first if not null.
530 /// @param variable
531 /// Variable name within application section.
532 /// If no value found in configuration file, environment variable with
533 /// name NCBI_CONFIG__section__variable or NCBI_CONFIG__variable will be
534 /// checked, depending on wether section is null.
535 /// @param env_var_name
536 /// If not empty, overrides the default NCBI_CONFIG__section__name
537 /// name of the environment variable.
538 /// @param default_value
539 /// If no value found neither in configuration file nor in environment,
540 /// this value will be returned, or empty string if this value is null.
541 /// @return
542 /// string configuration value.
543 /// @sa g_GetConfigInt(), g_GetConfigFlag()
544 string NCBI_XNCBI_EXPORT g_GetConfigString(const char* section,
545  const char* variable,
546  const char* env_var_name,
547  const char* default_value,
548  CParamBase::EParamSource* src = nullptr);
549 
550 /// Get integer configuration value.
551 ///
552 /// @param section
553 /// Check application configuration named section first if not null.
554 /// @param variable
555 /// Variable name within application section.
556 /// If no value found in configuration file, environment variable with
557 /// name NCBI_CONFIG__section__variable or NCBI_CONFIG__variable will be
558 /// checked, depending on wether section is null.
559 /// @param env_var_name
560 /// If not empty, overrides the default NCBI_CONFIG__section__name
561 /// name of the environment variable.
562 /// @param default_value
563 /// If no value found neither in configuration file nor in environment,
564 /// this value will be returned.
565 /// @return
566 /// integer configuration value.
567 /// @sa g_GetConfigString(), g_GetConfigFlag()
568 int NCBI_XNCBI_EXPORT g_GetConfigInt(const char* section,
569  const char* variable,
570  const char* env_var_name,
571  int default_value);
572 
573 /// Get boolean configuration value.
574 ///
575 /// @param section
576 /// Check application configuration named section first if not null.
577 /// @param variable
578 /// Variable name within application section.
579 /// If no value found in configuration file, environment variable with
580 /// name NCBI_CONFIG__section__variable or NCBI_CONFIG__variable will be
581 /// checked, depending on wether section is null.
582 /// @param env_var_name
583 /// If not empty, overrides the default NCBI_CONFIG__section__name
584 /// name of the environment variable.
585 /// @param default_value
586 /// If no value found neither in configuration file nor in environment,
587 /// this value will be returned.
588 /// @return
589 /// boolean configuration value.
590 /// @sa g_GetConfigString(), g_GetConfigInt()
591 bool NCBI_XNCBI_EXPORT g_GetConfigFlag(const char* section,
592  const char* variable,
593  const char* env_var_name,
594  bool default_value);
595 
596 
597 /// Get double configuration value.
598 ///
599 /// @param section
600 /// Check application configuration named section first if not null.
601 /// @param variable
602 /// Variable name within application section.
603 /// If no value found in configuration file, environment variable with
604 /// name NCBI_CONFIG__section__variable or NCBI_CONFIG__variable will be
605 /// checked, depending on wether section is null.
606 /// @param env_var_name
607 /// If not empty, overrides the default NCBI_CONFIG__section__name
608 /// name of the environment variable.
609 /// @param default_value
610 /// If no value found neither in configuration file nor in environment,
611 /// this value will be returned.
612 /// @return
613 /// double configuration value.
614 /// @sa g_GetConfigString(), g_GetConfigInt()
615 double NCBI_XNCBI_EXPORT g_GetConfigDouble(const char* section,
616  const char* variable,
617  const char* env_var_name,
618  double default_value);
619 
620 
622 
623 
624 /* @} */
625 
627 
628 #endif /* CORELIB___NCBI_PARAM__HPP */
CCoreException –.
Definition: ncbiexpt.hpp:1476
CParamBase.
Definition: ncbi_param.hpp:376
CParamException.
Definition: ncbi_param.hpp:323
CParamParser.
Definition: ncbi_param.hpp:356
CParam.
Definition: ncbi_param.hpp:447
#define true
Definition: bool.h:35
static const char * str(char *buf, int n)
Definition: stats.c:84
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
Definition: ncbiexpt.cpp:757
static void ResetDefault(void)
Reload the global default value from the environment/registry or reset it to the initial value specif...
int g_GetConfigInt(const char *section, const char *variable, const char *env_var_name, int default_value)
Get integer configuration value.
Definition: ncbi_param.cpp:229
void Reset(void)
Reset value as if it has not been initialized yet.
EParamState
Current param state flag - indicates which possible sources for the param have been checked.
Definition: ncbi_param.hpp:383
double g_GetConfigDouble(const char *section, const char *variable, const char *env_var_name, double default_value)
Get double configuration value.
Definition: ncbi_param.cpp:311
static EParamState GetState(bool *sourcing_complete=nullptr, EParamSource *param_source=nullptr)
Get current state of the param.
CParam< TDescription > TParam
Definition: ncbi_param.hpp:449
~CParam(void)
Definition: ncbi_param.hpp:468
static void SetThreadDefault(const TValueType &val)
Set new thread-local default value.
static bool sx_IsSetFlag(ENcbiParamFlags flag)
CParamParser< TParamDescription, TTagType > TParamParser
Definition: ncbi_param.hpp:453
NCBI_EXCEPTION_DEFAULT(CParamException, CCoreException)
TParamDescription::TValueType TValueType
Definition: ncbi_param.hpp:452
void Set(const TValueType &val)
Set new parameter value (this instance only).
static TValueType GetThreadDefault(void)
Get thread-local default value if set or global default value.
static bool sx_CanGetDefault(void)
TValueType m_Value
Definition: ncbi_param.hpp:517
EParamCacheFlag
Caching default value on construction of a param.
Definition: ncbi_param.hpp:424
static SSystemMutex & s_GetLock(void)
static TTls & sx_GetTls(void)
static string ValueToString(const TValueType &val, const TParamDesc &descr)
TDescription TParamDesc
Definition: ncbi_param.hpp:358
static EParamSource & sx_GetSource(void)
TValueType Get(void) const
Get current parameter value.
TDescription::TTls TTls
Definition: ncbi_param.hpp:454
TDescription::TTagType TTagType
Definition: ncbi_param.hpp:450
ENcbiParamFlags
ENcbiParamFlags.
Definition: ncbi_param.hpp:415
TDescription::TValueType TValueType
Definition: ncbi_param.hpp:359
CParam(const string &section, const string &name)
Load parameter value from registry or environment.
static void ResetThreadDefault(void)
Reset thread default value as if it has not been set.
CParam(const TValueType &val)
Create parameter with a given value, ignore defaults.
Definition: ncbi_param.hpp:461
int TNcbiParamFlags
Definition: ncbi_param.hpp:421
string g_GetConfigString(const char *section, const char *variable, const char *env_var_name, const char *default_value, CParamBase::EParamSource *src=nullptr)
Helper functions for getting values from registry/environment.
Definition: ncbi_param.cpp:397
static void SetDefault(const TValueType &val)
Set new global default value.
static EParamState & sx_GetState(void)
EParamSource
Source of the value returned by CParam::GetDefault().
Definition: ncbi_param.hpp:395
static TValueType GetDefault(void)
Get global default value.
static TValueType & sx_GetDefault(bool force_reset=false)
TDescription::TDescription TParamDescription
Definition: ncbi_param.hpp:451
atomic< bool > m_ValueSet
Definition: ncbi_param.hpp:516
bool g_GetConfigFlag(const char *section, const char *variable, const char *env_var_name, bool default_value)
Get boolean configuration value.
Definition: ncbi_param.cpp:133
static TValueType StringToValue(const string &str, const TParamDesc &descr)
@ eNoThreadValue
Per-thread value is prohibited by flags.
Definition: ncbi_param.hpp:328
@ eParserError
Can not convert string to value.
Definition: ncbi_param.hpp:326
@ eBadValue
Unexpected parameter value.
Definition: ncbi_param.hpp:327
@ eParamCache_Try
Cache the default value if the application registry is already initialized.
Definition: ncbi_param.hpp:426
@ eParamCache_Force
Force caching currently set default value.
Definition: ncbi_param.hpp:425
@ eParamCache_Defer
Do not try to cache the default value.
Definition: ncbi_param.hpp:428
@ eParam_NoLoad
Do not load from registry or environment.
Definition: ncbi_param.hpp:417
@ eParam_NoThread
Do not use per-thread values.
Definition: ncbi_param.hpp:418
@ eParam_Default
Default flags.
Definition: ncbi_param.hpp:416
@ eSource_EnvVar
Environment.
Definition: ncbi_param.hpp:400
@ eSource_NotSet
Not fully initialized.
Definition: ncbi_param.hpp:396
@ eSource_Func
Initialization function.
Definition: ncbi_param.hpp:398
@ eSource_Default
Hardcoded default.
Definition: ncbi_param.hpp:397
@ eSource_User
User code.
Definition: ncbi_param.hpp:399
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:104
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:101
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1299
CParam(void)
Definition: Param.hpp:84
Multi-threading – classes, functions, and features.
Modified on Thu Nov 12 14:29:19 2026 by modify_doxy.py rev. 717554