BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balcl_occurrenceinfo.h
Go to the documentation of this file.
1/// @file balcl_occurrenceinfo.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// balcl_occurrenceinfo.h -*-C++-*-
8#ifndef INCLUDED_BALCL_OCCURRENCEINFO
9#define INCLUDED_BALCL_OCCURRENCEINFO
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup balcl_occurrenceinfo balcl_occurrenceinfo
15/// @brief Provide a type describing requirement and default value of option.
16/// @addtogroup bal
17/// @{
18/// @addtogroup balcl
19/// @{
20/// @addtogroup balcl_occurrenceinfo
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#balcl_occurrenceinfo-purpose"> Purpose</a>
25/// * <a href="#balcl_occurrenceinfo-classes"> Classes </a>
26/// * <a href="#balcl_occurrenceinfo-description"> Description </a>
27/// * <a href="#balcl_occurrenceinfo-attributes"> Attributes </a>
28/// * <a href="#balcl_occurrenceinfo-usage"> Usage </a>
29///
30/// # Purpose {#balcl_occurrenceinfo-purpose}
31/// Provide a type describing requirement and default value of option.
32///
33/// # Classes {#balcl_occurrenceinfo-classes}
34///
35/// - balcl::OccurrenceInfo: specify option necessity and other attributes
36///
37/// @see `balcl_commandline`
38///
39/// # Description {#balcl_occurrenceinfo-description}
40/// This component provides a single complex-constrained
41/// (value-semantic) attribute class, `balcl::OccurrenceInfo`, that describes
42/// whether a command-line argument must be supplied by the user or whether that
43/// option is truly optional. If a command-line option is optional, it may have
44/// the additional attribute of being "hidden" -- i.e., omitted by the
45/// `printUsage` method of `balcl::CommandLine` (see `{balcl_commandline}`).
46/// Additionally, default values can be provided for non-required options.
47///
48/// For further details see @ref balcl_commandline-occurrence-information-field
49/// and @ref balcl_commandline-example-occurrence-information-field .
50///
51/// ## Attributes {#balcl_occurrenceinfo-attributes}
52///
53///
54/// @code
55/// Attribute Type Default Constraints
56/// -------------- ------------------ ------- -------------------------------
57/// isHiddenFlag bool false isHiddenFlag && !isRequiredFlag
58///
59/// isRequiredFlag bool false none
60///
61/// defaultValue balcl::OptionValue e_VOID e_VOID != type() &&
62/// (e_BOOL != type()
63/// false == isNull()
64/// false == isRequiredFlag)
65/// @endcode
66///
67/// ## Usage {#balcl_occurrenceinfo-usage}
68///
69///
70/// The intended use of this component is illustrated in
71/// @ref balcl_commandline-usage .
72/// @}
73/** @} */
74/** @} */
75
76/** @addtogroup bal
77 * @{
78 */
79/** @addtogroup balcl
80 * @{
81 */
82/** @addtogroup balcl_occurrenceinfo
83 * @{
84 */
85
86#include <balscm_version.h>
87
88#include <balcl_optionvalue.h>
89
90#include <bdlb_printmethods.h> // 'bdlb::HasPrintMethod'
91
93
94#include <bslma_allocator.h>
96
97#include <bsls_types.h> // 'bsls::Types::Int64'
98
99#include <bsl_iosfwd.h>
100#include <bsl_string.h>
101#include <bsl_vector.h>
102
103#include <bdlt_date.h>
104#include <bdlt_datetime.h>
105#include <bdlt_time.h>
106
107
108
109
110namespace balcl {
111 // ====================
112 // class OccurrenceInfo
113 // ====================
114
115/// This `class` is a simple attribute class that describes a command-line
116/// option occurrence requirement (i.e., required, optional, or optional but
117/// hidden) and default value, if any.
118///
119/// See @ref balcl_occurrenceinfo
121
122 // DATA
123 bool d_isRequired; // 'true' if option is required
124 bool d_isHidden; // 'true' if option is hidden
125 OptionValue d_defaultValue; // default value (if any), or null
126
127 public:
128 // TYPES
130 e_REQUIRED = 0, // option is required and not hidden
131 e_OPTIONAL = 1, // option is optional and not hidden
132 e_HIDDEN = 2 // option is optional and hidden
133 };
134
135 // TRAITS
138
139 // CREATORS
140
142 /// Construct an `OccurrenceInfo` object that describes a command-line
143 /// option that is optional but not hidden (i.e., `e_OPTIONAL ==
144 /// occurrenceType()`) and has no default value. Optionally specify a
145 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0, the
146 /// currently installed default allocator is used.
147 explicit
149
150 /// Construct an `OccurrenceInfo` object that describes a command-line
151 /// option of the specified `type` and has no default value. Optionally
152 /// specify a `basicAllocator` used to supply memory. If `basicAllocator`
153 /// is 0, the currently installed default allocator is used.
155 bslma::Allocator *basicAllocator = 0); // IMPLICIT
156
157 explicit
159 bslma::Allocator *basicAllocator = 0);
160 explicit
162 bslma::Allocator *basicAllocator = 0);
163 explicit
165 bslma::Allocator *basicAllocator = 0);
166 explicit
168 bslma::Allocator *basicAllocator = 0);
169 explicit
171 bslma::Allocator *basicAllocator = 0);
172 explicit
174 bslma::Allocator *basicAllocator = 0);
175 explicit
177 bslma::Allocator *basicAllocator = 0);
178 explicit
180 bslma::Allocator *basicAllocator = 0);
181 explicit
183 bslma::Allocator *basicAllocator = 0);
184 explicit
186 bslma::Allocator *basicAllocator = 0);
187 explicit
189 bslma::Allocator *basicAllocator = 0);
190 explicit
192 bslma::Allocator *basicAllocator = 0);
193 explicit
195 bslma::Allocator *basicAllocator = 0);
196 explicit
198 bslma::Allocator *basicAllocator = 0);
199 explicit
201 bslma::Allocator *basicAllocator = 0);
202 /// Construct an `OccurrenceInfo` object that describes a command-line
203 /// option that is not required or hidden, and that has the specified
204 /// `defaultValue`. Optionally specify a `basicAllocator` used to supply
205 /// memory. If `basicAllocator` is 0, the currently installed default
206 /// allocator is used.
207 explicit
209 bslma::Allocator *basicAllocator = 0);
210
211 /// Construct a `OccurrenceInfo` object having the value of the specified
212 /// `original` object. Optionally specify a `basicAllocator` used to
213 /// supply memory. If `basicAllocator` is 0, the currently installed
214 /// default allocator is used.
216 bslma::Allocator *basicAllocator = 0);
217
218 /// Destroy this object.
220
221 // MANIPULATORS
222
223 /// Assign to this object the value of the specified `rhs` object, and
224 /// return a reference providing modifiable access to this object.
226
227 /// Set the type and default value of the associated option to the
228 /// specified `defaultValue`. The behavior is undefined unless the this
229 /// object describes an optional argument
230 /// (`e_REQUIRED != occurrenceType()`) and `defaultValue.type()` is
231 /// neither `OptionType::e_BOOL` nor 'OptionType::e_VOID nor a null
232 /// value (`false == defaultValue.isNull()`).
234
235 /// Set the associated option to be hidden. The behavior is undefined
236 /// unless the option is optional (`e_REQUIRED != occurrenceType()`).
237 void setHidden();
238
239 // ACCESSORS
240
241 /// Return a `const` reference to the default value of this object.
242 const OptionValue& defaultValue() const;
243
244 /// Return `true` if this object has a default value, and `false`
245 /// otherwise.
246 bool hasDefaultValue() const;
247
248 /// Return `true` if the described option is hidden (i.e., not printed in
249 /// the usage string), and `false` otherwise.
250 bool isHidden() const;
251
252 /// Return `true` if the described option is required, and `false`
253 /// otherwise.
254 bool isRequired() const;
255
256 /// Return the occurrence type of the described option (i.e., required,
257 /// optional, or hidden).
259
260 // Aspects
261
262 /// Return the allocator used by this object to supply memory. Note that
263 /// if no allocator was supplied at construction the currently installed
264 /// default allocator at construction is used.
266
267 /// Format this object to the specified output `stream` at the (absolute
268 /// value of) the optionally specified indentation `level` and return a
269 /// reference to `stream`. If `level` is specified, optionally specify
270 /// `spacesPerLevel`, the number of spaces per indentation level for this
271 /// object. If `level` is negative, suppress indentation of the first
272 /// line. If `stream` is not valid on entry, this operation has no effect.
273 /// The behavior is undefined if `spacesPerLevel` is negative.
274 bsl::ostream& print(bsl::ostream& stream,
275 int level = 0,
276 int spacesPerLevel = 4) const;
277};
278
279// FREE OPERATORS
280
281/// Return `true` if the specified `lhs` and `rhs` have the same value, and
282/// `false` otherwise. Two objects of type `OccurrenceInfo` have the same
283/// value if and only if they have the same occurrence type and either both do
284/// not have a default value, or their respective default values have the same
285/// type and value.
286bool operator==(const OccurrenceInfo& lhs, const OccurrenceInfo& rhs);
287
288/// Return `true` if the specified `lhs` and `rhs` do not have the same value,
289/// and `false` otherwise. Two objects of type `OccurrenceInfo` do not have
290/// the same value if and only if they have different occurrence types, or
291/// exactly one has a default value, or else both have a default value but
292/// their respective default values have either different types or different
293/// values.
294bool operator!=(const OccurrenceInfo& lhs, const OccurrenceInfo& rhs);
295
296/// Write the value of the specified `rhs` object to the specified `stream` in
297/// a (multi-line) human readable format and return a reference to the
298/// `stream`. Note that the last line is *not* terminated by a newline
299/// character.
300bsl::ostream& operator<<(bsl::ostream& stream, const OccurrenceInfo& rhs);
301
302} // close package namespace
303
304
305#endif
306
307// ----------------------------------------------------------------------------
308// Copyright 2020 Bloomberg Finance L.P.
309//
310// Licensed under the Apache License, Version 2.0 (the "License");
311// you may not use this file except in compliance with the License.
312// You may obtain a copy of the License at
313//
314// http://www.apache.org/licenses/LICENSE-2.0
315//
316// Unless required by applicable law or agreed to in writing, software
317// distributed under the License is distributed on an "AS IS" BASIS,
318// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
319// See the License for the specific language governing permissions and
320// limitations under the License.
321// ----------------------------- END-OF-FILE ----------------------------------
322
323/** @} */
324/** @} */
325/** @} */
Definition balcl_occurrenceinfo.h:120
bool isRequired() const
~OccurrenceInfo()
Destroy this object.
OccurrenceInfo(const bsl::vector< bdlt::Datetime > &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(const bdlt::Time &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(bsls::Types::Int64 defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(bslma::Allocator *basicAllocator)
OccurrenceType
Definition balcl_occurrenceinfo.h:129
@ e_REQUIRED
Definition balcl_occurrenceinfo.h:130
@ e_OPTIONAL
Definition balcl_occurrenceinfo.h:131
@ e_HIDDEN
Definition balcl_occurrenceinfo.h:132
OccurrenceInfo(const bsl::vector< bdlt::Time > &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceType occurrenceType() const
OccurrenceInfo(const bdlt::Date &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(double defaultValue, bslma::Allocator *basicAllocator=0)
bslma::Allocator * allocator() const
OccurrenceInfo(const bsl::vector< double > &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(const bdlt::Datetime &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(OccurrenceType type, bslma::Allocator *basicAllocator=0)
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
OccurrenceInfo(const OccurrenceInfo &original, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(const bsl::vector< char > &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(const bsl::vector< bsls::Types::Int64 > &defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(char defaultValue, bslma::Allocator *basicAllocator=0)
const OptionValue & defaultValue() const
Return a const reference to the default value of this object.
OccurrenceInfo(const bsl::vector< bsl::string > &defaultValue, bslma::Allocator *basicAllocator=0)
bool hasDefaultValue() const
OccurrenceInfo(const bsl::string &defaultValue, bslma::Allocator *basicAllocator=0)
BSLMF_NESTED_TRAIT_DECLARATION(OccurrenceInfo, bdlb::HasPrintMethod)
OccurrenceInfo(const bsl::vector< bdlt::Date > &defaultValue, bslma::Allocator *basicAllocator=0)
BSLMF_NESTED_TRAIT_DECLARATION(OccurrenceInfo, bslma::UsesBslmaAllocator)
OccurrenceInfo(int defaultValue, bslma::Allocator *basicAllocator=0)
OccurrenceInfo(const bsl::vector< int > &defaultValue, bslma::Allocator *basicAllocator=0)
void setDefaultValue(const OptionValue &defaultValue)
OccurrenceInfo & operator=(const OccurrenceInfo &rhs)
bool isHidden() const
Definition balcl_optionvalue.h:393
Definition bdlt_date.h:294
Definition bdlt_datetime.h:331
Definition bdlt_time.h:196
Definition bslstl_string.h:1281
Definition bslstl_vector.h:1025
Definition bslma_allocator.h:457
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition balcl_commandline.h:1364
bsl::ostream & operator<<(bsl::ostream &stream, const CommandLine &rhs)
Definition bdlb_printmethods.h:306
Definition bslma_usesbslmaallocator.h:343
long long Int64
Definition bsls_types.h:132