sources/network/bytestream.h

changeset 88
08ccaf26cffd
parent 73
07dda51a7a8e
child 98
4f0f0b1b8e0b
--- a/sources/network/bytestream.h	Thu Jul 23 00:16:47 2015 +0300
+++ b/sources/network/bytestream.h	Thu Jul 23 01:52:04 2015 +0300
@@ -31,10 +31,14 @@
 #pragma once
 #include <stdexcept>
 #include "../main.h"
+BEGIN_ZFC_NAMESPACE
 
 class String;
 
-enum { MAX_NETWORK_STRING = 0x800 };
+enum
+{
+	MAX_NETWORK_STRING = 0x800
+};
 
 // TODO: Make able to handle big-endian too
 class Bytestream
@@ -48,10 +52,9 @@
 		IOError (String message) :
 			m_message (message) {}
 
-		inline METHOD
-		what() const throw() -> const char*
+		const char* what() const throw()
 		{
-			return m_message.chars();
+			return m_message;
 		}
 	};
 
@@ -61,37 +64,80 @@
 	Bytestream (const Bytestream& other);
 	~Bytestream();
 
-	inline METHOD allocated_size() const -> unsigned long;
-	inline METHOD bytes_left() const -> unsigned long;
-	       METHOD clear() -> void;
-	inline METHOD data() -> unsigned char*;
-	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) -> 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;
-	inline METHOD to_vector() const -> Vector<unsigned char>;
-	       METHOD write (const unsigned char* val, unsigned int length) -> void;
-	       METHOD write_buffer (const Bytestream& other) -> void;
-	       METHOD write_buffer (const Vector<unsigned char>& other) -> void;
-	       METHOD write_byte (char val) -> void;
-	       METHOD write_double (double val) -> void;
-	       METHOD write_float (float val) -> void;
-	       METHOD write_long (long int val) -> void;
-	       METHOD write_short (short int val) -> void;
-	       METHOD write_string (const String& val) -> void;
-	inline METHOD written_length() const -> unsigned long;
+	void clear();
+	void grow_to_fit (unsigned long bytes);
+	void read (unsigned char* buffer, unsigned long length);
+	char read_byte();
+	short int read_short();
+	long int read_long();
+	String read_string();
+	float read_float();
+	void resize (unsigned long length);
+	void write (const unsigned char* val, unsigned int length);
+	void write_buffer (const Bytestream& other);
+	void write_buffer (const Vector<unsigned char>& other);
+	void write_byte (char val);
+	void write_double (double val);
+	void write_float (float val);
+	void write_long (long int val);
+	void write_short (short int val);
+	void write_string (const String& val);
+
+	Bytestream& operator= (const Bytestream& other);
+
+	unsigned long allocated_size() const
+	{
+		return m_allocatedSize;
+	}
+
+	unsigned long bytes_left() const
+	{
+		return m_writtenLength - (m_cursor - &m_data[0]);
+	}
 
-	inline METHOD operator[] (unsigned long idx) -> unsigned char&;
-	inline METHOD operator[] (unsigned long idx) const -> unsigned char;
-	       METHOD operator= (const Bytestream& other) -> Bytestream&;
+	inline unsigned char* data()
+	{
+		return m_data;
+	}
+	inline const unsigned char* data() const
+	{
+		return m_data;
+	}
+
+	unsigned long position() const
+	{
+		return m_cursor - m_data;
+	}
+
+	void rewind()
+	{
+		m_cursor = m_data;
+	}
+
+	void seek (unsigned long pos)
+	{
+		m_cursor = m_data + pos;
+	}
+
+	Vector<unsigned char> to_vector() const
+	{
+		return Vector<unsigned char> (m_data, m_writtenLength);
+	}
+
+	unsigned long written_length() const
+	{
+		return m_writtenLength;
+	}
+
+	unsigned char& operator[] (unsigned long idx)
+	{
+		return m_data[idx];
+	}
+
+	unsigned char operator[] (unsigned long idx) const
+	{
+		return m_data[idx];
+	}
 
 private:
 	unsigned char* m_data;
@@ -99,104 +145,14 @@
 	unsigned long m_allocatedSize;
 	unsigned long m_writtenLength;
 
-	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;
+	void init (const unsigned char* data, unsigned long length);
+	void write (unsigned char val);
+	void ensure_read_space (unsigned int bytes);
+
+	unsigned long space_left() const
+	{
+		return m_allocatedSize - m_writtenLength;
+	}
 };
 
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::allocated_size() const -> unsigned long
-{
-	return m_allocatedSize;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::written_length() const -> unsigned long
-{
-	return m_writtenLength;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::operator[] (unsigned long idx) -> unsigned char&
-{
-	return m_data[idx];
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::operator[] (unsigned long idx) const -> unsigned char
-{
-	return m_data[idx];
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::position() const -> unsigned long
-{
-	return m_cursor - m_data;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::seek (unsigned long pos) -> void
-{
-	m_cursor = m_data + pos;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::rewind() -> void
-{
-	m_cursor = m_data;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::bytes_left() const -> unsigned long
-{
-	return (m_writtenLength - (m_cursor - &m_data[0]));
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::space_left() const -> unsigned long
-{
-	return (m_allocatedSize - m_writtenLength);
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::data() -> unsigned char*
-{
-	return m_data;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::data() const -> const unsigned char*
-{
-	return m_data;
-}
-
-// -------------------------------------------------------------------------------------------------
-//
-inline METHOD
-Bytestream::to_vector() const -> Vector<unsigned char>
-{
-	return Vector<unsigned char> (m_data, m_writtenLength);
-}
+END_ZFC_NAMESPACE

mercurial