BDE 4.39.x 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
141 /// Construct an `OccurrenceInfo` object that describes a command-line
142 /// option that is optional but not hidden (i.e., `e_OPTIONAL ==
143 /// occurrenceType()`) and has no default value. Optionally specify a
144 /// `basicAllocator` used to supply memory. If `basicAllocator` is 0, the
145 /// 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 /// Construct an `OccurrenceInfo` object that describes a command-line
158 /// option that is not required or hidden, and that has the specified
159 /// `defaultValue`. Optionally specify a `basicAllocator` used to supply
160 /// memory. If `basicAllocator` is 0, the currently installed default
161 /// allocator is used.
162 explicit
164 bslma::Allocator *basicAllocator = 0);
165 explicit
167 bslma::Allocator *basicAllocator = 0);
168 explicit
170 bslma::Allocator *basicAllocator = 0);
171 explicit
173 bslma::Allocator *basicAllocator = 0);
174 explicit
176 bslma::Allocator *basicAllocator = 0);
177 explicit
179 bslma::Allocator *basicAllocator = 0);
180 explicit
182 bslma::Allocator *basicAllocator = 0);
183 explicit
185 bslma::Allocator *basicAllocator = 0);
186 explicit
188 bslma::Allocator *basicAllocator = 0);
189 explicit
191 bslma::Allocator *basicAllocator = 0);
192 explicit
194 bslma::Allocator *basicAllocator = 0);
195 explicit
197 bslma::Allocator *basicAllocator = 0);
198 explicit
200 bslma::Allocator *basicAllocator = 0);
201 explicit
203 bslma::Allocator *basicAllocator = 0);
204 explicit
206 bslma::Allocator *basicAllocator = 0);
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 specified `defaultValue`.
228 ///
229 /// \pre The behavior is undefined unless the this
230 /// object describes an optional argument
231 /// (`e_REQUIRED != occurrenceType()`) and `defaultValue.type()` is
232 /// neither `OptionType::e_BOOL` nor 'OptionType::e_VOID nor a null
233 /// value (`false == defaultValue.isNull()`).
235
236 /// Set the associated option to be hidden.
237 ///
238 /// \pre The behavior is undefined unless the option is optional (`e_REQUIRED != occurrenceType()`).
239 void setHidden();
240
241 // ACCESSORS
242
243 /// Return a `const` reference to the default value of this object.
244 const OptionValue& defaultValue() const;
245
246 /// Return `true` if this object has a default value, and `false`
247 /// otherwise.
248 bool hasDefaultValue() const;
249
250 /// Return `true` if the described option is hidden (i.e., not printed in
251 /// the usage string), and `false` otherwise.
252 bool isHidden() const;
253
254 /// Return `true` if the described option is required, and `false`
255 /// otherwise.
256 bool isRequired() const;
257
258 /// Return the occurrence type of the described option (i.e., required,
259 /// optional, or hidden).
261
262 // Aspects
263
264 /// Return the allocator used by this object to supply memory.
265 ///
266 /// \note Note that if no allocator was supplied at construction the currently installed
267 /// default allocator at construction is used.
269
270 /// Format this object to the specified output `stream` at the (absolute
271 /// value of) the optionally specified indentation `level` and return a
272 /// reference to `stream`. If `level` is specified, optionally specify
273 /// `spacesPerLevel`, the number of spaces per indentation level for this
274 /// object. If `level` is negative, suppress indentation of the first
275 /// line. If `stream` is not valid on entry, this operation has no effect.
276 ///
277 /// \pre The behavior is undefined if `spacesPerLevel` is negative.
278 bsl::ostream& print(bsl::ostream& stream,
279 int level = 0,
280 int spacesPerLevel = 4) const;
281};
282
283// FREE OPERATORS
284
285/// Return `true` if the specified `lhs` and `rhs` have the same value, and
286/// `false` otherwise. Two objects of type `OccurrenceInfo` have the same
287/// value if and only if they have the same occurrence type and either both do
288/// not have a default value, or their respective default values have the same
289/// type and value.
290bool operator==(const OccurrenceInfo& lhs, const OccurrenceInfo& rhs);
291
292/// Return `true` if the specified `lhs` and `rhs` do not have the same value,
293/// and `false` otherwise. Two objects of type `OccurrenceInfo` do not have
294/// the same value if and only if they have different occurrence types, or
295/// exactly one has a default value, or else both have a default value but
296/// their respective default values have either different types or different
297/// values.
298bool operator!=(const OccurrenceInfo& lhs, const OccurrenceInfo& rhs);
299
300/// Write the value of the specified `rhs` object to the specified `stream` in
301/// a (multi-line) human readable format and return a reference to the `stream`.
302///
303/// \note Note that the last line is *not* terminated by a newline
304/// character.
305bsl::ostream& operator<<(bsl::ostream& stream, const OccurrenceInfo& rhs);
306
307} // close package namespace
308
309
310#endif
311
312// ----------------------------------------------------------------------------
313// Copyright 2020 Bloomberg Finance L.P.
314//
315// Licensed under the Apache License, Version 2.0 (the "License");
316// you may not use this file except in compliance with the License.
317// You may obtain a copy of the License at
318//
319// http://www.apache.org/licenses/LICENSE-2.0
320//
321// Unless required by applicable law or agreed to in writing, software
322// distributed under the License is distributed on an "AS IS" BASIS,
323// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
324// See the License for the specific language governing permissions and
325// limitations under the License.
326// ----------------------------- END-OF-FILE ----------------------------------
327
328/** @} */
329/** @} */
330/** @} */
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:396
Definition bdlt_date.h:294
Definition bdlt_datetime.h:330
Definition bdlt_time.h:195
Definition bslstl_string.h:1252
Definition bslstl_vector.h:1120
Definition bslma_allocator.h:545
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition balcl_commandline.h:1364
bsl::ostream & operator<<(bsl::ostream &stream, const CommandLine &rhs)
Definition bdlb_printmethods.h:306
Definition bslma_usesbslmaallocator.h:344
long long Int64
Definition bsls_types.h:134