memgraph/include/transactions/transaction_store.hpp

36 lines
584 B
C++
Raw Normal View History

#pragma once
2015-10-04 15:47:15 +08:00
#include <map>
#include <memory>
#include "transactions/transaction.hpp"
2015-10-04 15:47:15 +08:00
namespace tx
{
template <class id_t>
class TransactionStore
2015-10-04 15:47:15 +08:00
{
public:
Transaction* get(id_t id) const
{
auto it = store.find(id);
return it != store.end() ? it->second.get() : nullptr;
2015-10-04 15:47:15 +08:00
}
void put(id_t id, Transaction* transaction)
{
store.emplace(std::make_pair(id, std::unique_ptr<Transaction>(transaction)));
2015-10-04 15:47:15 +08:00
}
void del(id_t id)
{
store.erase(id);
2015-10-04 15:47:15 +08:00
}
private:
std::map<id_t, std::unique_ptr<Transaction>> store;
2015-10-04 15:47:15 +08:00
};
}