newspeoplefor developersdocumentationdownloads

nFile Class Reference
[File I/O and File System Access]

#include <nfile.h>

Inheritance diagram for nFile:

nRefCounted nNpkFile nRamFile List of all members.

Detailed Description

Wrapper class for accessing file system files.

provides functions for reading and writing files

(C) 2002 RadonLabs GmbH

Definition at line 32 of file nfile.h.


Public Types

enum  nSeekType {
  CURRENT,
  START,
  END
}
 start point for seeking in file More...

Public Member Functions

virtual bool Exists (const nString &fileName) const
 does the file physically exist on disk?
virtual bool Open (const nString &fileName, const nString &accessMode)
 opens a file
virtual void Close ()
 closes the file
virtual int Write (const void *buffer, int numBytes)
 writes some bytes to the file
virtual int Read (void *buffer, int numBytes)
 reads some bytes from the file
virtual int Tell () const
 gets actual position in file
virtual bool Seek (int byteOffset, nSeekType origin)
 sets new position in file
virtual bool Eof () const
 is the file at the end
virtual int GetSize () const
 get size of file in bytes
virtual nFileTime GetLastWriteTime () const
 get the last write time
bool PutS (const nString &buffer)
 writes a string to the file
bool GetS (char *buffer, int numChars)
 reads a string from the file
int GetLineNumber () const
 get current line number (incremented by PutS() and GetS())
bool IsOpen () const
 determines whether the file is opened
virtual int AppendFile (nFile *other)
 append one file to another file
int PutInt (int val)
 write a 32bit int to the file
int PutShort (short val)
 write a 16bit int to the file
int PutChar (char val)
 write a 8bit int to the file
int PutFloat (float val)
 write a float to the file
int PutDouble (double val)
 write a double to the file
int GetInt ()
 read a 32 bit int from the file
short GetShort ()
 read a signed 16 bit int from the file
ushort GetUShort ()
 read an unsigned 16 bit int from the file
char GetChar ()
 read a 8 bit int from the file
float GetFloat ()
 read a float from the file
double GetDouble ()
 read a double from the file

Protected Member Functions

 nFile ()
 NOTE: constructor is private because only nFileServer2 may create objects.
virtual ~nFile ()
 destructor

Protected Attributes

ushort lineNumber
bool isOpen
FILE * fp

Friends

class nFileServer2

Member Enumeration Documentation

enum nFile::nSeekType
 

start point for seeking in file

Enumerator:
CURRENT 
START 
END 

Definition at line 36 of file nfile.h.


Constructor & Destructor Documentation

nFile::nFile  )  [protected]
 

NOTE: constructor is private because only nFileServer2 may create objects.

history:

  • 30-Jan-2002 peter created
  • 11-Feb-2002 floh Linux stuff

Definition at line 21 of file nfile.cc.

nFile::~nFile  )  [protected, virtual]
 

destructor

history:

  • 30-Jan-2002 peter created

Definition at line 38 of file nfile.cc.


Member Function Documentation

bool nFile::Exists const nString fileName  )  const [virtual]
 

does the file physically exist on disk?

Check if file exists physically on disk by opening it in read-only mode. Close file if it was opened.

  • 05-Jan-05 floh Bugfix: missing GENERIC_READ access mode didn't work in Win98
  • 12-Oct-05 floh access move back to 0, Win98 is no longer relevant

Reimplemented in nNpkFile, and nRamFile.

Definition at line 55 of file nfile.cc.

bool nFile::Open const nString fileName,
const nString accessMode
[virtual]
 

opens a file

opens the specified file

Parameters:
fileName the name of the file to open
accessMode the access mode ("(r|w|a)[+]")
Returns:
success
history:
  • 30-Jan-2002 peter created
  • 11-Feb-2002 floh Linux stuff
  • 12-Oct-2005 floh fixed read mode to also open a file which is already open by another application for writing

Reimplemented in nNpkFile, and nRamFile.

Definition at line 108 of file nfile.cc.

void nFile::Close  )  [virtual]
 

closes the file

closes the file

history:

  • 30-Jan-2002 peter created
  • 11-Feb-2002 floh Linux stuff

Reimplemented in nNpkFile, and nRamFile.

Definition at line 172 of file nfile.cc.

int nFile::Write const void *  buffer,
int  numBytes
[virtual]
 

writes some bytes to the file

writes a number of bytes to the file

Parameters:
buffer buffer with data
numBytes number of bytes to write
Returns:
number of bytes written
history:
  • 30-Jan-2002 peter created
  • 11-Feb-2002 floh Linux stuff

Reimplemented in nNpkFile, and nRamFile.

Definition at line 205 of file nfile.cc.

int nFile::Read void *  buffer,
int  numBytes
[virtual]
 

reads some bytes from the file

reads a number of bytes from the file

Parameters:
buffer buffer for data
numBytes number of bytes to read
Returns:
number of bytes read
history:
  • 30-Jan-2002 peter created

Reimplemented in nNpkFile, and nRamFile.

Definition at line 233 of file nfile.cc.

int nFile::Tell  )  const [virtual]
 

gets actual position in file

gets current position of file pointer

Returns:
position of pointer
history:
  • 30-Jan-2002 peter created

Reimplemented in nNpkFile, and nRamFile.

Definition at line 260 of file nfile.cc.

bool nFile::Seek int  byteOffset,
nSeekType  origin
[virtual]
 

sets new position in file

sets the file pointer to given absolute or relative position

Parameters:
byteOffset the offset
origin position from which to count
Returns:
success
history:
  • 30-Jan-2002 peter created

Reimplemented in nNpkFile, and nRamFile.

Definition at line 282 of file nfile.cc.

bool nFile::Eof  )  const [virtual]
 

is the file at the end

Reimplemented in nNpkFile, and nRamFile.

Definition at line 327 of file nfile.cc.

int nFile::GetSize  )  const [virtual]
 

get size of file in bytes

Returns size of file in bytes.

Returns:
byte-size of file

Reimplemented in nNpkFile, and nRamFile.

Definition at line 349 of file nfile.cc.

nFileTime nFile::GetLastWriteTime  )  const [virtual]
 

get the last write time

Returns time of last write access. The file must be opened in "read" mode before this function can be called!

Reimplemented in nNpkFile, and nRamFile.

Definition at line 370 of file nfile.cc.

bool nFile::PutS const nString buffer  ) 
 

writes a string to the file

writes a string to the file

Parameters:
buffer the string to write
Returns:
success
history:
  • 30-Jan-02 peter created
  • 29-Jan-03 floh the method suddenly wrote a newLine. WRONG!

Definition at line 401 of file nfile.cc.

bool nFile::GetS char *  buf,
int  bufSize
 

reads a string from the file

reads a string from the file up to and including the first newline character or up to the end of the buffer

Parameters:
buf buffer for string
bufSize maximum number of chars to read
Returns:
success (false if eof is reached)
history:
  • 30-Jan-2002 peter created
  • 28-Sep-2005 floh complete rewrite, there were error if bufSize was below a line length

Definition at line 433 of file nfile.cc.

int nFile::GetLineNumber  )  const [inline]
 

get current line number (incremented by PutS() and GetS())

Returns:
the current line number (only valid with GetS()/PutS())

Definition at line 132 of file nfile.h.

bool nFile::IsOpen  )  const [inline]
 

determines whether the file is opened

Definition at line 121 of file nfile.h.

int nFile::AppendFile nFile other  )  [virtual]
 

append one file to another file

Append the contents of another file to this file. This and the 'other' file must both be open! Returns number of bytes copied. Warning: current implementation reads the complete source file into a ram buffer.

Returns:
number of bytes appended

Definition at line 506 of file nfile.cc.

int nFile::PutInt int  val  )  [inline]
 

write a 32bit int to the file

Parameters:
val a 32 bit int value
Returns:
number of bytes written

Definition at line 144 of file nfile.h.

int nFile::PutShort short  val  )  [inline]
 

write a 16bit int to the file

Parameters:
val a 16 bit int value
Returns:
number of bytes written

Definition at line 156 of file nfile.h.

int nFile::PutChar char  val  )  [inline]
 

write a 8bit int to the file

Parameters:
val a 8 bit int value
Returns:
number of bytes written

Definition at line 168 of file nfile.h.

int nFile::PutFloat float  val  )  [inline]
 

write a float to the file

Parameters:
val a 32 bit float value
Returns:
number of bytes written

Definition at line 180 of file nfile.h.

int nFile::PutDouble double  val  )  [inline]
 

write a double to the file

Parameters:
val a 64 bit double value
Returns:
number of bytes written

Definition at line 192 of file nfile.h.

int nFile::GetInt  )  [inline]
 

read a 32 bit int from the file

Returns:
the value

Definition at line 203 of file nfile.h.

short nFile::GetShort  )  [inline]
 

read a signed 16 bit int from the file

Returns:
the value

Definition at line 216 of file nfile.h.

ushort nFile::GetUShort  )  [inline]
 

read an unsigned 16 bit int from the file

Returns:
the value

Definition at line 229 of file nfile.h.

char nFile::GetChar  )  [inline]
 

read a 8 bit int from the file

Returns:
the value

Definition at line 242 of file nfile.h.

float nFile::GetFloat  )  [inline]
 

read a float from the file

Returns:
the value

Definition at line 255 of file nfile.h.

double nFile::GetDouble  )  [inline]
 

read a double from the file

Returns:
the value

Definition at line 268 of file nfile.h.


Friends And Related Function Documentation

friend class nFileServer2 [friend]
 

Definition at line 97 of file nfile.h.


Member Data Documentation

ushort nFile::lineNumber [protected]
 

Definition at line 104 of file nfile.h.

bool nFile::isOpen [protected]
 

Definition at line 105 of file nfile.h.

FILE* nFile::fp [protected]
 

Definition at line 112 of file nfile.h.


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

Copyright © 1999-2005 by the contributing authors. Ideas, requests, problems: Send feedback.