BDE 4.39.x 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).
175///
176/// See @ref bslx_versionfunctions
177template <class TYPE>
179
180 /// Return the maximum valid BDEX format version, as indicated by the
181 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
182 /// method while streaming an object of the (template parameter) type `TYPE`.
183 ///
184 /// \note Note that it is highly recommended that `versionSelector`
185 /// be formatted as "YYYYMMDD", a date representation. Also note that
186 /// `versionSelector` should be a *compile*-time-chosen value that
187 /// selects a format version supported by both externalizer and
188 /// unexternalizer. See the `bslx` package-level documentation for more
189 /// information on BDEX streaming of value-semantic types and
190 /// containers.
191 static int maxSupportedBdexVersion(int versionSelector);
192
193#ifndef BDE_OMIT_INTERNAL_DEPRECATED
194
195 // DEPRECATED METHODS
196
197 /// Return the maximum valid BDEX format version to be passed to the
198 /// `bdexStreamOut` method while streaming an object of the (template
199 /// parameter) type `TYPE`. See the `bslx` package-level documentation
200 /// for more information on BDEX streaming of value-semantic types and
201 /// containers.
202 static int maxSupportedBdexVersion();
203
204#endif
205};
206
207/// Return the maximum valid BDEX format version, as indicated by the
208/// specified `versionSelector`, to be passed to the `bdexStreamOut`
209/// method while streaming an object of the (template parameter) type `bsl::vector<TYPE, ALLOC>`.
210///
211/// \note Note that it is highly recommended that
212/// `versionSelector` be formatted as "YYYYMMDD", a date representation.
213/// Also note that `versionSelector` should be a *compile*-time-chosen
214/// value that selects a format version supported by both externalizer
215/// and unexternalizer. See the `bslx` package-level documentation for
216/// more information on BDEX streaming of value-semantic types and
217/// containers.
218template <class TYPE, class ALLOC>
219struct VersionFunctions_NonFundamentalImpl<bsl::vector<TYPE, ALLOC> > {
220 static int maxSupportedBdexVersion(int versionSelector);
221
222#ifndef BDE_OMIT_INTERNAL_DEPRECATED
223
224 // DEPRECATED METHODS
225
226 /// Return the maximum valid BDEX format version to be passed to the
227 /// `bdexStreamOut` method while streaming an object of the (template
228 /// parameter) type `bsl::vector<TYPE, ALLOC>`. See the `bslx`
229 /// package-level documentation for more information on BDEX streaming
230 /// of value-semantic types and containers.
231 static int maxSupportedBdexVersion();
232
233#endif
234};
235
236 // ===============================
237 // namespace VersionFunctions_Impl
238 // ===============================
239
240namespace VersionFunctions_Impl {
241
242 // This namespace contains functions that allow the computation of version
243 // information for a (template parameter) type 'TYPE' as per the BDEX
244 // protocol (see the 'bslx' package-level documentation). These functions
245 // presume that all 'const' and 'volatile' qualifiers have been stripped
246 // from the (template parameter) 'TYPE'.
247
248 // CLASS METHODS
249
250 /// Return `k_NO_VERSION`.
251 /// \note Note that this function is called only for
252 /// enumerations, fundamental types, and `bsl::string`, which do not
253 /// require versioning as per the BDEX protocol.
254 template <class TYPE>
256 int,
258
259 /// Return the maximum valid BDEX format version, as indicated by the
260 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
261 /// method while streaming an object of the (template parameter) type `TYPE`.
262 ///
263 /// \note Note that it is highly recommended that `versionSelector`
264 /// be formatted as "YYYYMMDD", a date representation. Also note that
265 /// `versionSelector` should be a *compile*-time-chosen value that
266 /// selects a format version supported by both externalizer and
267 /// unexternalizer. Also note that this function assumes the `TYPE` is
268 /// neither `const` nor `volatile` and that this function is called only
269 /// for types which are not enumerations, not fundamental types, and not
270 /// `bsl::string` (vectors and other BDEX-compliant types will use this
271 /// function). See the `bslx` package-level documentation for more
272 /// information on BDEX streaming of value-semantic types and
273 /// containers.
274 template <class TYPE>
276 int versionSelector,
278
279 /// Return the maximum valid BDEX format version, as indicated by the
280 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
281 /// method while streaming an object of the (template parameter) type `TYPE`.
282 ///
283 /// \note Note that it is highly recommended that `versionSelector`
284 /// be formatted as "YYYYMMDD", a date representation. Also note that
285 /// `versionSelector` should be a *compile*-time-chosen value that
286 /// selects a format version supported by both externalizer and
287 /// unexternalizer. Also note that this function assumes the `TYPE` is
288 /// neither `const` nor `volatile`. See the `bslx` package-level
289 /// documentation for more information on BDEX streaming of
290 /// value-semantic types and containers.
291 template <class TYPE>
292 int maxSupportedBdexVersion(int versionSelector);
293
294#ifndef BDE_OMIT_INTERNAL_DEPRECATED
295
296 // DEPRECATED METHODS
297
298 /// Return `k_NO_VERSION`.
299 /// \note Note that this function is called only for
300 /// enumerations, fundamental types, and `bsl::string`, which do not
301 /// require versioning as per the BDEX protocol.
302 template <class TYPE>
305
306 /// Return the maximum valid BDEX format version to be passed to the
307 /// `bdexStreamOut` method while streaming an object of the (template parameter) type `TYPE`.
308 ///
309 /// \note Note that this function assumes the `TYPE`
310 /// is neither `const` nor `volatile` and that this function is called
311 /// only for types which are not enumerations, not fundamental types,
312 /// and not `bsl::string` (vectors and other BDEX-compliant types will
313 /// use this function). See the `bslx` package-level documentation for
314 /// more information on BDEX streaming of value-semantic types and
315 /// containers.
316 template <class TYPE>
318
319 /// Return the maximum valid BDEX format version to be passed to the
320 /// `bdexStreamOut` method while streaming an object of the (template parameter) type `TYPE`.
321 ///
322 /// \note Note that this function assumes the `TYPE`
323 /// is neither `const` nor `volatile`. See the `bslx` package-level
324 /// documentation for more information on BDEX streaming of
325 /// value-semantic types and containers.
326 template <class TYPE>
328
329#endif
330
331} // close namespace VersionFunctions_Impl
332
333 // ==========================
334 // namespace VersionFunctions
335 // ==========================
336
337namespace VersionFunctions {
338
339 // This namespace contains functions that allow the computation of version
340 // information for a (template parameter) type 'TYPE' as per the BDEX
341 // protocol (see the 'bslx' package-level documentation).
342
343 enum {
344 k_NO_VERSION = -1 // Value to be used when there is no BDEX version.
345 };
346
347 // CLASS METHODS
348
349 /// Return the maximum valid BDEX format version, as indicated by the
350 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
351 /// method while streaming an object of the (template parameter) type `TYPE`.
352 ///
353 /// \note Note that it is highly recommended that `versionSelector`
354 /// be formatted as "YYYYMMDD", a date representation. Also note that
355 /// `versionSelector` should be a *compile*-time-chosen value that
356 /// selects a format version supported by both externalizer and
357 /// unexternalizer. Also note that this function ignores any `const`
358 /// and `volatile` qualifiers on the `TYPE`. See the `bslx`
359 /// package-level documentation for more information on BDEX streaming
360 /// of value-semantic types and containers.
361 template <class TYPE>
362 int maxSupportedBdexVersion(const TYPE *, int versionSelector);
363
364#ifndef BDE_OMIT_INTERNAL_DEPRECATED
365
366 // DEPRECATED METHODS
367
368 /// @deprecated Use @ref maxSupportedBdexVersion(const TYPE *, int)
369 /// instead.
370 ///
371 /// Return the maximum valid BDEX format version to be passed to the
372 /// `bdexStreamOut` method while streaming an object of the (template parameter) type `TYPE`.
373 ///
374 /// \note Note that this function ignores any `const`
375 /// and `volatile` qualifiers on the `TYPE`. See the `bslx`
376 /// package-level documentation for more information on BDEX streaming
377 /// of value-semantic types and containers.
378 template <class TYPE>
379 int maxSupportedBdexVersion(const TYPE *);
380
381#endif
382
383} // close namespace VersionFunctions
384
385// ============================================================================
386// INLINE DEFINITIONS
387// ============================================================================
388
389 // ------------------------------------------
390 // struct VersionFunctions_NonFundamentalImpl
391 // ------------------------------------------
392
393// CLASS METHODS
394template <class TYPE>
395inline
397 maxSupportedBdexVersion(int versionSelector)
398{
399 // A compilation error indicating the next line of code implies the class
400 // of 'TYPE' does not support the 'maxSupportedBdexVersion' method.
401
402 return TYPE::maxSupportedBdexVersion(versionSelector);
403}
404
405#ifndef BDE_OMIT_INTERNAL_DEPRECATED
406
407// DEPRECATED METHODS
408template <class TYPE>
409inline
411{
412 // A compilation error indicating the next line of code implies the class
413 // of 'TYPE' does not support the 'maxSupportedBdexVersion' method.
414
415 return TYPE::maxSupportedBdexVersion();
416}
417
418#endif
419
420template <class TYPE, class ALLOC>
421inline
423 maxSupportedBdexVersion(int versionSelector)
424{
426
427 const int version = maxSupportedBdexVersion(reinterpret_cast<TYPE *>(0),
428 versionSelector);
429
430 return version != VersionFunctions::k_NO_VERSION ? version : 1;
431}
432
433#ifndef BDE_OMIT_INTERNAL_DEPRECATED
434
435// DEPRECATED METHODS
436template <class TYPE, class ALLOC>
437inline
439 maxSupportedBdexVersion()
440{
442
443 const int version = maxSupportedBdexVersion(reinterpret_cast<TYPE *>(0));
444
445 return version != VersionFunctions::k_NO_VERSION ? version : 1;
446}
447
448#endif
449
450 // -------------------------------
451 // namespace VersionFunctions_Impl
452 // -------------------------------
453
454// CLASS METHODS
455template <class TYPE>
456inline
463
464template <class TYPE>
465inline
473
474template <class TYPE>
475inline
477{
478 typedef typename bsl::conditional<
483 VersionFunctions_HasBdexVersion>::type dummyType;
484
485 return VersionFunctions_Impl::
486 maxSupportedBdexVersion<TYPE>(versionSelector, dummyType());
487}
488
489#ifndef BDE_OMIT_INTERNAL_DEPRECATED
490
491// DEPRECATED METHODS
492template <class TYPE>
493inline
499
500template <class TYPE>
501inline
508
509template <class TYPE>
510inline
512{
513 typedef typename bsl::conditional<
518 VersionFunctions_HasBdexVersion>::type dummyType;
519
520 return VersionFunctions_Impl::maxSupportedBdexVersion<TYPE>(dummyType());
521}
522
523#endif
524 // --------------------------
525 // namespace VersionFunctions
526 // --------------------------
527
528// CLASS METHODS
529template <class TYPE>
530inline
532 int versionSelector)
533{
534 return VersionFunctions_Impl::
535 maxSupportedBdexVersion<typename bsl::remove_cv<TYPE>::type>(
536 versionSelector);
537}
538
539#ifndef BDE_OMIT_INTERNAL_DEPRECATED
540
541// DEPRECATED METHODS
542template <class TYPE>
543inline
545{
546 return VersionFunctions_Impl::
547 maxSupportedBdexVersion<typename bsl::remove_cv<TYPE>::type>();
548}
549
550#endif
551
552} // close package namespace
553
554
555#endif
556
557// ----------------------------------------------------------------------------
558// Copyright 2016 Bloomberg Finance L.P.
559//
560// Licensed under the Apache License, Version 2.0 (the "License");
561// you may not use this file except in compliance with the License.
562// You may obtain a copy of the License at
563//
564// http://www.apache.org/licenses/LICENSE-2.0
565//
566// Unless required by applicable law or agreed to in writing, software
567// distributed under the License is distributed on an "AS IS" BASIS,
568// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
569// See the License for the specific language governing permissions and
570// limitations under the License.
571// ----------------------------- END-OF-FILE ----------------------------------
572
573/** @} */
574/** @} */
575/** @} */
Definition bslx_versionfunctions.h:152
Definition bslx_versionfunctions.h:164
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlat_valuetypefunctions.h:939
int maxSupportedBdexVersion()
Definition bslx_versionfunctions.h:511
int maxSupportedBdexVersion(const TYPE *, int versionSelector)
Definition bslx_versionfunctions.h:531
@ k_NO_VERSION
Definition bslx_versionfunctions.h:344
Definition bslx_byteinstream.h:377
Definition bslmf_conditional.h:123
Definition bslmf_issame.h:146
Definition bslmf_isenum.h:173
Definition bslmf_isfundamental.h:303
Definition bslx_versionfunctions.h:178
static int maxSupportedBdexVersion()
Definition bslx_versionfunctions.h:410