Przeglądaj źródła

Fix streams docs

Daniele Bartolini 12 lat temu
rodzic
commit
ac6472714f

+ 40 - 33
src/core/streams/FileStream.h

@@ -32,59 +32,64 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/**
-	File stream.
-	Read/write access to files on disk.
-*/
+
+/// File stream.
+/// Provides common facilities to access files on disk.
 class FileStream: public Stream
 {
 
 public:
 
-					/**
-						Constructor.
-					@param filename
-						The name of the file to access
-					@param openMode
-						The mode of access
-					*/
+	/// Opens @filename with specified @mode
 					FileStream(StreamOpenMode mode, const char* filename);
-					/**
-						Destructor
-					*/
 	virtual			~FileStream();
 
-					/** @copydoc Stream::seek() */
+	/// @copydoc Stream::seek() 
 	void			seek(size_t position);
-					/** @copydoc Stream::seek_to_end() */
+
+	/// @copydoc Stream::seek_to_end() 
 	void			seek_to_end();
-					/** @copydoc Stream::skip() */
+
+	/// @copydoc Stream::skip() 
 	void			skip(size_t bytes);
-					/** @copydoc Stream::ReadByte() */
+
+	/// @copydoc Stream::read_byte() 
 	uint8_t			read_byte();
-					/** @copydoc Stream::ReadDataBlock() */
+
+	/// @copydoc Stream::read() 
 	void			read(void* buffer, size_t size);
-					/** @copydoc Stream::WriteByte() */
+
+	/// @copydoc Stream::write_byte() 
 	void			write_byte(uint8_t val);
-					/** @copydoc Stream::WriteDataBlock() */
+
+	/// @copydoc Stream::write() 
 	void			write(const void* buffer, size_t size);
-					/** @copydoc Stream::CopyTo() */
+
+	/// @copydoc Stream::copy_to() 
 	bool			copy_to(Stream* stream, size_t size = 0);
-					/** @copydoc Stream::Flush() */
+
+	/// @copydoc Stream::flush() 
 	void			flush();
-					/** @copydoc Stream::EndOfStream() */
+
+	/// @copydoc Stream::end_of_stream() 
 	bool			end_of_stream() const;
-					/** @copydoc Stream::is_valid() */
+
+	/// @copydoc Stream::is_valid() 
 	bool			is_valid() const;
-					/** @copydoc Stream::GetSize() */
+
+	/// @copydoc Stream::size() 
 	size_t			size() const;
-					/** @copydoc Stream::GetPosition() */
+
+	/// @copydoc Stream::position() 
 	size_t			position() const;
-					/** @copydoc Stream::CanRead() */
+
+	/// @copydoc Stream::can_read() 
 	bool			can_read() const;
-					/** @copydoc Stream::CanWrite() */
+
+	/// @copydoc Stream::can_write() 
 	bool			can_write() const;
-					/** @copydoc Stream::CanSeek() */
+
+	/// @copydoc Stream::can_seek() 
 	bool			can_seek() const;
 
 protected:
@@ -92,10 +97,12 @@ protected:
 	File*			m_file;
 	bool			m_last_was_read;
 
+protected:
+
 	inline void		check_valid() const
-					{
-						assert(m_file != NULL);
-					}
+	{
+		assert(m_file != NULL);
+	}
 };
 
 } // namespace crown

+ 7 - 6
src/core/streams/MemoryStream.cpp

@@ -24,12 +24,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include <stdlib.h>
-#include <stdio.h>
 #include "MemoryStream.h"
 #include "MathUtils.h"
 #include "Log.h"
 #include "Types.h"
 #include "Allocator.h"
+#include "OS.h"
 
 namespace crown
 {
@@ -46,10 +46,10 @@ MemoryBuffer::~MemoryBuffer()
 
 //-----------------------------------------------------------------------------
 DynamicMemoryBuffer::DynamicMemoryBuffer(Allocator& allocator, size_t initial_capacity) :
-	m_allocator(&allocator),
+	m_allocator(allocator),
 	m_buffer(NULL)
 {
-	m_buffer = (uint8_t*)m_allocator->allocate(initial_capacity);
+	m_buffer = (uint8_t*)m_allocator.allocate(initial_capacity);
 }
 
 //-----------------------------------------------------------------------------
@@ -57,7 +57,7 @@ DynamicMemoryBuffer::~DynamicMemoryBuffer()
 {
 	if (m_buffer)
 	{
-		m_allocator->deallocate(m_buffer);
+		m_allocator.deallocate(m_buffer);
 	}
 }
 
@@ -120,7 +120,8 @@ void MemoryStream::seek(size_t position)
 	
 	m_memory_offset = position;
 
-	//Allow seek to m_memory->getSize() position, that means end of stream, reading not allowed but you can write if it's dynamic
+	// Allow seek to m_memory->size() position, that means end of stream,
+	// reading not allowed but you can write if it's dynamic
 	assert(m_memory_offset <= m_memory->size());
 }
 
@@ -215,7 +216,7 @@ void MemoryStream::dump()
 
 	for (size_t i = 0; i < m_memory->size(); i++)
 	{
-		printf("%3i ", buff[i]);
+		os::printf("%3i ", buff[i]);
 	}
 }
 

+ 32 - 7
src/core/streams/MemoryStream.h

@@ -74,49 +74,74 @@ public:
 
 protected:
 
-	Allocator*			m_allocator;
+	Allocator&			m_allocator;
 	uint8_t*			m_buffer;
 	size_t				m_capacity;
 	size_t				m_size;
 };
 
-/**
-	Memory stream.
-
-	Access memory buffers.
-*/
+/// Memory stream.
+/// Access memory buffers.
 class MemoryStream: public Stream
 {
 
 public:
 
+	/// @copydoc Stream::Stream()
 						MemoryStream(MemoryBuffer* buffer, StreamOpenMode mode);
-	virtual				~MemoryStream();
 
+	/// @copydoc Stream::~Stream()
+	virtual				~MemoryStream();
 
+	/// @copydoc Stream::seek()
 	void				seek(size_t position);
+
+	/// @copydoc Stream::seek_to_end()
 	void				seek_to_end();
+
+	/// @copydoc Stream::skip()
 	void				skip(size_t bytes);
 
+	/// @copydoc Stream::read_byte()
 	uint8_t				read_byte();
+
+	/// @copydoc Stream::read()
 	void				read(void* buffer, size_t size);
+
+	/// @copydoc Stream::write_byte()
 	void				write_byte(uint8_t val);
+
+	/// @copydoc Stream::write()
 	void				write(const void* buffer, size_t size);
 
+	/// @copydoc Stream::copy_to()
 	bool				copy_to(Stream* stream, size_t size = 0);
 
+	/// @copydoc Stream::flush()
 	void				flush();
 
+	/// @copydoc Stream::end_of_stream()
 	bool				end_of_stream() const { return size() == m_memory_offset; }
+
+	/// @copydoc Stream::is_valid()
 	bool				is_valid() const { assert(m_memory != NULL); return m_memory->is_valid(); }
 
+	/// @copydoc Stream::size()
 	size_t				size() const { assert(m_memory != NULL); return m_memory->size(); }
+
+	/// @copydoc Stream::position()
 	size_t				position() const { return m_memory_offset; }
 
+	/// @copydoc Stream::can_read()
 	bool				can_read() const { return true; }
+
+	/// @copydoc Stream::can_write()
 	bool				can_write() const { return true; }
+
+	/// @copydoc Stream::can_seek()
 	bool				can_seek() const { return true; }
 
+	/// Dumps the data to the console.
 	void				dump();
 
 protected:

+ 59 - 60
src/core/streams/NullStream.h

@@ -30,103 +30,102 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/**
-	Bit bucket stream.
 
-	Discards all data written to it and provides null data reading from it; plain and simple.
-*/
+/// Bit bucket stream.
+/// Discards all data written to it and provides null data reading from it; plain and simple.
 class NullStream: public Stream
 {
 
 public:
 
-				/// @copydoc Stream::Stream()
+	/// @copydoc Stream::Stream()
 				NullStream(StreamOpenMode mode) : Stream(mode) {}
-				/// @copydoc Stream::~Stream()
+
+	/// @copydoc Stream::~Stream()
 	virtual		~NullStream() {}
 
-				/// @copydoc Stream::seek()
+	/// @copydoc Stream::seek()
 	void		seek(size_t position) { (void)position; }
 
-				/// @copydoc Stream::seek_to_end()
+	/// @copydoc Stream::seek_to_end()
 	void		seek_to_end() {}
 
-				/// @copydoc Stream::skip()
+	/// @copydoc Stream::skip()
 	void		skip(size_t bytes) { (void)bytes; }
 
-				/// @copydoc Stream::ReadByte()
-				/// @note
-				///	Returns always zero
+	/// @copydoc Stream::read_byte()
+	/// @note
+	///	Returns always zero
 	uint8_t		read_byte() { return 0; }
 				
-				/// @copydoc Stream::ReadDataBlock()
-				/// @note
-				///	Fills buffer with zeroes
+	/// @copydoc Stream::read()
+	/// @note
+	///	Fills buffer with zeroes
 	void		read(void* buffer, size_t size)
-				{
-					for (size_t i = 0; i < size; i++)
-					{
-						((uint8_t*)buffer)[i] = 0;
-					}
-				}
-
-				/// @copydoc Stream::WriteByte()
+	{
+		for (size_t i = 0; i < size; i++)
+		{
+			((uint8_t*)buffer)[i] = 0;
+		}
+	}
+
+	/// @copydoc Stream::write_byte()
 	void		write_byte(uint8_t val) { (void)val; }
 
-				/// @copydoc Stream::WriteDataBlock()
+	/// @copydoc Stream::write()
 	void		write(const void* buffer, size_t size) { (void)buffer; (void)size; }
 
-				/// @copydoc Stream::CopyTo()
-				/// @note
-				///	Returns always true
+	/// @copydoc Stream::copy_to()
+	/// @note
+	///	Returns always true
 	bool		copy_to(Stream* stream, size_t size = 0)
-				{
-					assert(stream != NULL);
-					
-					for (size_t i = 0; i < size; i++)
-					{
-						stream->write_byte(0);
-					}
-					
-					return true;
-				}
-
-				/// @copydoc Stream::Flush()
+	{
+		assert(stream != NULL);
+		
+		for (size_t i = 0; i < size; i++)
+		{
+			stream->write_byte(0);
+		}
+		
+		return true;
+	}
+
+	/// @copydoc Stream::flush()
 	void		flush() {};
 				
-				/// @copydoc Stream::IsValid()
-				/// @note
-				///	Returns always true
+	/// @copydoc Stream::is_valid()
+	/// @note
+	///	Returns always true
 	bool		is_valid() { return true; }
 				
-				/// @copydoc Stream::EndOfStream()
-				/// @note
-				///	Returns always false
+	/// @copydoc Stream::end_of_stream()
+	/// @note
+	///	Returns always false
 	bool		end_of_stream() { return false; }
 				
-				/// @copydoc Stream::GetSize()
-				/// @note
-				///	Returns always 0xFFFFFFFF
+	/// @copydoc Stream::size()
+	/// @note
+	///	Returns always 0xFFFFFFFF
 	size_t		size() { return ~0; }
 				
-				/// @copydoc Stream::GetPosition()
-				/// @note
-				///	Returns always zero
+	/// @copydoc Stream::position()
+	/// @note
+	///	Returns always zero
 	size_t		position() { return 0; }
 				
-				/// @copydoc Stream::CanRead()
-				/// @note
-				///	Returns always true
+	/// @copydoc Stream::can_read()
+	/// @note
+	///	Returns always true
 	bool		can_read() { return true; }
 				
-				/// @copydoc Stream::CanWrite()
-				/// @note
-				///	Returns always true
+	/// @copydoc Stream::can_write()
+	/// @note
+	///	Returns always true
 	bool		can_write() { return true; }
 				
-				/// @copydoc Stream::CanSeek()
-				/// @note
-				///	Returns always true
+	/// @copydoc Stream::can_seek()
+	/// @note
+	///	Returns always true
 	bool		can_seek() { return true; }
 };
 

+ 30 - 30
src/core/streams/Stream.h

@@ -49,74 +49,74 @@ class Stream
 {
 public:
 
-						/// Constructor
+	/// Constructor
 						Stream(StreamOpenMode mode) : m_open_mode(mode) {}
 
-						/// Destructor
+	/// Destructor
 	virtual				~Stream() {};
 
-						/// Sets the position indicator of the stream to position.
+	/// Sets the position indicator of the stream to position.
 	virtual void		seek(size_t position) = 0;
 
-						/// Sets the position indicator to the end of the stream
+	/// Sets the position indicator to the end of the stream
 	virtual void		seek_to_end() = 0;
 
-						/// Sets the position indicator to bytes after current position
+	/// Sets the position indicator to bytes after current position
 	virtual void		skip(size_t bytes) = 0;
 
-						/// Reads a byte from the stream starting at current position.
+	/// Reads a byte from the stream starting at current position.
 	virtual uint8_t		read_byte() = 0;
 
-						/// Reads a block of data from the stream.
+	/// Reads a block of data from the stream.
 	virtual void		read(void* buffer, size_t size) = 0;
 
-						/// Writes a byte to the stream starting at current position.
+	/// Writes a byte to the stream starting at current position.
 	virtual void		write_byte(uint8_t val) = 0;
 
-						/// Writes a block of data to the stream.
+	/// Writes a block of data to the stream.
 	virtual void		write(const void* buffer, size_t size) = 0;
 
-						/// Copies a chunk of 'size' bytes of data from this to another stream.
+	/// Copies a chunk of 'size' bytes of data from this to another stream.
 	virtual bool		copy_to(Stream* stream, size_t size = 0) = 0;
 
-						/// Zips a chunk of 'size' bytes of data from this to another stream using compressor.
+	/// Zips a chunk of 'size' bytes of data from this to another stream using compressor.
 	virtual bool		compress_to(Stream* stream, size_t size, size_t& compressed_size, Compressor* compressor);
 
-						/// Unzip a zipped stream of data from this to another stream using compressor.
+	/// Unzip a zipped stream of data from this to another stream using compressor.
 	virtual bool		uncompress_to(Stream* stream, size_t& uncompressed_size, Compressor* compressor);
 
-						/// Forces the previouses write operations to complete.
-						/// Generally, when a Stream is attached to a file,
-						/// write operations are not performed instantly, the output data
-						/// may be stored to a temporary buffer before making its way to
-						/// the file. This method forces all the pending output operations
-						/// to be written to the stream.
+	/// Forces the previouses write operations to complete.
+	/// Generally, when a Stream is attached to a file,
+	/// write operations are not performed instantly, the output data
+	/// may be stored to a temporary buffer before making its way to
+	/// the file. This method forces all the pending output operations
+	/// to be written to the stream.
 	virtual void		flush() = 0;
 
-						/// Returns whether the stream is valid.
-						/// A stream is valid when the buffer where it operates
-						/// exists. (i.e. a file descriptor is attached to the stream, 
-						/// a memory area is attached to the stream etc.)
+	/// Returns whether the stream is valid.
+	/// A stream is valid when the buffer where it operates
+	/// exists. (i.e. a file descriptor is attached to the stream, 
+	/// a memory area is attached to the stream etc.)
 	virtual bool		is_valid() const = 0;
 
-						/// Returns whether the position is at end of stream.
+	/// Returns whether the position is at end of stream.
 	virtual bool		end_of_stream() const = 0;
 
-						/// Returns the size of stream in bytes.
+	/// Returns the size of stream in bytes.
 	virtual size_t		size() const = 0;
 
-						/// Returns the current position in stream.
-						/// Generally, for binary data, it means the number of bytes
-						/// from the beginning of the stream.
+	/// Returns the current position in stream.
+	/// Generally, for binary data, it means the number of bytes
+	/// from the beginning of the stream.
 	virtual size_t		position() const = 0;
 
-						/// Returns whether the stream can be read.
+	/// Returns whether the stream can be read.
 	virtual bool		can_read() const = 0;
 
-						/// Returns whether the stream can be wrote.
+	/// Returns whether the stream can be wrote.
 	virtual bool		can_write() const = 0;
 
-						/// Returns whether the stream can be sought.
+	/// Returns whether the stream can be sought.
 	virtual bool		can_seek() const = 0;
 
 protected:

+ 9 - 8
src/core/streams/TextReader.h

@@ -39,16 +39,17 @@ public:
 						TextReader(Stream* s);
 						~TextReader();
 
+	/// Read a single character from the stream
 	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.
+	/// 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:

+ 6 - 6
src/core/streams/TextWriter.h

@@ -37,13 +37,13 @@ public:
 						TextWriter(Stream* s);
 	virtual				~TextWriter();
 
+	/// Writes a single character to the stream.
 	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.
-						*/
+	
+	/// 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: