db_conn  v0.2.1-alpha
Database Connection API
driver.hpp
1 /*
2  * File: driver.hpp
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef DRIVER_HPP
20 #define DRIVER_HPP
21 
22 #include <memory>
23 #include <functional>
24 #include <map>
25 #include "connection.hpp"
26 
27 namespace vgi { namespace dbconn { namespace dbd {
28 
33 struct idriver
34 {
35  virtual ~idriver() { }
36  virtual dbi::connection create_connection(dbi::iconnection* iconn) = 0;
37 };
38 
43 template <typename T>
44 class driver : public T
45 {
46 public:
47  // c++1y guarantees no threading issues
48  static T& load()
49  {
50  static driver<T> d;
51  return d;
52  }
53 
54 protected:
55  virtual dbi::connection create_connection(dbi::iconnection* iconn)
56  {
57  return dbi::connection(iconn);
58  }
59 
60 private:
61  driver() {}
62  driver(const driver&);
63  driver(driver&&);
64  driver& operator=(const driver&);
65  driver& operator=(driver&&);
66  driver** operator&();
67 }; // driver
68 
69 
70 }}} // namespace vgi::dbconn::dbd
71 
72 #endif // DRIVER_HPP
73 
driver is a singleton template class which creates a concrete driver on load() and returns its instan...
Definition: connection.hpp:28
iconnection - is an interface that describes common functionality for all concrete native implementat...
Definition: connection.hpp:38
idriver - is an interface for driver classes which declares function for creating a connection object...
Definition: driver.hpp:33
connection - is a class that manages native driver connection handle.
Definition: connection.hpp:62