+void *Buffer::map()
+{
+ if(size==0 || !can_map() || mapped)
+ throw invalid_operation("Buffer::map");
+ void *result = BufferBackend::map();
+ mapped = true;
+ return result;
+}
+
+bool Buffer::unmap()
+{
+ if(size==0 || !can_map() || !mapped)
+ throw invalid_operation("Buffer::unmap");
+ bool result = BufferBackend::unmap();
+ mapped = false;
+ return result;
+}
+
+
+Buffer::AsyncTransfer::AsyncTransfer(Buffer &b, size_t o, size_t s):
+ buffer(&b),
+ offset(o),
+ size(s),
+ dest_addr(0)
+{
+ allocate();
+}
+
+Buffer::AsyncTransfer::AsyncTransfer(AsyncTransfer &&other):
+ buffer(other.buffer),
+ offset(other.offset),
+ size(other.size),
+ dest_addr(other.dest_addr)
+{
+ other.dest_addr = 0;
+}
+
+Buffer::AsyncTransfer &Buffer::AsyncTransfer::operator=(AsyncTransfer &&other)
+{
+ if(dest_addr)
+ finalize();
+
+ buffer = other.buffer;
+ offset = other.offset;
+ size = other.size;
+ dest_addr = other.dest_addr;
+
+ other.dest_addr = 0;
+
+ return *this;
+}
+
+Buffer::AsyncTransfer::~AsyncTransfer()
+{
+ if(dest_addr)
+ finalize();
+}
+