3#include <sysio/vm/exceptions.hpp>
4#include <sysio/vm/allocator.hpp>
11namespace sysio {
namespace vm {
13 template <
typename T,
typename Allocator>
28 _data = _allocator->template alloc<T>(
size );
30 _allocator->template reclaim<T>( _data +
size, _size -
size );
34 template <
typename U,
typename = std::enable_if_t<std::is_same_v<T, std::decay_t<U>>,
int>>
37 if ( _index >= _size )
39 _data[_index++] = std::forward<U>(val);
43 if ( _index >= _size )
45 _data[_index++] = std::move(val);
48 constexpr inline void back() {
53 SYS_VM_ASSERT( _index >= 0, wasm_vector_oob_exception,
"vector pop out of bounds" );
57 constexpr inline T&
at(
size_t i ) {
58 SYS_VM_ASSERT( i < _size, wasm_vector_oob_exception,
"vector read out of bounds" );
62 constexpr inline T&
at(
size_t i )
const {
63 SYS_VM_ASSERT( i < _size, wasm_vector_oob_exception,
"vector read out of bounds" );
77 constexpr inline T*
raw()
const {
return _data; }
78 constexpr inline size_t size()
const {
return _size; }
79 constexpr inline void set(
T* data,
size_t size,
size_t index=-1 ) { _size =
size; _data = data; _index = index == -1 ?
size - 1 : index; }
80 constexpr inline void copy(
T* data,
size_t size ) {
82 std::copy_n(data,
size, _data);
93 struct unmanaged_base_member {
100 template <
typename T,
typename Allocator>
107 template <
typename T>
110 template <
typename T>
113 str.reserve(vec.size());
114 for (
int i=0; i < vec.size(); i++)
Concept for allocating, resizing and freeing memory block.
constexpr vector & operator=(vector &&mv)=default
constexpr vector(Allocator &allocator, size_t size=0)
constexpr T & at_no_check(size_t i)
constexpr void set(T *data, size_t size, size_t index=-1)
constexpr void pop_back()
constexpr vector(const vector &mv)=delete
constexpr T & operator[](size_t i) const
constexpr T & at(size_t i) const
constexpr vector(vector &&mv)=default
constexpr void emplace_back(T &&val)
constexpr void push_back(U &&val)
constexpr T & at(size_t i)
constexpr T * raw() const
constexpr T & at_no_check(size_t i) const
constexpr void copy(T *data, size_t size)
constexpr void resize(size_t size)
constexpr size_t size() const
constexpr void set_owner(Allocator &alloc)
bip::allocator< T, pinnable_mapped_file::segment_manager > allocator
std::string vector_to_string(T &&vec)
std::vector< T > unmanaged_vector
#define T(meth, val, expected)
unmanaged_base_member(size_t sz)
#define SYS_VM_ASSERT(expr, exc_type, msg)
yubihsm_pkcs11_object_template template