Add missing files
Former-commit-id: 4eadf8f0923ee70ffa3af329a4d636d508bfad8d
This commit is contained in:
parent
94ea48978d
commit
0ab5ea7b9b
81
src/storage/teststorageprovider.cpp
Normal file
81
src/storage/teststorageprovider.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "teststorageprovider.h"
|
||||
#include <assert.h>
|
||||
|
||||
IStorage *TestStorageFactory::create(int)
|
||||
{
|
||||
return new TestStorageProvider();
|
||||
}
|
||||
|
||||
const char *TestStorageFactory::name() const
|
||||
{
|
||||
return "TEST Storage Provider";
|
||||
}
|
||||
|
||||
TestStorageProvider::TestStorageProvider()
|
||||
{
|
||||
}
|
||||
|
||||
TestStorageProvider::~TestStorageProvider()
|
||||
{
|
||||
}
|
||||
|
||||
void TestStorageProvider::insert(const char *key, size_t cchKey, void *data, size_t cb)
|
||||
{
|
||||
m_map.insert(std::make_pair(std::string(key, cchKey), std::string((char*)data, cb)));
|
||||
}
|
||||
|
||||
|
||||
bool TestStorageProvider::erase(const char *key, size_t cchKey)
|
||||
{
|
||||
auto itr = m_map.find(std::string(key, cchKey));
|
||||
if (itr != m_map.end())
|
||||
{
|
||||
m_map.erase(itr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TestStorageProvider::retrieve(const char *key, size_t cchKey, callbackSingle fn) const
|
||||
{
|
||||
auto itr = m_map.find(std::string(key, cchKey));
|
||||
if (itr != m_map.end())
|
||||
fn(key, cchKey, itr->second.data(), itr->second.size());
|
||||
}
|
||||
|
||||
size_t TestStorageProvider::clear()
|
||||
{
|
||||
size_t size = m_map.size();
|
||||
m_map.clear();
|
||||
return size;
|
||||
}
|
||||
|
||||
bool TestStorageProvider::enumerate(callback fn) const
|
||||
{
|
||||
bool fAll = true;
|
||||
for (auto &pair : m_map)
|
||||
{
|
||||
if (!fn(pair.first.data(), pair.first.size(), pair.second.data(), pair.second.size()))
|
||||
{
|
||||
fAll = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return fAll;
|
||||
}
|
||||
|
||||
size_t TestStorageProvider::count() const
|
||||
{
|
||||
return m_map.size();
|
||||
}
|
||||
|
||||
void TestStorageProvider::flush()
|
||||
{
|
||||
/* NOP */
|
||||
}
|
||||
|
||||
/* This is permitted to be a shallow clone */
|
||||
const IStorage *TestStorageProvider::clone() const
|
||||
{
|
||||
return new TestStorageProvider(*this);
|
||||
}
|
30
src/storage/teststorageprovider.h
Normal file
30
src/storage/teststorageprovider.h
Normal file
@ -0,0 +1,30 @@
|
||||
#include "../IStorage.h"
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class TestStorageFactory : public IStorageFactory
|
||||
{
|
||||
virtual class IStorage *create(int db) override;
|
||||
virtual const char *name() const override;
|
||||
};
|
||||
|
||||
class TestStorageProvider final : public IStorage
|
||||
{
|
||||
std::unordered_map<std::string, std::string> m_map;
|
||||
|
||||
public:
|
||||
TestStorageProvider();
|
||||
virtual ~TestStorageProvider();
|
||||
|
||||
virtual void insert(const char *key, size_t cchKey, void *data, size_t cb) override;
|
||||
virtual bool erase(const char *key, size_t cchKey) override;
|
||||
virtual void retrieve(const char *key, size_t cchKey, callbackSingle fn) const override;
|
||||
virtual size_t clear() override;
|
||||
virtual bool enumerate(callback fn) const override;
|
||||
virtual size_t count() const override;
|
||||
|
||||
virtual void flush() override;
|
||||
|
||||
/* This is permitted to be a shallow clone */
|
||||
virtual const IStorage *clone() const override;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user