diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-05-09 23:03:00 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-05-09 23:03:00 -0300 |
| commit | c375b1c69665ae7c16ffa3f17264386dfc257d8e (patch) | |
| tree | c0a45b370512ae6d4b4a9500c244419567a357ef /src/CursorManager.cpp | |
| parent | 921de259fa441fb562aec701f0c8c14310f126e4 (diff) | |
| download | RNT-c375b1c69665ae7c16ffa3f17264386dfc257d8e.tar.gz RNT-c375b1c69665ae7c16ffa3f17264386dfc257d8e.zip | |
FOL VM with cursor mocked storage
Diffstat (limited to 'src/CursorManager.cpp')
| -rw-r--r-- | src/CursorManager.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/CursorManager.cpp b/src/CursorManager.cpp index 8ae4496..f80ac54 100644 --- a/src/CursorManager.cpp +++ b/src/CursorManager.cpp @@ -1,5 +1,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)); + } } |
