BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bdlat.h
Go to the documentation of this file.
1/// @file bdlat.h
2///
3///
4/// @defgroup bdlat Package bdlat
5/// @brief Basic Development Library Attribute Types (bdlat)
6/// @addtogroup bdl
7/// @{
8/// @addtogroup bdlat
9/// @{
10/// * <a href="#bdlat-purpose"> Purpose</a>
11/// * <a href="#bdlat-mnemonic"> Mnemonic </a>
12/// * <a href="#bdlat-description"> Description </a>
13/// * <a href="#bdlat-other-key-facilities"> Other Key Facilities </a>
14/// * <a href="#bdlat-arrays"> Arrays </a>
15/// * <a href="#bdlat-choices"> Choices </a>
16/// * <a href="#bdlat-customized-types"> Customized Types </a>
17/// * <a href="#bdlat-dynamic-types"> Dynamic Types </a>
18/// * <a href="#bdlat-enumerations"> Enumerations </a>
19/// * <a href="#bdlat-nullable-values"> Nullable Values </a>
20/// * <a href="#bdlat-sequences"> Sequences </a>
21/// * <a href="#bdlat-simple-types"> Simple Types </a>
22/// * <a href="#bdlat-formatting-mode"> Formatting Mode </a>
23/// * <a href="#bdlat-hierarchical-synopsis"> Hierarchical Synopsis </a>
24/// * <a href="#bdlat-component-synopsis"> Component Synopsis </a>
25///
26/// # Purpose {#bdlat-purpose}
27/// Provide generic functions to manipulate attribute types
28///
29/// # Mnemonic {#bdlat-mnemonic}
30/// Basic Development Library Attribute Types (bdlat)
31///
32/// # Description {#bdlat-description}
33/// The `bdlat` package provides a compile time framework to allow
34/// introspecting the types and values of a document representations, as long as
35/// that document representation conforms to the `bdlat` concepts defined in this
36/// package (and documented below). This allows, for example, writing encoders
37/// (and decoders) for various message formats (like JSON, XML, BER) in a way that
38/// is agnostic to the concrete types of the message objects being encoded (and
39/// decoded). The encoder can navigate the message representation using the
40/// `bdlat` concepts to encode its value without a dependency on the concrete
41/// (non-simple) types involved. More generically, `bdlat` enables users to
42/// decouple a set of operations provided on message objects, from the one or more
43/// concrete representation of those messages.
44///
45/// As an example, the `baljsn` package provides an encoder (and decoder) for JSON
46/// that works on `bdlat` compatible message objects. In practice, `baljsn`
47/// encoders and decoders are instantiated on a wide variety of message types
48/// including: dynamic in-process message object representations (e.g.,
49/// `Aggregate` objects), code generated message representations that are specific
50/// (and optimized) for a specific schema, and a variety of other user defined
51/// message types.
52///
53/// The `bdlat` package defines 8 different "type categories", which are the set
54/// of concepts that are used to model a document. These type categories are
55/// summarized below, and then described in more detail in the next sections.
56///
57/// 1. **array** - a sequence of elements of the same type, analogous to a C++
58/// array ([details](@ref bdlat-arrays) ).
59///
60/// 2. **choice** - a value whose type is selected from a fixed set of types,
61/// analogous to a `std::variant` ([details](@ref bdlat-choices) ).
62///
63/// 3. **customized type** - used to customize an existing type, such as strings
64/// with a limited number of characters and/or with a restricted character set,
65/// or integers with a limited range of values ([details](@ref bdlat-customized-types) ).
66///
67/// 4. **dynamic type** - another variant-like type, but with a different
68/// interface - the number of alternatives is not fixed and they are not
69/// indexed. The actual type category can be determined at runtime only
70/// ([details](@ref bdlat-dynamic-types) ).
71///
72/// 5. **enumeration** - a closed set of named integer constants, analogous to a
73/// C++ `enum` ([details](@ref bdlat-enumerations) ).
74///
75/// 6. **nullable value** - represents a value that may, or may not, be present,
76/// analogous to a `std::optional` ([details](@ref bdlat-nullable-values) ).
77///
78/// 7. **sequence** - a sequence of elements of different types, where the number
79/// of elements, order, and types in the sequence are fixed, analogous to a C++
80/// `struct` ([details](@ref bdlat-sequences) ).
81///
82/// 8. **simple type** - a scalar type represented by specific concrete C++
83/// vocabulary type, like `int`, `double`, `bsl::string`, `bdlt::Date`, etc.
84/// It is a kind of default category - if a type does not belong to any of the
85/// above categories, it is a simple type ([details](@ref bdlat-simple-types) ).
86///
87/// For each category of type listed above, the set of customization points a user
88/// should define in order to expose this category can be found in the
89/// corresponding `bdlat_*functions` component:
90///
91/// | Concept (Type Category) | Component with Customization Points |
92/// |-------------------------|-------------------------------------|
93/// | Array | @ref bdlat_arrayfunctions |
94/// | Choice | @ref bdlat_choicefunctions |
95/// | Customized Type | @ref bdlat_customizedtypefunctions |
96/// | Dynamic Type | @ref bdlat_typecategory |
97/// | Enumeration | @ref bdlat_enumfunctions |
98/// | Nullable Value | @ref bdlat_nullablevaluefunctions |
99/// | Sequence | @ref bdlat_sequencefunctions |
100/// | Simple Type | N/A |
101///
102/// ### Other Key Facilities {#bdlat-other-key-facilities}
103///
104///
105/// - @ref bdlat_typecategory - this component provides a function to query which
106/// type category (or concept) that an object within a document models. Note
107/// that this is **not** a user customization point, but determines the type
108/// from the customization points defined for a type.
109///
110/// - @ref bdlat_valuetypefunctions - Provides additional customization points that
111/// apply across type categories, including assign and reset operations.
112///
113/// ### Arrays {#bdlat-arrays}
114///
115///
116/// An array is a sequence of elements of the same type. Each element can be
117/// addressed by a unique index, starting from 0.
118///
119/// The main properties of an array are:
120///
121/// - The number of elements, called "size", and
122/// - Element type.
123///
124/// The size can be requested and set. When setting the size, either the excess
125/// elements at the end of the sequence are removed or new elements with a default
126/// value are added.
127///
128/// Individual array elements can be accessed (and manipulated) using their index
129/// and an accessor- or manipulator-callback.
130///
131/// An array type must implement the following customization points:
132///
133/// | Customization Point (manipulator) | Note |
134/// |-----------------------------------|----------------------------------------|
135/// | `bdlat_arrayManipulateElement` | apply manipulator callback to element |
136/// | `bdlat_arrayResize` | set the new size |
137///
138/// | Customization Point (accessor) | Note |
139/// |-----------------------------------|----------------------------------------|
140/// | `bdlat_arrayAccessElement` | apply accessor callback to element |
141/// | `bdlat_arraySize` | return array size |
142///
143/// | Customization Point (meta-function) | Note |
144/// |----------------------------------------------|-----------------------------|
145/// | `bdlat_ArrayFunctions::IsArray<T>::value` | is an array? |
146/// | `bdlat_ArrayFunctions::ElementType<T>::Type` | element type |
147///
148/// Details of these operations are described in: @ref bdlat_arrayfunctions
149///
150/// ### Choices {#bdlat-choices}
151///
152///
153/// A choice type is defined by a fixed set of types. At every moment in time it
154/// has a value of one of these types, or has no value if no selection has been
155/// made. Each type from the set has a unique numeric ID and a unique symbolic
156/// name that can be used to address it.
157///
158/// The current selection can be changed using the "make selection" operation.
159/// Either numeric or symbolic ID can be used to specify the desired type. After
160/// a successful selection change, the choice contains the default value for the
161/// selected type.
162///
163/// The current selection ID can be requested, but only its numeric value.
164///
165/// The value of a selection can be accessed or manipulated by supplying an
166/// appropriate callbacks to the respective "access" or "manipulate" function. The
167/// accessor (or manipulator) callback is supplied not only the value, but also an
168/// additional read-only meta-information object. The exact type of the
169/// meta-information object supplied to the accessor/manipulator callback is
170/// unspecified, but it is guaranteed to provide the following member functions:
171///
172/// - `int id()` - a numeric selection ID.
173/// - `const char *name()` - a pointer to a symbolic name.
174/// - `int nameLength()` - the symbolic name length.
175/// - `const char *annotation()` - a null-terminated description text.
176/// - `int formattingMode()` - a value formating mode used by encoders/decoders
177/// (see @ref bdlat-formatting-mode for more info).
178///
179/// A choice type must implement the following customization points:
180///
181/// | Customization Point (manipulator) | Note |
182/// |-----------------------------------|----------------------------------------|
183/// | `bdlat_choiceManipulateSelection` | apply manipulator callback to selection|
184/// | `bdlat_choiceMakeSelection` | make new selection |
185///
186/// | Customization Point (accessor) | Note |
187/// |-----------------------------------|----------------------------------------|
188/// | `bdlat_choiceAccessSelection` | apply accessor callback to selection |
189/// | `bdlat_choiceSelectionId` | return selection ID |
190///
191/// | Customization Point (meta-function) | Note |
192/// |----------------------------------------------|-----------------------------|
193/// | `bdlat_ChoiceFunctions::IsChoice<T>::value` | is a choice? |
194///
195/// Details of these operations are described in: @ref bdlat_choicefunctions
196///
197/// ### Customized Types {#bdlat-customized-types}
198///
199///
200/// A customized type is a wrapper for another "base" type, such as `int` or
201/// `string`. Only 2 operations are available for such types:
202///
203/// - Convert to a reference to base type.
204/// - Convert from a reference to base type.
205///
206/// Additional post-processing logic can be applied inside the second operation,
207/// such as the limits/restrictions check.
208///
209/// A customized type must implement the following customization points:
210///
211/// | Customization Point (manipulator) | Note |
212/// |-------------------------------------------|--------------------------------|
213/// | `bdlat_customizedTypeConvertFromBaseType` | convert from base value |
214///
215/// | Customization Point (accessor) | Note |
216/// |-------------------------------------------|--------------------------------|
217/// | `bdlat_customizedTypeConvertToBaseType` | convert to base value |
218///
219/// | Customization Point (meta-function) | Note |
220/// |-------------------------------------------------------------|--------------|
221/// | `bdlat_CustomizedTypeFunctions::IsCustomizedType<T>::value` | is a cust. T?|
222/// | `bdlat_CustomizedTypeFunctions::BaseType<T>::Type` | base type |
223///
224/// Details of these operations are described in: @ref bdlat_customizedtypefunctions
225///
226/// ### Dynamic Types {#bdlat-dynamic-types}
227///
228///
229/// Dynamic types are used to implement generic in-process document objects that
230/// can be used to represent any `bdlat`-compatible document. For example,
231/// `bdld::Datum`, `bdljsn::Json`, or "Aggregate" object types might implement
232/// this dynamic type concept in order to allow `bdlat` documents to be encoded
233/// and decoded from that representation.
234///
235/// As a consequence of this fact, the actual category of such a type can only be
236/// determined at runtime. The `bdlat_TypeCategory::Select` meta-function applied
237/// to a dynamic type always returns "dynamic type" category. In order to detect
238/// the current category the `bdlat_TypeCategory::select` function is to be
239/// applied to an instance (object) of the type. However, applications should
240/// generally use the `bdlat_TypeCategoryUtil::manipulateByCategory` and
241/// `bdlat_TypeCategoryUtil::accessByCategory` functions instead to handle dynamic
242/// values. These functions detect the category inside and invoke the
243/// appropriate handler, providing it with this information.
244///
245/// A dynamic type must implement the following customization points:
246///
247/// | Customization Point (manipulator) | Note |
248/// |----------------------------------------------|-----------------------------|
249/// | `bdlat_typeCategoryManipulateArray` | manipulate array |
250/// | `bdlat_typeCategoryManipulateChoice` | manipulate choice |
251/// | `bdlat_typeCategoryManipulateCustomizedType` | manipulate customized type |
252/// | `bdlat_typeCategoryManipulateEnumeration` | manipulate enumeration |
253/// | `bdlat_typeCategoryManipulateNullableValue` | manipulate nullable value |
254/// | `bdlat_typeCategoryManipulateSequence` | manipulate sequence |
255/// | `bdlat_typeCategoryManipulateSimple` | manipulate simple type |
256///
257/// | Customization Point (accessor) | Note |
258/// |----------------------------------------------|-----------------------------|
259/// | `bdlat_typeCategoryAccessArray` | access array |
260/// | `bdlat_typeCategoryAccessChoice` | access choice |
261/// | `bdlat_typeCategoryAccessCustomizedType` | access customized type |
262/// | `bdlat_typeCategoryAccessEnumeration` | access enumeration |
263/// | `bdlat_typeCategoryAccessNullableValue` | access nullable value |
264/// | `bdlat_typeCategoryAccessSequence` | access sequence |
265/// | `bdlat_typeCategoryAccessSimple` | access simple type |
266///
267/// | Customization Point (meta-function) | Note |
268/// |----------------------------------------------|-----------------------------|
269/// | `bdlat_TypeCategoryDeclareDynamic<T>::value` | is a dynamic type? |
270///
271/// Details of these operations are described in:
272/// @ref bdlat_typecategory-dynamic-types chapter in @ref bdlat_typecategory
273///
274/// ### Enumerations {#bdlat-enumerations}
275///
276///
277/// An enumeration is a fixed set of integer values, each of which additionally
278/// has a symbolic (string) name. Each enumeration type must provide 4 functions
279/// to convert values from/to int/string.
280///
281/// One of the enumeration values can optionally be declared as a special
282/// "fallback" value. In this case 2 more operations are required - setting and
283/// checking the value.
284///
285/// An enumeration type must implement the following customization points:
286///
287/// | Customization Point (manipulator) | Note |
288/// |-----------------------------------|----------------------------------------|
289/// | `bdlat_enumFromInt` | convert from integer value |
290/// | `bdlat_enumFromString` | convert from symbolic name |
291/// | `bdlat_enumMakeFallback` | assign the fallback value |
292///
293/// | Customization Point (accessor) | Note |
294/// |-----------------------------------|----------------------------------------|
295/// | `bdlat_enumToInt` | convert to integer value |
296/// | `bdlat_enumToString` | convert from symbolic name |
297/// | `bdlat_enumHasFallback` | has fallback value? |
298/// | `bdlat_enumIsFallback` | is the fallback value? |
299///
300/// | Customization Point (meta-function) | Note |
301/// |--------------------------------------------------------|-------------------|
302/// | `bdlat_EnumFunctions::IsEnumeration<T>::value` | is an enumeration?|
303/// | `bdlat_EnumFunctions::HasFallbackEnumerator<T>::value` | has fallback? |
304///
305/// Details of these operations are described in: @ref bdlat_enumfunctions
306///
307/// ### Nullable Values {#bdlat-nullable-values}
308///
309///
310/// A nullable value is a type that has special "empty" or "null" value among
311/// others. It provides the following operations:
312///
313/// - Check whether the current value is null or not.
314/// - Set a default non-null value.
315/// - Access the current non-null value using an accessor callback.
316/// - Manipulate the current non-null value using a manipulator callback.
317///
318/// A nullable value type must implement the following customization points:
319///
320/// | Customization Point (manipulator) | Note |
321/// |--------------------------------------|-------------------------------------|
322/// | `bdlat_nullableValueMakeValue` | assign default non-null value |
323/// | `bdlat_nullableValueManipulateValue` | apply manipulator callback to value |
324///
325/// | Customization Point (accessor) | Note |
326/// |--------------------------------------|-------------------------------------|
327/// | `bdlat_nullableValueAccessValue` | apply accessor callback to value |
328/// | `bdlat_nullableValueIsNull` | is null? |
329///
330/// | Customization Point (meta-function) | Note |
331/// |-----------------------------------------------------------|----------------|
332/// | `bdlat_NullableValueFunctions::IsNullableValue<T>::value` | is a null. v.? |
333/// | `bdlat_NullableValueFunctions::ValueType<T>::Type` | value type |
334///
335/// Details of these operations are described in: @ref bdlat_nullablevaluefunctions
336///
337/// ### Sequences {#bdlat-sequences}
338///
339///
340/// A sequence is a fixed ordered sequence of elements of different types, called
341/// "attributes". Each attribute has a unique numeric ID and a unique symbolic
342/// name. Each attribute can be accessed or manipulated by a callback
343/// individually using its ID or name. Also, all attributes can be processed in
344/// one call - the provided generic callback is applied to each attribute in
345/// consecutive order.
346///
347/// Each accessor and manipulator invoked on an attribute is supplied with an
348/// additional read-only meta-information object. The exact type of the
349/// meta-information object supplied to the accessor/manipulator callback is
350/// unspecified, but it is guaranteed to provide the following member functions:
351///
352/// - `int id()` - a numeric attribute ID.
353/// - `const char *name()` - a pointer to a symbolic attribute name.
354/// - `int nameLength()` - the symbolic name length.
355/// - `const char *annotation()` - a null-terminated description text.
356/// - `int formattingMode()` - a value formating mode used by encoders/decoders
357/// (see @ref bdlat-formatting-mode for more info).
358///
359/// A sequence type must implement the following customization points:
360///
361/// | Customization Point (manipulator) | Note |
362/// |--------------------------------------|-------------------------------------|
363/// | `bdlat_sequenceManipulateAttribute` | apply manipulator callback to attr. |
364/// | `bdlat_sequenceManipulateAttributes` | apply manipulator callback to attrs.|
365///
366/// | Customization Point (accessor) | Note |
367/// |--------------------------------------|-------------------------------------|
368/// | `bdlat_sequenceAccessAttribute` | apply accessor callback to attr. |
369/// | `bdlat_sequenceAccessAttributes` | apply accessor callback to attrs. |
370/// | `bdlat_sequenceHasAttribute` | has the attibute? |
371///
372/// | Customization Point (meta-function) | Note |
373/// |-------------------------------------------------|--------------------------|
374/// | `bdlat_SequenceFunctions::IsSequence<T>::value` | is a sequence? |
375///
376/// Details of these operations are described in: @ref bdlat_sequencefunctions
377///
378/// ### Simple Types {#bdlat-simple-types}
379///
380///
381/// Simple types (sometimes referred as "scalar types") are all types that do not
382/// belong to any of the other categories, such as numbers, strings, and date-time
383/// values. Simple types include:
384///
385/// - `bool`
386/// - `int`
387/// - `unsigned int`
388/// - `long`
389/// - `float`
390/// - `double`
391/// - `bdldfp::Decimal64`
392/// - `bsl::string`
393/// - `bdlt::Date`
394/// - `bdlt::DateTz`
395/// - `bdlt::Datetime`
396/// - `bdlt::DatetimeTz`
397/// - `bdlt::Time`
398/// - `bdlt::TimeTz`
399///
400/// The list above is incomplete and provided as an example only.
401///
402/// No special customization traits or common operations are required for simple
403/// types - operations performed on `bdlat` message (e.g., encoding to JSON, or
404/// decoding to BER) define concrete logic for handling these types.
405///
406/// ### Formatting Mode {#bdlat-formatting-mode}
407///
408///
409/// Elements of a `bdlat`-message can have an associated formatting mode,
410/// described in @ref bdlat_formattingmode . This mode does not affect the value nor
411/// is it used by `bdlat` in any way. The formatting mode can be used by message
412/// encoders and decoders. For example, the `char` type can represent either a
413/// character or a tiny integer value. Explicitly specifying the formatting mode
414/// in this case helps codecs choose the correct representation.
415///
416/// See @ref balber_beruniversaltagnumber or @ref balxml_typesprintutil for examples of
417/// how the formatting modes are applied.
418///
419/// ## Hierarchical Synopsis {#bdlat-hierarchical-synopsis}
420///
421/// The 'bdlat' package currently has 22 components having 6 levels of physical
422/// dependency. The list below shows the hierarchical ordering of the components.
423/// The order of components within each level is not architecturally significant,
424/// just alphabetical.
425/// @code
426/// 6. bdlat_arrayiterators
427/// bdlat_symbolicconverter
428///
429/// 5. bdlat_arrayutil
430/// bdlat_fuzzutil
431/// bdlat_nullablevalueutil
432/// bdlat_valuetypefunctions
433///
434/// 4. bdlat_enumutil
435/// bdlat_typecategory
436///
437/// 3. bdlat_arrayfunctions
438/// bdlat_choicefunctions
439/// bdlat_customizedtypefunctions
440/// bdlat_enumfunctions
441/// bdlat_sequencefunctions
442/// bdlat_typename
443///
444/// 2. bdlat_attributeinfo
445/// bdlat_enumeratorinfo
446/// bdlat_formattingmode
447/// bdlat_nullablevaluefunctions
448/// bdlat_selectioninfo
449/// bdlat_typetraits
450///
451/// 1. bdlat_bdeatoverrides
452/// bdlat_fuzzutiloptions
453/// @endcode
454///
455/// ## Component Synopsis {#bdlat-component-synopsis}
456///
457/// @ref bdlat_arrayfunctions :
458/// Provide a namespace defining "array" functions.
459///
460/// @ref bdlat_arrayiterators :
461/// Provide iterator support for bdlat_ArrayFunction-conformant types.
462///
463/// @ref bdlat_arrayutil :
464/// Provide utilities for operating on `bdlat` "array" types.
465///
466/// @ref bdlat_attributeinfo :
467/// Provide a container for attribute information.
468///
469/// @ref bdlat_bdeatoverrides :
470/// Provide macros to map `bdeat` names to `bdlat` names.
471///
472/// @ref bdlat_choicefunctions :
473/// Provide a namespace defining choice functions.
474///
475/// @ref bdlat_customizedtypefunctions :
476/// Provide a namespace defining customized type functions.
477///
478/// @ref bdlat_enumeratorinfo :
479/// Provide a container for enumerator information.
480///
481/// @ref bdlat_enumfunctions :
482/// Provide a namespace defining enumeration functions.
483///
484/// @ref bdlat_enumutil :
485/// Provide functions for decoding enumerations with fallback values.
486///
487/// @ref bdlat_formattingmode :
488/// Provide formatting mode constants.
489///
490/// @ref bdlat_fuzzutil :
491/// Provide fuzz test utilities for `bdlat`-types.
492///
493/// @ref bdlat_fuzzutiloptions :
494/// Provide options for `bdlat::FuzzUtil`.
495///
496/// @ref bdlat_nullablevaluefunctions :
497/// Provide a namespace defining nullable value functions.
498///
499/// @ref bdlat_nullablevalueutil :
500/// Provide utilities for operating on `bdlat` "nullable value" types.
501///
502/// @ref bdlat_selectioninfo :
503/// Provide a container for selection information.
504///
505/// @ref bdlat_sequencefunctions :
506/// Provide a namespace defining sequence functions.
507///
508/// @ref bdlat_symbolicconverter :
509/// Provide a utility for convert types with matching member symbols.
510///
511/// @ref bdlat_typecategory :
512/// Provide type category tags and a tag selection meta-function.
513///
514/// @ref bdlat_typename :
515/// Provide string representations for data type names.
516///
517/// @ref bdlat_typetraits :
518/// Provide compile-time traits for generated types.
519///
520/// @ref bdlat_valuetypefunctions :
521/// Provide a namespace for "value type" functions.
522///
523/// @}
524/** @} */