Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::CFile Class Reference

#include <cFile.h>

Inheritance diagram for Gray::CFile:
Gray::CObject Gray::cFile Gray::cFileText GrayLib::cFileMem GrayLib::cHeartbeatFile GrayLib::cScriptFileWriter GrayLib::cScriptFileReader

Public Member Functions

virtual ~CFile ()
 
virtual STREAM_SEEKRET_t Seek (STREAM_OFFSET_t lOffset=0, SEEK_ORIGIN_TYPE eSeekOrigin=SEEK_Set)
 
virtual STREAM_POS_t GetPosition () const
 
virtual STREAM_POS_t GetLength () const
 
virtual void SetLength (STREAM_SEEKRET_t dwNewLen)
 
virtual void Close ()
 
HRESULT Write (const void *pData, size_t nDataSize)
 
HRESULT Read (void *pData, size_t nDataSize)
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 

Public Attributes

cOSHandle m_hFile
 OSHandle for the open file. More...
 

Protected Member Functions

bool isFileOpen () const noexcept
 
HRESULT OpenCreate (cStringF sFilePath="", OF_FLAGS_t nOpenFlags=OF_CREATE|OF_WRITE, _SECURITY_ATTRIBUTES *pSa=nullptr)
 

Protected Attributes

cStringF m_strFileName
 store a copy of the full file path. MFC defined name. More...
 

Detailed Description

try to be compatible with MFC CFile class.

Note
Don't use this directly. Use cFile.

Constructor & Destructor Documentation

◆ ~CFile()

virtual Gray::CFile::~CFile ( )
inlinevirtual

Member Function Documentation

◆ Close()

virtual void Gray::CFile::Close ( void  )
inlinevirtual

Reimplemented in Gray::cFileText, and Gray::cFile.

◆ GetLength()

STREAM_POS_t Gray::CFile::GetLength ( ) const
virtual

Get the size of the open file in bytes. like MFC

Returns
<0 = error. (or directory?)

Reimplemented in GrayLib::cFileMem, and Gray::cFile.

◆ GetPosition()

STREAM_POS_t Gray::CFile::GetPosition ( ) const
virtual

Get the current read position in the file. Seek( 0, SEEK_CUR ) like MFC Use _tell( m_hFile ) for linux ?

Reimplemented in GrayLib::cFileMem, Gray::cFileText, and Gray::cFile.

◆ isFileOpen()

bool Gray::CFile::isFileOpen ( ) const
inlineprotectednoexcept

◆ OpenCreate()

HRESULT Gray::CFile::OpenCreate ( cStringF  sFilePath = "",
OF_FLAGS_t  nOpenFlags = OF_CREATE | OF_WRITE,
_SECURITY_ATTRIBUTES *  pSa = nullptr 
)
protected

Open a file handle.

  1. OF_EXIST = just test if this file exists, don't really open it.
  2. OF_READ = open for read. file must exist.
  3. OF_WRITE = open for over write. file must exist unless OF_CREATE is set.
  4. OF_READWRITE = open file for write append. file must exist unless OF_CREATE is set. | OF_CREATE = create. wipe any existing file. | OF_TEXT = this is really a FILE* handle on "t" mode. else OF_BINARY | OF_CACHE_SEQ = we read this sequentially only. no seek will be used. FILE_FLAG_SEQUENTIAL_SCAN OF_READWRITE | OF_CREATE = Open for write but create if it does not already exist.

◆ Read()

HRESULT Gray::CFile::Read ( void *  pData,
size_t  nDataSize 
)
inline

◆ Seek()

STREAM_SEEKRET_t Gray::CFile::Seek ( STREAM_OFFSET_t  lOffset = 0,
SEEK_ORIGIN_TYPE  eSeekOrigin = SEEK_Set 
)
virtual

Change or get the current file position pointer. Compatible with MFC definition. Might be 'const' but MFC wont allow that

  • eSeekOrigin = // SEEK_SET ?
    Returns
    the New position, -1=FAILED

Reimplemented in Gray::cFileText, GrayLib::cFileMem, and Gray::cFile.

◆ SetLength()

void Gray::CFile::SetLength ( STREAM_SEEKRET_t  dwNewLen)
virtual

Grow/Shrink the file. Stupid MFC has void return. use HResult::GetLast()

Reimplemented in GrayLib::cFileMem.

◆ Write()

HRESULT Gray::CFile::Write ( const void *  pData,
size_t  nDataSize 
)

Write a block to the stream. advance the current position. Like WriteX

Returns
length written. <0 = FAILED ERROR_INVALID_USER_BUFFER = too many async calls ?? wait ERROR_IO_PENDING = must wait!?

Member Data Documentation

◆ m_hFile

cOSHandle Gray::CFile::m_hFile

OSHandle for the open file.

◆ m_strFileName

cStringF Gray::CFile::m_strFileName
protected

store a copy of the full file path. MFC defined name.


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