BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlat_attributeinfo.h
Go to the documentation of this file.
1/// @file bdlat_attributeinfo.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlat_attributeinfo.h -*-C++-*-
8#ifndef INCLUDED_BDLAT_ATTRIBUTEINFO
9#define INCLUDED_BDLAT_ATTRIBUTEINFO
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlat_attributeinfo bdlat_attributeinfo
15/// @brief Provide a container for attribute information.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlat
19/// @{
20/// @addtogroup bdlat_attributeinfo
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlat_attributeinfo-purpose"> Purpose</a>
25/// * <a href="#bdlat_attributeinfo-classes"> Classes </a>
26/// * <a href="#bdlat_attributeinfo-description"> Description </a>
27/// * <a href="#bdlat_attributeinfo-usage"> Usage </a>
28/// * <a href="#bdlat_attributeinfo-example-1-basic-usage"> Example 1: Basic Usage </a>
29///
30/// # Purpose {#bdlat_attributeinfo-purpose}
31/// Provide a container for attribute information.
32///
33/// # Classes {#bdlat_attributeinfo-classes}
34///
35/// - bdlat_AttributeInfo: container for attribute information
36///
37/// @see bdlat_sequencefunctions
38///
39/// # Description {#bdlat_attributeinfo-description}
40/// This component provides the `bdlat_AttributeInfo` `struct`,
41/// which is a container for holding information (properties) about a sequence
42/// attribute. The properties of an attribute include its name and the length
43/// of its name, its distinct id within its containing type, its formatting
44/// mode, and a brief annotation. Although each attribute property is publicly
45/// accessible, a manipulator and accessor is also supplied for each.
46///
47/// When accessing or manipulating an attribute of a "sequence" type (using one
48/// of the functions from the `bdlat_SequenceFunctions` namespace), an instance
49/// of 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_attributeinfo-usage}
55///
56///
57/// This section illustrates intended use of this component.
58///
59/// ### Example 1: Basic Usage {#bdlat_attributeinfo-example-1-basic-usage}
60///
61///
62/// Suppose you create an accessor for sequence attributes that prints each
63/// attribute to an output stream:
64/// @code
65/// #include <bdlat_attributeinfo.h>
66/// #include <ostream>
67///
68/// using namespace BloombergLP;
69///
70/// class PrintAttributeWithInfo {
71/// // Print the attribute along with its name and annotation.
72///
73/// // PRIVATE DATA MEMBERS
74/// bsl::ostream *d_stream_p;
75///
76/// public:
77/// // CREATORS
78/// PrintAttributeWithInfo(bsl::ostream *stream)
79/// : d_stream_p(stream)
80/// {
81/// }
82///
83/// // OPERATIONS
84/// template <typename TYPE>
85/// int operator()(const TYPE& attribute,
86/// const bdlat_AttributeInfo& info)
87/// {
88/// (*d_stream_p) << attribute << " ("
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_attributeinfo
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 // ==========================
132 // struct bdlat_AttributeInfo
133 // ==========================
134
135/// This `struct` holds information about an attribute. Its data members
136/// are `public` by design so that instances may be statically initialized.
138
139 // PUBLIC DATA -- DO *NOT* REORDER
140 int d_id; // distinct id of attribute
141 const char *d_name_p; // name of attribute
142 int d_nameLength; // length of attribute name (0-terminator
143 // not included)
144 const char *d_annotation_p; // attribute annotation
145 int d_formattingMode; // formatting mode
146
147 // TRAITS
152
153 // CREATORS
154
155 // The following methods are not defined by design:
156 //..
157 // bdlat_AttributeInfo();
158 // bdlat_AttributeInfo(const bdlat_AttributeInfo& original);
159 // ~bdlat_AttributeInfo();
160 //..
161 // The corresponding methods supplied by the compiler are sufficient.
162
163 // MANIPULATORS
164
165 // The following method is not defined by design:
166 //..
167 // bdlat_AttributeInfo& operator=(const bdlat_AttributeInfo& rhs);
168 //..
169 // The assignment operator supplied by the compiler is sufficient.
170
171 /// Return a reference to the modifiable annotation of this attribute
172 /// info object.
173 const char *& annotation();
174
175 /// Return a reference to the modifiable formatting mode of this
176 /// attribute info object.
177 int& formattingMode();
178
179 /// Return a reference to the modifiable id of this attribute info
180 /// object.
181 int& id();
182
183 /// Return a reference to the modifiable name of this attribute info
184 /// object.
185 const char *& name();
186
187 /// Return a reference to the modifiable length of the name of this
188 /// attribute info object. Note that the 0-terminator is not included
189 /// in the length.
190 int& nameLength();
191
192 // ACCESSORS
193
194 /// Return the non-modifiable annotation of this attribute info object.
196 const char *annotation() const;
197
198 /// Return the formatting mode of this attribute info object.
200 int formattingMode() const;
201
202 /// Return the id of this attribute info object.
204 int id() const;
205
206 /// Return the non-modifiable name of this attribute info object.
208 const char *name() const;
209
210 /// Return the length of the name of this attribute info object. Note
211 /// that the 0-terminator is not included in the length.
213 int nameLength() const;
214};
215
216// ============================================================================
217// INLINE DEFINITIONS
218// ============================================================================
219
220// FREE OPERATORS
221
222/// Return `true` if the specified `lhs` and `rhs` attribute info objects
223/// have the same value, and `false` otherwise. Two attribute info objects
224/// have the same value if each of their respective properties are
225/// identical.
226inline
227bool operator==(const bdlat_AttributeInfo& lhs,
228 const bdlat_AttributeInfo& rhs);
229
230/// Return `true` if the specified `lhs` and `rhs` attribute info objects do
231/// not have the same value, and `false` otherwise. Two attribute info
232/// objects do not have the same value if at least one of their respective
233/// properties is not identical.
234inline
235bool operator!=(const bdlat_AttributeInfo& lhs,
236 const bdlat_AttributeInfo& rhs);
237
238/// Write the value of the specified `attributeInfo` to the specified
239/// `stream`.
240bsl::ostream& operator<<(bsl::ostream& stream,
241 const bdlat_AttributeInfo& attributeInfo);
242
243// MANIPULATORS
244inline
246{
247 return d_annotation_p;
248}
249
250inline
255
256inline
258{
259 return d_id;
260}
261
262inline
264{
265 return d_name_p;
266}
267
268inline
273
274// ACCESSORS
275inline
278{
279 return d_annotation_p;
280}
281
282inline
288
289inline
292{
293 return d_id;
294}
295
296inline
298const char *bdlat_AttributeInfo::name() const
299{
300 return d_name_p;
301}
302
303inline
306{
307 return d_nameLength;
308}
309
310// FREE OPERATORS
311
312inline
313bool operator==(const bdlat_AttributeInfo& lhs, const bdlat_AttributeInfo& rhs)
314{
315 return lhs.formattingMode() == rhs.formattingMode()
316 && lhs.id() == rhs.id()
317 && lhs.nameLength() == rhs.nameLength()
318 && 0 == bsl::memcmp(lhs.name(), rhs.name(), lhs.nameLength())
319 && 0 == bsl::strcmp(lhs.annotation(), rhs.annotation());
320}
321
322inline
323bool operator!=(const bdlat_AttributeInfo& lhs, const bdlat_AttributeInfo& rhs)
324{
325 return !(lhs == rhs);
326}
327
328
329
330#endif
331
332// ----------------------------------------------------------------------------
333// Copyright 2015 Bloomberg Finance L.P.
334//
335// Licensed under the Apache License, Version 2.0 (the "License");
336// you may not use this file except in compliance with the License.
337// You may obtain a copy of the License at
338//
339// http://www.apache.org/licenses/LICENSE-2.0
340//
341// Unless required by applicable law or agreed to in writing, software
342// distributed under the License is distributed on an "AS IS" BASIS,
343// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
344// See the License for the specific language governing permissions and
345// limitations under the License.
346// ----------------------------- END-OF-FILE ----------------------------------
347
348/** @} */
349/** @} */
350/** @} */
int & formattingMode()
Definition bdlat_attributeinfo.h:251
const char *& name()
Definition bdlat_attributeinfo.h:263
int & nameLength()
Definition bdlat_attributeinfo.h:269
const char *& annotation()
Definition bdlat_attributeinfo.h:245
bsl::ostream & operator<<(bsl::ostream &stream, const bdlat_AttributeInfo &attributeInfo)
int & id()
Definition bdlat_attributeinfo.h:257
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
Definition bdlat_attributeinfo.h:137
const char * d_annotation_p
Definition bdlat_attributeinfo.h:144
const char * d_name_p
Definition bdlat_attributeinfo.h:141
int d_nameLength
Definition bdlat_attributeinfo.h:142
BSLMF_NESTED_TRAIT_DECLARATION(bdlat_AttributeInfo, bsl::is_trivially_default_constructible)
int d_formattingMode
Definition bdlat_attributeinfo.h:145
BSLMF_NESTED_TRAIT_DECLARATION(bdlat_AttributeInfo, bsl::is_trivially_copyable)
int d_id
Definition bdlat_attributeinfo.h:140
Definition bslmf_istriviallycopyable.h:329
Definition bslmf_istriviallydefaultconstructible.h:293