Well, I've come to a conclusion . . .
[aesalon.git] / src / platform / Memory.cpp
blob36e61588d01ee7c0f40c9e0a310541a3804eb108
1 #include "Memory.h"
2 #include "BlockEvent.h"
4 namespace Aesalon {
5 namespace Platform {
7 Misc::SmartPointer<MemoryBlock> Memory::get_block(MemoryAddress address) const {
8 for(block_set_t::const_iterator i = block_set.begin(); i != block_set.end(); i ++) {
9 if((*i)->get_address() == address) return *i;
11 return NULL;
14 void Memory::remove_block(Misc::SmartPointer<MemoryBlock> block) {
15 for(block_set_t::iterator i = block_set.begin(); i != block_set.end(); i ++) {
16 if((*i) != block) continue;
17 block_set.erase(i);
18 break;
22 void Memory::handle_event(Misc::SmartPointer<Event> event) {
23 if(event->get_type() == Event::BLOCK_EVENT) {
24 Misc::SmartPointer<BlockEvent> be = event.to<BlockEvent>();
25 switch(be->get_block_type()) {
26 case BlockEvent::ALLOC_EVENT:
27 add_block(new MemoryBlock(be->get_address(), be->get_size()));
28 break;
29 case BlockEvent::FREE_EVENT:
30 remove_block(get_block(be->get_address()));
31 break;
32 case BlockEvent::REALLOC_EVENT:
33 Misc::SmartPointer<MemoryBlock> block = get_block(be->get_address());
34 block->set_address(be->get_new_address());
35 block->set_size(be->get_size());
36 break;
41 } // namespace Platform
42 } // namespace Aesalon