FilesystemConfiguration.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // FilesystemConfiguration.h
  3. //
  4. // Library: Util
  5. // Package: Configuration
  6. // Module: FilesystemConfiguration
  7. //
  8. // Definition of the FilesystemConfiguration 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_FilesystemConfiguration_INCLUDED
  16. #define Util_FilesystemConfiguration_INCLUDED
  17. #include "Poco/Util/Util.h"
  18. #include "Poco/Util/AbstractConfiguration.h"
  19. #include "Poco/Path.h"
  20. namespace Poco {
  21. namespace Util {
  22. class Util_API FilesystemConfiguration: public AbstractConfiguration
  23. /// An implementation of AbstractConfiguration that stores configuration data
  24. /// in a directory hierarchy in the filesystem.
  25. ///
  26. /// Every period-separated part of a property name is represented
  27. /// as a directory in the filesystem, relative to the base directory.
  28. /// Values are stored in files named "data".
  29. ///
  30. /// All changes to properties are immediately persisted in the filesystem.
  31. ///
  32. /// For example, a configuration consisting of the properties
  33. ///
  34. /// logging.loggers.root.channel.class = ConsoleChannel
  35. /// logging.loggers.app.name = Application
  36. /// logging.loggers.app.channel = c1
  37. /// logging.formatters.f1.class = PatternFormatter
  38. /// logging.formatters.f1.pattern = [%p] %t
  39. ///
  40. /// is stored in the filesystem as follows:
  41. ///
  42. /// logging/
  43. /// loggers/
  44. /// root/
  45. /// channel/
  46. /// class/
  47. /// data ("ConsoleChannel")
  48. /// app/
  49. /// name/
  50. /// data ("Application")
  51. /// channel/
  52. /// data ("c1")
  53. /// formatters/
  54. /// f1/
  55. /// class/
  56. /// data ("PatternFormatter")
  57. /// pattern/
  58. /// data ("[%p] %t")
  59. {
  60. public:
  61. FilesystemConfiguration(const std::string& path);
  62. /// Creates a FilesystemConfiguration using the given path.
  63. /// All directories are created as necessary.
  64. void clear();
  65. /// Clears the configuration by erasing the configuration
  66. /// directory and all its subdirectories and files.
  67. protected:
  68. bool getRaw(const std::string& key, std::string& value) const;
  69. void setRaw(const std::string& key, const std::string& value);
  70. void enumerate(const std::string& key, Keys& range) const;
  71. void removeRaw(const std::string& key);
  72. Poco::Path keyToPath(const std::string& key) const;
  73. ~FilesystemConfiguration();
  74. private:
  75. Poco::Path _path;
  76. };
  77. } } // namespace Poco::Util
  78. #endif // Util_FilesystemConfiguration_INCLUDED