9.5. Selecting the type traits library

The library uses C++ templates heavily as a way to achieve the desired behaviour according to the type of the object that is being operated upon.

For example, integers, floating point values, strings and binary data (also known as blobs) are all treated as "native SQL types", meaning that each type corresponds to a specific SQL type in any column of a database table. For example, integers (char, short, int, long, long long and the unsigned variants) are all mapped to the SQL INTEGER type. Similarly, floating point values are mapped to the SQL REAL type, strings are mapped to the SQL TEXT type, std::tm objects are mapped to the SQL DATETIME type, and blobs are mapped to the SQL BINARY type.

When an integer is passed to the library, it uses type traits testing to route the saving and loading of integers to the "native_SQL_type" class.

Because the Standard C++ library in the current C++ standard does not have a type traits facility, the library requires the use of a type traits facility from a third party library. Specifying which type traits library to use is done by defining values for the USE_XYZ_LIBRARY macros in tmp.hpp. Clients can override the default selection by defining these macros before including the serialization.hpp or tmp.hpp files. For example, to select boost for the type traits library, do this:

#define USE_TR1_LIBRARY 0
#define USE_LOKI_LIBRARY 0
#define USE_BOOST_LIBRARY 1

#include "ccs/db_access.hpp"
#include DEFAULT_BACKEND_HPP
#include "ccs/serialization.hpp"

Alternatively, you can edit the config.hpp file or set up the compiler macro definitions in your makefile or IDE's settings panel.

If no macros are defined, then the tmp.hpp file will choose a library using the following order of precedence: std::tr1, Loki, boost. It will only select a library if the library is declared as available by its corresponding HAVE_XYZ_LIBRARY macro. So Loki can only be selected if the HAVE_LOKI_LIBRARY macro has a non-zero value. After choosing a library, the library's corresponding USE_XYZ_LIBRARY macro will be set to one. If no library can be selected, a compile-time error will occur.