Selaa lähdekoodia

Filesystem is now an abstract interface, FileSource is replaced by Filesystem and DiskFileSource is not DiskFilesystem

Daniele Bartolini 12 vuotta sitten
vanhempi
sitoutus
844aeb9adc

+ 3 - 3
engine/CMakeLists.txt

@@ -151,19 +151,19 @@ set (MATH_HEADERS
 set (FILESYSTEM_SRC
 	core/filesystem/File.cpp
 	core/filesystem/DiskFile.cpp
-	core/filesystem/DiskFileSource.cpp
+	core/filesystem/DiskFilesystem.cpp
 )
 
 set (FILESYSTEM_HEADERS
 	core/filesystem/File.h
 	core/filesystem/NullFile.h
 	core/filesystem/DiskFile.h
-	core/filesystem/DiskFileSource.h
-	core/filesystem/Filesystem.h
 	core/filesystem/BinaryReader.h
 	core/filesystem/BinaryWriter.h
 	core/filesystem/TextReader.h
 	core/filesystem/TextWriter.h
+	core/filesystem/Filesystem.h
+	core/filesystem/DiskFilesystem.h
 )
 
 set (JSON_SRC

+ 11 - 14
engine/core/filesystem/DiskFileSource.cpp → engine/core/filesystem/DiskFilesystem.cpp

@@ -24,10 +24,9 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#include "DiskFileSource.h"
+#include "DiskFilesystem.h"
 #include "StringUtils.h"
 #include "TempAllocator.h"
-#include "DynamicString.h"
 #include "DiskFile.h"
 #include "OS.h"
 
@@ -35,15 +34,13 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-DiskFileSource::DiskFileSource()
-	: FileSource(true)
+DiskFilesystem::DiskFilesystem()
 {
 	string::strncpy(m_root_path, os::get_cwd(), MAX_PATH_LENGTH);
 }
 
 //-----------------------------------------------------------------------------
-DiskFileSource::DiskFileSource(const char* root_path)
-	: FileSource(true)
+DiskFilesystem::DiskFilesystem(const char* root_path)
 {
 	CE_ASSERT_NOT_NULL(root_path);
 
@@ -51,7 +48,7 @@ DiskFileSource::DiskFileSource(const char* root_path)
 }
 
 //-----------------------------------------------------------------------------
-File* DiskFileSource::open(const char* path, FileOpenMode mode)
+File* DiskFilesystem::open(const char* path, FileOpenMode mode)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -63,7 +60,7 @@ File* DiskFileSource::open(const char* path, FileOpenMode mode)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::close(File* file)
+void DiskFilesystem::close(File* file)
 {
 	CE_ASSERT_NOT_NULL(file);
 
@@ -71,7 +68,7 @@ void DiskFileSource::close(File* file)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::create_directory(const char* path)
+void DiskFilesystem::create_directory(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -83,7 +80,7 @@ void DiskFileSource::create_directory(const char* path)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::delete_directory(const char* path)
+void DiskFilesystem::delete_directory(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -95,7 +92,7 @@ void DiskFileSource::delete_directory(const char* path)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::create_file(const char* path)
+void DiskFilesystem::create_file(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -107,7 +104,7 @@ void DiskFileSource::create_file(const char* path)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::delete_file(const char* path)
+void DiskFilesystem::delete_file(const char* path)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -119,7 +116,7 @@ void DiskFileSource::delete_file(const char* path)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::list_files(const char* path, Vector<DynamicString>& files)
+void DiskFilesystem::list_files(const char* path, Vector<DynamicString>& files)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -131,7 +128,7 @@ void DiskFileSource::list_files(const char* path, Vector<DynamicString>& files)
 }
 
 //-----------------------------------------------------------------------------
-void DiskFileSource::get_absolute_path(const char* path, DynamicString& os_path)
+void DiskFilesystem::get_absolute_path(const char* path, DynamicString& os_path)
 {
 	if (os::is_absolute_path(path))
 	{

+ 5 - 10
engine/core/filesystem/DiskFileSource.h → engine/core/filesystem/DiskFilesystem.h

@@ -26,35 +26,30 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
-#include "File.h"
-#include "FileSource.h"
-#include "Vector.h"
-#include "DynamicString.h"
-#include "OS.h"
+#include "Filesystem.h"
+#include "OS.h" // For MAX_PATH_LENGTH
 
 namespace crown
 {
 
-class DynamicString;
-
 /// Access files on disk.
 /// All the file paths can be either relative or absolute.
 /// When a relative path is given, it is automatically translated
 /// to its absolute counterpart based on the file source's root path.
 /// Accessing files using absolute path directly is also possible,
 /// but platform-specific and thus generally not recommended.
-class DiskFileSource : public FileSource
+class DiskFilesystem : public Filesystem
 {
 public:
 
 	/// Sets the root path to the current working directory of
 	/// the engine executable.
-	DiskFileSource();
+	DiskFilesystem();
 
 	/// Sets the root path to the given @a root_path.
 	/// @note
 	/// The @a root_path must be absolute.
-	DiskFileSource(const char* root_path);
+	DiskFilesystem(const char* root_path);
 
 	/// Opens the file at the given @a path with the given @a mode.
 	File* open(const char* path, FileOpenMode mode);

+ 0 - 65
engine/core/filesystem/FileSource.h

@@ -1,65 +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.
-*/
-
-#pragma once
-
-#include "File.h"
-#include "Vector.h"
-#include "DynamicString.h"
-
-namespace crown
-{
-
-/// Abstract base class for providing access to files
-/// on a particular physical/logical device.
-class FileSource
-{
-public:
-
-	FileSource(bool can_write) : m_can_write(can_write) {}
-	virtual ~FileSource() {}
-
-	virtual File* open(const char* path, FileOpenMode mode) = 0;
-	virtual void close(File* file) = 0;
-
-	virtual void create_directory(const char* path) = 0;
-	virtual void delete_directory(const char* path) = 0;
-	virtual void create_file(const char* path) = 0;
-	virtual void delete_file(const char* path) = 0;
-	virtual void list_files(const char* path, Vector<DynamicString>& files) = 0;
-	virtual void get_absolute_path(const char* path, DynamicString& abs_path) = 0;
-
-	bool can_write() const
-	{
-		return m_can_write;
-	}
-
-protected:
-
-	bool m_can_write;
-};
-
-} // namespace crown

+ 1 - 0
engine/core/filesystem/Filesystem.h

@@ -82,6 +82,7 @@ class Filesystem
 {
 public:
 
+						Filesystem() {};
 	virtual				~Filesystem() {};
 
 	/// Opens the file at the given @a path with the given @a mode.