NCBI C++ ToolKit
ncbi_config.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_config.cpp 99115 2023-02-15 17:18:08Z vasilche $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Anatoliy Kuznetsov
27  *
28  * File Description:
29  * Parameters tree implementations
30  *
31  * ===========================================================================
32  */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbi_config.hpp>
37 #include <corelib/ncbidll.hpp>
38 #include <corelib/ncbireg.hpp>
39 #include <corelib/error_codes.hpp>
40 
41 #include <algorithm>
42 #include <memory>
43 #include <set>
44 
45 
46 #define NCBI_USE_ERRCODE_X Corelib_Config
47 
48 
50 
51 
52 static const char* kSubNode = ".SubNode";
53 static const char* kSubSection = ".SubSection";
54 static const char* kNodeName = ".NodeName";
55 static const char* kIncludeSections = ".Include";
56 
57 
58 template<class ResultSet>
59 void s_List2Set(const list<string>& src, ResultSet* dst)
60 {
61  ITERATE(list<string>, it, src) {
62  dst->insert(*it);
63  }
64 }
65 
66 
67 static
68 bool s_IsSubNode(const string& str)
69 {
70  if (NStr::CompareNocase(kSubNode, str) == 0) {
71  return true;
72  }
73  if (NStr::CompareNocase(kSubSection, str) == 0) {
74  return true;
75  }
76  return false;
77 }
78 
79 
83 
84 static
86  const string& element_name,
87  const string& element_value)
88 {
89  TParamTree* existing_node = const_cast<TParamTree*>
90  (node_ptr->FindNode(element_name,
92  if ( existing_node ) {
93  existing_node->GetValue().value = element_value;
94  }
95  else {
96  node_ptr->AddNode(TParamValue(element_name, element_value));
97  }
98 }
99 
100 
101 static
102 TParamTree* s_FindSubNode(const string& path,
103  TParamTree* tree_root)
104 {
105  list<string> name_list;
106  list<TParamTree*> node_list;
107 
108  NStr::Split(path, "/", name_list,
110  tree_root->FindNodes(name_list, &node_list);
111  return node_list.empty() ? 0 : *node_list.rbegin();
112 }
113 
114 
115 static
116 void s_ParseSubNodes(const string& sub_nodes,
117  TParamTree* parent_node,
118  TSectionMap& inc_sections,
119  set<string>& rm_sections)
120 {
121  list<string> sub_list;
122  NStr::Split(sub_nodes, ",; \t\n\r", sub_list,
124  typedef set<string, PNocase_Conditional> TSubSet;
125  TSubSet sub_set(parent_node->GetKeyEqual());
126  s_List2Set(sub_list, &sub_set);
127  ITERATE(TSubSet, sub_it, sub_set) {
128  unique_ptr<TParamTree> sub_node(new TParamTree(parent_node->GetKeyEqual()));
129  size_t pos = sub_it->rfind('/');
130  if (pos == string::npos) {
131  sub_node->GetKey() = *sub_it;
132  } else {
133  // extract the last element in the path
134  sub_node->GetKey() = sub_it->substr(pos + 1, sub_it->length());
135  }
136  inc_sections[sub_node.get()].insert(*sub_it);
137  rm_sections.insert(*sub_it);
138  parent_node->AddNode(sub_node.release());
139  }
140 }
141 
142 
143 static
144 bool s_IsParentNode(TParamTree* parent, TParamTree* child)
145 {
146  TParamTree* node = child;
147  while ( node ) {
148  if (node == parent) {
149  return true;
150  }
151  node = (TParamTree*)node->GetParent();
152  }
153  return false;
154 }
155 
156 
157 static
158 void s_IncludeNode(TParamTree* parent_node,
159  const TParamTree* inc_node)
160 {
161  TParamTree::TNodeList_CI sub_it = inc_node->SubNodeBegin();
162  TParamTree::TNodeList_CI sub_end = inc_node->SubNodeEnd();
163  for ( ; sub_it != sub_end; ++sub_it) {
164  TParamTree* sub_node =
165  parent_node->FindSubNode((*sub_it)->GetKey());
166  if ( sub_node ) {
167  // Update the existing subtree to include all missing nodes
168  s_IncludeNode(sub_node, *sub_it);
169  }
170  else {
171  // Copy the whole subtree
172  parent_node->AddNode(new TParamTree(**sub_it));
173  }
174  }
175 }
176 
177 
178 static
179 void s_ExpandSubNodes(TSectionMap& inc_sections,
180  TParamTree* tree_root,
181  TParamTree* node)
182 {
183  TSectionMap::iterator current;
184  if ( node ) {
185  current = inc_sections.find(node);
186  }
187  else {
188  current = inc_sections.begin();
189  node = current->first;
190  }
191  if (current != inc_sections.end()) {
192  // Node has included sections, expand them first.
193  ITERATE(set<string>, inc_it, current->second) {
194  TParamTree* inc_node = s_FindSubNode(*inc_it, tree_root);
195  if ( !inc_node ) {
196  continue;
197  }
198  if ( s_IsParentNode(inc_node, node) ) {
199  _TRACE(Error << "Circular section reference: "
200  << node->GetKey() << "->" << *inc_it);
201  continue; // skip the offending subnode
202  }
203  s_ExpandSubNodes(inc_sections, tree_root, inc_node);
204  s_IncludeNode(node, inc_node);
205  }
206  inc_sections.erase(current);
207  }
208  // In case there are includes on deeper levels expand them too
209  TParamTree::TNodeList_I sub_it = node->SubNodeBegin();
210  TParamTree::TNodeList_I sub_end = node->SubNodeEnd();
211  for ( ; sub_it != sub_end; ++sub_it) {
212  s_ExpandSubNodes(inc_sections, tree_root, *sub_it);
213  }
214 }
215 
216 
218 {
221  SNodeNameUpdater(TNodeSet& node_set) : rm_node_name(node_set) {}
222 
224  int /* delta_level */);
225 };
226 
227 
229  int /* delta_level */)
230 {
231  if (NStr::CompareNocase(node.GetKey(), kNodeName) == 0) {
232  TParamTree* parent = node.GetParent();
233  if ( parent && !node.GetValue().value.empty() ) {
234  parent->GetKey() = node.GetValue().value;
235  rm_node_name.insert(&node);
236  }
237  }
238  return eTreeTraverse;
239 }
240 
241 
242 static void x_Print(const CConfig::TParamTree* tree, const string& section)
243 {
244  bool started_section = false;
245  for ( auto iter = tree->SubNodeBegin(); iter != tree->SubNodeEnd(); ++iter ) {
246  auto node = *iter;
247  if ( node->IsLeaf() ) {
248  if ( !started_section ) {
249  cout << "[" << section << "]\n";
250  started_section = true;
251  }
252  cout << node->GetKey() << "=" << node->GetValue().value << "\n";
253  }
254  }
255  for ( auto iter = tree->SubNodeBegin(); iter != tree->SubNodeEnd(); ++iter ) {
256  auto node = *iter;
257  if ( !node->IsLeaf() ) {
258  x_Print(node, section + (section.empty()? "": "/") + node->GetKey());
259  }
260  }
261 }
262 
263 
265  NStr::ECase use_case)
266 {
267  const bool debug = 0;
268  unique_ptr<TParamTree> tree_root(new TParamTree(TParamTree::TKeyGetter(use_case)));
269 
270  list<string> sections;
271  reg.EnumerateSections(&sections);
272  if ( debug ) {
273  cout << "Sections:\n";
274  for ( auto& s : sections ) {
275  cout << s << "\n";
276  }
277  }
278 
279  // find the non-redundant set of top level sections
280 
281  set<string> all_section_names;
282  s_List2Set(sections, &all_section_names);
283 
284  // Collect included and sub-noded names for each section.
285  TSectionMap inc_sections;
286  // Nodes used in .SubNode must be removed from the tree root.
287  set<string> rm_sections;
288 
289  ITERATE(set<string>, name_it, all_section_names) {
290  const string& section_name = *name_it;
291  TParamTree* node_ptr;
292  if (section_name.find('/') == string::npos) {
293  unique_ptr<TParamTree> node(new TParamTree(TParamTree::TKeyGetter(use_case)));
294  node->GetKey() = section_name;
295  tree_root->AddNode(node_ptr = node.release());
296  } else {
297  list<string> sub_node_list;
298  NStr::Split(section_name, "/", sub_node_list,
300  node_ptr = tree_root->FindOrCreateNode(sub_node_list);
301  }
302 
303  bool have_explicit_name = false;
304 
305  // Create section entries
306  list<string> entries;
307  reg.EnumerateEntries(section_name, &entries);
308  if ( debug ) {
309  cout << "Entries of " << section_name << ":\n";
310  for ( auto& s : entries ) {
311  cout << s << "\n";
312  }
313  }
314 
315  ITERATE(list<string>, eit, entries) {
316  const string& element_name = *eit;
317  const string& element_value = reg.Get(section_name, element_name);
318 
319  if (NStr::CompareNocase(element_name, kNodeName) == 0) {
320  have_explicit_name = true;
321  }
322  if (NStr::CompareNocase(element_name, kIncludeSections) == 0) {
323  list<string> inc_list;
324  NStr::Split(element_value, ",; \t\n\r", inc_list,
326  s_List2Set(inc_list, &inc_sections[node_ptr]);
327  continue;
328  }
329  if (s_IsSubNode(element_name)) {
330  s_ParseSubNodes(element_value,
331  node_ptr,
332  inc_sections,
333  rm_sections);
334  continue;
335  }
336 
337  if ( debug ) {
338  cout << "[" << section_name << "]: "<<element_name<<"="<<element_value<<"\n";
339  }
340  s_AddOrReplaceSubNode(node_ptr, element_name, element_value);
341  }
342  // Force node name to prevent overriding it by includes
343  if ( !have_explicit_name ) {
344  node_ptr->AddNode(TParamValue(kNodeName, node_ptr->GetKey()));
345  }
346  }
347  s_ExpandSubNodes(inc_sections, tree_root.get(), tree_root.get());
348 
349  // Remove nodes used in .SubNode
350  ITERATE(set<string>, rm_it, rm_sections) {
351  TParamTree* rm_node = s_FindSubNode(*rm_it, tree_root.get());
352  if ( rm_node ) {
353  rm_node->GetParent()->RemoveNode(rm_node);
354  }
355  }
356 
357  // Rename nodes as requested and remove .NodeName entries
358  set<TParamTree*> rm_node_names;
359  SNodeNameUpdater name_updater(rm_node_names);
360  TreeDepthFirstTraverse(*tree_root, name_updater);
361  ITERATE(set<TParamTree*>, rm_it, rm_node_names) {
362  (*rm_it)->GetParent()->RemoveNode(*rm_it);
363  }
364 
365  /*
366  set<string> all_sections;
367  set<string> sub_sections;
368  set<string> top_sections;
369  set<string> inc_sections;
370 
371  s_List2Set(sections, &all_sections);
372 
373  {{
374  ITERATE(list<string>, it, sections) {
375  const string& section_name = *it;
376  s_GetSubNodes(reg, section_name, &sub_sections);
377  s_GetIncludes(reg, section_name, &inc_sections);
378  }
379  set<string> non_top;
380  non_top.insert(sub_sections.begin(), sub_sections.end());
381  //non_top.insert(inc_sections.begin(), inc_sections.end());
382  insert_iterator<set<string> > ins(top_sections, top_sections.begin());
383  set_difference(all_sections.begin(), all_sections.end(),
384  non_top.begin(), non_top.end(),
385  ins);
386  }}
387 
388  ITERATE(set<string>, sit, top_sections) {
389  const string& section_name = *sit;
390 
391  TParamTree* node_ptr;
392  if (section_name.find('/') == string::npos) {
393  unique_ptr<TParamTree> node(new TParamTree(TParamTree::TKeyGetter(use_case)));
394  node->GetKey() = section_name;
395  tree_root->AddNode(node_ptr = node.release());
396  } else {
397  list<string> sub_node_list;
398  NStr::Split(section_name, "/", sub_node_list);
399  node_ptr = tree_root->FindOrCreateNode( sub_node_list);
400  }
401 
402  // Get section components
403 
404  list<string> entries;
405  reg.EnumerateEntries(section_name, &entries);
406 
407  // Include other sections before processing any values
408  s_ParamTree_IncludeSections(reg, section_name, node_ptr);
409 
410  ITERATE(list<string>, eit, entries) {
411  const string& element_name = *eit;
412  const string& element_value = reg.Get(section_name, element_name);
413 
414  if (NStr::CompareNocase(element_name, kIncludeSections) == 0) {
415  continue;
416  }
417  if (NStr::CompareNocase(element_name, kNodeName) == 0) {
418  node_ptr->GetKey() = element_value;
419  continue;
420  }
421  if (s_IsSubNode(element_name)) {
422  s_ParamTree_SplitConvertSubNodes(reg, element_value, node_ptr);
423  continue;
424  }
425 
426  s_AddOrReplaceSubNode(node_ptr, element_name, element_value);
427  } // ITERATE eit
428 
429  } // ITERATE sit
430  */
431 
432  if ( debug ) {
433  x_Print(tree_root.get(), "");
434  }
435 
436  return tree_root.release();
437 }
438 
439 
441  : m_ParamTree(param_tree, own)
442 {
443  if ( !param_tree ) {
445  }
446 }
447 
448 
450 {
451  m_ParamTree.reset(ConvertRegToTree(reg, use_case), eTakeOwnership);
452  _ASSERT(m_ParamTree.get());
453 }
454 
455 
456 CConfig::CConfig(const TParamTree* param_tree, NStr::ECase use_case)
457 {
458  if ( !param_tree ) {
460  }
461  else {
462  m_ParamTree.reset(const_cast<TParamTree*>(param_tree), eNoOwnership);
463  }
464 }
465 
466 
468 {
469 }
470 
471 
472 string CConfig::GetString(const string& driver_name,
473  const string& param_name,
474  EErrAction on_error,
475  const string& default_value,
476  const list<string>* synonyms)
477 {
478  return x_GetString(driver_name, param_name,
479  on_error, default_value, synonyms);
480 }
481 
482 
483 const string& CConfig::GetString(const string& driver_name,
484  const string& param_name,
485  EErrAction on_error,
486  const list<string>* synonyms)
487 {
488  return x_GetString(driver_name, param_name,
489  on_error, kEmptyStr, synonyms);
490 }
491 
492 
493 const string& CConfig::x_GetString(const string& driver_name,
494  const string& param_name,
495  EErrAction on_error,
496  const string& default_value,
497  const list<string>* synonyms)
498 {
499  list<const TParamTree*> tns;
500  const TParamTree* tn = m_ParamTree->FindSubNode(param_name);
501 
502  if (tn && !tn->GetValue().value.empty())
503  tns.push_back(tn);
504  if (synonyms) {
505  ITERATE(list<string>, it, *synonyms) {
506  tn = m_ParamTree->FindSubNode(*it);
507  if (tn && !tn->GetValue().value.empty())
508  tns.push_back(tn);
509  }
510  }
511  if (tns.empty()) {
512  if (on_error == eErr_NoThrow) {
513  return default_value;
514  }
515  string msg = "Cannot init plugin " + driver_name +
516  ", missing parameter:" + param_name;
517  if (synonyms) {
518  ITERATE(list<string>, it, *synonyms) {
519  if ( it == synonyms->begin() ) msg += " or ";
520  else msg += ", ";
521  msg += *it;
522  }
523  }
524 
525  NCBI_THROW(CConfigException, eParameterMissing, msg);
526  }
527  if (tns.size() > 1 ) {
528  string msg = "There are more then 1 synonyms parameters (";
529  ITERATE(list<const TParamTree*>, it, tns) {
530  if (it != tns.begin()) msg += ", ";
531  msg += (*it)->GetKey();
532  }
533  msg += ") defined";
534  if (on_error == eErr_NoThrow) {
535  msg += " for driver " + driver_name + ". Default value is used.";
536  ERR_POST_X_ONCE(1, msg);
537  return default_value;
538  }
539  msg = "Cannot init plugin " + driver_name + ". " + msg;
540  NCBI_THROW(CConfigException, eSynonymDuplicate, msg);
541  }
542  return (*tns.begin())->GetValue().value;
543 }
544 
545 
546 int CConfig::GetInt(const string& driver_name,
547  const string& param_name,
548  EErrAction on_error,
549  int default_value,
550  const list<string>* synonyms)
551 {
552  const string& param = GetString(driver_name, param_name, on_error, synonyms);
553 
554  if (param.empty()) {
555  if (on_error == eErr_Throw) {
556  string msg = "Cannot init " + driver_name +
557  ", empty parameter:" + param_name;
558  NCBI_THROW(CConfigException, eParameterMissing, msg);
559  } else {
560  return default_value;
561  }
562  }
563 
564  try {
565  return NStr::StringToInt(param);
566  }
567  catch (CStringException& ex)
568  {
569  if (on_error == eErr_Throw) {
570  string msg = "Cannot init " + driver_name +
571  ", incorrect parameter format:" +
572  param_name + " : " + param +
573  " " + ex.what();
574  NCBI_THROW(CConfigException, eInvalidParameter, msg);
575  } else {
576  string msg = "Configuration error " + driver_name +
577  ", incorrect parameter format:" +
578  param_name + " : " + param +
579  " " + ex.what() + ". Default value is used";
580  ERR_POST_X_ONCE(2, msg);
581  }
582  }
583  return default_value;
584 }
585 
586 Uint8 CConfig::GetDataSize(const string& driver_name,
587  const string& param_name,
588  EErrAction on_error,
589  unsigned int default_value,
590  const list<string>* synonyms)
591 {
592  const string& param = GetString(driver_name, param_name, on_error, synonyms);
593 
594  if (param.empty()) {
595  if (on_error == eErr_Throw) {
596  string msg = "Cannot init " + driver_name +
597  ", empty parameter:" + param_name;
598  NCBI_THROW(CConfigException, eParameterMissing, msg);
599  } else {
600  return default_value;
601  }
602  }
603 
604  try {
605  return NStr::StringToUInt8_DataSize(param);
606  }
607  catch (CStringException& ex)
608  {
609  if (on_error == eErr_Throw) {
610  string msg = "Cannot init " + driver_name +
611  ", incorrect parameter format:" +
612  param_name + " : " + param +
613  " " + ex.what();
614  NCBI_THROW(CConfigException, eInvalidParameter, msg);
615  } else {
616  string msg = "Configuration error " + driver_name +
617  ", incorrect parameter format:" +
618  param_name + " : " + param +
619  " " + ex.what() + ". Default value is used";
620  ERR_POST_X_ONCE(3, msg);
621  }
622  }
623  return default_value;
624 }
625 
626 
627 bool CConfig::GetBool(const string& driver_name,
628  const string& param_name,
629  EErrAction on_error,
630  bool default_value,
631  const list<string>* synonyms)
632 {
633  const string& param = GetString(driver_name, param_name, on_error, synonyms);
634 
635  if (param.empty()) {
636  if (on_error == eErr_Throw) {
637  string msg = "Cannot init " + driver_name +
638  ", empty parameter:" + param_name;
639  NCBI_THROW(CConfigException, eParameterMissing, msg);
640  } else {
641  return default_value;
642  }
643  }
644 
645  try {
646  return NStr::StringToBool(param);
647  }
648  catch (CStringException& ex)
649  {
650  if (on_error == eErr_Throw) {
651  string msg = "Cannot init " + driver_name +
652  ", incorrect parameter format:" +
653  param_name + " : " + param +
654  ". " + ex.what();
655  NCBI_THROW(CConfigException, eInvalidParameter, msg);
656  } else {
657  string msg = "Configuration error " + driver_name +
658  ", incorrect parameter format:" +
659  param_name + " : " + param +
660  " " + ex.what() + ". Default value is used";
661  ERR_POST_X_ONCE(4, msg);
662  }
663  }
664  return default_value;
665 }
666 
667 double CConfig::GetDouble(const string& driver_name,
668  const string& param_name,
669  EErrAction on_error,
670  double default_value,
671  const list<string>* synonyms)
672 {
673  const string& param = GetString(driver_name, param_name, on_error, synonyms);
674 
675  if (param.empty()) {
676  if (on_error == eErr_Throw) {
677  string msg = "Cannot init " + driver_name +
678  ", empty parameter:" + param_name;
679  NCBI_THROW(CConfigException, eParameterMissing, msg);
680  } else {
681  return default_value;
682  }
683  }
684 
685  try {
687  }
688  catch (CStringException& ex)
689  {
690  if (on_error == eErr_Throw) {
691  string msg = "Cannot init " + driver_name +
692  ", incorrect parameter format:" +
693  param_name + " : " + param +
694  " " + ex.what();
695  NCBI_THROW(CConfigException, eInvalidParameter, msg);
696  } else {
697  string msg = "Configuration error " + driver_name +
698  ", incorrect parameter format:" +
699  param_name + " : " + param +
700  " " + ex.what() + ". Default value is used";
701  ERR_POST_X_ONCE(5, msg);
702  }
703  }
704  return default_value;
705 }
706 
707 const char* CConfigException::GetErrCodeString(void) const
708 {
709  switch (GetErrCode()) {
710  case eParameterMissing: return "eParameterMissing";
711  case eSynonymDuplicate: return "eSynonymDuplicate";
712  case eInvalidParameter: return "eInvalidParameter";
713  default: return CException::GetErrCodeString();
714  }
715 }
716 
717 
CConfigException –.
Definition: ncbi_config.hpp:53
CStringException –.
Definition: ncbistr.hpp:4508
definition of a Culling tree
Definition: ncbi_tree.hpp:100
IRegistry –.
Definition: ncbireg.hpp:73
void erase(iterator pos)
Definition: map.hpp:167
container_type::iterator iterator
Definition: map.hpp:54
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * str(char *buf, int n)
Definition: stats.c:84
void debug()
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
@ eNoOwnership
No ownership is assumed.
Definition: ncbi_types.h:135
#define _TRACE(message)
Definition: ncbidbg.hpp:122
#define ERR_POST_X_ONCE(err_subcode, message)
Error posting only once during program execution with default error code and given error subcode.
Definition: ncbidiag.hpp:621
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
TErrCode GetErrCode(void) const
Definition: ncbiexpt.hpp:1493
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
EErrAction
Defines how to behave when parameter is missing.
Uint8 GetDataSize(const string &driver_name, const string &param_name, EErrAction on_error, unsigned int default_value, const list< string > *synonyms=NULL)
Utility function to get an integer element of parameter tree Throws an exception when mandatory param...
double GetDouble(const string &driver_name, const string &param_name, EErrAction on_error, double default_value, const list< string > *synonyms=NULL)
Utility function to get a double element of parameter tree Throws an exception when mandatory paramet...
CTreePair< string, string, PEqualNocase_Conditional > TParamValue
Instantiation parameters tree.
Definition: ncbi_config.hpp:81
static TParamTree * ConvertRegToTree(const IRegistry &reg, NStr::ECase use_case=NStr::eNocase)
Reconstruct param tree from the application registry.
TParamValue::TPairTreeNode TParamTree
Definition: ncbi_config.hpp:82
int GetInt(const string &driver_name, const string &param_name, EErrAction on_error, int default_value, const list< string > *synonyms=NULL)
Utility function to get an integer element of parameter tree Throws an exception when mandatory param...
const string & x_GetString(const string &driver_name, const string &param_name, EErrAction on_error, const string &default_value, const list< string > *synonyms)
string GetString(const string &driver_name, const string &param_name, EErrAction on_error, const string &default_value, const list< string > *synonyms=NULL)
Utility function to get an element of parameter tree Throws an exception when mandatory parameter is ...
AutoPtr< TParamTree > m_ParamTree
bool GetBool(const string &driver_name, const string &param_name, EErrAction on_error, bool default_value, const list< string > *synonyms=NULL)
Utility function to get an integer element of parameter tree Throws an exception when mandatory param...
CConfig(TParamTree *param_tree, EOwnership own=eTakeOwnership, NStr::ECase use_case=NStr::eNocase)
Optionally takes ownership on passed param_tree.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
@ eErr_NoThrow
Return default value on error.
@ eErr_Throw
Throw an exception on error.
@ eParameterMissing
Missing mandatory parameter.
Definition: ncbi_config.hpp:56
@ eInvalidParameter
Invalid parameter value.
Definition: ncbi_config.hpp:58
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
virtual void EnumerateSections(list< string > *sections, TFlags flags=fAllLayers) const
Enumerate section names.
Definition: ncbireg.cpp:497
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
virtual void EnumerateEntries(const string &section, list< string > *entries, TFlags flags=fAllLayers) const
Enumerate parameter names for a specified section.
Definition: ncbireg.cpp:514
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool StringToBool(const CTempString str)
Convert string to bool.
Definition: ncbistr.cpp:2812
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3452
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
Definition: ncbistr.cpp:1381
static Uint8 StringToUInt8_DataSize(const CTempString str, TStringToNumFlags flags=0)
Convert string that can contain "software" qualifiers to Uint8.
Definition: ncbistr.cpp:1530
ECase
Which type of string comparison.
Definition: ncbistr.hpp:1204
@ fDecimalPosixOrLocal
StringToDouble*(): For decimal point, try both C and current locale.
Definition: ncbistr.hpp:301
@ fSplit_Truncate
Definition: ncbistr.hpp:2503
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2500
TNodeList::iterator TNodeList_I
Definition: ncbi_tree.hpp:109
const TKeyType & GetKey(void) const
Definition: ncbi_tree.hpp:197
const TTreeType * FindNode(const TKeyType &key, TNodeSearchMode sflag=eImmediateAndTop) const
Search for node.
Definition: ncbi_tree.hpp:970
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
Definition: ncbi_tree.hpp:504
void RemoveNode(TTreeType *subnode)
Remove subnode of the current node.
Definition: ncbi_tree.hpp:698
TKeyGetterP TKeyGetter
Definition: ncbi_tree.hpp:103
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
Definition: ncbi_tree.hpp:51
TNodeList_CI SubNodeBegin(void) const
Return first const iterator on subnode list.
Definition: ncbi_tree.hpp:160
void FindNodes(const TKeyList &node_path, TNodeList *res)
Find tree nodes corresponding to the path from the top.
Definition: ncbi_tree.hpp:840
const TKeyEqual & GetKeyEqual() const
Return key equal predicate.
Definition: ncbi_tree.hpp:201
TNodeList::const_iterator TNodeList_CI
Definition: ncbi_tree.hpp:110
void AddNode(TTreeType *subnode)
Add new subnode.
Definition: ncbi_tree.hpp:743
const TTreeType * FindSubNode(const TKeyType &key) const
Non recursive linear scan of all subnodes, with key comparison.
Definition: ncbi_tree.hpp:940
TNodeList_CI SubNodeEnd(void) const
Return last const iterator on subnode list.
Definition: ncbi_tree.hpp:166
const TValue & GetValue(void) const
Return node's value.
Definition: ncbi_tree.hpp:184
TTreeType * FindOrCreateNode(const TKeyList &node_path)
Find or create tree node corresponding to the path from the top.
Definition: ncbi_tree.hpp:873
const TTreeType * GetParent(void) const
Get node's parent.
Definition: ncbi_tree.hpp:139
@ eTreeTraverse
Keep traversal.
Definition: ncbi_tree.hpp:52
@ eImmediateSubNodes
Search direct subnodes.
Definition: ncbi_tree.hpp:346
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in corelib (xncbi.lib).
static bool s_IsParentNode(TParamTree *parent, TParamTree *child)
map< TParamTree *, set< string > > TSectionMap
Definition: ncbi_config.cpp:82
static const char * kNodeName
Definition: ncbi_config.cpp:54
static bool s_IsSubNode(const string &str)
Definition: ncbi_config.cpp:68
static TParamTree * s_FindSubNode(const string &path, TParamTree *tree_root)
static void s_AddOrReplaceSubNode(TParamTree *node_ptr, const string &element_name, const string &element_value)
Definition: ncbi_config.cpp:85
static const char * kSubSection
Definition: ncbi_config.cpp:53
static const char * kSubNode
Definition: ncbi_config.cpp:52
static const char * kIncludeSections
Definition: ncbi_config.cpp:55
static void s_ExpandSubNodes(TSectionMap &inc_sections, TParamTree *tree_root, TParamTree *node)
void s_List2Set(const list< string > &src, ResultSet *dst)
Definition: ncbi_config.cpp:59
static void s_IncludeNode(TParamTree *parent_node, const TParamTree *inc_node)
CConfig::TParamTree TParamTree
Definition: ncbi_config.cpp:80
static void s_ParseSubNodes(const string &sub_nodes, TParamTree *parent_node, TSectionMap &inc_sections, set< string > &rm_sections)
CConfig::TParamValue TParamValue
Definition: ncbi_config.cpp:81
static void x_Print(const CConfig::TParamTree *tree, const string &section)
Parameters initialization model.
Define class Dll and for Portable DLL handling.
Process information in the NCBI Registry, including working with configuration files.
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Node data template for id-value trees.
Definition: ncbi_tree.hpp:453
set< TParamTree * > TNodeSet
ETreeTraverseCode operator()(TParamTree &node, int)
TNodeSet & rm_node_name
SNodeNameUpdater(TNodeSet &node_set)
#define _ASSERT
static wxAcceleratorEntry entries[3]
Modified on Wed Sep 04 15:00:03 2024 by modify_doxy.py rev. 669887