Back to index

nux  3.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
nux::NGNUSerialFileReader Class Reference

#include <NFileManagerGNU.h>

Inheritance diagram for nux::NGNUSerialFileReader:
Inheritance graph
[legend]
Collaboration diagram for nux::NGNUSerialFileReader:
Collaboration graph
[legend]

List of all members.

Public Types

enum  {
  OutputErrorIfFail = 0x01, NoOverWrite = 0x02, OverWriteReadOnly = 0x04, Unbuffered = 0x08,
  Append = 0x10, Read = 0x20, Write = 0x40
}
enum  SeekPos { SeekStart = 0x00, SeekCurrent = 0x01, SeekEnd = 0x02 }

Public Member Functions

 NGNUSerialFileReader (int InFileDescriptor, LogOutputDevice &InError, int InSize)
 ~NGNUSerialFileReader ()
virtual bool Precache (int PrecacheOffset, int PrecacheSize)
virtual long long Seek (long long InPos, NSerializer::SeekPos seekpos)
virtual long long Tell ()
virtual long long GetFileSize ()
virtual bool Close ()
virtual void SerializeFinal (void *V, long long Length)
virtual bool isReader ()
virtual bool isWriter ()
virtual bool Precache (INT PrecacheOffset, INT PrecacheSize)
virtual void Flush ()
virtual bool GetError ()
NSerializerByteOrderSerialize (void *V, INT Length)
NUX_INLINE bool IsError () const
virtual void Serialize (char &data)
virtual void Serialize (wchar_t &data)
virtual void Serialize (bool &data)
virtual void Serialize (unsigned char &data)
virtual void Serialize (unsigned short &data)
virtual void Serialize (short &data)
virtual void Serialize (unsigned int &data)
virtual void Serialize (int &data)
virtual void Serialize (long &data)
virtual void Serialize (unsigned long &data)
virtual void Serialize (float &data)
virtual void Serialize (double &data)
virtual void Serialize (unsigned long long &data)
virtual void Serialize (long long &data)
virtual void Serialize (wchar_t *buffer, unsigned int len, unsigned int stride=sizeof(wchar_t))
virtual void Serialize (bool *buffer, unsigned int len, unsigned int stride=sizeof(bool))
virtual void Serialize (char *buffer, unsigned int len, unsigned int stride=sizeof(char))
virtual void Serialize (unsigned char *buffer, unsigned int len, unsigned int stride=sizeof(unsigned char))
virtual void Serialize (unsigned short *buffer, unsigned int len, unsigned int stride=sizeof(unsigned short))
virtual void Serialize (short *buffer, unsigned int len, unsigned int stride=sizeof(short))
virtual void Serialize (unsigned int *buffer, unsigned int len, unsigned int stride=sizeof(unsigned int))
virtual void Serialize (int *buffer, unsigned int len, unsigned int stride=sizeof(int))
virtual void Serialize (long *buffer, unsigned int len, unsigned int stride=sizeof(long))
virtual void Serialize (unsigned long *buffer, unsigned int len, unsigned int stride=sizeof(unsigned long))
virtual void Serialize (float *buffer, unsigned int len, unsigned int stride=sizeof(float))
virtual void Serialize (double *buffer, unsigned int len, unsigned int stride=sizeof(double))
virtual void Serialize (unsigned long long *buffer, unsigned int len, unsigned int stride=sizeof(unsigned long long))
virtual void Serialize (long long *buffer, unsigned int len, unsigned int stride=sizeof(long long))
virtual void Identify (const char *name)
virtual void Begin ()
virtual void End ()

Protected Member Functions

void Reset (void)

Protected Attributes

int m_FileDescriptor
LogOutputDevicem_Error
long long m_FileSize
long long m_FilePos
long long m_BufferBase
int m_BufferCount
BYTEm_Buffer
bool m_ErrorCode

Static Protected Attributes

static const int sBufferSize = 1024

Detailed Description

Definition at line 34 of file NFileManagerGNU.h.


Member Enumeration Documentation

anonymous enum [inherited]
Enumerator:
OutputErrorIfFail 
NoOverWrite 
OverWriteReadOnly 
Unbuffered 
Append 
Read 
Write 

Definition at line 32 of file NSerializer.h.

    {
      OutputErrorIfFail   = 0x01,
      NoOverWrite         = 0x02,
      OverWriteReadOnly   = 0x04,
      Unbuffered          = 0x08,
      Append                    = 0x10,
      Read                = 0x20,
      Write               = 0x40,
    };
enum nux::NSerializer::SeekPos [inherited]
Enumerator:
SeekStart 
SeekCurrent 
SeekEnd 

Definition at line 43 of file NSerializer.h.

    {
      SeekStart           = 0x00,
      SeekCurrent         = 0x01,
      SeekEnd             = 0x02,
    } SeekPos;

Constructor & Destructor Documentation

nux::NGNUSerialFileReader::NGNUSerialFileReader ( int  InFileDescriptor,
LogOutputDevice InError,
int  InSize 
)

Definition at line 31 of file NFileManagerGNU.cpp.

    :   m_FileDescriptor    (InFileDescriptor)
    ,   m_Error             (InError)
    ,   m_FileSize          (InSize)
    ,   m_FilePos           (0)
    ,   m_BufferBase        (0)
    ,   m_BufferCount       (0)
  {
    m_Buffer = new BYTE[sBufferSize];
  }

Definition at line 41 of file NFileManagerGNU.cpp.

Here is the call graph for this function:


Member Function Documentation

virtual void nux::NSerializer::Begin ( ) [inline, virtual, inherited]

Definition at line 142 of file NSerializer.h.

{};
NSerializer& nux::NSerializer::ByteOrderSerialize ( void *  V,
INT  Length 
) [inline, inherited]

Definition at line 81 of file NSerializer.h.

    {
      BOOL SwapBytes = 0;

      if ( SwapBytes )
      {
        // Transferring between memory and file, so flip the byte order.
        for ( INT i = Length - 1; i >= 0; i-- )
          Serialize ( (unsigned char *) V + i, 1 );
      }
      else
      {
        // Transferring around within memory, so keep the byte order.
        Serialize ( (unsigned char *) V, Length);
      }

      return *this;
    }

Here is the call graph for this function:

Implements nux::NSerializer.

Definition at line 134 of file NFileManagerGNU.cpp.

  {
    if (m_FileDescriptor)
    {
      int ret = close (m_FileDescriptor);

      if (ret == -1)
      {
        m_ErrorCode = 1;
        m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Close] Error while closing file") );
      }
    }

    m_FileDescriptor = 0;
    return !m_ErrorCode;
  }

Here is the caller graph for this function:

virtual void nux::NSerializer::End ( ) [inline, virtual, inherited]

Definition at line 143 of file NSerializer.h.

{};
virtual void nux::NSerializer::Flush ( ) [inline, virtual, inherited]

Reimplemented in nux::NGNUSerialFileWriter.

Definition at line 74 of file NSerializer.h.

{};

Here is the caller graph for this function:

virtual bool nux::NSerializer::GetError ( ) [inline, virtual, inherited]

Definition at line 76 of file NSerializer.h.

    {
      return m_ErrorCode;
    }
long long nux::NGNUSerialFileReader::GetFileSize ( ) [virtual]

Reimplemented from nux::NSerializer.

Definition at line 129 of file NFileManagerGNU.cpp.

  {
    return m_FileSize;
  }
virtual void nux::NSerializer::Identify ( const char *  name) [inline, virtual, inherited]

Definition at line 141 of file NSerializer.h.

{};
NUX_INLINE bool nux::NSerializer::IsError ( ) const [inline, inherited]

Definition at line 106 of file NSerializer.h.

    {
      return m_ErrorCode;
    }

Here is the caller graph for this function:

virtual bool nux::NGNUSerialFileReader::isReader ( ) [inline, virtual]

Implements nux::NSerializer.

Definition at line 46 of file NFileManagerGNU.h.

    {
      return true;
    }
virtual bool nux::NGNUSerialFileReader::isWriter ( ) [inline, virtual]

Implements nux::NSerializer.

Definition at line 50 of file NFileManagerGNU.h.

    {
      return false;
    }
bool nux::NGNUSerialFileReader::Precache ( int  PrecacheOffset,
int  PrecacheSize 
) [virtual]

Definition at line 51 of file NFileManagerGNU.cpp.

  {
    // Only pre-cache at current position and avoid work if pre-caching same offset twice.
    if ( (m_FilePos == PrecacheOffset) && (!m_BufferBase || !m_BufferCount || m_BufferBase != m_FilePos) )
    {
      m_BufferBase = m_FilePos;
      // (sBufferSize - 1) contains only '1', i.e 1111111111.
      // So (m_FilePos & (sBufferSize-1)) is equal to m_FilePos if m_FilePos <= (sBufferSize-1).
      m_BufferCount = Min<long long> (Min<long long> (PrecacheSize, (int) (sBufferSize - (m_FilePos & (sBufferSize - 1) ) ) ), m_FileSize - m_FilePos);
      long long Count = 0;
      //GTotalBytesReadViaFileManager += m_BufferCount;
      Count = read (m_FileDescriptor, m_Buffer, m_BufferCount);

      if (Count == 0)
      {
        m_ErrorCode = 1;
        m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Precache] Reached end of file while attempting to read %i bytes"), m_BufferCount);
      }

      if (Count == -1)
      {
        m_ErrorCode = 1;
        m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Precache]  Read error while attempting to read file: ???") );
      }
    }

    return TRUE;
  }

Here is the caller graph for this function:

virtual bool nux::NSerializer::Precache ( INT  PrecacheOffset,
INT  PrecacheSize 
) [inline, virtual, inherited]

Definition at line 70 of file NSerializer.h.

    {
      return TRUE;
    }
void nux::NSerializer::Reset ( void  ) [inline, protected, inherited]

Definition at line 146 of file NSerializer.h.

    {
      m_ErrorCode = FALSE;
    }

Here is the caller graph for this function:

long long nux::NGNUSerialFileReader::Seek ( long long  InPos,
NSerializer::SeekPos  seekpos 
) [virtual]

Implements nux::NSerializer.

Definition at line 80 of file NFileManagerGNU.cpp.

  {
    nuxAssert (InPos >= 0);
    nuxAssert (InPos <= m_FileSize);

    Flush();
    // Because we precache our reads, we must perform Seek accordingly.

    long long pos = m_FilePos;
    long long filepos = 0;

    // Set the file pointer to m_FilePos.
    filepos = lseek (m_FileDescriptor, pos, SEEK_SET);

    if (filepos == -1)
    {
      m_ErrorCode = 1;
      m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Seek] Seek to %i has failed."), InPos);
    }

    // Now the file pointer is current with what we have read so far.
    pos = InPos;
    filepos = lseek (m_FileDescriptor, pos, (seekpos == SeekStart) ? SEEK_SET : (seekpos == SeekCurrent) ? SEEK_CUR : SEEK_END);

    if ( filepos == -1)
    {
      m_ErrorCode = 1;
      m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Seek] Seek to %i has failed."), InPos);
    }

    m_FilePos       = filepos;
    m_BufferBase    = 0;
    m_BufferCount   = 0;
    Precache (m_FilePos, sBufferSize);
    return filepos;
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( char &  data) [virtual, inherited]

Definition at line 50 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (char)   );
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void nux::NSerializer::Serialize ( wchar_t &  data) [virtual, inherited]

Definition at line 55 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (wchar_t)   );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( bool &  data) [virtual, inherited]

Definition at line 60 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (bool)    );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned char &  data) [virtual, inherited]

Definition at line 65 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (unsigned char)      );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned short &  data) [virtual, inherited]

Definition at line 70 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (unsigned short)     );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( short &  data) [virtual, inherited]

Definition at line 74 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (short)     );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned int &  data) [virtual, inherited]

Definition at line 78 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (unsigned int)  );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( int &  data) [virtual, inherited]

Definition at line 82 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (int)   );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( long &  data) [virtual, inherited]

Definition at line 86 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (long)    );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned long &  data) [virtual, inherited]

Definition at line 90 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (unsigned long)   );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( float &  data) [virtual, inherited]

Definition at line 94 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (float)   );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( double &  data) [virtual, inherited]

Definition at line 98 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (double)  );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned long long &  data) [virtual, inherited]

Definition at line 102 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (unsigned long long)     );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( long long &  data) [virtual, inherited]

Definition at line 106 of file NSerializer.cpp.

  {
    SerializeFinal (&data, sizeof (long long)     );
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( wchar_t *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (wchar_t) 
) [virtual, inherited]

Definition at line 111 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( bool *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (bool) 
) [virtual, inherited]

Definition at line 115 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( char *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (char) 
) [virtual, inherited]

Definition at line 119 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned char *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (unsigned char) 
) [virtual, inherited]

Definition at line 123 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned short *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (unsigned short) 
) [virtual, inherited]

Definition at line 127 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( short *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (short) 
) [virtual, inherited]

Definition at line 131 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned int *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (unsigned int) 
) [virtual, inherited]

Definition at line 135 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( int *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (int) 
) [virtual, inherited]

Definition at line 139 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( long *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (long) 
) [virtual, inherited]

Definition at line 143 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned long *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (unsigned long) 
) [virtual, inherited]

Definition at line 147 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( float *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (float) 
) [virtual, inherited]

Definition at line 151 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( double *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (double) 
) [virtual, inherited]

Definition at line 155 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( unsigned long long *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (unsigned long long) 
) [virtual, inherited]

Definition at line 159 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NSerializer::Serialize ( long long *  buffer,
unsigned int  len,
unsigned int  stride = sizeof (long long) 
) [virtual, inherited]

Definition at line 163 of file NSerializer.cpp.

  {
    SerializeFinal (buffer, len * stride);
  }

Here is the call graph for this function:

void nux::NGNUSerialFileReader::SerializeFinal ( void *  V,
long long  Length 
) [virtual]

Implements nux::NSerializer.

Definition at line 151 of file NFileManagerGNU.cpp.

  {
    nuxAssert (Dest);

    while (Length > 0)
    {
      int DataSize = Min<long long> (Length, m_BufferBase + m_BufferCount - m_FilePos);

      if (DataSize == 0)
      {
        if (Length >= sBufferSize)
        {
          long long Count = 0;
          //GTotalBytesReadViaFileManager += Length;
          Count = read (m_FileDescriptor, Dest, Length);

          if (Count == 0)
          {
            m_ErrorCode = 1;
            m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Serialize] Reached end of file while attempting to read %i bytes"), Length);
          }

          if (Count == -1)
          {
            m_ErrorCode = 1;
            m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileReader::Serialize]  Read error while attempting to read file: ???") );
          }

          m_FilePos += Length;
          m_BufferBase += Length;
          return;
        }

        Precache (m_FilePos, 0x7FFFFFFF);
        DataSize = Min<long long> (Length, m_BufferBase + m_BufferCount - m_FilePos);

        if (DataSize <= 0)
        {
          m_ErrorCode = 1;
          m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("ReadFile beyond EOF %i+%i/%i"), m_FilePos, Length, m_FileSize);
        }

        if (m_ErrorCode)
          return;
      }

      Memcpy (Dest, m_Buffer + m_FilePos - m_BufferBase, DataSize);
      m_FilePos   += DataSize;
      Length      -= DataSize;
      Dest        = (BYTE *) Dest + DataSize;
    }
  }

Here is the call graph for this function:

long long nux::NGNUSerialFileReader::Tell ( ) [virtual]

Implements nux::NSerializer.

Definition at line 117 of file NFileManagerGNU.cpp.

  {
    //     Flush();
    //     LARGE_INTEGER pos;
    //     LARGE_INTEGER filepos;
    //     pos.QuadPart = 0;
    //     ::SetFilePointerEx(m_FileDescriptor, pos, &filepos, FILE_CURRENT);
    //     return filepos.QuadPart;

    return m_FilePos;
  }

Member Data Documentation

Definition at line 62 of file NFileManagerGNU.h.

Definition at line 60 of file NFileManagerGNU.h.

Definition at line 61 of file NFileManagerGNU.h.

Definition at line 57 of file NFileManagerGNU.h.

bool nux::NSerializer::m_ErrorCode [protected, inherited]

Definition at line 150 of file NSerializer.h.

Definition at line 56 of file NFileManagerGNU.h.

long long nux::NGNUSerialFileReader::m_FilePos [protected]

Definition at line 59 of file NFileManagerGNU.h.

Definition at line 58 of file NFileManagerGNU.h.

const int nux::NGNUSerialFileReader::sBufferSize = 1024 [static, protected]

Definition at line 63 of file NFileManagerGNU.h.


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