Back to index

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

#include <NFileManagerGNU.h>

Inheritance diagram for nux::NGNUSerialFileWriter:
Inheritance graph
[legend]
Collaboration diagram for nux::NGNUSerialFileWriter:
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

 NGNUSerialFileWriter (int InFileDescriptor, LogOutputDevice &InError, int InPos)
 ~NGNUSerialFileWriter ()
virtual long long Seek (long long InPos, NSerializer::SeekPos seekpos)
virtual long long Tell ()
virtual bool Close ()
virtual void SerializeFinal (void *V, long long Length)
virtual void Flush ()
virtual long long GetFileSize ()
virtual bool isReader ()
virtual bool isWriter ()
virtual bool Precache (INT PrecacheOffset, INT PrecacheSize)
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 _Flush ()
void Reset (void)

Protected Attributes

int m_FileDescriptor
LogOutputDevicem_Error
long long m_Pos
int m_BufferCount
BYTEm_Buffer
NCriticalSection m_CriticalSection
bool m_ErrorCode

Static Protected Attributes

static const int sBufferSize = 32

Detailed Description

Definition at line 66 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::NGNUSerialFileWriter::NGNUSerialFileWriter ( int  InFileDescriptor,
LogOutputDevice InError,
int  InPos 
)

Definition at line 207 of file NFileManagerGNU.cpp.

    :   m_FileDescriptor (InFileDescriptor)
    ,   m_Error         (InError)
    ,   m_BufferCount   (0)
  {
    m_Pos = Tell();
    m_Buffer = new BYTE[sBufferSize];
  }

Here is the call graph for this function:

Definition at line 216 of file NFileManagerGNU.cpp.

Here is the call graph for this function:


Member Function Documentation

void nux::NGNUSerialFileWriter::_Flush ( ) [protected]

Definition at line 354 of file NFileManagerGNU.cpp.

  {
    //GTotalBytesWrittenViaFileManager += m_BufferCount;
    if (m_BufferCount)
    {
      long long Result = 0;
      Result = write (m_FileDescriptor, m_Buffer, m_BufferCount);

      if (Result == -1)
      {
        m_ErrorCode = 1;
        m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::Flush] Write error.") );
      }
    }

    m_BufferCount = 0;
  }

Here is the caller graph for this function:

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 271 of file NFileManagerGNU.cpp.

  {
    NScopeLock Scope (&m_CriticalSection);
    nuxAssert (m_FileDescriptor);

    if (m_FileDescriptor == 0)
      return true;

    _Flush();
    int ret = close (m_FileDescriptor);

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

    m_FileDescriptor = 0;
    return !m_ErrorCode;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 143 of file NSerializer.h.

{};

Reimplemented from nux::NSerializer.

Definition at line 343 of file NFileManagerGNU.cpp.

  {
    NScopeLock Scope (&m_CriticalSection);
    nuxAssert (m_FileDescriptor);

    if (m_FileDescriptor == 0)
      return;

    _Flush();
  }

Here is the call 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::NGNUSerialFileWriter::GetFileSize ( ) [virtual]

Reimplemented from nux::NSerializer.

Definition at line 292 of file NFileManagerGNU.cpp.

  {
    NScopeLock Scope (&m_CriticalSection);
    nuxAssert (m_FileDescriptor);

    if (m_FileDescriptor == 0)
      return -1;

    struct stat sb;

    if (fstat (m_FileDescriptor, &sb) != 0)
    {
      m_Error.LogFunction (NUX_MSG_SEVERITY_NONE, TEXT ("[NGNUSerialFileWriter::GetFileSize] Can't get file size.") );
      return -1;
    }

    return sb.st_size;
  }
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::NGNUSerialFileWriter::isReader ( ) [inline, virtual]

Implements nux::NSerializer.

Definition at line 78 of file NFileManagerGNU.h.

    {
      return false;
    }
virtual bool nux::NGNUSerialFileWriter::isWriter ( ) [inline, virtual]

Implements nux::NSerializer.

Definition at line 82 of file NFileManagerGNU.h.

    {
      return true;
    }
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::NGNUSerialFileWriter::Seek ( long long  InPos,
NSerializer::SeekPos  seekpos 
) [virtual]

Implements nux::NSerializer.

Definition at line 226 of file NFileManagerGNU.cpp.

  {
    NScopeLock Scope (&m_CriticalSection);
    nuxAssert (m_FileDescriptor);

    if (m_FileDescriptor == 0)
      return -1;

    _Flush();
    long long pos = InPos;
    long long filepos = 0;
    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 ("[NGNUSerialFileWriter::Seek] Seek to %i has failed."), InPos);
    }

    m_Pos = filepos;
    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::NGNUSerialFileWriter::SerializeFinal ( void *  V,
long long  Length 
) [virtual]

Implements nux::NSerializer.

Definition at line 311 of file NFileManagerGNU.cpp.

  {
    // This method is not re-entrant by itself. It relies on m_Buffer and other variables
    // that belong to this object. Therefore, it is not thread safe. We add a critical section
    // to make it thread safe.

    NScopeLock Scope (&m_CriticalSection);
    nuxAssert (m_FileDescriptor);
    nuxAssert (V);

    NUX_RETURN_IF_NULL (m_FileDescriptor);

    m_Pos += Length;
    int FreeSpace;

    while (Length > (FreeSpace = sBufferSize - m_BufferCount) )
    {
      // m_Buffer is Full. Write it to the file.
      Memcpy (m_Buffer + m_BufferCount, V, FreeSpace);
      m_BufferCount   += FreeSpace;
      Length          -= FreeSpace;
      V               = (BYTE *) V + FreeSpace;
      _Flush();
    }

    if (Length)
    {
      Memcpy (m_Buffer + m_BufferCount, V, Length);
      m_BufferCount += Length; // Count the number of Characters stored in m_Buffer.
    }
  }

Here is the call graph for this function:

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

Implements nux::NSerializer.

Definition at line 249 of file NFileManagerGNU.cpp.

  {
    NScopeLock Scope (&m_CriticalSection);
    nuxAssert (m_FileDescriptor);

    if (m_FileDescriptor == 0)
      return -1;

    _Flush();
    long long pos = 0;
    long long filepos = 0;
    filepos = lseek (m_FileDescriptor, pos, SEEK_CUR);

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

    return filepos;
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 93 of file NFileManagerGNU.h.

Definition at line 92 of file NFileManagerGNU.h.

Definition at line 95 of file NFileManagerGNU.h.

Definition at line 90 of file NFileManagerGNU.h.

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

Definition at line 150 of file NSerializer.h.

Definition at line 89 of file NFileManagerGNU.h.

long long nux::NGNUSerialFileWriter::m_Pos [protected]

Definition at line 91 of file NFileManagerGNU.h.

const int nux::NGNUSerialFileWriter::sBufferSize = 32 [static, protected]

Definition at line 94 of file NFileManagerGNU.h.


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