first thoughts about cache

This commit is contained in:
Blue 2022-09-20 20:16:48 +03:00
parent 2f34fa69e8
commit a613eaed27
Signed by: blue
GPG key ID: 9B203B252A63EE38
6 changed files with 205 additions and 7 deletions

View file

@ -33,6 +33,8 @@ class DataBase
public:
template <class K, class V>
class Table;
template <class K, class V>
class Cache;
DataBase(const QString& name, uint16_t mapSize = 10);
~DataBase();
@ -47,9 +49,15 @@ public:
template <class K, class V>
Table<K, V>* addTable(const std::string& name);
template <class K, class V>
Cache<K, V>* addCache(const std::string& name);
template <class K, class V>
Table<K, V>* getTable(const std::string& name);
template <class K, class V>
Cache<K, V>* getCache(const std::string& name);
public:
//exceptions
class Exception;
@ -80,9 +88,25 @@ DataBase::Table<K, V>* DataBase::addTable(const std::string& p_name) {
return table;
}
template<class K, class V>
DataBase::Cache<K, V> * DataBase::addCache(const std::string& p_name) {
if (opened) {
throw Opened(name, "add cache " + p_name);
}
DataBase::Cache<K, V>* cache = new DataBase::Cache<K, V>(p_name, this);
tables.insert(std::make_pair(p_name, (_Table*)cache));
return cache;
}
template <class K, class V>
DataBase::Table<K, V>* DataBase::getTable(const std::string& p_name) {
return static_cast<DataBase::Table<K, V>*>(tables.at(p_name));
}
template <class K, class V>
DataBase::Cache<K, V>* DataBase::getCache(const std::string& p_name) {
return static_cast<DataBase::Cache<K, V>*>(tables.at(p_name));
}
#endif // CORE_DATABASE_H