9#ifndef __HRCORE_VIRTUALMMU_HPP__
10#define __HRCORE_VIRTUALMMU_HPP__
16#if HRCORE_ENABLE_STORAGE_VMMU
26 struct data_t :
public item_t {
31 ival_t data[N] = { 0 };
42 this->_pool[0] =
new node_t;
48 delete this->_pool[--this->_len];
55 if (n >= this->_count)
59 auto x = this->_pool[p];
62 ret.data = x->data + f;
68 virtual item_t end()
override {
return this->
at(this->_count - 1); }
69 virtual size_t length()
override {
return this->_count; }
73 data_t* helper = (data_t*)&cur;
75 if (!cur || helper->
index >= this->_count - 1 || helper->index + 1 < helper->index)
78 size_t p = helper->index / N;
79 size_t f = helper->index % N;
80 auto x = this->_pool[p];
83 ret.index = helper->index;
84 ret.data = x->data + f;
90 data_t* helper = (data_t*)&cur;
92 if (!cur || helper->
index >= this->_count + 1 || helper->index - 1 > helper->index)
95 size_t p = helper->index / N;
96 size_t f = helper->index % N;
97 auto x = this->_pool[p];
100 ret.index = helper->index;
101 ret.data = x->data + f;
109 size_t rlen = c / N + (c % N ? 1 : 0);
110 while (this->_len > rlen) {
111 delete this->_pool[--(this->_len)];
112 this->_pool[this->_len] =
nullptr;
122 size_t rlen = c / N + (c % N ? 1 : 0);
123 while (this->_len < rlen)
124 this->_pool[this->_len++] =
new node_t;
A class as a storage interface, pure virtual.
An implement of Storage::Interface as Virtual MMU.
virtual item_t begin() override
Return the first item of storage.
virtual item_t at(size_t n)
Access to storage[pos].
virtual void delObject(const Interface *ptr) override
Delete a object from newObject()
virtual item_t end() override
Returns the last item of storage.
virtual size_t length() override
Get the length of storage.
virtual bool extend(size_t c) override
Extend the storage to a given length.
virtual item_t prev(item_t cur) override
virtual item_t next(item_t cur) override
Get next item.
virtual Interface * newObject() override
Get a new object of same type.
virtual bool shrink(size_t c) override
Remove data from the end to shrink the size to a given length.
#define HRCORE_STORAGE_VMMU_MAX_LEN
Define the max length of table of VMMU. Default: 1024.
HRCore main namespace, contains all classes.
size_t index
Store the index of data.