blob: f80ac5471f4989b2ba5bf56560335b4ae14d4bea (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#include "CursorManager.h"
#include <numeric>
namespace nt
{
static std::string JoinPath(const std::vector<std::string>& path)
{
return std::accumulate(
std::next(path.begin()), path.end(), path.front(),
[](std::string a, const std::string& b) { return std::move(a) + "/" + b; });
}
CursorManager::cursor* CursorManager::Open(HandlerManager::handle* handle)
{
if (handle == nullptr || handle->object == nullptr)
return nullptr;
if (handle->object->head->type->label != RELATION)
return nullptr;
const std::string key = JoinPath(handle->object->head->path);
auto it = mock_store_.find(key);
if (it == mock_store_.end())
return nullptr;
auto* c = new cursor();
c->handle = handle;
for (const auto& row : it->second)
c->tuples.emplace_back(row);
return c;
}
Tuple* CursorManager::Next(cursor* cursor)
{
if (cursor == nullptr || cursor->position >= cursor->tuples.size())
return nullptr;
return &cursor->tuples[cursor->position++];
}
void CursorManager::Close(cursor* cursor)
{
delete cursor;
}
void CursorManager::MockInsert(std::vector<std::string> path, std::vector<Attribute> tuple)
{
mock_store_[JoinPath(path)].push_back(std::move(tuple));
}
}
|