BDE 4.14.0 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.
137
138 // PUBLIC DATA -- DO *NOT* REORDER
139 int d_id; // distinct id of selection
140 const char *d_name_p; // name of selection
141 int d_nameLength; // length of selection name (0-terminator
142 // not included)
143 const char *d_annotation_p; // selection annotation
144 int d_formattingMode; // formatting mode
145
146 // TRAITS
151
152 // CREATORS
153
154 // The following methods are not defined by design:
155 //..
156 // bdlat_SelectionInfo();
157 // bdlat_SelectionInfo(const bdlat_SelectionInfo& original);
158 // ~bdlat_SelectionInfo();
159 //..
160 // The corresponding methods supplied by the compiler are sufficient.
161
162 // MANIPULATORS
163
164 // The following method is not defined by design:
165 //..
166 // bdlat_SelectionInfo& operator=(const bdlat_SelectionInfo& rhs);
167 //..
168 // The assignment operator supplied by the compiler is sufficient.
169
170 /// Return a reference to the modifiable annotation of this selection
171 /// info object.
172 const char *& annotation();
173
174 /// Return a reference to the modifiable formatting mode of this
175 /// selection info object.
176 int& formattingMode();
177
178 /// Return a reference to the modifiable id of this selection info
179 /// object.
180 int& id();
181
182 /// Return a reference to the modifiable name of this selection info
183 /// object.
184 const char *& name();
185
186 /// Return a reference to the modifiable length of the name of this
187 /// selection info object. Note that the 0-terminator is not included
188 /// in the length.
189 int& nameLength();
190
191 // ACCESSORS
192
193 /// Return the non-modifiable annotation of this selection info object.
195 const char *annotation() const;
196
197 /// Return the formatting mode of this selection info object.
199 int formattingMode() const;
200
201 /// Return the id of this selection info object.
203 int id() const;
204
205 /// Return the non-modifiable name of this selection info object.
207 const char *name() const;
208
209 /// Return the length of the name of this selection info object. Note
210 /// that the 0-terminator is not included in the length.
212 int nameLength() const;
213};
214
215// ============================================================================
216// INLINE DEFINITIONS
217// ============================================================================
218
219// FREE OPERATORS
220
221/// Return `true` if the specified `lhs` and `rhs` selection info objects
222/// have the same value, and `false` otherwise. Two selection info objects
223/// have the same value if each of their respective properties are
224/// identical.
225inline
226bool operator==(const bdlat_SelectionInfo& lhs,
227 const bdlat_SelectionInfo& rhs);
228
229/// Return `true` if the specified `lhs` and `rhs` selection info objects do
230/// not have the same value, and `false` otherwise. Two selection info
231/// objects do not have the same value if at least one of their respective
232/// properties is not identical.
233inline
234bool operator!=(const bdlat_SelectionInfo& lhs,
235 const bdlat_SelectionInfo& rhs);
236
237/// Write the value of the specified `selectionInfo` to the specified
238/// `stream`.
239bsl::ostream& operator<<(bsl::ostream& stream,
240 const bdlat_SelectionInfo& selectionInfo);
241
242// MANIPULATORS
243inline
245{
246 return d_annotation_p;
247}
248
249inline
254
255inline
257{
258 return d_id;
259}
260
261inline
263{
264 return d_name_p;
265}
266
267inline
272
273// ACCESSORS
274inline
277{
278 return d_annotation_p;
279}
280
281inline
287
288inline
291{
292 return d_id;
293}
294
295inline
297const char *bdlat_SelectionInfo::name() const
298{
299 return d_name_p;
300}
301
302inline
305{
306 return d_nameLength;
307}
308
309// FREE OPERATORS
310
311inline
312bool operator==(const bdlat_SelectionInfo& lhs, const bdlat_SelectionInfo& rhs)
313{
314 return lhs.formattingMode() == rhs.formattingMode()
315 && lhs.id() == rhs.id()
316 && lhs.nameLength() == rhs.nameLength()
317 && 0 == bsl::strncmp(lhs.name(), rhs.name(), lhs.nameLength())
318 && 0 == bsl::strcmp(lhs.annotation(), rhs.annotation());
319}
320
321inline
322bool operator!=(const bdlat_SelectionInfo& lhs, const bdlat_SelectionInfo& rhs)
323{
324 return !(lhs == rhs);
325}
326
327
328
329#endif
330
331// ----------------------------------------------------------------------------
332// Copyright 2015 Bloomberg Finance L.P.
333//
334// Licensed under the Apache License, Version 2.0 (the "License");
335// you may not use this file except in compliance with the License.
336// You may obtain a copy of the License at
337//
338// http://www.apache.org/licenses/LICENSE-2.0
339//
340// Unless required by applicable law or agreed to in writing, software
341// distributed under the License is distributed on an "AS IS" BASIS,
342// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
343// See the License for the specific language governing permissions and
344// limitations under the License.
345// ----------------------------- END-OF-FILE ----------------------------------
346
347/** @} */
348/** @} */
349/** @} */
int & id()
Definition bdlat_selectioninfo.h:256
int & nameLength()
Definition bdlat_selectioninfo.h:268
bsl::ostream & operator<<(bsl::ostream &stream, const bdlat_SelectionInfo &selectionInfo)
const char *& name()
Definition bdlat_selectioninfo.h:262
const char *& annotation()
Definition bdlat_selectioninfo.h:244
int & formattingMode()
Definition bdlat_selectioninfo.h:250
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
Definition bdlat_selectioninfo.h:136
const char * d_name_p
Definition bdlat_selectioninfo.h:140
int d_formattingMode
Definition bdlat_selectioninfo.h:144
int d_nameLength
Definition bdlat_selectioninfo.h:141
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:139
const char * d_annotation_p
Definition bdlat_selectioninfo.h:143
Definition bslmf_istriviallycopyable.h:329
Definition bslmf_istriviallydefaultconstructible.h:293