3 This file is part of libmspio
4 Copyright © 2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
18 Memory::Memory(char *d, unsigned s)
23 Memory::Memory(char *b, char *e)
28 Memory::Memory(const char *cd, unsigned s)
30 char *d = const_cast<char *>(cd);
34 Memory::Memory(const char *b, const char *e)
36 init(const_cast<char *>(b), const_cast<char *>(e), M_READ);
39 void Memory::init(char *b, char *e, Mode m)
47 unsigned Memory::put(char c)
54 bool Memory::getline(string &line)
56 char *nl = find(pos, end, '\n');
58 bool result = (nl!=pos);
71 return static_cast<unsigned char>(*pos++);
74 unsigned Memory::seek(int off, SeekType type)
84 throw InvalidParameterValue("Invalid seek type");
86 if(new_pos<begin || new_pos>end)
87 throw InvalidParameterValue("Invalid seek offset");
93 Handle Memory::get_event_handle()
95 throw Exception("Memory doesn't support events");
98 unsigned Memory::do_write(const char *buf, unsigned size)
102 size = min<unsigned>(size, end-pos);
103 memcpy(pos, buf, size);
108 unsigned Memory::do_read(char *buf, unsigned size)
116 size = min<unsigned>(size, end-pos);
117 memcpy(buf, pos, size);
122 void Memory::check_mode(Mode m) const
127 throw InvalidState("Memory is not writable");
129 throw InvalidState("Attempt to write past end of Memory");