1.码表管理支持
common下新增文件:
.base_code_table.h:定义码表元素和码表资源名称
.code_table_mgr.h:码表管理器模板定义
template <class T,class Key> class CCodeTableMgr : public ICodeTableMgr<T,Key> {
CAutoVector<T*> data_;
.i_code_table_mgr.h:码表管理器接口定义;
template <class T,class Key=int> class ICodeTableMgr {
public:
///< 增加一个对象
virtual int Add(T* obj) = 0;
///< 获取对象总数
virtual unsigned int GetSize() const = 0;
///< 获取指定索引的对象
virtual T* operator[](unsigned int index) = 0;
///< 根据Key查找对象
virtual T* Find(Key key) = 0;
///< 删除指定Key的对象
virtual void Remove(Key key) = 0;
};
2.实现
const char CODE_TABLE_DB[] = "CodeTable.db"; ///< 码表数据库名称
class CGDSNSup_Plugin {
int Prepare();
private:
///< 码表管理器
CCodeTableMgr<CTaxRate> tax_rate_code_table_mgr_;
CCodeTableMgr<CSaleUnit> sale_unit_code_table_mgr_;
CCodeTableMgr<CCountry> country_code_table_mgr_;
CCodeTableMgr<CGpc> gpc_code_table_mgr_;
///< 初始化码表数据(仅用于测试数据准备)
int init_code_table(); ///< 每个表的建表操作,表初始数据写入
///< 加载码表
int LoadTaxRate();
int LoadSaleUnit();
int LoadCountry();
int LoadGPC();
};
///< 共享码表资源
int CGDSNSup_Plugin::Prepare() {
parent::Prepare();
CPluginHelper::ShareResource(&tax_rate_code_table_mgr_,TAXRATE_CODETABLE_MGR,this);
CPluginHelper::ShareResource(&sale_unit_code_table_mgr_,SALEUNIT_CODETABLE_MGR,this);
CPluginHelper::ShareResource(&country_code_table_mgr_,COUNTRY_CODETABLE_MGR,this);
CPluginHelper::ShareResource(&gpc_code_table_mgr_,GPC_CODETABLE,this);
return 0;
}
3.使用
如需要在TForm或者其它插件中访问税率码表,获取接口然后使用接口方法.
ICodeTableMgr<CTaxRate> *mgr = (ICodeTableMgr*)CPluginHelper::GetResource(TAXRATE_CODETABLE_MGR);