Library Version 12.1.6.2

Chapter 26. DbstlElemTraits
Prev |  | Next

## Chapter 26. DbstlElemTraits

This class is used to register callbacks to manipulate an object of a complex type.

These callbacks are used by dbstl at runtime to manipulate the object.

A complex type is a type whose members are not located in a contiguous chunk of memory. For example, the following class A is a complex type because for any instance a of class A, a.b_ points to another object of type B, and dbstl treats the object that a.b_ points to as part of the data of the instance a. Hence, if the user needs to store a.b_ into a dbstl container, the user needs to register an appropriate callback to de-reference and store the object referenced by a.b. Similarly, the user also needs to register callbacks to marshall an array as well as to count the number of elements in such an array.

class A { int m; B *p_; }; class B { int n; };

The user also needs to register callbacks for i). returning an object¡¯s size in bytes; ii). Marshalling and unmarshalling an object; iii). Copying a complex object and and assigning an object to another object of the same type; iv). Element comparison. v). Compare two sequences of any type of objects; Measuring the length of an object sequence and copy an object sequence.

Several elements located in a contiguous chunk of memory form a sequence. An element of a sequence may be a simple object located at a contigous memory chunk, or a complex object, i.e. some of its members may contain references (pointers) to another region of memory. It is not necessary to store a special object to denote the end of the sequence. The callback to traverse the constituent elements of the sequence needs to able to determine the end of the sequence.

Marshalling means packing the object's data members into a contiguous chunk of memory; unmarshalling is the opposite of marshalling. In other words, when you unmarshall an object, its data members are populated with values from a previously marshalled version of the object.

The callbacks need not be set to every type explicitly. . dbstl will check if a needed callback function of this type is provided. If one is available, dbstl will use the registered callback. If the appropriate callback is not provided, dbstl will use reasonable defaults to do the job.

For returning the size of an object, the default behavior is to use the sizeof() operator; For marshalling and unmarshalling, dbstl uses memcpy, so the default behavior is sufficient for simple types whose data reside in a contiguous chunk of memory; Dbstl uses uses >, == and < for comparison operations; For char* and wchar_t * strings, dbstl already provides the appropriate callbacks, so you do not need to register them. In general, if the default behavior is adequate, you don't need to register the corresponding callback.

If you have registered proper callbacks, the DbstlElemTraits<T> can also be used as the char_traits<T> class for std::basic_string<T, char_traits<T> >, and you can enable your class T to form a basic_string<T, DbstlElemTraits<T>>, and use basic_string's functionality and the algorithms to manipulate it.

#### Public Members

Member | Description
--- | ---
assign | Assignone object to another.
eq | Check for equality of two objects.
lt | Less than comparison.
compare | Sequence comparison.
length | Returns the number of elements in sequence seq1.
copy | Copy first cnt number of elements from seq2 to seq1.
find | Find within the first cnt elements of sequence seq the position of element equal to elem.
move | Sequence movement.
to_char_type |
to_int_type |
eq_int_type |
eof |
not_eof |
set_restore_function |
get_restore_function |
set_assign_function |
get_assign_function |
get_size_function |
set_size_function |
get_copy_function |
set_copy_function |
set_sequence_len_function |
get_sequence_len_function |
get_sequence_copy_function |
set_sequence_copy_function |
set_compare_function |
get_compare_function |
set_sequence_compare_function |
get_sequence_compare_function |
set_sequence_n_compare_function |
get_sequence_n_compare_function |
instance | Factory method to create a singeleton instance of this class.
~DbstlElemTraits |
DbstlElemTraits |

#### Group

Dbstl Helper Classes

## assign

### Function Details

    static void assign(T &left,
        const T &right)

Assignone object to another.

    static T* assign(T *seq, size_t cnt,
        T elem)

Assign first cnt number of elements of sequence seq with the value of elem.

### Group: Interface compatible with std::string's char_traits.

Following are char_traits funcitons, which make this class char_traits compatiable, so that it can be used in std::basic_string template, and be manipulated by the c++ stl algorithms.

### Class

DbstlElemTraits

Prev |  | Next
operator= | Home | eq