Daniele Bartolini 12 лет назад
Родитель
Сommit
3b3a1b9d31

+ 0 - 102
engine/core/filesystem/BinaryReader.cpp

@@ -1,102 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "File.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-BinaryReader::BinaryReader(File& file) : m_file(file)
-{
-}
-
-//-----------------------------------------------------------------------------
-int8_t BinaryReader::read_byte()
-{
-	int8_t buffer;
-	m_file.read(&buffer, sizeof(int8_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-int16_t BinaryReader::read_int16()
-{
-	int16_t buffer;
-	m_file.read(&buffer, sizeof(int16_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-uint16_t BinaryReader::read_uint16()
-{
-	uint16_t buffer;
-	m_file.read(&buffer, sizeof(uint16_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-int32_t BinaryReader::read_int32()
-{
-	int32_t buffer;
-	m_file.read(&buffer, sizeof(int32_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-uint32_t BinaryReader::read_uint32()
-{
-	uint32_t buffer;
-	m_file.read(&buffer, sizeof(uint32_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-int64_t BinaryReader::read_int64()
-{
-	int64_t buffer;
-	m_file.read(&buffer, sizeof(int64_t));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-double BinaryReader::read_double()
-{
-	double buffer;
-	m_file.read(&buffer, sizeof(double));
-	return buffer;
-}
-
-//-----------------------------------------------------------------------------
-float BinaryReader::read_float()
-{
-	float buffer;
-	m_file.read(&buffer, sizeof(float));
-	return buffer;
-}
-
-} // namespace crown

+ 66 - 10
engine/core/filesystem/BinaryReader.h

@@ -36,20 +36,76 @@ class BinaryReader
 {
 public:
 
-						BinaryReader(File& file);
+	//-----------------------------------------------------------------------------
+	BinaryReader(File& file) : m_file(file) {}
 
-	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();
+	//-----------------------------------------------------------------------------
+	int8_t read_byte()
+	{
+		int8_t buffer;
+		m_file.read(&buffer, sizeof(int8_t));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	int16_t read_int16()
+	{
+		int16_t buffer;
+		m_file.read(&buffer, sizeof(int16_t));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	uint16_t read_uint16()
+	{
+		uint16_t buffer;
+		m_file.read(&buffer, sizeof(uint16_t));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	int32_t read_int32()
+	{
+		int32_t buffer;
+		m_file.read(&buffer, sizeof(int32_t));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	uint32_t read_uint32()
+	{
+		uint32_t buffer;
+		m_file.read(&buffer, sizeof(uint32_t));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	int64_t read_int64()
+	{
+		int64_t buffer;
+		m_file.read(&buffer, sizeof(int64_t));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	double read_double()
+	{
+		double buffer;
+		m_file.read(&buffer, sizeof(double));
+		return buffer;
+	}
+
+	//-----------------------------------------------------------------------------
+	float read_float()
+	{
+		float buffer;
+		m_file.read(&buffer, sizeof(float));
+		return buffer;
+	}
 
 private:
 
-	File&				m_file;
+	File& m_file;
 };
 
 } // namespace crown

+ 0 - 87
engine/core/filesystem/BinaryWriter.cpp

@@ -1,87 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "File.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-BinaryWriter::BinaryWriter(File& file) : m_file(file)
-{
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_byte(int8_t buffer)
-{
-	m_file.write(&buffer, sizeof(int8_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_int16(int16_t buffer)
-{
-	m_file.write(&buffer, sizeof(int16_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_uint16(uint16_t buffer)
-{
-	m_file.write(&buffer, sizeof(uint16_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_int32(int32_t buffer)
-{
-	m_file.write(&buffer, sizeof(int32_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_uint32(uint32_t buffer)
-{
-	m_file.write(&buffer, sizeof(uint32_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_int64(int64_t buffer)
-{
-	m_file.write(&buffer, sizeof(int64_t));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_double(double buffer)
-{
-	m_file.write(&buffer, sizeof(double));
-}
-
-//-----------------------------------------------------------------------------
-void BinaryWriter::write_float(float buffer)
-{
-	m_file.write(&buffer, sizeof(float));
-}
-
-} // namespace crown
-

+ 50 - 10
engine/core/filesystem/BinaryWriter.h

@@ -36,20 +36,60 @@ class BinaryWriter
 {
 public:
 
-						BinaryWriter(File& file);
+	//-----------------------------------------------------------------------------
+	BinaryWriter(File& file) : m_file(file) {}
 
-	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 write_byte(int8_t buffer)
+	{
+		m_file.write(&buffer, sizeof(int8_t));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_int16(int16_t buffer)
+	{
+		m_file.write(&buffer, sizeof(int16_t));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_uint16(uint16_t buffer)
+	{
+		m_file.write(&buffer, sizeof(uint16_t));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_int32(int32_t buffer)
+	{
+		m_file.write(&buffer, sizeof(int32_t));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_uint32(uint32_t buffer)
+	{
+		m_file.write(&buffer, sizeof(uint32_t));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_int64(int64_t buffer)
+	{
+		m_file.write(&buffer, sizeof(int64_t));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_double(double buffer)
+	{
+		m_file.write(&buffer, sizeof(double));
+	}
+
+	//-----------------------------------------------------------------------------
+	void write_float(float buffer)
+	{
+		m_file.write(&buffer, sizeof(float));
+	}
 
 private:
 
-	File&				m_file;
+	File& m_file;
 };
 
 } // namespace crown

+ 0 - 64
engine/core/filesystem/TextReader.cpp

@@ -1,64 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "File.h"
-#include "Types.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-TextReader::TextReader(File& file) : m_file(file)
-{
-}
-
-//-----------------------------------------------------------------------------
-size_t TextReader::read_string(char* string, size_t size)
-{
-	char current_char;
-	size_t bytes_read = 0;
-
-	while(!m_file.end_of_file() && bytes_read < size - 1)
-	{
-		m_file.read(&current_char, 1);
-		string[bytes_read] = current_char;
-
-		bytes_read++;
-
-		if (current_char == '\n')
-		{
-			break;
-		}
-	}
-
-	string[bytes_read] = '\0';
-
-	return bytes_read;
-}
-
-} // namespace crown
-

+ 27 - 3
engine/core/filesystem/TextReader.h

@@ -36,7 +36,10 @@ class TextReader
 {
 public:
 
-						TextReader(File& file);
+	//-----------------------------------------------------------------------------
+	TextReader::TextReader(File& file) : m_file(file)
+	{
+	}
 
 	/// Reads characters from file and stores them as a C string
 	/// into string until (size-1) characters have been read or
@@ -46,11 +49,32 @@ public:
 	/// 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.
-	size_t				read_string(char* string, size_t size);
+	size_t TextReader::read_string(char* string, size_t size)
+	{
+		char current_char;
+		size_t bytes_read = 0;
+
+		while(!m_file.end_of_file() && bytes_read < size - 1)
+		{
+			m_file.read(&current_char, 1);
+			string[bytes_read] = current_char;
+
+			bytes_read++;
+
+			if (current_char == '\n')
+			{
+				break;
+			}
+		}
+
+		string[bytes_read] = '\0';
+
+		return bytes_read;
+	}
 
 private:
 
-	File&				m_file;
+	File& m_file;
 };
 
 } // namespace crown

+ 0 - 46
engine/core/filesystem/TextWriter.cpp

@@ -1,46 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "File.h"
-#include "StringUtils.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-TextWriter::TextWriter(File& file) : m_file(file)
-{
-}
-
-//-----------------------------------------------------------------------------
-void TextWriter::write_string(const char* string)
-{
-	m_file.write(string, string::strlen(string));
-}
-
-} // namespace crown
-

+ 10 - 4
engine/core/filesystem/TextWriter.h

@@ -34,17 +34,23 @@ class TextWriter
 {
 public:
 
-						TextWriter(File& file);
-	
+	//-----------------------------------------------------------------------------
+	TextWriter(File& file) : m_file(file)
+	{
+	}
+
 	/// Writes the string pointed by string to the file.
 	/// The function begins copying from the address specified (string)
 	/// until it reaches the terminating null character ('\0').
 	/// The final null character is not copied to the file.
-	void				write_string(const char* string);
+	void write_string(const char* string)
+	{
+		m_file.write(string, string::strlen(string));
+	}
 
 private:
 
-	File&				m_file;
+	File& m_file;
 };
 
 } // namespace crown