diff options
Diffstat (limited to 'src/storage.cc')
-rw-r--r-- | src/storage.cc | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/storage.cc b/src/storage.cc index 4ad916b..ee2e7e7 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -1,8 +1,10 @@ #include "storage.h" #include "definitions.h" #include <algorithm> +#include <stdexcept> -Storage::Storage(int delay) { +Storage::Storage(int delay) +{ this->data = new std::vector<std::array<signed int, LINE_SIZE>>; this->delay = delay; this->lower = nullptr; @@ -18,3 +20,32 @@ Storage::view(int base, int lines) const std::copy(this->data->begin() + base, this->data->begin() + base + lines, ret.begin()); return ret; } + +int +Storage::preprocess(void *id) +{ + if (id == nullptr) + throw std::invalid_argument("Accessor cannot be nullptr."); + + if (this->current_request == nullptr) + this->current_request = id; + + return this->current_request == id; +} + +int +Storage::is_data_ready() +{ + int r; + + r = 0; + if (this->wait_time == 0) { + this->current_request = nullptr; + this->wait_time = delay; + r = 1; + } else { + --this->wait_time; + } + + return r; +} |