jaffarCommon
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
jaffarCommon::file::MemoryFile Class Reference

#include <file.hpp>

Public Member Functions

 MemoryFile (const MemoryFile &)=delete
 
void operator= (const MemoryFile &)=delete
 
 ~MemoryFile ()
 
__JAFFAR_COMMON__INLINE__ void setReadOnly ()
 
__JAFFAR_COMMON__INLINE__ void unsetReadOnly ()
 
__JAFFAR_COMMON__INLINE__ void setWriteOnly ()
 
__JAFFAR_COMMON__INLINE__ void unsetWriteOnly ()
 
__JAFFAR_COMMON__INLINE__ void setOpened ()
 
__JAFFAR_COMMON__INLINE__ void unsetOpened ()
 
__JAFFAR_COMMON__INLINE__ bool isReadOnly () const
 
__JAFFAR_COMMON__INLINE__ bool isWriteOnly () const
 
__JAFFAR_COMMON__INLINE__ bool isOpened () const
 
__JAFFAR_COMMON__INLINE__ void setWriteCallback (const std::function< void(const int64_t, MemoryFile *)> callback)
 
__JAFFAR_COMMON__INLINE__ void setReadCallback (const std::function< void(const int64_t, MemoryFile *)> callback)
 
__JAFFAR_COMMON__INLINE__ void unsetWriteCallback ()
 
__JAFFAR_COMMON__INLINE__ void unsetReadCallback ()
 
__JAFFAR_COMMON__INLINE__ int resize (const size_t newSize)
 
__JAFFAR_COMMON__INLINE__ void setSize (const size_t size)
 
__JAFFAR_COMMON__INLINE__ size_t getSize () const
 

Static Public Member Functions

static __JAFFAR_COMMON__INLINE__ int64_t fread (void *const buffer, const size_t size, const size_t count, MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ int64_t fwrite (const void *buffer, const size_t size, const size_t count, MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ int64_t ftello64 (MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ int64_t ftell (MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ void rewind (MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ int fflush (MemoryFile *file)
 
static __JAFFAR_COMMON__INLINE__ int fseeko64 (MemoryFile *const file, const int64_t offset, const int origin)
 
static __JAFFAR_COMMON__INLINE__ int fseek (MemoryFile *const file, const int64_t offset, const int origin)
 
static __JAFFAR_COMMON__INLINE__ int feof (MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ void clearerr (MemoryFile *const file)
 
static __JAFFAR_COMMON__INLINE__ int ferror (MemoryFile *const file)
 

Friends

class MemoryFileDirectory
 

Detailed Description

Represents a file object that exists entirely in memory. It exposes a C-like interface for light refactoring of programs that depend on accessing the filesystem directly

Constructor & Destructor Documentation

◆ ~MemoryFile()

jaffarCommon::file::MemoryFile::~MemoryFile ( )
inline

Destructor for the memory file class. it frees the buffer created at allocation time

Member Function Documentation

◆ clearerr()

static __JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::clearerr ( MemoryFile *const  file)
inlinestatic

Clears the error code(s)

Parameters
[in]fileThe file to clear errors for

◆ feof()

static __JAFFAR_COMMON__INLINE__ int jaffarCommon::file::MemoryFile::feof ( MemoryFile *const  file)
inlinestatic

Indicates whether we've reached the end of file

Parameters
[in]fileThe file to inquire for end of file
Returns
Non-zero, if the end has been reached. Zero, otherwise.

◆ ferror()

static __JAFFAR_COMMON__INLINE__ int jaffarCommon::file::MemoryFile::ferror ( MemoryFile *const  file)
inlinestatic

Returns the value of the internal error value corresponding to the last operation

Parameters
[in]fileThe file to check errors for
Returns
Zero, if last operation was successful. Non-zero, otherwise.

◆ fflush()

static __JAFFAR_COMMON__INLINE__ int jaffarCommon::file::MemoryFile::fflush ( MemoryFile file)
inlinestatic

Ensures the write operations have finished. No effect for mem buffers as all operations finish within their call.

Parameters
[in]fileThe file to flush
Returns
Zero in case of success. -1 in case of error

◆ fread()

static __JAFFAR_COMMON__INLINE__ int64_t jaffarCommon::file::MemoryFile::fread ( void *const  buffer,
const size_t  size,
const size_t  count,
MemoryFile *const  file 
)
inlinestatic

Reads from the mem file into a buffer.

Reading advances the internal head for as many bytes as size*count, until the end of file.

Parameters
[in]bufferThe buffer onto which to copy the data
[in]sizeThe size of each element to copy
[in]countThe number of elements to copy
[in]fileThe memory file from which to read
Returns
The number of bytes read. Negative in case of error.

◆ fseek()

static __JAFFAR_COMMON__INLINE__ int jaffarCommon::file::MemoryFile::fseek ( MemoryFile *const  file,
const int64_t  offset,
const int  origin 
)
inlinestatic

Ensures the write operations have finished. No effect for mem buffers as all operations finish within their call.

Parameters
[in]fileThe file whose head to move
[in]offsetThe number of bytes to move the internal head
[in]originThe point relative to which we apply the offset
Returns
Zero in case of success. -1 in case of error

◆ fseeko64()

static __JAFFAR_COMMON__INLINE__ int jaffarCommon::file::MemoryFile::fseeko64 ( MemoryFile *const  file,
const int64_t  offset,
const int  origin 
)
inlinestatic

(mirror for fseek - has no different effect or interface) Ensures the write operations have finished. No effect for mem buffers as all operations finish within their call.

Parameters
[in]fileThe file whose head to move
[in]offsetThe number of bytes to move the internal head
[in]originThe point relative to which we apply the offset
Returns
Zero in case of success. -1 in case of error

◆ ftell()

static __JAFFAR_COMMON__INLINE__ int64_t jaffarCommon::file::MemoryFile::ftell ( MemoryFile *const  file)
inlinestatic

Returns the internal position of the file's head

Parameters
[in]fileThe file to evaluate
Returns
The internal position of the head. -1 if the file is not open

◆ ftello64()

static __JAFFAR_COMMON__INLINE__ int64_t jaffarCommon::file::MemoryFile::ftello64 ( MemoryFile *const  file)
inlinestatic

(mirror for ftell - has no different effect or interface) Returns the internal position of the file's head

Parameters
[in]fileThe file to evaluate
Returns
The internal position of the head. -1 if the file is not open

◆ fwrite()

static __JAFFAR_COMMON__INLINE__ int64_t jaffarCommon::file::MemoryFile::fwrite ( const void *  buffer,
const size_t  size,
const size_t  count,
MemoryFile *const  file 
)
inlinestatic

Writes into the mem file from a buffer

Writing advances the internal head for as many bytes as size*count, until the end of file.

Parameters
[in]bufferThe buffer from which to read the data
[in]sizeThe size of each element to copy
[in]countThe number of elements to copy
[in]fileThe memory file to write into
Returns
The number of bytes written. Negative in case of error.

◆ getSize()

__JAFFAR_COMMON__INLINE__ size_t jaffarCommon::file::MemoryFile::getSize ( ) const
inline

Function to get file size directly

Returns
The internal size to set

◆ isOpened()

__JAFFAR_COMMON__INLINE__ bool jaffarCommon::file::MemoryFile::isOpened ( ) const
inline

Gets the opened flag from the file

Returns
The file's opened flag

◆ isReadOnly()

__JAFFAR_COMMON__INLINE__ bool jaffarCommon::file::MemoryFile::isReadOnly ( ) const
inline

Gets the read-only flag from the file

Returns
The file's read-only flag

◆ isWriteOnly()

__JAFFAR_COMMON__INLINE__ bool jaffarCommon::file::MemoryFile::isWriteOnly ( ) const
inline

Gets the write-only flag from the file

Returns
The file's write-only flag

◆ resize()

__JAFFAR_COMMON__INLINE__ int jaffarCommon::file::MemoryFile::resize ( const size_t  newSize)
inline

Function to resize file It fills with zeroes any additional bytes allocated In case of shrinking, this operation keeps the internal buffer unchanged (no freed space).

Parameters
[in]newSizeThe new desired size for the file
Returns
Zero, if successful. Non-zero if an error ocurred.

◆ rewind()

static __JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::rewind ( MemoryFile *const  file)
inlinestatic

Resets the internal position of the file's head to the start of the file

Parameters
[in]fileThe file to rewind

◆ setOpened()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::setOpened ( )
inline

Sets the opened flag in the file

◆ setReadCallback()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::setReadCallback ( const std::function< void(const int64_t, MemoryFile *)>  callback)
inline

Sets a callback that will be called when a read is made

Parameters
[in]callbackRead-callback to set

◆ setReadOnly()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::setReadOnly ( )
inline

Sets the read only flag in the file

◆ setSize()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::setSize ( const size_t  size)
inline

Function to set size directly without resizing internal buffer – use at your own risk.

Parameters
[in]sizeThe internal size to set

◆ setWriteCallback()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::setWriteCallback ( const std::function< void(const int64_t, MemoryFile *)>  callback)
inline

Sets a callback that will be called when a write is made

Parameters
[in]callbackWrite-callback to set

◆ setWriteOnly()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::setWriteOnly ( )
inline

Sets the write only flag in the file

◆ unsetOpened()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::unsetOpened ( )
inline

Clears the opened flag from the file

◆ unsetReadCallback()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::unsetReadCallback ( )
inline

Function to unset the read callback

◆ unsetReadOnly()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::unsetReadOnly ( )
inline

Clears the read only flag from the file

◆ unsetWriteCallback()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::unsetWriteCallback ( )
inline

Function to unset the write callback

◆ unsetWriteOnly()

__JAFFAR_COMMON__INLINE__ void jaffarCommon::file::MemoryFile::unsetWriteOnly ( )
inline

Clears the read only flag from the file


The documentation for this class was generated from the following file: