Преглед изворни кода

Extract Binary{Reader,Writer} and Text{Reader,Writer} from Stream.h

Daniele Bartolini пре 13 година
родитељ
комит
efa643fda1

+ 10 - 0
src/CMakeLists.txt

@@ -134,6 +134,11 @@ set (STREAMS_SRC
 	core/streams/FileStream.cpp
 	core/streams/MemoryStream.cpp
 	core/streams/Stream.cpp
+	
+	core/streams/BinaryReader.cpp
+	core/streams/BinaryWriter.cpp
+	core/streams/TextReader.cpp
+	core/streams/TextWriter.cpp
 )
 
 set (STREAMS_HEADERS
@@ -141,6 +146,11 @@ set (STREAMS_HEADERS
 	core/streams/MemoryStream.h
 	core/streams/NullStream.h
 	core/streams/Stream.h
+
+	core/streams/BinaryReader.h
+	core/streams/BinaryWriter.h
+	core/streams/TextReader.h
+	core/streams/TextWriter.h
 )
 
 set (STRINGS_SRC

+ 5 - 0
src/Crown.h

@@ -76,6 +76,11 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "MemoryStream.h"
 #include "NullStream.h"
 
+#include "BinaryReader.h"
+#include "BinaryWriter.h"
+#include "TextReader.h"
+#include "TextWriter.h"
+
 // Engine
 #include "Camera.h"
 #include "Device.h"

+ 105 - 0
src/core/streams/BinaryReader.cpp

@@ -0,0 +1,105 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "BinaryReader.h"
+#include "Stream.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+BinaryReader::BinaryReader(Stream* stream) : m_stream(stream)
+{
+}
+
+//-----------------------------------------------------------------------------
+BinaryReader::~BinaryReader()
+{
+}
+
+//-----------------------------------------------------------------------------
+int8_t BinaryReader::read_byte()
+{
+	int8_t buffer;
+	m_stream->read(&buffer, sizeof(int8_t));
+	return buffer;
+}
+
+//-----------------------------------------------------------------------------
+int16_t BinaryReader::read_int16()
+{
+	int16_t buffer;
+	m_stream->read(&buffer, sizeof(int16_t));
+	return buffer;
+}
+
+//-----------------------------------------------------------------------------
+uint16_t BinaryReader::read_uint16()
+{
+	uint16_t buffer;
+	m_stream->read(&buffer, sizeof(uint16_t));
+	return buffer;
+}
+
+//-----------------------------------------------------------------------------
+int32_t BinaryReader::read_int32()
+{
+	int32_t buffer;
+	m_stream->read(&buffer, sizeof(int32_t));
+	return buffer;
+}
+
+//-----------------------------------------------------------------------------
+uint32_t BinaryReader::read_uint32()
+{
+	uint32_t buffer;
+	m_stream->read(&buffer, sizeof(uint32_t));
+	return buffer;
+}
+
+//-----------------------------------------------------------------------------
+int64_t BinaryReader::read_int64()
+{
+	int64_t buffer;
+	m_stream->read(&buffer, sizeof(int64_t));
+	return buffer;
+}
+
+//-----------------------------------------------------------------------------
+double BinaryReader::read_double()
+{
+	double buffer;
+	m_stream->read(&buffer, sizeof(double));
+	return buffer;
+}
+
+float BinaryReader::read_float()
+{
+	float buffer;
+	m_stream->read(&buffer, sizeof(float));
+	return buffer;
+}
+
+} // namespace crown

+ 57 - 0
src/core/streams/BinaryReader.h

@@ -0,0 +1,57 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "Types.h"
+
+namespace crown
+{
+
+class Stream;
+
+/// A reader that offers a convenient way to read from a Stream
+class BinaryReader
+{
+
+public:
+
+						BinaryReader(Stream* s);
+						~BinaryReader();
+
+	int8_t				read_byte();
+	int16_t				read_int16();
+	uint16_t			read_uint16();
+	int32_t				read_int32();
+	uint32_t			read_uint32();
+	int64_t				read_int64();
+	float				read_float();
+	double				read_double();
+
+private:
+
+	Stream*				m_stream;
+};
+
+} // namespace crown
+

+ 109 - 0
src/core/streams/BinaryWriter.cpp

@@ -0,0 +1,109 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "BinaryWriter.h"
+#include "Stream.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+BinaryWriter::BinaryWriter(Stream* stream) : m_stream(stream)
+{
+}
+
+//-----------------------------------------------------------------------------
+BinaryWriter::~BinaryWriter()
+{
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_byte(int8_t buffer)
+{
+	m_stream->write(&buffer, sizeof(int8_t));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_int16(int16_t buffer)
+{
+	m_stream->write(&buffer, sizeof(int16_t));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_uint16(uint16_t buffer)
+{
+	m_stream->write(&buffer, sizeof(uint16_t));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_int32(int32_t buffer)
+{
+	m_stream->write(&buffer, sizeof(int32_t));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_uint32(uint32_t buffer)
+{
+	m_stream->write(&buffer, sizeof(uint32_t));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_int64(int64_t buffer)
+{
+	m_stream->write(&buffer, sizeof(int64_t));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_double(double buffer)
+{
+	m_stream->write(&buffer, sizeof(double));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::write_float(float buffer)
+{
+	m_stream->write(&buffer, sizeof(float));
+}
+
+//-----------------------------------------------------------------------------
+void BinaryWriter::insert_byte(int8_t val, size_t offset)
+{
+	size_t tmpSize = m_stream->size() - offset;
+	int8_t* tmp = new int8_t[tmpSize];
+
+	m_stream->seek(offset);
+	m_stream->read(tmp, tmpSize);
+
+	m_stream->seek(offset);
+
+	m_stream->write_byte(val);
+
+	m_stream->write(tmp, tmpSize);
+
+	delete[] tmp;
+}
+
+} // namespace crown
+

+ 59 - 0
src/core/streams/BinaryWriter.h

@@ -0,0 +1,59 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "Types.h"
+
+namespace crown
+{
+
+class Stream;
+
+/// A writer that offers a convenient way to write to a Stream
+class BinaryWriter
+{
+
+public:
+
+						BinaryWriter(Stream* s);
+	virtual				~BinaryWriter();
+
+	void				write_byte(int8_t);
+	void				write_int16(int16_t);
+	void				write_uint16(uint16_t);
+	void				write_int32(int32_t);
+	void				write_uint32(uint32_t);
+	void				write_int64(int64_t);
+	void				write_double(double);
+	void				write_float(float);
+
+	void				insert_byte(int8_t val, size_t offset);
+
+private:
+
+	Stream*				m_stream;
+};
+
+} // namespace crown
+

+ 0 - 227
src/core/streams/Stream.cpp

@@ -69,232 +69,5 @@ bool Stream::uncompress_to(Stream* stream, size_t& unzipped_size, Compressor* co
 	return true;
 }
 
-//-----------------------------------------------------------------------------
-BinaryReader::BinaryReader(Stream* s)
-{
-	//BinaryReader takes the ownership of the stream.
-	m_stream = s;
-}
-
-//-----------------------------------------------------------------------------
-BinaryReader::~BinaryReader()
-{
-}
-
-//-----------------------------------------------------------------------------
-int8_t BinaryReader::read_byte()
-{
-	int8_t buffer;
-	m_stream->read(&buffer, sizeof(int8_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-int16_t BinaryReader::read_int16()
-{
-	int16_t buffer;
-	m_stream->read(&buffer, sizeof(int16_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-uint16_t BinaryReader::read_uint16()
-{
-	uint16_t buffer;
-	m_stream->read(&buffer, sizeof(uint16_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-int32_t BinaryReader::read_int32()
-{
-	int32_t buffer;
-	m_stream->read(&buffer, sizeof(int32_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-uint32_t BinaryReader::read_uint32()
-{
-	uint32_t buffer;
-	m_stream->read(&buffer, sizeof(uint32_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-int64_t BinaryReader::read_int64()
-{
-	int64_t buffer;
-	m_stream->read(&buffer, sizeof(int64_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-double BinaryReader::read_double()
-{
-	double buffer;
-	m_stream->read(&buffer, sizeof(double));
-	return buffer;
-}
-
-float BinaryReader::read_float()
-{
-	float buffer;
-	m_stream->read(&buffer, sizeof(float));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-BinaryWriter::BinaryWriter(Stream* s)
-{
-	//BinaryWriter takes the ownership of the stream.
-	m_stream = s;
-}
-
-//-----------------------------------------------------------------------------
-BinaryWriter::~BinaryWriter()
-{
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_byte(int8_t buffer)
-{
-	m_stream->write(&buffer, sizeof(int8_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_int16(int16_t buffer)
-{
-	m_stream->write(&buffer, sizeof(int16_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_uint16(uint16_t buffer)
-{
-	m_stream->write(&buffer, sizeof(uint16_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_int32(int32_t buffer)
-{
-	m_stream->write(&buffer, sizeof(int32_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_uint32(uint32_t buffer)
-{
-	m_stream->write(&buffer, sizeof(uint32_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_int64(int64_t buffer)
-{
-	m_stream->write(&buffer, sizeof(int64_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_double(double buffer)
-{
-	m_stream->write(&buffer, sizeof(double));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_float(float buffer)
-{
-	m_stream->write(&buffer, sizeof(float));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::insert_byte(int8_t val, size_t offset)
-{
-	size_t tmpSize = m_stream->size() - offset;
-	int8_t* tmp = new int8_t[tmpSize];
-
-	m_stream->seek(offset);
-	m_stream->read(tmp, tmpSize);
-
-	m_stream->seek(offset);
-
-	m_stream->write_byte(val);
-
-	m_stream->write(tmp, tmpSize);
-
-	delete[] tmp;
-}
-
-//-----------------------------------------------------------------------------
-TextReader::TextReader(Stream* s)
-{
-	m_stream = s;
-}
-
-//-----------------------------------------------------------------------------
-TextReader::~TextReader()
-{
-}
-
-//-----------------------------------------------------------------------------
-char TextReader::read_char()
-{
-	return m_stream->read_byte();
-}
-
-//-----------------------------------------------------------------------------
-char* TextReader::read_string(char* string, uint32_t count)
-{
-	char currentChar;
-	uint32_t i = 0;
-
-	while(!m_stream->end_of_stream() && i < count - 1)
-	{
-		currentChar = m_stream->read_byte();
-		string[i] = currentChar;
-
-		i++;
-
-		if (currentChar == '\n')
-		{
-			break;
-		}
-	}
-
-	if (i == 0)
-	{
-		return NULL;
-	}
-
-	string[i] = '\0';
-
-	return string;
-}
-
-//-----------------------------------------------------------------------------
-TextWriter::TextWriter(Stream* s)
-{
-	m_stream = s;
-}
-
-//-----------------------------------------------------------------------------
-TextWriter::~TextWriter()
-{
-}
-
-void TextWriter::write_char(char c)
-{
-	m_stream->write_byte(c);
-}
-
-//-----------------------------------------------------------------------------
-void TextWriter::write_string(const char* string)
-{
-	size_t count = 0;
-
-	while(string[count] != '\0')
-	{
-		m_stream->write_byte(string[count]);
-		count++;
-	}
-}
-
 } // namespace crown
 

+ 1 - 111
src/core/streams/Stream.h

@@ -124,115 +124,5 @@ protected:
 	StreamOpenMode		m_open_mode;
 };
 
-///! A reader that offers a convenient way to read from a stream
-class BinaryReader
-{
-
-public:
-
-						BinaryReader(Stream* s);
-	virtual				~BinaryReader();
-
-	int8_t				read_byte();
-	int16_t				read_int16();
-	uint16_t			read_uint16();
-	int32_t				read_int32();
-	uint32_t			read_uint32();
-	int64_t				read_int64();
-	double				read_double();
-	float				read_float();
-
-	inline Stream*		get_stream() { return m_stream; }
-	inline void			set_stream(Stream* stream) { m_stream = stream; }
-
-private:
-
-	Stream*				m_stream;
-};
-
-///! A writer that offers a convenient way to write to a stream
-class BinaryWriter
-{
-
-public:
-
-						BinaryWriter(Stream* s);
-	virtual				~BinaryWriter();
-
-	void				write_byte(int8_t);
-	void				write_int16(int16_t);
-	void				write_uint16(uint16_t);
-	void				write_int32(int32_t);
-	void				write_uint32(uint32_t);
-	void				write_int64(int64_t);
-	void				write_double(double);
-	void				write_float(float);
-
-	void				insert_byte(int8_t val, size_t offset);
-
-	inline Stream*		get_stream() { return m_stream; }
-	inline void			set_stream(Stream* stream) { m_stream = stream; }
-
-private:
-
-	Stream*				m_stream;
-};
-
-///! A reader that offers a convenient way to read text to a stream
-class TextReader
-{
-
-public:
-
-						TextReader(Stream* s);
-	virtual				~TextReader();
-
-	char				read_char();
-						/**
-							Reads characters from stream and stores them as a C string
-							into string until (count-1) characters have been read or
-							either a newline or the End-of-Stream is reached, whichever
-							comes first.
-							A newline character makes fgets stop reading, but it is considered
-							a valid character and therefore it is included in the string copied to string.
-							A null character is automatically appended in str after the characters read to
-							signal the end of the C string.
-						*/
-	char*				read_string(char* string, uint32_t count);
-
-	inline Stream*		get_stream() { return m_stream; }
-	inline void			set_stream(Stream* stream) { m_stream = stream; }
-
-private:
-
-	Stream*				m_stream;
-};
-
-///! A reader that offers a convenient way to write text to a stream
-class TextWriter
-{
-
-public:
-
-						TextWriter(Stream* s);
-	virtual				~TextWriter();
-
-	void				write_char(char c);
-						/**
-							Writes the string point32_ted by string to the stream.
-							The function begins copying from the address specified (string)
-							until it reaches the terminating null character ('\0').
-							This final null character is not copied to the stream.
-						*/
-	void				write_string(const char* string);
-
-	inline Stream*		get_stream() { return m_stream; }
-	inline void			set_stream(Stream* stream) { m_stream = stream; }
-
-private:
-
-	Stream*				m_stream;
-};
-
-} /// namespace crown
+} // namespace crown
 

+ 79 - 0
src/core/streams/TextReader.cpp

@@ -0,0 +1,79 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "TextReader.h"
+#include "Stream.h"
+#include "Types.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+TextReader::TextReader(Stream* stream) : m_stream(stream)
+{
+}
+
+//-----------------------------------------------------------------------------
+TextReader::~TextReader()
+{
+}
+
+//-----------------------------------------------------------------------------
+char TextReader::read_char()
+{
+	return m_stream->read_byte();
+}
+
+//-----------------------------------------------------------------------------
+char* TextReader::read_string(char* string, uint32_t count)
+{
+	char currentChar;
+	uint32_t i = 0;
+
+	while(!m_stream->end_of_stream() && i < count - 1)
+	{
+		currentChar = m_stream->read_byte();
+		string[i] = currentChar;
+
+		i++;
+
+		if (currentChar == '\n')
+		{
+			break;
+		}
+	}
+
+	if (i == 0)
+	{
+		return NULL;
+	}
+
+	string[i] = '\0';
+
+	return string;
+}
+
+} // namespace crown
+

+ 60 - 0
src/core/streams/TextReader.h

@@ -0,0 +1,60 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "Types.h"
+
+namespace crown
+{
+
+class Stream;
+
+/// A reader that offers a convenient way to read text from a Stream
+class TextReader
+{
+
+public:
+
+						TextReader(Stream* s);
+						~TextReader();
+
+	char				read_char();
+
+						/// Reads characters from stream and stores them as a C string
+						/// into string until (count-1) characters have been read or
+						/// either a newline or the End-of-Stream is reached, whichever
+						/// comes first.
+						/// A newline character makes fgets stop reading, but it is considered
+						/// a valid character and therefore it is included in the string copied to string.
+						/// A null character is automatically appended in str after the characters read to
+						/// signal the end of the C string.
+	char*				read_string(char* string, uint32_t count);
+
+private:
+
+	Stream*				m_stream;
+};
+
+} // namespace crown
+

+ 60 - 0
src/core/streams/TextWriter.cpp

@@ -0,0 +1,60 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "TextWriter.h"
+#include "Stream.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+TextWriter::TextWriter(Stream* stream) : m_stream(stream)
+{
+}
+
+//-----------------------------------------------------------------------------
+TextWriter::~TextWriter()
+{
+}
+
+void TextWriter::write_char(char c)
+{
+	m_stream->write_byte(c);
+}
+
+//-----------------------------------------------------------------------------
+void TextWriter::write_string(const char* string)
+{
+	size_t count = 0;
+
+	while(string[count] != '\0')
+	{
+		m_stream->write_byte(string[count]);
+		count++;
+	}
+}
+
+} // namespace crown
+

+ 55 - 0
src/core/streams/TextWriter.h

@@ -0,0 +1,55 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+namespace crown
+{
+
+class Stream;
+
+/// A reader that offers a convenient way to write text to a Stream
+class TextWriter
+{
+
+public:
+
+						TextWriter(Stream* s);
+	virtual				~TextWriter();
+
+	void				write_char(char c);
+						/**
+							Writes the string point32_ted by string to the stream.
+							The function begins copying from the address specified (string)
+							until it reaches the terminating null character ('\0').
+							This final null character is not copied to the stream.
+						*/
+	void				write_string(const char* string);
+
+private:
+
+	Stream*				m_stream;
+};
+
+} // namespace crown
+