--- a/sources/network/bytestream.h Sat Dec 13 04:32:15 2014 +0200 +++ b/sources/network/bytestream.h Sat Dec 13 04:50:33 2014 +0200 @@ -29,6 +29,7 @@ */ #pragma once +#include <stdexcept> #include "../main.h" class String; @@ -39,7 +40,20 @@ class Bytestream { public: - static bool sink; + class IOError : public std::exception + { + String m_message; + + public: + IOError (String message) : + m_message (message) {} + + inline METHOD + what() const throw() -> const char* + { + return m_message.chars(); + } + }; Bytestream (unsigned long length = 0x800); Bytestream (const unsigned char* data, unsigned long length); @@ -54,12 +68,12 @@ inline METHOD data() const -> const unsigned char*; METHOD grow_to_fit (unsigned long bytes) -> void; inline METHOD position() const -> unsigned long; - METHOD read (unsigned char* buffer, unsigned long length, bool* ok = &sink) -> void; - METHOD read_byte (bool* ok = &sink) -> char; - METHOD read_short (bool* ok = &sink) -> short int; - METHOD read_long (bool* ok = &sink) -> long int; - METHOD read_string (bool* ok = &sink) -> String; - METHOD read_float (bool* ok = &sink) -> float; + METHOD read (unsigned char* buffer, unsigned long length) -> void; + METHOD read_byte() -> char; + METHOD read_short() -> short int; + METHOD read_long() -> long int; + METHOD read_string() -> String; + METHOD read_float() -> float; METHOD resize (unsigned long length) -> void; inline METHOD rewind() -> void; inline METHOD seek (unsigned long pos) -> void; @@ -87,6 +101,7 @@ METHOD init (const unsigned char* data, unsigned long length) -> void; METHOD write (unsigned char val) -> void; + METHOD ensure_read_space (unsigned int bytes) -> void; inline METHOD space_left() const -> unsigned long; };