#ifndef _fwk_CentralConfig_h_ #define _fwk_CentralConfig_h_ #include #include #include #include #include #include #include #include namespace utl { class Reader; class Branch; } namespace fwk { /** \class ConfigLink \brief container for a file, file type id, and corresponding utl::Reader \author T. Paul \date 4 March 2003 \version $Id: CentralConfig.h 19309 2011-06-16 07:57:26Z javierg $ \ingroup steering */ class ConfigLink { public: ConfigLink() : fReader(0) { } std::string GetLink() const { return fXLink; } std::string GetFileType() const { return fFileType; } utl::Reader* GetReader() const { return fReader; } private: std::string fXLink; std::string fFileType; utl::Reader* fReader; friend class CentralConfig; }; class CentralConfig { typedef std::map::iterator InternalConfigIterator; struct InternalIdFunctor { std::string operator()(const std::pair& pair) const { return pair.first; } }; public: //! Use this the first time you get an instance of central configuration /*! Option checkFingerprints can be set to false if you do not want an exception thrown in case the md5 fingerprints have been altered (though they will still be checked and warnings issued in case of mismatch). When it's set to true, any alteration aborts the execution of the method with an exception. */ static CentralConfig* GetInstance(const std::string& bootstrapFileName, const bool fingerprintFatal = false, const bool validate = true); //! Use this the first time you get an instance of central configuration static CentralConfig* GetInstance(); //! Get top branch for moduleConfigLink with given id (XML files) utl::Branch GetTopBranch(const std::string& id); //! Get the Reader for moduleConfigLink with given id (XML files) const utl::Reader* GetReader(const std::string& id); //! Get the link name for moduleConfigLink with given id (any) //std::string GetLinkName(const std::string Id); //! Write configuration to file void WriteConfig(std::string fileName = ""); //! Get configuration in a string std::string GetConfig(); /// IdIterator returns a pointer to a config link Id. typedef boost::transform_iterator IdIterator; /// Id's begin IdIterator IdsBegin(); /// Id's end IdIterator IdsEnd(); protected: // These two methods need to be here so I can inherit from this class. CentralConfig(); ~CentralConfig(); // At least one of the following two methods is needed to be able // to change the configuration. static void Reset(const std::string& bootstrapFileName, const bool fingerprintFatal = false, const bool validate = true); void SetTopBranch(const std::string& id, utl::Branch branch); // Implementing leaky singleton static CentralConfig* fgInstance; private: std::string GetBootstrapUri(); utl::Reader* GetNonConstReader(const std::string& id); // Fill fConfigMap from bootstrap XML file void FindConfigBranch(); void FillMap(const utl::Branch& branch); void ReplaceParameters(const utl::Branch&); void DescendAndReplace(utl::Branch replacement, utl::Branch original); void ReadConfig(const std::string& bootstrapFile); void LogBootstrap(); void CheckFingerprints(const bool fingerprintFatal); void FillConfigTimeFingerMap(); void FillMd5Excludes(); void AbortParse(const std::string&); utl::Branch Find(std::string path); std::string AsString(const utl::Branch branch, const int indent = 0, const int indentIncrement = 2); static bool fgIsInitialized; std::map fConfigMap; std::set fMd5Excludes; std::set fUsedConfigs; std::stringstream fConfigInfo; bool fConfigInfoIsValid; // config file md5 fingerprints, generated by config std::multimap fConfigTimeFingerMap; std::list fNoMd5List; std::list fMismatchedMd5List; utl::Reader* fBootstrapReader; static bool fgValidate; friend class std::auto_ptr; }; } #endif // Configure (x)emacs for this file ... // Local Variables: // mode: c++ // End: