|
BDE 4.14.0 Production release
|
Provide a utility to build a Datum object holding an int-map.
Datum objects holding int-mapsThis component defines a mechanism, bdld::DatumIntMapBuilder, used to populate a Datum int-map value in an exception-safe manner. In addition to providing exception safety, a DatumIntMapBuilder is particularly useful when the size of the int-map to be constructed is not known in advance. The user can append elements to the datum int-map as needed, and when there are no more elements to append the user calls commit or sortAndCommit and ownership of the populated Datum object is transferred to the caller. After calling commit or sortAndCommit, no additional elements can be appended to the Datum int-map value. Note that sortAndCommit method will sort the populated int-map (by keys) and tag the resulting Datum int-map value as sorted. Also note that the user can insert elements in a (ascending) sorted order and tag the int-map as sorted. The behavior is undefined if unsorted int-map is tagged sorted.
This section illustrates intended use of this component.
Suppose we need a data map for some UX data. The keys of the map are 32-bit integers; and the values in that map can be different types. The following code illustrates how to use bdld::DatumIntMapBuilder to create such map easily.
First, we need data to fill our int-map:
Next, we create an object of DatumIntMapBuilder class with initial capacity sufficient for storing all our data:
Then, we load our builder with these data:
Next, we adopt the int-map, held by our builder, by newly created Datum object:
Now, we can check that all data have been correctly added to the int-map at the required order:
Finally, we destroy the Datum object to release all allocated memory correctly: