CppDB
|
00001 00002 // 00003 // Copyright (C) 2010-2011 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com> 00004 // 00005 // Distributed under: 00006 // 00007 // the Boost Software License, Version 1.0. 00008 // (See accompanying file LICENSE_1_0.txt or copy at 00009 // http://www.boost.org/LICENSE_1_0.txt) 00010 // 00011 // or (at your opinion) under: 00012 // 00013 // The MIT License 00014 // (See accompanying file MIT.txt or a copy at 00015 // http://www.opensource.org/licenses/mit-license.php) 00016 // 00018 #ifndef CPPDB_DRIVER_MANAGER_H 00019 #define CPPDB_DRIVER_MANAGER_H 00020 00021 #include <cppdb/defs.h> 00022 #include <cppdb/ref_ptr.h> 00023 #include <cppdb/mutex.h> 00024 #include <map> 00025 #include <string> 00026 #include <vector> 00027 00028 namespace cppdb { 00029 namespace backend { 00030 class connection; 00031 class driver; 00032 } 00033 class connection_info; 00034 00040 class CPPDB_API driver_manager { 00041 public: 00045 static driver_manager &instance(); 00049 void install_driver(std::string const &name,ref_ptr<backend::driver> drv); 00053 void collect_unused(); 00054 00058 void add_search_path(std::string const &); 00062 void clear_search_paths(); 00066 void use_default_search_path(bool v); 00070 backend::connection *connect(connection_info const &ci); 00074 backend::connection *connect(std::string const &connectoin_string); 00075 00076 private: 00077 driver_manager(driver_manager const &); 00078 void operator=(driver_manager const &); 00079 // Borland erros on hidden destructors in classes without only static methods. 00080 #ifndef __BORLANDC__ 00081 ~driver_manager(); 00082 #endif 00083 driver_manager(); 00084 00085 ref_ptr<backend::driver> load_driver(connection_info const &ci); 00086 00087 typedef std::map<std::string,ref_ptr<backend::driver> > drivers_type; 00088 std::vector<std::string> search_paths_; 00089 bool no_default_directory_; 00090 drivers_type drivers_; 00091 mutex lock_; 00092 }; 00093 } 00094 00095 #endif