2015-01-07 01:26:14 +08:00
|
|
|
/*
|
|
|
|
* DatabaseDriverFactory.cpp
|
|
|
|
*
|
|
|
|
* Created on: 2012-8-14
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2019-08-16 01:17:24 +08:00
|
|
|
#include "base_info/sqlite/SQLiteBaseInfoDriver.h"
|
2016-04-03 00:08:31 +08:00
|
|
|
#include "block_info/qianlong/QLBlockInfoDriver.h"
|
2017-10-20 02:11:57 +08:00
|
|
|
#include "kdata/hdf5/H5KDataDriver.h"
|
2015-01-07 01:26:14 +08:00
|
|
|
#include "DataDriverFactory.h"
|
|
|
|
#include "KDataDriver.h"
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
map<string, BaseInfoDriverPtr> default_baseinfo_driver() {
|
|
|
|
map<string, BaseInfoDriverPtr> result;
|
2019-08-16 01:17:24 +08:00
|
|
|
result["SQLITE3"] = make_shared<SQLiteBaseInfoDriver>();
|
2017-10-09 02:25:02 +08:00
|
|
|
return result;
|
|
|
|
}
|
2015-01-07 01:26:14 +08:00
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
map<string, BlockInfoDriverPtr> default_block_driver() {
|
|
|
|
map<string, BlockInfoDriverPtr> result;
|
|
|
|
result["QIANLONG"] = make_shared<QLBlockInfoDriver>();
|
2015-01-07 01:26:14 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-20 02:11:57 +08:00
|
|
|
map<string, KDataDriverPtr> default_kdata_driver() {
|
|
|
|
map<string, KDataDriverPtr> result;
|
|
|
|
result["HDF5"] = make_shared<H5KDataDriver>();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
map<string, BaseInfoDriverPtr> DataDriverFactory::m_baseInfoDrivers(default_baseinfo_driver());
|
|
|
|
map<string, BlockInfoDriverPtr> DataDriverFactory::m_blockDrivers(default_block_driver());
|
2017-10-20 02:11:57 +08:00
|
|
|
map<string, KDataDriverPtr> DataDriverFactory::m_kdataDrivers(default_kdata_driver());
|
2017-10-12 01:58:08 +08:00
|
|
|
map<Parameter, KDataDriverPtr> DataDriverFactory::m_param_kdataDrivers;
|
2015-01-07 01:26:14 +08:00
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
|
|
|
|
void DataDriverFactory
|
|
|
|
::regBaseInfoDriver(const BaseInfoDriverPtr& driver) {
|
|
|
|
string new_type(driver->name());
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(new_type);
|
2017-10-09 02:25:02 +08:00
|
|
|
m_baseInfoDrivers[new_type] = driver;
|
2016-04-03 00:08:31 +08:00
|
|
|
}
|
2015-01-07 01:26:14 +08:00
|
|
|
|
2017-10-09 02:25:02 +08:00
|
|
|
void DataDriverFactory::removeBaseInfoDriver(const string& name) {
|
|
|
|
string new_type(name);
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(new_type);
|
2017-10-09 02:25:02 +08:00
|
|
|
m_baseInfoDrivers.erase(new_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseInfoDriverPtr DataDriverFactory
|
|
|
|
::getBaseInfoDriver(const Parameter& params) {
|
|
|
|
map<string, BaseInfoDriverPtr>::const_iterator iter;
|
|
|
|
string type = params.get<string>("type");
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(type);
|
2017-10-09 02:25:02 +08:00
|
|
|
iter = m_baseInfoDrivers.find(type);
|
|
|
|
BaseInfoDriverPtr result;
|
|
|
|
if (iter != m_baseInfoDrivers.end()) {
|
|
|
|
result = iter->second;
|
2017-10-20 02:11:57 +08:00
|
|
|
result->init(params);
|
2017-10-09 02:25:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataDriverFactory::regBlockDriver(const BlockInfoDriverPtr& driver) {
|
|
|
|
string name(driver->name());
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(name);
|
2017-10-09 02:25:02 +08:00
|
|
|
m_blockDrivers[name] = driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataDriverFactory::removeBlockDriver(const string& name) {
|
|
|
|
string new_name(name);
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(new_name);
|
2017-10-09 02:25:02 +08:00
|
|
|
m_blockDrivers.erase(new_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockInfoDriverPtr DataDriverFactory::getBlockDriver(const Parameter& params) {
|
|
|
|
BlockInfoDriverPtr result;
|
|
|
|
map<string, BlockInfoDriverPtr>::const_iterator iter;
|
|
|
|
string name = params.get<string>("type");
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(name);
|
2017-10-09 02:25:02 +08:00
|
|
|
iter = m_blockDrivers.find(name);
|
|
|
|
if (iter != m_blockDrivers.end()) {
|
|
|
|
result = iter->second;
|
2017-10-20 02:11:57 +08:00
|
|
|
result->init(params);
|
2017-10-09 02:25:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-12 01:58:08 +08:00
|
|
|
void DataDriverFactory::regKDataDriver(const KDataDriverPtr& driver) {
|
|
|
|
string new_type(driver->name());
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(new_type);
|
2017-10-12 01:58:08 +08:00
|
|
|
m_kdataDrivers[new_type] = driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataDriverFactory::removeKDataDriver(const string& name) {
|
|
|
|
string new_name(name);
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(new_name);
|
2017-10-12 01:58:08 +08:00
|
|
|
m_kdataDrivers.erase(new_name);
|
|
|
|
auto iter = m_param_kdataDrivers.begin();
|
|
|
|
for (; iter != m_param_kdataDrivers.end(); ++iter) {
|
|
|
|
string new_type(iter->first.get<string>("type"));
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(new_type);
|
2017-10-12 01:58:08 +08:00
|
|
|
if (new_type == new_name) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iter != m_param_kdataDrivers.end()) {
|
|
|
|
m_param_kdataDrivers.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KDataDriverPtr DataDriverFactory::getKDataDriver(const Parameter& params) {
|
|
|
|
KDataDriverPtr result;
|
|
|
|
auto param_iter = m_param_kdataDrivers.find(params);
|
|
|
|
if (param_iter != m_param_kdataDrivers.end()) {
|
|
|
|
result = param_iter->second;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string name;
|
|
|
|
try {
|
|
|
|
name = params.get<string>("type");
|
|
|
|
} catch (...) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-08-03 01:44:57 +08:00
|
|
|
to_upper(name);
|
2017-10-12 01:58:08 +08:00
|
|
|
auto iter = m_kdataDrivers.find(name);
|
|
|
|
if (iter != m_kdataDrivers.end()) {
|
|
|
|
result = iter->second;
|
|
|
|
result->init(params);
|
|
|
|
m_param_kdataDrivers[params] = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
} /* namespace hku */
|