Use C ++ Traits to expand OTL

Source: Internet
Author: User
Tags traits

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.