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