started to work on duplicates support

This commit is contained in:
Blue 2023-08-15 15:48:19 -03:00
parent 7b26d57ab6
commit f0727aa73d
Signed by: blue
GPG key ID: 9B203B252A63EE38
9 changed files with 132 additions and 108 deletions

View file

@ -69,16 +69,16 @@ public:
void abortTransaction(TransactionID id) const;
template <class K, class V>
LMDBAL::Storage<K, V>* addStorage(const std::string& name);
LMDBAL::Storage<K, V>* addStorage(const std::string& storageName, bool duplicates = false);
template <class K, class V>
LMDBAL::Cache<K, V>* addCache(const std::string& name);
LMDBAL::Cache<K, V>* addCache(const std::string& storageName);
template <class K, class V>
LMDBAL::Storage<K, V>* getStorage(const std::string& name);
LMDBAL::Storage<K, V>* getStorage(const std::string& storageName);
template <class K, class V>
LMDBAL::Cache<K, V>* getCache(const std::string& name);
LMDBAL::Cache<K, V>* getCache(const std::string& storageName);
private:
typedef std::map<std::string, LMDBAL::iStorage*> Storages; /**<Storage and Cache pointers are saved in the std::map*/
@ -114,7 +114,8 @@ private:
* Defines that the database is going to have the following storage.
* The LMDBAL::Base must be closed
*
* \param[in] _name - storage name
* \param[in] storageName - storage name
*
* \returns storage pointer. LMDBAL::Base keeps the ownership of the added storage, you don't need to destoroy it
*
* \tparam K - key type of the storage
@ -124,14 +125,14 @@ private:
* \exception LMDBAL::StorageDuplicate thrown if somebody tries to add storage with repeating name
*/
template <class K, class V>
LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& _name) {
LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& storageName, bool duplicates) {
if (opened) {
throw Opened(name, "add storage " + _name);
throw Opened(name, "add storage " + storageName);
}
Storage<K, V>* storage = new Storage<K, V>(_name, this);
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(_name, (iStorage*)storage));
Storage<K, V>* storage = new Storage<K, V>(this, storageName, duplicates);
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(storageName, (iStorage*)storage));
if (!pair.second)
throw StorageDuplicate(name, _name);
throw StorageDuplicate(name, storageName);
return storage;
}
@ -142,7 +143,7 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& _name) {
* Defines that the database is going to have the following cache.
* The LMDBAL::Base must be closed
*
* \param[in] _name - cache name
* \param[in] storageName - cache name
* \returns cache pointer. LMDBAL::Base keeps the ownership of the added cache, you don't need to destoroy it
*
* \tparam K - key type of the cache
@ -152,14 +153,14 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::addStorage(const std::string& _name) {
* \exception LMDBAL::StorageDuplicate thrown if somebody tries to add cache with repeating name
*/
template<class K, class V>
LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& _name) {
LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& storageName) {
if (opened) {
throw Opened(name, "add cache " + _name);
throw Opened(name, "add cache " + storageName);
}
Cache<K, V>* cache = new Cache<K, V>(_name, this);
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(_name, (iStorage*)cache));
Cache<K, V>* cache = new Cache<K, V>(this, storageName, false);
std::pair<Storages::const_iterator, bool> pair = storages.insert(std::make_pair(storageName, (iStorage*)cache));
if (!pair.second)
throw StorageDuplicate(name, _name);
throw StorageDuplicate(name, storageName);
return cache;
}
@ -173,7 +174,7 @@ LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& _name) {
* this method with template parameters <std::string, std::string>
* on the same name of the previously added storage, or calling it on cache - the behaviour is undefined
*
* \param[in] _name - storage name
* \param[in] storageName - storage name
* \returns storage pointer. LMDBAL::Base keeps the ownership of the added storage, you don't need to destoroy it
*
* \tparam K - key type of the storage
@ -182,8 +183,8 @@ LMDBAL::Cache<K, V> * LMDBAL::Base::addCache(const std::string& _name) {
* \exception std::out_of_range thrown if storage with the given name was not found
*/
template <class K, class V>
LMDBAL::Storage<K, V>* LMDBAL::Base::getStorage(const std::string& _name) {
return static_cast<Storage<K, V>*>(storages.at(_name));
LMDBAL::Storage<K, V>* LMDBAL::Base::getStorage(const std::string& storageName) {
return static_cast<Storage<K, V>*>(storages.at(storageName));
}
/**
@ -195,7 +196,7 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::getStorage(const std::string& _name) {
* this method with template parameters <std::string, std::string>
* on the same name of the previously added cache, or calling it on storage - the behaviour is undefined
*
* \param[in] _name - cache name
* \param[in] storageName - cache name
* \returns cache pointer. LMDBAL::Base keeps the ownership of the added cache, you don't need to destoroy it
*
* \tparam K - key type of the cache
@ -204,8 +205,8 @@ LMDBAL::Storage<K, V>* LMDBAL::Base::getStorage(const std::string& _name) {
* \exception std::out_of_range thrown if cache with the given name was not found
*/
template <class K, class V>
LMDBAL::Cache<K, V>* LMDBAL::Base::getCache(const std::string& _name) {
return static_cast<Cache<K, V>*>(storages.at(_name));
LMDBAL::Cache<K, V>* LMDBAL::Base::getCache(const std::string& storageName) {
return static_cast<Cache<K, V>*>(storages.at(storageName));
}
#endif //LMDBAL_BASE_H