1 | // |
---|
2 | // OptionSet.h |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Util/include/Poco/Util/OptionSet.h#1 $ |
---|
5 | // |
---|
6 | // Library: Util |
---|
7 | // Package: Options |
---|
8 | // Module: OptionSet |
---|
9 | // |
---|
10 | // Definition of the OptionSet class. |
---|
11 | // |
---|
12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
13 | // and Contributors. |
---|
14 | // |
---|
15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
20 | // do so, all subject to the following: |
---|
21 | // |
---|
22 | // The copyright notices in the Software and this entire statement, including |
---|
23 | // the above license grant, this restriction and the following disclaimer, |
---|
24 | // must be included in all copies of the Software, in whole or in part, and |
---|
25 | // all derivative works of the Software, unless such copies or derivative |
---|
26 | // works are solely in the form of machine-executable object code generated by |
---|
27 | // a source language processor. |
---|
28 | // |
---|
29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
35 | // DEALINGS IN THE SOFTWARE. |
---|
36 | // |
---|
37 | |
---|
38 | |
---|
39 | #ifndef Util_OptionSet_INCLUDED |
---|
40 | #define Util_OptionSet_INCLUDED |
---|
41 | |
---|
42 | |
---|
43 | #include "Poco/Util/Util.h" |
---|
44 | #include "Poco/Util/Option.h" |
---|
45 | #include <vector> |
---|
46 | |
---|
47 | |
---|
48 | namespace Poco { |
---|
49 | namespace Util { |
---|
50 | |
---|
51 | |
---|
52 | class Util_API OptionSet |
---|
53 | /// A collection of Option objects. |
---|
54 | { |
---|
55 | public: |
---|
56 | typedef std::vector<Option> OptionVec; |
---|
57 | typedef OptionVec::const_iterator Iterator; |
---|
58 | |
---|
59 | OptionSet(); |
---|
60 | /// Creates the OptionSet. |
---|
61 | |
---|
62 | OptionSet(const OptionSet& options); |
---|
63 | /// Creates an option set from another one. |
---|
64 | |
---|
65 | ~OptionSet(); |
---|
66 | /// Destroys the OptionSet. |
---|
67 | |
---|
68 | OptionSet& operator = (const OptionSet& options); |
---|
69 | /// Assignment operator. |
---|
70 | |
---|
71 | void addOption(const Option& option); |
---|
72 | /// Adds an option to the collection. |
---|
73 | |
---|
74 | bool hasOption(const std::string& name, bool matchShort = false) const; |
---|
75 | /// Returns a true iff an option with the given name exists. |
---|
76 | /// |
---|
77 | /// The given name can either be a fully specified short name, |
---|
78 | /// or a partially specified full name. If a partial name |
---|
79 | /// matches more than one full name, false is returned. |
---|
80 | /// The name must either match the short or full name of an |
---|
81 | /// option. Comparison case sensitive for the short name and |
---|
82 | /// not case sensitive for the full name. |
---|
83 | |
---|
84 | const Option& getOption(const std::string& name, bool matchShort = false) const; |
---|
85 | /// Returns a reference to the option with the given name. |
---|
86 | /// |
---|
87 | /// The given name can either be a fully specified short name, |
---|
88 | /// or a partially specified full name. |
---|
89 | /// The name must either match the short or full name of an |
---|
90 | /// option. Comparison case sensitive for the short name and |
---|
91 | /// not case sensitive for the full name. |
---|
92 | /// Throws a NotFoundException if no matching option has been found. |
---|
93 | /// Throws an UnknownOptionException if a partial full name matches |
---|
94 | /// more than one option. |
---|
95 | |
---|
96 | Iterator begin() const; |
---|
97 | /// Supports iterating over all options. |
---|
98 | |
---|
99 | Iterator end() const; |
---|
100 | /// Supports iterating over all options. |
---|
101 | |
---|
102 | private: |
---|
103 | OptionVec _options; |
---|
104 | }; |
---|
105 | |
---|
106 | |
---|
107 | } } // namespace Poco::Util |
---|
108 | |
---|
109 | |
---|
110 | #endif // Util_OptionSet_INCLUDED |
---|