OptionSet.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // OptionSet.h
  3. //
  4. // Library: Util
  5. // Package: Options
  6. // Module: OptionSet
  7. //
  8. // Definition of the OptionSet 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_OptionSet_INCLUDED
  16. #define Util_OptionSet_INCLUDED
  17. #include "Poco/Util/Util.h"
  18. #include "Poco/Util/Option.h"
  19. #include <vector>
  20. namespace Poco {
  21. namespace Util {
  22. class Util_API OptionSet
  23. /// A collection of Option objects.
  24. {
  25. public:
  26. typedef std::vector<Option> OptionVec;
  27. typedef OptionVec::const_iterator Iterator;
  28. OptionSet();
  29. /// Creates the OptionSet.
  30. OptionSet(const OptionSet& options);
  31. /// Creates an option set from another one.
  32. ~OptionSet();
  33. /// Destroys the OptionSet.
  34. OptionSet& operator = (const OptionSet& options);
  35. /// Assignment operator.
  36. void addOption(const Option& option);
  37. /// Adds an option to the collection.
  38. bool hasOption(const std::string& name, bool matchShort = false) const;
  39. /// Returns a true iff an option with the given name exists.
  40. ///
  41. /// The given name can either be a fully specified short name,
  42. /// or a partially specified full name. If a partial name
  43. /// matches more than one full name, false is returned.
  44. /// The name must either match the short or full name of an
  45. /// option. Comparison case sensitive for the short name and
  46. /// not case sensitive for the full name.
  47. const Option& getOption(const std::string& name, bool matchShort = false) const;
  48. /// Returns a reference to the option with the given name.
  49. ///
  50. /// The given name can either be a fully specified short name,
  51. /// or a partially specified full name.
  52. /// The name must either match the short or full name of an
  53. /// option. Comparison case sensitive for the short name and
  54. /// not case sensitive for the full name.
  55. /// Throws a NotFoundException if no matching option has been found.
  56. /// Throws an UnknownOptionException if a partial full name matches
  57. /// more than one option.
  58. Iterator begin() const;
  59. /// Supports iterating over all options.
  60. Iterator end() const;
  61. /// Supports iterating over all options.
  62. private:
  63. OptionVec _options;
  64. };
  65. } } // namespace Poco::Util
  66. #endif // Util_OptionSet_INCLUDED