2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _RSTL_LIST
|
|
|
|
#define _RSTL_LIST
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-08-09 23:03:51 +00:00
|
|
|
#include "rstl/rmemory_allocator.hpp"
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
namespace rstl {
|
|
|
|
template < typename T, typename Alloc = rmemory_allocator >
|
|
|
|
class list {
|
|
|
|
public:
|
2022-10-01 06:19:09 +00:00
|
|
|
list() : x4_start(&xc_empty), x8_end(&xc_empty), xc_empty(&xc_empty, &xc_empty) {}
|
2022-04-10 00:17:06 +00:00
|
|
|
~list() {
|
|
|
|
node* cur = x4_start;
|
2022-10-01 06:19:09 +00:00
|
|
|
while (cur != x8_end) {
|
|
|
|
cur->get_value()->~T();
|
2022-10-04 00:00:46 +00:00
|
|
|
x0_allocator.deallocate(cur->get_value());
|
2022-10-01 06:19:09 +00:00
|
|
|
cur = cur->get_next();
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-10 09:46:24 +00:00
|
|
|
void push_back(const T&);
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct node {
|
|
|
|
node* x0_prev;
|
|
|
|
node* x4_next;
|
|
|
|
union {
|
|
|
|
T* x8_item;
|
2022-10-09 05:37:23 +00:00
|
|
|
uint x8_count;
|
2022-04-10 00:17:06 +00:00
|
|
|
};
|
2022-09-13 04:26:54 +00:00
|
|
|
|
|
|
|
node(node* prev, node* next) : x0_prev(prev), x4_next(next), x8_count(0) {}
|
2022-10-01 06:19:09 +00:00
|
|
|
|
|
|
|
node* get_prev() const { return x0_prev; }
|
|
|
|
node* get_next() const { return x4_next; }
|
|
|
|
T* get_value() { return x8_item; }
|
|
|
|
|
|
|
|
// todo set_next / set_prev
|
2022-04-10 00:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Alloc x0_allocator;
|
|
|
|
node* x4_start;
|
|
|
|
node* x8_end;
|
|
|
|
node xc_empty;
|
|
|
|
};
|
|
|
|
} // namespace rstl
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _RSTL_LIST
|