ConfigurationMapper.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // ConfigurationMapper.h
  3. //
  4. // Library: Util
  5. // Package: Configuration
  6. // Module: ConfigurationMapper
  7. //
  8. // Definition of the ConfigurationMapper class.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Util_ConfigurationMapper_INCLUDED
  16. #define Util_ConfigurationMapper_INCLUDED
  17. #include "Poco/Util/Util.h"
  18. #include "Poco/Util/AbstractConfiguration.h"
  19. namespace Poco {
  20. namespace Util {
  21. class Util_API ConfigurationMapper: public AbstractConfiguration
  22. /// This configuration maps a property hierarchy into another
  23. /// hierarchy.
  24. ///
  25. /// For example, given a configuration with the following properties:
  26. /// config.value1
  27. /// config.value2
  28. /// config.sub.value1
  29. /// config.sub.value2
  30. /// and a ConfigurationView with fromPrefix == "config" and toPrefix == "root.conf", then
  31. /// the above properties will be available via the mapper as
  32. /// root.conf.value1
  33. /// root.conf.value2
  34. /// root.conf.sub.value1
  35. /// root.conf.sub.value2
  36. ///
  37. /// FromPrefix can be empty, in which case, and given toPrefix == "root",
  38. /// the properties will be available as
  39. /// root.config.value1
  40. /// root.config.value2
  41. /// root.config.sub.value1
  42. /// root.config.sub.value2
  43. ///
  44. /// This is equivalent to the functionality of the ConfigurationView class.
  45. ///
  46. /// Similarly, toPrefix can also be empty. Given fromPrefix == "config" and
  47. /// toPrefix == "", the properties will be available as
  48. /// value1
  49. /// value2
  50. /// sub.value1
  51. /// sub.value2
  52. ///
  53. /// If both fromPrefix and toPrefix are empty, no mapping is performed.
  54. ///
  55. /// A ConfigurationMapper is most useful in combination with a
  56. /// LayeredConfiguration.
  57. {
  58. public:
  59. ConfigurationMapper(const std::string& fromPrefix, const std::string& toPrefix, AbstractConfiguration* pConfig);
  60. /// Creates the ConfigurationMapper. The ConfigurationMapper does not take
  61. /// ownership of the passed configuration.
  62. protected:
  63. bool getRaw(const std::string& key, std::string& value) const;
  64. void setRaw(const std::string& key, const std::string& value);
  65. void enumerate(const std::string& key, Keys& range) const;
  66. void removeRaw(const std::string& key);
  67. std::string translateKey(const std::string& key) const;
  68. ~ConfigurationMapper();
  69. private:
  70. ConfigurationMapper(const ConfigurationMapper&);
  71. ConfigurationMapper& operator = (const ConfigurationMapper&);
  72. std::string _fromPrefix;
  73. std::string _toPrefix;
  74. AbstractConfiguration* _pConfig;
  75. };
  76. } } // namespace Poco::Util
  77. #endif // Util_ConfigurationMapper_INCLUDED