OTL has a set of databases for Oracle and ODBC, including their respective otl_connect and otl_stream. The two are differentiated by namespaces. However, suppose we have a class, which may use Oracle or ODBC, so we have to write n template parameters for it. We can use the C ++ traits method to solve this problem.
Template <typename C, typename S, typename R, typename I>
Struct cotltraits
...{
Typedef C otl_connect;
Typedef s otl_stream;
Typedef R otl_refcur_stream;
Typedef I otl_stream_read_iterator;
};
Typedef otl_stream_read_iterator <ORACLE: otl_stream,
ORACLE: otl_exception,
ORACLE: otl_lob_stream> oracle_stream_read_iterator;
Typedef otl_stream_read_iterator <ODBC: otl_stream,
ODBC: otl_exception,
ODBC: otl_lob_stream> odbc_stream_read_iterator;
Typedef COTLTraits <oracle: otl_connect,
Oracle: otl_stream,
Oracle: otl_refcur_stream,
Oracle_stream_read_iterator> COracleTraits;
Typedef COTLTraits <odbc: otl_connect,
Odbc: otl_stream,
Void,
Odbc_stream_read_iterator> codbctraits;
In actual application, we can directly use the coracletraits and codbctraits classes to access two sets of database access interfaces.