Skip to content

Commit 94fe5e5

Browse files
authored
feat(file): Add flush function to LocalFile (#1385)
1 parent 9aa57e8 commit 94fe5e5

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

Core/GameEngine/Include/Common/LocalFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class LocalFile : public File
101101
virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read
102102
virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write
103103
virtual Int seek( Int new_pos, seekMode mode = CURRENT ); ///< Set file position: See File::seek
104+
virtual Bool flush(); ///< flush data to disk
104105
virtual void nextLine(Char *buf = NULL, Int bufSize = 0); ///< moves file position to after the next new-line
105106
virtual Bool scanInt(Int &newInt); ///< return what gets read in as an integer at the current file position.
106107
virtual Bool scanReal(Real &newReal); ///< return what gets read in as a float at the current file position.

Core/GameEngine/Include/Common/RAMFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class RAMFile : public File
9292
virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read
9393
virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write
9494
virtual Int seek( Int new_pos, seekMode mode = CURRENT ); ///< Set file position: See File::seek
95+
virtual Bool flush(); ///< flush data to disk
9596
virtual void nextLine(Char *buf = NULL, Int bufSize = 0); ///< moves current position to after the next new-line
9697

9798
virtual Bool scanInt(Int &newInt); ///< return what gets read as an integer from the current memory position.

Core/GameEngine/Include/Common/file.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ class File : public MemoryPoolObject
147147
virtual Bool open( const Char *filename, Int access = NONE, size_t bufferSize = BUFFERSIZE ); ///< Open a file for access
148148
virtual void close( void ); ///< Close the file !!! File object no longer valid after this call !!!
149149

150-
virtual Int read( void *buffer, Int bytes ) = NULL ; /**< Read the specified number of bytes from the file in to the
150+
virtual Int read( void *buffer, Int bytes ) = 0 ; /**< Read the specified number of bytes from the file in to the
151151
* memory pointed at by buffer. Returns the number of bytes read.
152152
* Returns -1 if an error occurred.
153153
*/
154-
virtual Int write( const void *buffer, Int bytes ) = NULL ; /**< Write the specified number of bytes from the
154+
virtual Int write( const void *buffer, Int bytes ) = 0 ; /**< Write the specified number of bytes from the
155155
* memory pointed at by buffer to the file. Returns the number of bytes written.
156156
* Returns -1 if an error occurred.
157157
*/
158-
virtual Int seek( Int bytes, seekMode mode = CURRENT ) = NULL; /**< Sets the file position of the next read/write operation. Returns the new file
158+
virtual Int seek( Int bytes, seekMode mode = CURRENT ) = 0; /**< Sets the file position of the next read/write operation. Returns the new file
159159
* position as the number of bytes from the start of the file.
160160
* Returns -1 if an error occurred.
161161
*
@@ -165,6 +165,7 @@ class File : public MemoryPoolObject
165165
* CURRENT: means seek the specified the number of bytes from the current file position
166166
* END: means seek the specified number of bytes back from the end of the file
167167
*/
168+
virtual Bool flush() = 0; ///< flush data to disk
168169
virtual void nextLine(Char *buf = NULL, Int bufSize = 0) = 0; ///< reads until it reaches a new-line character
169170

170171
virtual Bool scanInt(Int &newInt) = 0; ///< read an integer from the current file position.

Core/GameEngine/Source/Common/System/LocalFile.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,15 @@ Int LocalFile::seek( Int pos, seekMode mode)
418418
return ret;
419419
}
420420

421+
//=================================================================
422+
// LocalFile::flush
423+
//=================================================================
424+
425+
Bool LocalFile::flush()
426+
{
427+
return fflush(m_file) != EOF;
428+
}
429+
421430
//=================================================================
422431
// LocalFile::scanInt
423432
//=================================================================

Core/GameEngine/Source/Common/System/RAMFile.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ Int RAMFile::seek( Int pos, seekMode mode)
334334

335335
}
336336

337+
//=================================================================
338+
// RAMFile::flush
339+
//=================================================================
340+
341+
Bool RAMFile::flush()
342+
{
343+
return false;
344+
}
345+
337346
//=================================================================
338347
// RAMFile::scanInt
339348
//=================================================================

0 commit comments

Comments
 (0)