/* * DatabaseDriverFactory.cpp * * Created on: 2012-8-14 * Author: fasiondog */ #include "../GlobalInitializer.h" #include #include "base_info/sqlite/SQLiteBaseInfoDriver.h" #include "base_info/mysql/MySQLBaseInfoDriver.h" #include "block_info/qianlong/QLBlockInfoDriver.h" #include "kdata/hdf5/H5KDataDriver.h" #include "kdata/mysql/MySQLKDataDriver.h" #include "kdata/tdx/TdxKDataDriver.h" #include "DataDriverFactory.h" #include "KDataDriver.h" namespace hku { map* DataDriverFactory::m_baseInfoDrivers{nullptr}; map* DataDriverFactory::m_blockDrivers{nullptr}; map* DataDriverFactory::m_kdataDrivers{nullptr}; void DataDriverFactory::init() { m_baseInfoDrivers = new map(); DataDriverFactory::regBaseInfoDriver(make_shared()); DataDriverFactory::regBaseInfoDriver(make_shared()); m_blockDrivers = new map(); DataDriverFactory::regBlockDriver(make_shared()); m_kdataDrivers = new map(); DataDriverFactory::regKDataDriver(make_shared()); DataDriverFactory::regKDataDriver(make_shared()); DataDriverFactory::regKDataDriver(make_shared()); } void DataDriverFactory::release() { m_baseInfoDrivers->clear(); delete m_baseInfoDrivers; m_blockDrivers->clear(); delete m_blockDrivers; m_kdataDrivers->clear(); delete m_kdataDrivers; } void DataDriverFactory::regBaseInfoDriver(const BaseInfoDriverPtr& driver) { HKU_CHECK(driver, "driver is nullptr!"); string new_type(driver->name()); to_upper(new_type); (*m_baseInfoDrivers)[new_type] = driver; } void DataDriverFactory::removeBaseInfoDriver(const string& name) { string new_type(name); to_upper(new_type); m_baseInfoDrivers->erase(new_type); } BaseInfoDriverPtr DataDriverFactory ::getBaseInfoDriver(const Parameter& params) { map::const_iterator iter; string type = params.get("type"); to_upper(type); iter = m_baseInfoDrivers->find(type); BaseInfoDriverPtr result; if (iter != m_baseInfoDrivers->end()) { result = iter->second; result->init(params); } return result; } void DataDriverFactory::regBlockDriver(const BlockInfoDriverPtr& driver) { HKU_CHECK(driver, "driver is nullptr!"); string name(driver->name()); to_upper(name); (*m_blockDrivers)[name] = driver; } void DataDriverFactory::removeBlockDriver(const string& name) { string new_name(name); to_upper(new_name); m_blockDrivers->erase(new_name); } BlockInfoDriverPtr DataDriverFactory::getBlockDriver(const Parameter& params) { BlockInfoDriverPtr result; map::const_iterator iter; string name = params.get("type"); to_upper(name); iter = m_blockDrivers->find(name); if (iter != m_blockDrivers->end()) { result = iter->second; result->init(params); } return result; } void DataDriverFactory::regKDataDriver(const KDataDriverPtr& driver) { string new_type(driver->name()); to_upper(new_type); (*m_kdataDrivers)[new_type] = driver; } void DataDriverFactory::removeKDataDriver(const string& name) { string new_name(name); to_upper(new_name); m_kdataDrivers->erase(new_name); } KDataDriverPtr DataDriverFactory::getKDataDriver(const Parameter& params) { KDataDriverPtr result; string name = params.get("type"); to_upper(name); auto iter = m_kdataDrivers->find(name); if (iter != m_kdataDrivers->end()) { result = iter->second; result->init(params); } return result; } } /* namespace hku */