2 #include <msp/strings/format.h>
11 void Buffer::storage(size_t sz, BufferUsage u)
16 throw incompatible_data("Buffer::storage");
20 throw invalid_argument("Buffer::storage");
28 void Buffer::data(const void *d)
30 return sub_data(0, size, d);
33 void Buffer::sub_data(size_t off, size_t sz, const void *d)
35 check_sub_data(off, sz, "Buffer::sub_data");
36 BufferBackend::sub_data(off, sz, d);
39 Buffer::AsyncTransfer Buffer::sub_data_async(size_t off, size_t sz)
41 check_sub_data(off, sz, "Buffer::sub_data_async");
42 return AsyncTransfer(*this, off, sz);
45 void Buffer::check_sub_data(size_t off, size_t sz, const char *func)
48 throw invalid_operation(func);
49 if(off>get_total_size() || off%size+sz>size)
50 throw out_of_range(func);
53 void Buffer::require_size(size_t req_sz) const
56 throw buffer_too_small(format("buffer has %d bytes; %d required", size, req_sz));
61 if(size==0 || !can_map() || mapped)
62 throw invalid_operation("Buffer::map");
63 void *result = BufferBackend::map();
70 if(size==0 || !can_map() || !mapped)
71 throw invalid_operation("Buffer::unmap");
72 bool result = BufferBackend::unmap();
78 Buffer::AsyncTransfer::AsyncTransfer(Buffer &b, size_t o, size_t s):
87 Buffer::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other):
91 dest_addr(other.dest_addr)
96 Buffer::AsyncTransfer &Buffer::AsyncTransfer::operator=(AsyncTransfer &&other)
101 buffer = other.buffer;
102 offset = other.offset;
104 dest_addr = other.dest_addr;
111 Buffer::AsyncTransfer::~AsyncTransfer()