PropertyFileConfiguration.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // PropertyFileConfiguration.h
  3. //
  4. // Library: Util
  5. // Package: Configuration
  6. // Module: PropertyFileConfiguration
  7. //
  8. // Definition of the PropertyFileConfiguration 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_PropertyFileConfiguration_INCLUDED
  16. #define Util_PropertyFileConfiguration_INCLUDED
  17. #include "Poco/Util/Util.h"
  18. #include "Poco/Util/MapConfiguration.h"
  19. #include <istream>
  20. #include <ostream>
  21. namespace Poco {
  22. namespace Util {
  23. class Util_API PropertyFileConfiguration: public MapConfiguration
  24. /// This implementation of a Configuration reads properties
  25. /// from a Java-style properties file.
  26. ///
  27. /// The file syntax is implemented as follows.
  28. /// - a line starting with a hash '#' or exclamation mark '!' is treated as a comment and ignored
  29. /// - every other line denotes a property assignment in the form
  30. /// <key> = <value> or
  31. /// <key> : <value>
  32. ///
  33. /// Keys and values may contain special characters represented by the following escape sequences:
  34. /// - \t: tab (0x09)
  35. /// - \n: line feed (0x0a)
  36. /// - \r: carriage return (0x0d)
  37. /// - \f: form feed (0x0c)
  38. ///
  39. /// For every other sequence that starts with a backslash, the backslash is removed.
  40. /// Therefore, the sequence \a would just yield an 'a'.
  41. ///
  42. /// A value can spread across multiple lines if the last character in a line (the character
  43. /// immediately before the carriage return or line feed character) is a single backslash.
  44. ///
  45. /// Property names are case sensitive. Leading and trailing whitespace is
  46. /// removed from both keys and values. A property name can neither contain
  47. /// a colon ':' nor an equal sign '=' character.
  48. {
  49. public:
  50. PropertyFileConfiguration();
  51. /// Creates an empty PropertyFileConfiguration.
  52. PropertyFileConfiguration(std::istream& istr);
  53. /// Creates an PropertyFileConfiguration and loads the configuration data
  54. /// from the given stream, which must be in properties file format.
  55. PropertyFileConfiguration(const std::string& path);
  56. /// Creates an PropertyFileConfiguration and loads the configuration data
  57. /// from the given file, which must be in properties file format.
  58. void load(std::istream& istr);
  59. /// Loads the configuration data from the given stream, which
  60. /// must be in properties file format.
  61. void load(const std::string& path);
  62. /// Loads the configuration data from the given file, which
  63. /// must be in properties file format.
  64. void save(std::ostream& ostr) const;
  65. /// Writes the configuration data to the given stream.
  66. ///
  67. /// The data is written as a sequence of statements in the form
  68. /// <key>: <value>
  69. /// separated by a newline character.
  70. void save(const std::string& path) const;
  71. /// Writes the configuration data to the given file.
  72. protected:
  73. ~PropertyFileConfiguration();
  74. private:
  75. void parseLine(std::istream& istr);
  76. static int readChar(std::istream& istr);
  77. };
  78. } } // namespace Poco::Util
  79. #endif // Util_PropertyFileConfiguration_INCLUDED