Well, I've come to a conclusion . . .
[aesalon.git] / src / platform / BlockEvent.cpp
blobfd99952335a7f512cba2644ff490e749a6ecc289
1 #include <sstream>
2 #include "BlockEvent.h"
3 #include "misc/Exception.h"
4 #include "misc/StreamAsString.h"
5 #include "misc/String.h"
7 namespace Aesalon {
8 namespace Platform {
10 std::string BlockEvent::serialize() {
11 std::string serialized = Event::serialize();
13 switch(block_type) {
14 case ALLOC_EVENT:
15 return Misc::StreamAsString() << Event::serialize() << std::hex << get_address() << ":" << get_size();
16 case REALLOC_EVENT:
17 return Misc::StreamAsString() << Event::serialize() << std::hex << get_address() << ":" << get_size() << ":" << get_new_address();
18 case FREE_EVENT:
19 return Misc::StreamAsString() << Event::serialize() << std::hex << get_address();
21 throw Misc::Exception("Asked to serialize invalid BlockEvent");
24 Misc::SmartPointer<Event> BlockEvent::deserialize(std::string data) {
25 MemoryAddress address;
26 Misc::String::to<MemoryAddress>(data, address, true);
27 /* If there's no colon, then it's a FREE_EVENT . . . */
28 if(data.find(":") == std::string::npos) {
29 return new BlockEvent(FREE_EVENT, address);
31 data.erase(0, data.find(":")+1);
33 MemoryAddress size;
34 Misc::String::to<MemoryAddress>(data, size, true);
35 if(data.find(":") == std::string::npos) {
36 return new BlockEvent(ALLOC_EVENT, address, size);
39 data.erase(0, data.find(":")+1);
40 MemoryAddress new_address;
41 Misc::String::to<MemoryAddress>(data, new_address, true);
43 return new BlockEvent(REALLOC_EVENT, address, size, new_address);
46 } // namespace Platform
47 } // namespace Aesalon