BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslx_versionfunctions.h
Go to the documentation of this file.
1/// @file bslx_versionfunctions.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslx_versionfunctions.h -*-C++-*-
8#ifndef INCLUDED_BSLX_VERSIONFUNCTIONS
9#define INCLUDED_BSLX_VERSIONFUNCTIONS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslx_versionfunctions bslx_versionfunctions
15/// @brief Provide functions to return BDEX version information for types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslx
19/// @{
20/// @addtogroup bslx_versionfunctions
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslx_versionfunctions-purpose"> Purpose</a>
25/// * <a href="#bslx_versionfunctions-classes"> Classes </a>
26/// * <a href="#bslx_versionfunctions-description"> Description </a>
27/// * <a href="#bslx_versionfunctions-usage"> Usage </a>
28/// * <a href="#bslx_versionfunctions-example-1-querying-bdex-version"> Example 1: Querying BDEX Version </a>
29///
30/// # Purpose {#bslx_versionfunctions-purpose}
31/// Provide functions to return BDEX version information for types.
32///
33/// # Classes {#bslx_versionfunctions-classes}
34///
35/// - bslx::VersionFunctions: namespace for functions returning version numbers
36///
37/// # Description {#bslx_versionfunctions-description}
38/// This component provides a namespace, `bslx::VersionFunctions`,
39/// that contains functions for determining the BDEX version number for types.
40///
41/// This namespace defines the `maxSupportedBdexVersion` function, which is
42/// overloaded to return a predetermined value, `k_NO_VERSION`, also defined in
43/// this namespace, for each of the fundamental types, `enum` types, and
44/// `bsl::string`. For `bsl::vector`, the `maxSupportedBdexVersion` function
45/// returns 1 if the vector is parameterized on one of the three types mentioned
46/// above. Otherwise, the version number returned is the same as that returned
47/// for `bsl::vector::value_type`. For BDEX-compliant types, the function
48/// returns the BDEX version number returned by the `maxSupportedBdexVersion`
49/// method provided by that type.
50///
51/// In general, this component is used by higher-level `bslx` components to
52/// query the version number for types.
53///
54/// ## Usage {#bslx_versionfunctions-usage}
55///
56///
57/// This section illustrates intended use of this component.
58///
59/// ### Example 1: Querying BDEX Version {#bslx_versionfunctions-example-1-querying-bdex-version}
60///
61///
62/// This component may be used by clients to query the version number for types
63/// in a convenient manner. First, define an `enum`, `my_Enum`:
64/// @code
65/// enum my_Enum {
66/// ENUM_VALUE1,
67/// ENUM_VALUE2,
68/// ENUM_VALUE3,
69/// ENUM_VALUE4
70/// };
71/// @endcode
72/// Then, define a BDEX-compliant class, `my_Class`:
73/// @code
74/// class my_Class {
75/// public:
76/// enum {
77/// VERSION = 1
78/// };
79///
80/// // CLASS METHODS
81/// static int maxSupportedBdexVersion(int) {
82/// return VERSION;
83/// }
84///
85/// // ...
86///
87/// };
88/// @endcode
89/// Finally, verify the value returned by `maxSupportedBdexVersion` for some
90/// fundamental types, `my_Enum`, and `my_Class` with an arbitrary
91/// `versionSelector`:
92/// @code
93/// using bslx::VersionFunctions::maxSupportedBdexVersion;
94/// using bslx::VersionFunctions::k_NO_VERSION;
95///
96/// assert(k_NO_VERSION ==
97/// maxSupportedBdexVersion(reinterpret_cast<char *>(0), 20131127));
98/// assert(k_NO_VERSION ==
99/// maxSupportedBdexVersion(reinterpret_cast<int *>(0), 20131127));
100/// assert(k_NO_VERSION ==
101/// maxSupportedBdexVersion(reinterpret_cast<double *>(0), 20131127));
102/// assert(k_NO_VERSION ==
103/// maxSupportedBdexVersion(reinterpret_cast<bsl::string *>(0), 20131127));
104///
105/// assert(k_NO_VERSION ==
106/// maxSupportedBdexVersion(reinterpret_cast<my_Enum *>(0), 20131127));
107///
108/// assert(my_Class::VERSION ==
109/// maxSupportedBdexVersion(reinterpret_cast<my_Class *>(0), 20131127));
110/// @endcode
111/// @}
112/** @} */
113/** @} */
114
115/** @addtogroup bsl
116 * @{
117 */
118/** @addtogroup bslx
119 * @{
120 */
121/** @addtogroup bslx_versionfunctions
122 * @{
123 */
124
125#include <bslscm_version.h>
126
127#include <bslmf_conditional.h>
128#include <bslmf_isenum.h>
129#include <bslmf_isfundamental.h>
130#include <bslmf_issame.h>
131#include <bslmf_removecv.h>
132
133#include <bsl_string.h>
134#include <bsl_vector.h>
135
136#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
137#include <bslmf_if.h>
138#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
139
140
141namespace bslx {
142
143 // =============================================
144 // class VersionFunctions_DoesNotHaveBdexVersion
145 // =============================================
146
147/// This class is used to perform function overload resolution for types
148/// that do *not* have BDEX versions. This class contains no interface or
149/// implementation by design.
150///
151/// See @ref bslx_versionfunctions
154
155 // =====================================
156 // class VersionFunctions_HasBdexVersion
157 // =====================================
158
159/// This class is used to perform function overload resolution for types
160/// that *have* BDEX versions. This class contains no interface or
161/// implementation by design.
162///
163/// See @ref bslx_versionfunctions
166
167 // ==========================================
168 // struct VersionFunctions_NonFundamentalImpl
169 // ==========================================
170
171/// This `struct` provides a namespace for functions used to obtain the
172/// BDEX-compliant version information for vectors and types requiring a
173/// `TYPE::maxSupportedBdexVersion` method as per the BDEX protocol (see the
174/// `bslx` package-level documentation).
175template <class TYPE>
177
178 /// Return the maximum valid BDEX format version, as indicated by the
179 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
180 /// method while streaming an object of the (template parameter) type
181 /// `TYPE`. Note that it is highly recommended that `versionSelector`
182 /// be formatted as "YYYYMMDD", a date representation. Also note that
183 /// `versionSelector` should be a *compile*-time-chosen value that
184 /// selects a format version supported by both externalizer and
185 /// unexternalizer. See the `bslx` package-level documentation for more
186 /// information on BDEX streaming of value-semantic types and
187 /// containers.
188 static int maxSupportedBdexVersion(int versionSelector);
189
190#ifndef BDE_OMIT_INTERNAL_DEPRECATED
191
192 // DEPRECATED METHODS
193
194 /// Return the maximum valid BDEX format version to be passed to the
195 /// `bdexStreamOut` method while streaming an object of the (template
196 /// parameter) type `TYPE`. See the `bslx` package-level documentation
197 /// for more information on BDEX streaming of value-semantic types and
198 /// containers.
199 static int maxSupportedBdexVersion();
200
201#endif
202};
203
204/// Return the maximum valid BDEX format version, as indicated by the
205/// specified `versionSelector`, to be passed to the `bdexStreamOut`
206/// method while streaming an object of the (template parameter) type
207/// `bsl::vector<TYPE, ALLOC>`. Note that it is highly recommended that
208/// `versionSelector` be formatted as "YYYYMMDD", a date representation.
209/// Also note that `versionSelector` should be a *compile*-time-chosen
210/// value that selects a format version supported by both externalizer
211/// and unexternalizer. See the `bslx` package-level documentation for
212/// more information on BDEX streaming of value-semantic types and
213/// containers.
214template <class TYPE, class ALLOC>
215struct VersionFunctions_NonFundamentalImpl<bsl::vector<TYPE, ALLOC> > {
216 static int maxSupportedBdexVersion(int versionSelector);
217
218#ifndef BDE_OMIT_INTERNAL_DEPRECATED
219
220 // DEPRECATED METHODS
221
222 /// Return the maximum valid BDEX format version to be passed to the
223 /// `bdexStreamOut` method while streaming an object of the (template
224 /// parameter) type `bsl::vector<TYPE, ALLOC>`. See the `bslx`
225 /// package-level documentation for more information on BDEX streaming
226 /// of value-semantic types and containers.
227 static int maxSupportedBdexVersion();
228
229#endif
230};
231
232 // ===============================
233 // namespace VersionFunctions_Impl
234 // ===============================
235
236namespace VersionFunctions_Impl {
237
238 // This namespace contains functions that allow the computation of version
239 // information for a (template parameter) type 'TYPE' as per the BDEX
240 // protocol (see the 'bslx' package-level documentation). These functions
241 // presume that all 'const' and 'volatile' qualifiers have been stripped
242 // from the (template parameter) 'TYPE'.
243
244 // CLASS METHODS
245
246 /// Return `k_NO_VERSION`. Note that this function is called only for
247 /// enumerations, fundamental types, and `bsl::string`, which do not
248 /// require versioning as per the BDEX protocol.
249 template <class TYPE>
251 int,
253
254 /// Return the maximum valid BDEX format version, as indicated by the
255 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
256 /// method while streaming an object of the (template parameter) type
257 /// `TYPE`. Note that it is highly recommended that `versionSelector`
258 /// be formatted as "YYYYMMDD", a date representation. Also note that
259 /// `versionSelector` should be a *compile*-time-chosen value that
260 /// selects a format version supported by both externalizer and
261 /// unexternalizer. Also note that this function assumes the `TYPE` is
262 /// neither `const` nor `volatile` and that this function is called only
263 /// for types which are not enumerations, not fundamental types, and not
264 /// `bsl::string` (vectors and other BDEX-compliant types will use this
265 /// function). See the `bslx` package-level documentation for more
266 /// information on BDEX streaming of value-semantic types and
267 /// containers.
268 template <class TYPE>
270 int versionSelector,
272
273 /// Return the maximum valid BDEX format version, as indicated by the
274 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
275 /// method while streaming an object of the (template parameter) type
276 /// `TYPE`. Note that it is highly recommended that `versionSelector`
277 /// be formatted as "YYYYMMDD", a date representation. Also note that
278 /// `versionSelector` should be a *compile*-time-chosen value that
279 /// selects a format version supported by both externalizer and
280 /// unexternalizer. Also note that this function assumes the `TYPE` is
281 /// neither `const` nor `volatile`. See the `bslx` package-level
282 /// documentation for more information on BDEX streaming of
283 /// value-semantic types and containers.
284 template <class TYPE>
285 int maxSupportedBdexVersion(int versionSelector);
286
287#ifndef BDE_OMIT_INTERNAL_DEPRECATED
288
289 // DEPRECATED METHODS
290
291 /// Return `k_NO_VERSION`. Note that this function is called only for
292 /// enumerations, fundamental types, and `bsl::string`, which do not
293 /// require versioning as per the BDEX protocol.
294 template <class TYPE>
297
298 /// Return the maximum valid BDEX format version to be passed to the
299 /// `bdexStreamOut` method while streaming an object of the (template
300 /// parameter) type `TYPE`. Note that this function assumes the `TYPE`
301 /// is neither `const` nor `volatile` and that this function is called
302 /// only for types which are not enumerations, not fundamental types,
303 /// and not `bsl::string` (vectors and other BDEX-compliant types will
304 /// use this function). See the `bslx` package-level documentation for
305 /// more information on BDEX streaming of value-semantic types and
306 /// containers.
307 template <class TYPE>
309
310 /// Return the maximum valid BDEX format version to be passed to the
311 /// `bdexStreamOut` method while streaming an object of the (template
312 /// parameter) type `TYPE`. Note that this function assumes the `TYPE`
313 /// is neither `const` nor `volatile`. See the `bslx` package-level
314 /// documentation for more information on BDEX streaming of
315 /// value-semantic types and containers.
316 template <class TYPE>
318
319#endif
320
321} // close namespace VersionFunctions_Impl
322
323 // ==========================
324 // namespace VersionFunctions
325 // ==========================
326
327namespace VersionFunctions {
328
329 // This namespace contains functions that allow the computation of version
330 // information for a (template parameter) type 'TYPE' as per the BDEX
331 // protocol (see the 'bslx' package-level documentation).
332
333 enum {
334 k_NO_VERSION = -1 // Value to be used when there is no BDEX version.
335 };
336
337 // CLASS METHODS
338
339 /// Return the maximum valid BDEX format version, as indicated by the
340 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
341 /// method while streaming an object of the (template parameter) type
342 /// `TYPE`. Note that it is highly recommended that `versionSelector`
343 /// be formatted as "YYYYMMDD", a date representation. Also note that
344 /// `versionSelector` should be a *compile*-time-chosen value that
345 /// selects a format version supported by both externalizer and
346 /// unexternalizer. Also note that this function ignores any `const`
347 /// and `volatile` qualifiers on the `TYPE`. See the `bslx`
348 /// package-level documentation for more information on BDEX streaming
349 /// of value-semantic types and containers.
350 template <class TYPE>
351 int maxSupportedBdexVersion(const TYPE *, int versionSelector);
352
353#ifndef BDE_OMIT_INTERNAL_DEPRECATED
354
355 // DEPRECATED METHODS
356
357 /// @deprecated Use @ref maxSupportedBdexVersion(const TYPE *, int)
358 /// instead.
359 ///
360 /// Return the maximum valid BDEX format version to be passed to the
361 /// `bdexStreamOut` method while streaming an object of the (template
362 /// parameter) type `TYPE`. Note that this function ignores any `const`
363 /// and `volatile` qualifiers on the `TYPE`. See the `bslx`
364 /// package-level documentation for more information on BDEX streaming
365 /// of value-semantic types and containers.
366 template <class TYPE>
367 int maxSupportedBdexVersion(const TYPE *);
368
369#endif
370
371} // close namespace VersionFunctions
372
373// ============================================================================
374// INLINE DEFINITIONS
375// ============================================================================
376
377 // ------------------------------------------
378 // struct VersionFunctions_NonFundamentalImpl
379 // ------------------------------------------
380
381// CLASS METHODS
382template <class TYPE>
383inline
385 maxSupportedBdexVersion(int versionSelector)
386{
387 // A compilation error indicating the next line of code implies the class
388 // of 'TYPE' does not support the 'maxSupportedBdexVersion' method.
389
390 return TYPE::maxSupportedBdexVersion(versionSelector);
391}
392
393#ifndef BDE_OMIT_INTERNAL_DEPRECATED
394
395// DEPRECATED METHODS
396template <class TYPE>
397inline
399{
400 // A compilation error indicating the next line of code implies the class
401 // of 'TYPE' does not support the 'maxSupportedBdexVersion' method.
402
403 return TYPE::maxSupportedBdexVersion();
404}
405
406#endif
407
408template <class TYPE, class ALLOC>
409inline
411 maxSupportedBdexVersion(int versionSelector)
412{
414
415 const int version = maxSupportedBdexVersion(reinterpret_cast<TYPE *>(0),
416 versionSelector);
417
418 return version != VersionFunctions::k_NO_VERSION ? version : 1;
419}
420
421#ifndef BDE_OMIT_INTERNAL_DEPRECATED
422
423// DEPRECATED METHODS
424template <class TYPE, class ALLOC>
425inline
427 maxSupportedBdexVersion()
428{
430
431 const int version = maxSupportedBdexVersion(reinterpret_cast<TYPE *>(0));
432
433 return version != VersionFunctions::k_NO_VERSION ? version : 1;
434}
435
436#endif
437
438 // -------------------------------
439 // namespace VersionFunctions_Impl
440 // -------------------------------
441
442// CLASS METHODS
443template <class TYPE>
444inline
451
452template <class TYPE>
453inline
461
462template <class TYPE>
463inline
465{
466 typedef typename bsl::conditional<
471 VersionFunctions_HasBdexVersion>::type dummyType;
472
473 return VersionFunctions_Impl::
474 maxSupportedBdexVersion<TYPE>(versionSelector, dummyType());
475}
476
477#ifndef BDE_OMIT_INTERNAL_DEPRECATED
478
479// DEPRECATED METHODS
480template <class TYPE>
481inline
487
488template <class TYPE>
489inline
496
497template <class TYPE>
498inline
500{
501 typedef typename bsl::conditional<
506 VersionFunctions_HasBdexVersion>::type dummyType;
507
508 return VersionFunctions_Impl::maxSupportedBdexVersion<TYPE>(dummyType());
509}
510
511#endif
512 // --------------------------
513 // namespace VersionFunctions
514 // --------------------------
515
516// CLASS METHODS
517template <class TYPE>
518inline
520 int versionSelector)
521{
522 return VersionFunctions_Impl::
523 maxSupportedBdexVersion<typename bsl::remove_cv<TYPE>::type>(
524 versionSelector);
525}
526
527#ifndef BDE_OMIT_INTERNAL_DEPRECATED
528
529// DEPRECATED METHODS
530template <class TYPE>
531inline
533{
534 return VersionFunctions_Impl::
535 maxSupportedBdexVersion<typename bsl::remove_cv<TYPE>::type>();
536}
537
538#endif
539
540} // close package namespace
541
542
543#endif
544
545// ----------------------------------------------------------------------------
546// Copyright 2016 Bloomberg Finance L.P.
547//
548// Licensed under the Apache License, Version 2.0 (the "License");
549// you may not use this file except in compliance with the License.
550// You may obtain a copy of the License at
551//
552// http://www.apache.org/licenses/LICENSE-2.0
553//
554// Unless required by applicable law or agreed to in writing, software
555// distributed under the License is distributed on an "AS IS" BASIS,
556// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
557// See the License for the specific language governing permissions and
558// limitations under the License.
559// ----------------------------- END-OF-FILE ----------------------------------
560
561/** @} */
562/** @} */
563/** @} */
Definition bslx_versionfunctions.h:152
Definition bslx_versionfunctions.h:164
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
int maxSupportedBdexVersion()
Definition bslx_versionfunctions.h:499
int maxSupportedBdexVersion(const TYPE *, int versionSelector)
Definition bslx_versionfunctions.h:519
@ k_NO_VERSION
Definition bslx_versionfunctions.h:334
Definition bslx_byteinstream.h:377
Definition bslmf_conditional.h:120
Definition bslmf_issame.h:146
Definition bslmf_isenum.h:173
Definition bslmf_isfundamental.h:303
Definition bslx_versionfunctions.h:176
static int maxSupportedBdexVersion()
Definition bslx_versionfunctions.h:398