Generic File for Input/Output. More...

#include <riofile.h>

Inheritance diagram for RIOFile:
[legend]
Collaboration diagram for RIOFile:
[legend]

Public Member Functions

 RIOFile (void)
 
 RIOFile (const RURI &uri)
 
 RIOFile (RIOFile &file)
 
RURI GetRealName (void) const
 
virtual void Open (RIO::ModeType mode)
 
void Open (const RURI &uri, RIO::ModeType mode)
 
bool IsOpen (void) const
 
virtual void Close (void)
 
size_t Read (char *buffer, size_t nb, bool move=true)
 
void Write (const char *buffer, size_t nb)
 
virtual void Seek (off_t pos)
 
virtual void SeekRel (off_t pos)
 
virtual void SeekToEnd (void)
 
void Truncate (off_t newsize)
 
bool End (void) const
 
off_t GetSize (void) const
 
off_t GetPos (void) const
 
virtual ~RIOFile (void)
 
- Public Member Functions inherited from RFile
 RFile (void)
 
 RFile (const RURI &uri)
 
 RFile (const RFile &file)
 
void Open (const RURI &uri, RIO::ModeType mode)
 
int Compare (const RFile &file) const
 
int Compare (const RFile *file) const
 
int Compare (const RString &uri) const
 
const RURIGetURI (void) const
 
void SetURI (const RURI &uri)
 
const RString GetFileName (void) const
 
virtual ~RFile (void)
 

Protected Attributes

bool CanWrite
 
bool CanRead
 
- Protected Attributes inherited from RFile
RIO::ModeType Mode
 
RURI URI
 

Private Member Functions

void Test (void)
 

Private Attributes

int Handle
 
off_t Size
 
off_t Pos
 
RURI File
 
char * Internal
 
size_t InternalToRead
 
off_t RealPos
 
off_t RealInternalPos
 
char * CurByte
 

Static Private Attributes

static RDownloadFile Get
 

Additional Inherited Members

- Static Public Member Functions inherited from RFile
static RChar GetDirSeparator (void)
 
static void RemoveFile (const RURI &uri)
 
static void RenameFile (const RURI &olduri, const RURI &newuri)
 
static RURI GetTempFile (void)
 
static bool Exists (const RURI &uri)
 
static bool IsDir (const RURI &uri)
 

Detailed Description

Generic File for Input/Output.

The RIOFile class represents a file that can do some input and/or output tasks. To read, the class works with an internal buffer of 10 Kb.

Here is an example:

#include <riofile.h>
using namespace R;
char Buffer[81];
RIOFile In("/home/user/Test.txt");
In.Open(RIO::Read);
size_t len=In.Read(Buffer,80);
Buffer[len]=0;
cout<<Buffer<<endl;
Note
When the file is read, an internal buffer is used to avoid to many accesses to the disk. When something must be written, it is first physically written on the disk and, if the file can also be read, the internal buffer is updated.

Constructor & Destructor Documentation

RIOFile ( void  )

Default constructor for a file.

RIOFile ( const RURI uri)

Construct a file.

Parameters
uriURI of the file.
RIOFile ( RIOFile file)

Copy constructor of a file.

Parameters
fileFile.
virtual ~RIOFile ( void  )
virtual

Destruct the file.

Member Function Documentation

void Test ( void  )
private
RURI GetRealName ( void  ) const

When the URI associated to a RIOFile is not local, it is downloaded and stored in a temporary file (which becomes the real name of the file).

Returns
the real name of the file.
virtual void Open ( RIO::ModeType  mode)
virtual

Open the file

Parameters
modeThe open mode for the file.

Reimplemented from RFile.

Reimplemented in RXMLParser, RTextFile, RKeyValueFile< K >, RRecFile< C, bOrder >, RBlockFile, RCSVFile, RXMLFile, RBinaryFile, and RHTMLFile.

void Open ( const RURI uri,
RIO::ModeType  mode 
)

Open the file

Parameters
uriURI of the file.
modeThe open mode for the file.
bool IsOpen ( void  ) const

Verify if the file is opened or not.

Returns
true if the file is open.
virtual void Close ( void  )
virtual

Close the file.

Reimplemented from RFile.

Reimplemented in RTextFile, RKeyValueFile< K >, RRecFile< C, bOrder >, RBlockFile, RCSVFile, and RXMLFile.

size_t Read ( char *  buffer,
size_t  nb,
bool  move = true 
)

Read a given number of bytes at the current position of the file.

Parameters
bufferBuffer (must be allocated).
nbNumber of bytes to read.
moveThe file position is moved (default).
Returns
Number of bytes read.
void Write ( const char *  buffer,
size_t  nb 
)

Write the first number of bytes of a buffer in the current position of the file.

Parameters
bufferBuffer.
nbNumber of bytes to read.
virtual void Seek ( off_t  pos)
virtual

Go to a specific position of the file.

Parameters
posPosition to reach.

Reimplemented in RKeyValueFile< K >, and RTextFile.

virtual void SeekRel ( off_t  pos)
virtual

Move for a given number of bytes from the current position of the file.

Parameters
posRelative position.

Reimplemented in RTextFile.

virtual void SeekToEnd ( void  )
virtual

Go to the end of the file.

void Truncate ( off_t  newsize)

Truncate the file.

Parameters
newsizeNew size.
bool End ( void  ) const

Return true if the file is at the end.

off_t GetSize ( void  ) const

Return the size of the file.

off_t GetPos ( void  ) const

Return the current position in the file.

Field Documentation

int Handle
private

Internal Handle of the file.

off_t Size
private

Size of the file.

off_t Pos
private

Current (virtual) position in the file.

RDownloadFile Get
staticprivate

Downloader for non-local files.

RURI File
private

File which is really treated.

char* Internal
private

Internal Buffer.

size_t InternalToRead
private

Number of bytes left to read in the internal buffer.

off_t RealPos
private

Physical (real) position in the file.

off_t RealInternalPos
private

Physical (real) position of the first byte of the internal buffer.

char* CurByte
private

Current byte to read.

bool CanWrite
protected

It is possible to write in the file.

bool CanRead
protected

It is possible to read from the file.