creator-level saving new files in fat
[quarnos.git] / resources / buffer.cpp
bloba4325fb95d19007f6eee84964b1f70187fa234da
1 #include "buffer.h"
2 #include "memm.h"
3 #include "manes/component.h"
4 #include "manes/manec.h"
6 using namespace resources;
7 using namespace manes;
9 buffer_impl::buffer_impl() : inited(false) {}
11 buffer_impl::operator void*() {
12 if (inited && !safe)
13 return (void*)address;
15 return (void*)0;
18 void buffer_impl::get_memory(int size) {
19 //if (inited && safe)
20 // ((memm*)manec::get()->get_component(owner->get_parent())->get_implementation())->deallocate_space(address);
22 /* FIXME: no comment, just look how ugly it is */
23 address = (char*)((memm*)get_parent()->get_implementation())->allocate_space(size);
25 buffer_impl::size = size;
26 inited = true;
27 safe = true;
30 void buffer_impl::set(void *addr) {
31 assert("buffer: attempt to set null pointer", (int)addr == 0);
33 inited = true;
34 safe = false;
35 address = (char*)addr;
38 void buffer_impl::set(void *addr, int siz) {
39 assert("buffer: attempt to set null pointer", (int)addr == 0);
41 inited = true;
42 safe = true;
43 address = (char*)addr;
44 size = siz;
47 void buffer_impl::unsafe() {
48 safe = false;
51 char &buffer_impl::operator[](int index) {
52 if (inited && safe && index<size && index>=0)
53 return address[index];
54 else if (inited && !safe)
55 return address[index];
57 debug("buffer: attempt to read out of range");
59 static char nop = '\0';
61 return nop;
64 void * const buffer_impl::get_address() const {
65 if (inited && !safe)
66 return (void * const)address;
67 else
68 return (void * const)0;
71 void buffer_impl::register_type() {
72 type_name buff_name("buffer", true);
73 delegate<implementation *> *buff_create = new delegate<implementation *>;
74 buff_create->function(create_object<implementation, buffer_impl>);
75 interface *buff_intf = new interface();
76 buff_intf->seal();
77 manec::get()->register_type(new type(type::buffer, (type_name)"slob", buff_name, *buff_intf, *buff_create));