BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlat_selectioninfo.h
Go to the documentation of this file.
1/// @file bdlat_selectioninfo.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlat_selectioninfo.h -*-C++-*-
8#ifndef INCLUDED_BDLAT_SELECTIONINFO
9#define INCLUDED_BDLAT_SELECTIONINFO
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlat_selectioninfo bdlat_selectioninfo
15/// @brief Provide a container for selection information.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlat
19/// @{
20/// @addtogroup bdlat_selectioninfo
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlat_selectioninfo-purpose"> Purpose</a>
25/// * <a href="#bdlat_selectioninfo-classes"> Classes </a>
26/// * <a href="#bdlat_selectioninfo-description"> Description </a>
27/// * <a href="#bdlat_selectioninfo-usage"> Usage </a>
28/// * <a href="#bdlat_selectioninfo-example-1-basic-usage"> Example 1: Basic Usage </a>
29///
30/// # Purpose {#bdlat_selectioninfo-purpose}
31/// Provide a container for selection information.
32///
33/// # Classes {#bdlat_selectioninfo-classes}
34///
35/// - bdlat_SelectionInfo: container for selection information
36///
37/// @see bdlat_choicefunctions
38///
39/// # Description {#bdlat_selectioninfo-description}
40/// This component provides the `bdlat_SelectionInfo` `struct`,
41/// which is a container for holding information (properties) about a choice
42/// selection. The properties of a selection include its name and the length of
43/// its name, its distinct id within its containing type, its formatting mode,
44/// and a brief annotation. Although each selection property is publicly
45/// accessible, a manipulator and accessor is also supplied for each.
46///
47/// When accessing or manipulating a selection of a "choice" type (using one of
48/// the functions from the `bdlat_ChoiceFunctions` namespace), an instance of
49/// this `struct` will be passed as the second argument to the accessor or
50/// manipulator.
51///
52/// Note that this `struct` needs to be a POD type.
53///
54/// ## Usage {#bdlat_selectioninfo-usage}
55///
56///
57/// This section illustrates intended use of this component.
58///
59/// ### Example 1: Basic Usage {#bdlat_selectioninfo-example-1-basic-usage}
60///
61///
62/// Suppose you create an accessor for choice selections that prints the
63/// selection to an output stream:
64/// @code
65/// #include <bdlat_selectioninfo.h>
66/// #include <ostream>
67///
68/// using namespace BloombergLP;
69///
70/// class PrintSelectionWithInfo {
71/// // Print the selection along with its name and annotation.
72///
73/// // PRIVATE DATA MEMBERS
74/// bsl::ostream *d_stream_p;
75///
76/// public:
77/// // CREATORS
78/// PrintSelectionWithInfo(bsl::ostream *stream)
79/// : d_stream_p(stream)
80/// {
81/// }
82///
83/// // OPERATIONS
84/// template <typename TYPE>
85/// int operator()(const TYPE& selection,
86/// const bdlat_SelectionInfo& info)
87/// {
88/// (*d_stream_p) << selection << " ("
89/// << bsl::string(info.name(),
90/// info.nameLength())
91/// << ", "
92/// << info.annotation() << ")\n";
93/// }
94/// };
95/// @endcode
96/// @}
97/** @} */
98/** @} */
99
100/** @addtogroup bdl
101 * @{
102 */
103/** @addtogroup bdlat
104 * @{
105 */
106/** @addtogroup bdlat_selectioninfo
107 * @{
108 */
109
110#include <bdlscm_version.h>
111
112#include <bdlat_bdeatoverrides.h>
113
117
118#include <bsls_keyword.h>
119
120#include <bsl_climits.h>
121#include <bsl_cstring.h>
122#include <bsl_iosfwd.h>
123
124#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
125#include <bslalg_typetraits.h>
126#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
127
128
129
130 // ==========================
131 // struct bdlat_SelectionInfo
132 // ==========================
133
134/// This `struct` holds information about an selection. Its data members
135/// are `public` by design so that instances may be statically initialized.
136///
137/// See @ref bdlat_selectioninfo
139
140 // PUBLIC DATA -- DO *NOT* REORDER
141 int d_id; // distinct id of selection
142 const char *d_name_p; // name of selection
143 int d_nameLength; // length of selection name (0-terminator
144 // not included)
145 const char *d_annotation_p; // selection annotation
146 int d_formattingMode; // formatting mode
147
148 // TRAITS
153
154 // CREATORS
155
156 // The following methods are not defined by design:
157 //..
158 // bdlat_SelectionInfo();
159 // bdlat_SelectionInfo(const bdlat_SelectionInfo& original);
160 // ~bdlat_SelectionInfo();
161 //..
162 // The corresponding methods supplied by the compiler are sufficient.
163
164 // MANIPULATORS
165
166 // The following method is not defined by design:
167 //..
168 // bdlat_SelectionInfo& operator=(const bdlat_SelectionInfo& rhs);
169 //..
170 // The assignment operator supplied by the compiler is sufficient.
171
172 /// Return a reference to the modifiable annotation of this selection
173 /// info object.
174 const char *& annotation();
175
176 /// Return a reference to the modifiable formatting mode of this
177 /// selection info object.
178 int& formattingMode();
179
180 /// Return a reference to the modifiable id of this selection info
181 /// object.
182 int& id();
183
184 /// Return a reference to the modifiable name of this selection info
185 /// object.
186 const char *& name();
187
188 /// Return a reference to the modifiable length of the name of this selection info object.
189 ///
190 /// \note Note that the 0-terminator is not included
191 /// in the length.
192 int& nameLength();
193
194 // ACCESSORS
195
196 /// Return the non-modifiable annotation of this selection info object.
198 const char *annotation() const;
199
200 /// Return the formatting mode of this selection info object.
202 int formattingMode() const;
203
204 /// Return the id of this selection info object.
206 int id() const;
207
208 /// Return the non-modifiable name of this selection info object.
210 const char *name() const;
211
212 /// Return the length of the name of this selection info object.
213 ///
214 /// \note Note that the 0-terminator is not included in the length.
216 int nameLength() const;
217};
218
219// ============================================================================
220// INLINE DEFINITIONS
221// ============================================================================
222
223// FREE OPERATORS
224
225/// Return `true` if the specified `lhs` and `rhs` selection info objects
226/// have the same value, and `false` otherwise. Two selection info objects
227/// have the same value if each of their respective properties are
228/// identical.
229inline
230bool operator==(const bdlat_SelectionInfo& lhs,
231 const bdlat_SelectionInfo& rhs);
232
233/// Return `true` if the specified `lhs` and `rhs` selection info objects do
234/// not have the same value, and `false` otherwise. Two selection info
235/// objects do not have the same value if at least one of their respective
236/// properties is not identical.
237inline
238bool operator!=(const bdlat_SelectionInfo& lhs,
239 const bdlat_SelectionInfo& rhs);
240
241/// Write the value of the specified `selectionInfo` to the specified
242/// `stream`.
243bsl::ostream& operator<<(bsl::ostream& stream,
244 const bdlat_SelectionInfo& selectionInfo);
245
246// MANIPULATORS
247inline
249{
250 return d_annotation_p;
251}
252
253inline
258
259inline
261{
262 return d_id;
263}
264
265inline
267{
268 return d_name_p;
269}
270
271inline
276
277// ACCESSORS
278inline
281{
282 return d_annotation_p;
283}
284
285inline
291
292inline
295{
296 return d_id;
297}
298
299inline
301const char *bdlat_SelectionInfo::name() const
302{
303 return d_name_p;
304}
305
306inline
309{
310 return d_nameLength;
311}
312
313// FREE OPERATORS
314
315inline
316bool operator==(const bdlat_SelectionInfo& lhs, const bdlat_SelectionInfo& rhs)
317{
318 return lhs.formattingMode() == rhs.formattingMode()
319 && lhs.id() == rhs.id()
320 && lhs.nameLength() == rhs.nameLength()
321 && 0 == bsl::strncmp(lhs.name(), rhs.name(), lhs.nameLength())
322 && 0 == bsl::strcmp(lhs.annotation(), rhs.annotation());
323}
324
325inline
326bool operator!=(const bdlat_SelectionInfo& lhs, const bdlat_SelectionInfo& rhs)
327{
328 return !(lhs == rhs);
329}
330
331
332
333#endif
334
335// ----------------------------------------------------------------------------
336// Copyright 2015 Bloomberg Finance L.P.
337//
338// Licensed under the Apache License, Version 2.0 (the "License");
339// you may not use this file except in compliance with the License.
340// You may obtain a copy of the License at
341//
342// http://www.apache.org/licenses/LICENSE-2.0
343//
344// Unless required by applicable law or agreed to in writing, software
345// distributed under the License is distributed on an "AS IS" BASIS,
346// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
347// See the License for the specific language governing permissions and
348// limitations under the License.
349// ----------------------------- END-OF-FILE ----------------------------------
350
351/** @} */
352/** @} */
353/** @} */
int & id()
Definition bdlat_selectioninfo.h:260
int & nameLength()
Definition bdlat_selectioninfo.h:272
bsl::ostream & operator<<(bsl::ostream &stream, const bdlat_SelectionInfo &selectionInfo)
const char *& name()
Definition bdlat_selectioninfo.h:266
const char *& annotation()
Definition bdlat_selectioninfo.h:248
int & formattingMode()
Definition bdlat_selectioninfo.h:254
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:624
Definition bdlat_selectioninfo.h:138
const char * d_name_p
Definition bdlat_selectioninfo.h:142
int d_formattingMode
Definition bdlat_selectioninfo.h:146
int d_nameLength
Definition bdlat_selectioninfo.h:143
BSLMF_NESTED_TRAIT_DECLARATION(bdlat_SelectionInfo, bsl::is_trivially_default_constructible)
BSLMF_NESTED_TRAIT_DECLARATION(bdlat_SelectionInfo, bsl::is_trivially_copyable)
int d_id
Definition bdlat_selectioninfo.h:141
const char * d_annotation_p
Definition bdlat_selectioninfo.h:145
Definition bslmf_istriviallycopyable.h:324
Definition bslmf_istriviallydefaultconstructible.h:296