CentralConfig.h
Go to the documentation of this file.
1 #ifndef _fwk_CentralConfig_h_
2 #define _fwk_CentralConfig_h_
3 
4 #include <utl/AugerException.h>
5 
6 #include <string>
7 #include <map>
8 #include <list>
9 #include <set>
10 #include <sstream>
11 
12 #include <boost/iterator/transform_iterator.hpp>
13 #include <boost/program_options.hpp>
14 
15 
16 namespace utl {
17  class Reader;
18  class Branch;
19 }
20 
21 
22 namespace fwk {
23 
34  class ConfigLink {
35 
36  public:
37  std::string GetLink() const { return fXLink; }
38  std::string GetFileType() const { return fFileType; }
39 
40  utl::Reader* GetReader() const { return fReader; }
41 
42  private:
43  std::string fXLink;
44  std::string fFileType;
45  utl::Reader* fReader = nullptr; // no delete in dtor, just a helper class
46 
47  friend class CentralConfig;
48  };
49 
50 
51  class CentralConfig {
52 
53  typedef std::map<std::string, ConfigLink>::iterator InternalConfigIterator;
54 
56  std::string
57  operator()(const std::pair<std::string, ConfigLink>& pair) const
58  { return pair.first; }
59  };
60 
61  public:
63 
68  static CentralConfig* GetInstance(const std::string& bootstrapFileName,
69  const bool fingerprintFatal = false,
70  const bool validate = true);
71 
73  static CentralConfig* GetInstance();
74 
76  utl::Branch GetTopBranch(const std::string& id);
77 
79  const utl::Reader* GetReader(const std::string& id);
80 
82  //std::string GetLinkName(const std::string Id);
83 
85  void WriteConfig(const std::string& fileName = "");
86 
88  std::string GetConfig();
89 
91  typedef boost::transform_iterator<InternalIdFunctor,
93  std::string> IdIterator;
98 
99  const std::string& GetInstallPath() const { return fInstallPath; }
100 
101  protected:
102  // These two methods need to be here so I can inherit from this class.
103  CentralConfig();
104  ~CentralConfig();
105 
106  // At least one of the following two methods is needed to be able
107  // to change the configuration.
108  static void Reset(const std::string& bootstrapFileName,
109  const bool fingerprintFatal = false,
110  const bool validate = true);
111 
112  //void SetTopBranch(const std::string& id, const utl::Branch& branch);
113 
114  // Implementing leaky singleton
116 
117  private:
118  std::string GetBootstrapUri();
119 
120  // Fill fConfigMap from bootstrap XML file
121  void FindConfigBranch();
122  void FillMap(const utl::Branch& branch);
123  void ReplaceParameters(const utl::Branch&);
124  void DescendAndReplace(utl::Branch replacement, utl::Branch& original);
125  void ReadConfig(const std::string& bootstrapFile);
126  void LogBootstrap();
127  void CheckFingerprints(const bool fingerprintFatal);
129  void FillMd5Excludes();
130  void AbortParse(const std::string& s = "");
131  utl::Branch Find(std::string path);
132  std::string AsString(const utl::Branch& branch,
133  const int indent = 0, const int indentIncrement = 2);
134 
135  static bool fgIsInitialized;
136  std::map<std::string, ConfigLink> fConfigMap;
137  std::set<std::string> fMd5Excludes;
138  std::set<std::string> fUsedConfigs;
139  std::stringstream fConfigInfo;
140  bool fConfigInfoIsValid = false;
141 
142  // config file md5 fingerprints, generated by config
143  std::multimap<std::string, std::string> fConfigTimeFingerMap;
144 
145  std::list<std::string> fNoMd5List;
146  std::list<std::string> fMismatchedMd5List;
147 
149 
150  static bool fgValidate;
151 
152  std::string fInstallPath;
153 
154  };
155 
156 
157  const char* GetLibraryPath();
158 
159 }
160 
161 
162 #endif
std::list< std::string > fMismatchedMd5List
const std::string & GetInstallPath() const
Definition: CentralConfig.h:99
IdIterator IdsEnd()
Id&#39;s end.
static bool fgIsInitialized
void FillConfigTimeFingerMap()
void DescendAndReplace(utl::Branch replacement, utl::Branch &original)
void CheckFingerprints(const bool fingerprintFatal)
boost::transform_iterator< InternalIdFunctor, InternalConfigIterator, std::string > IdIterator
IdIterator returns a pointer to a config link Id.
Definition: CentralConfig.h:93
std::string GetConfig()
Get configuration in a string.
void FillMap(const utl::Branch &branch)
static void Reset(const std::string &bootstrapFileName, const bool fingerprintFatal=false, const bool validate=true)
std::map< std::string, ConfigLink > fConfigMap
std::list< std::string > fNoMd5List
std::set< std::string > fUsedConfigs
static CentralConfig * fgInstance
utl::Branch Find(std::string path)
const char * GetLibraryPath()
Utility for parsing XML files.
Definition: Reader.h:25
Class representing a document branch.
Definition: Branch.h:107
void AbortParse(const std::string &s="")
constexpr double s
Definition: AugerUnits.h:163
std::string fInstallPath
std::multimap< std::string, std::string > fConfigTimeFingerMap
std::map< std::string, ConfigLink >::iterator InternalConfigIterator
Definition: CentralConfig.h:53
void ReplaceParameters(const utl::Branch &)
void ReadConfig(const std::string &bootstrapFile)
static bool fgValidate
std::string AsString(const utl::Branch &branch, const int indent=0, const int indentIncrement=2)
const utl::Reader * GetReader(const std::string &id)
Get the Reader for moduleConfigLink with given id (XML files)
std::string GetBootstrapUri()
utl::Reader * fBootstrapReader
std::set< std::string > fMd5Excludes
std::stringstream fConfigInfo
std::string operator()(const std::pair< std::string, ConfigLink > &pair) const
Definition: CentralConfig.h:57
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Main configuration utility.
Definition: CentralConfig.h:51
void WriteConfig(const std::string &fileName="")
Get the link name for moduleConfigLink with given id (any)
IdIterator IdsBegin()
Id&#39;s begin.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.