3 #include "manes/component.h"
4 #include "manes/manec.h"
6 using namespace resources
;
9 buffer_impl::buffer_impl() : inited(false) {}
11 buffer_impl::operator void*() {
13 return (void*)address
;
18 void buffer_impl::get_memory(int size
) {
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
;
30 void buffer_impl::set(void *addr
) {
31 assert("buffer: attempt to set null pointer", (int)addr
== 0);
35 address
= (char*)addr
;
38 void buffer_impl::set(void *addr
, int siz
) {
39 assert("buffer: attempt to set null pointer", (int)addr
== 0);
43 address
= (char*)addr
;
47 void buffer_impl::unsafe() {
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';
64 void * const buffer_impl::get_address() const {
66 return (void * const)address
;
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();
77 manec::get()->register_type(new type(type::buffer
, (type_name
)"slob", buff_name
, *buff_intf
, *buff_create
));