Daniele Bartolini преди 10 години
родител
ревизия
104180ccfd
променени са 6 файла, в които са добавени 78 реда и са изтрити 117 реда
  1. 15 20
      src/core/filesystem/apk_file.cpp
  2. 9 12
      src/core/filesystem/apk_file.h
  3. 15 24
      src/core/filesystem/disk_file.cpp
  4. 9 13
      src/core/filesystem/disk_file.h
  5. 15 22
      src/core/filesystem/file.h
  6. 15 26
      src/core/filesystem/null_file.h

+ 15 - 20
src/core/filesystem/apk_file.cpp

@@ -41,6 +41,21 @@ void ApkFile::close()
 	}
 	}
 }
 }
 
 
+u32 ApkFile::size()
+{
+	return AAsset_getLength(_asset);
+}
+
+u32 ApkFile::position()
+{
+	return u32(AAsset_getLength(_asset) - AAsset_getRemainingLength(_asset));
+}
+
+bool ApkFile::end_of_file()
+{
+	return AAsset_getRemainingLength(_asset) == 0;
+}
+
 void ApkFile::seek(u32 position)
 void ApkFile::seek(u32 position)
 {
 {
 	off_t seek_result = AAsset_seek(_asset, (off_t)position, SEEK_SET);
 	off_t seek_result = AAsset_seek(_asset, (off_t)position, SEEK_SET);
@@ -79,26 +94,6 @@ void ApkFile::flush()
 	// Not needed
 	// Not needed
 }
 }
 
 
-bool ApkFile::is_valid()
-{
-	return _asset != NULL;
-}
-
-bool ApkFile::end_of_file()
-{
-	return AAsset_getRemainingLength(_asset) == 0;
-}
-
-u32 ApkFile::size()
-{
-	return AAsset_getLength(_asset);
-}
-
-u32 ApkFile::position()
-{
-	return (u32)(AAsset_getLength(_asset) - AAsset_getRemainingLength(_asset));
-}
-
 } // namespace crown
 } // namespace crown
 
 
 #endif // CROWN_PLATFORM_ANDROID
 #endif // CROWN_PLATFORM_ANDROID

+ 9 - 12
src/core/filesystem/apk_file.h

@@ -34,6 +34,15 @@ public:
 	/// @copydoc File::close()
 	/// @copydoc File::close()
 	void close();
 	void close();
 
 
+	/// @copydoc File::size()
+	u32 size();
+
+	/// @copydoc File::position()
+	u32 position();
+
+	/// @copydoc File::end_of_file()
+	bool end_of_file();
+
 	/// @copydoc File::seek()
 	/// @copydoc File::seek()
 	void seek(u32 position);
 	void seek(u32 position);
 
 
@@ -51,18 +60,6 @@ public:
 
 
 	/// @copydoc File::flush()
 	/// @copydoc File::flush()
 	void flush();
 	void flush();
-
-	/// @copydoc File::is_valid()
-	bool is_valid();
-
-	/// @copydoc File::end_of_file()
-	bool end_of_file();
-
-	/// @copydoc File::size()
-	u32 size();
-
-	/// @copydoc File::position()
-	u32 position();
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 15 - 24
src/core/filesystem/disk_file.cpp

@@ -7,10 +7,6 @@
 
 
 namespace crown
 namespace crown
 {
 {
-DiskFile::DiskFile()
-{
-}
-
 DiskFile::~DiskFile()
 DiskFile::~DiskFile()
 {
 {
 	close();
 	close();
@@ -26,6 +22,21 @@ void DiskFile::close()
 	_file.close();
 	_file.close();
 }
 }
 
 
+u32 DiskFile::size()
+{
+	return _file.size();
+}
+
+u32 DiskFile::position()
+{
+	return _file.position();
+}
+
+bool DiskFile::end_of_file()
+{
+	return position() == size();
+}
+
 void DiskFile::seek(u32 position)
 void DiskFile::seek(u32 position)
 {
 {
 	_file.seek(position);
 	_file.seek(position);
@@ -51,29 +62,9 @@ u32 DiskFile::write(const void* data, u32 size)
 	return _file.write(data, size);
 	return _file.write(data, size);
 }
 }
 
 
-bool DiskFile::end_of_file()
-{
-	return position() == size();
-}
-
-bool DiskFile::is_valid()
-{
-	return _file.is_open();
-}
-
 void DiskFile::flush()
 void DiskFile::flush()
 {
 {
 	_file.flush();
 	_file.flush();
 }
 }
 
 
-u32 DiskFile::position()
-{
-	return _file.position();
-}
-
-u32 DiskFile::size()
-{
-	return _file.size();
-}
-
 } // namespace crown
 } // namespace crown

+ 9 - 13
src/core/filesystem/disk_file.h

@@ -19,7 +19,6 @@ class DiskFile: public File
 
 
 public:
 public:
 
 
-	DiskFile();
 	virtual ~DiskFile();
 	virtual ~DiskFile();
 
 
 	/// @copydoc File::open()
 	/// @copydoc File::open()
@@ -28,6 +27,15 @@ public:
 	/// @copydoc File::close()
 	/// @copydoc File::close()
 	void close();
 	void close();
 
 
+	/// @copydoc File::size()
+	u32 size();
+
+	/// @copydoc File::position()
+	u32 position();
+
+	/// @copydoc File::end_of_file()
+	bool end_of_file();
+
 	/// @copydoc File::seek()
 	/// @copydoc File::seek()
 	void seek(u32 position);
 	void seek(u32 position);
 
 
@@ -45,18 +53,6 @@ public:
 
 
 	/// @copydoc File::flush()
 	/// @copydoc File::flush()
 	void flush();
 	void flush();
-
-	/// @copydoc File::end_of_file()
-	bool end_of_file();
-
-	/// @copydoc File::is_valid()
-	bool is_valid();
-
-	/// @copydoc File::size()
-	u32 size();
-
-	/// @copydoc File::position()
-	u32 position();
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 15 - 22
src/core/filesystem/file.h

@@ -26,40 +26,33 @@ public:
 	/// Closes the file.
 	/// Closes the file.
 	virtual void close() = 0;
 	virtual void close() = 0;
 
 
-	/// Sets the position indicator of the file to position.
+	/// Returns the size of file in bytes.
+	virtual u32 size() = 0;
+
+	/// Returns the number of bytes from the beginning of the file
+	/// to the cursor position.
+	virtual u32 position() = 0;
+
+	/// Returns whether the position is at end of file.
+	virtual bool end_of_file() = 0;
+
+	/// Sets the cursor to @a position.
 	virtual void seek(u32 position) = 0;
 	virtual void seek(u32 position) = 0;
 
 
-	/// Sets the position indicator to the end of the file
+	/// Sets the cursor position to the end of the file.
 	virtual void seek_to_end() = 0;
 	virtual void seek_to_end() = 0;
 
 
-	/// Sets the position indicator to bytes after current position
+	/// Sets the cursor position to @a bytes after current position.
 	virtual void skip(u32 bytes) = 0;
 	virtual void skip(u32 bytes) = 0;
 
 
-	/// Reads a block of data from the file.
+	/// Reads @a size bytes from file.
 	virtual u32 read(void* data, u32 size) = 0;
 	virtual u32 read(void* data, u32 size) = 0;
 
 
-	/// Writes a block of data to the file.
+	/// Writes @a size bytes to file.
 	virtual u32 write(const void* data, u32 size) = 0;
 	virtual u32 write(const void* data, u32 size) = 0;
 
 
 	/// Forces the previouses write operations to complete.
 	/// Forces the previouses write operations to complete.
 	virtual void flush() = 0;
 	virtual void flush() = 0;
-
-	/// Returns whether the file is valid.
-	/// A file is valid when the buffer where it operates
-	/// exists. (i.e. a file descriptor is attached to the file,
-	/// a memory area is attached to the file etc.)
-	virtual bool is_valid() = 0;
-
-	/// Returns whether the position is at end of file.
-	virtual bool end_of_file() = 0;
-
-	/// Returns the size of file in bytes.
-	virtual u32 size() = 0;
-
-	/// Returns the current position in file.
-	/// Generally, for binary data, it means the number of bytes
-	/// from the beginning of the file.
-	virtual u32 position() = 0;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 15 - 26
src/core/filesystem/null_file.h

@@ -17,18 +17,27 @@ class NullFile: public File
 {
 {
 public:
 public:
 
 
-	/// @copydoc File::File()
-	NullFile() {}
-
-	/// @copydoc File::~File()
-	virtual ~NullFile() {}
-
 	/// @copydoc File::open()
 	/// @copydoc File::open()
 	void open(const char* /*path*/, FileOpenMode::Enum /*mode*/) {}
 	void open(const char* /*path*/, FileOpenMode::Enum /*mode*/) {}
 
 
 	/// @copydoc File::close()
 	/// @copydoc File::close()
 	void close() {}
 	void close() {}
 
 
+	/// @copydoc File::size()
+	/// @note
+	///	Returns always 0xFFFFFFFF
+	u32 size() { return ~0; }
+
+	/// @copydoc File::position()
+	/// @note
+	///	Returns always zero
+	u32 position() { return 0; }
+
+	/// @copydoc File::end_of_file()
+	/// @note
+	///	Returns always false
+	bool end_of_file() { return false; }
+
 	/// @copydoc File::seek()
 	/// @copydoc File::seek()
 	void seek(u32 position) { (void)position; }
 	void seek(u32 position) { (void)position; }
 
 
@@ -58,26 +67,6 @@ public:
 
 
 	/// @copydoc File::flush()
 	/// @copydoc File::flush()
 	void flush() {};
 	void flush() {};
-
-	/// @copydoc File::is_valid()
-	/// @note
-	///	Returns always true
-	bool is_valid() { return true; }
-
-	/// @copydoc File::end_of_file()
-	/// @note
-	///	Returns always false
-	bool end_of_file() { return false; }
-
-	/// @copydoc File::size()
-	/// @note
-	///	Returns always 0xFFFFFFFF
-	u32 size() { return ~0; }
-
-	/// @copydoc File::position()
-	/// @note
-	///	Returns always zero
-	u32 position() { return 0; }
 };
 };
 
 
 } // namespace crown
 } // namespace crown