simgear  3.5.0 [next] git://gitorious.org/fg/simgear.git
SimGear - Simulator Construction Tools
SGFile Class Reference

#include <sg_file.hxx>

Inheritance diagram for SGFile:
SGIOChannel

Public Member Functions

 SGFile (const std::string &file, int repeat_=1)
 
 SGFile (int existingFd)
 
 ~SGFile ()
 
bool close ()
 
virtual bool eof () const
 
SGProtocolDir get_dir () const
 
std::string get_file_name () const
 
SGChannelType get_type () const
 
bool isvalid () const
 
bool open (const SGProtocolDir dir)
 
int read (char *buf, int length)
 
int readline (char *buf, int length)
 
void set_dir (const SGProtocolDir d)
 
void set_type (SGChannelType t)
 
void set_valid (const bool v)
 
int write (const char *buf, const int length)
 
int writestring (const char *str)
 

Private Attributes

bool eof_flag
 
std::string file_name
 
int fp
 
int iteration
 
const int repeat
 

Detailed Description

A file I/O class based on SGIOChannel.

Definition at line 33 of file sg_file.hxx.

Constructor & Destructor Documentation

SGFile::SGFile ( const std::string &  file,
int  repeat_ = 1 
)

Create an instance of SGFile. When calling the constructor you need to provide a file name. This file is not opened immediately, but instead will be opened when the open() method is called.

Parameters
filename of file to open
repeatOn eof restart at the beginning of the file

Definition at line 48 of file sg_file.cxx.

SGFile::SGFile ( int  existingFd)

Create an SGFile from an existing, open file-descriptor

Definition at line 54 of file sg_file.cxx.

SGFile::~SGFile ( )

Destructor

Definition at line 63 of file sg_file.cxx.

Member Function Documentation

bool SGFile::close ( void  )
virtual

The close() method is modeled after the close() Unix system call and will close an open device. You should call this method when you are done using your IO class, before it is destructed.

Returns
result of close

Reimplemented from SGIOChannel.

Definition at line 173 of file sg_file.cxx.

virtual bool SGFile::eof ( ) const
inlinevirtual
Returns
true of eof conditions exists

Reimplemented from SGIOChannel.

Definition at line 85 of file sg_file.hxx.

SGProtocolDir SGIOChannel::get_dir ( ) const
inlineinherited

Definition at line 158 of file iochannel.hxx.

Referenced by open(), and SGSocketUDP::open().

std::string SGFile::get_file_name ( ) const
inline
Returns
the name of the file being manipulated.

Definition at line 82 of file sg_file.hxx.

Referenced by main().

SGChannelType SGIOChannel::get_type ( ) const
inlineinherited

Definition at line 155 of file iochannel.hxx.

bool SGIOChannel::isvalid ( ) const
inlineinherited
bool SGFile::open ( const SGProtocolDir  d)
virtual

Open a channel.

Parameters
dchannel communication "direction" Direction can be one of:
  • SG_IO_IN - data will be flowing into this object to the application.
  • SG_IO_OUT - data will be flowing out of this object from the application.
  • SG_IO_BI - data will be flowing in both directions.
  • SG_IO_NONE - data will not be flowing in either direction. This is here for the sake of completeness.
Returns
result of open

Reimplemented from SGIOChannel.

Definition at line 68 of file sg_file.cxx.

Referenced by main().

int SGFile::read ( char *  buf,
int  length 
)
virtual

The read() method is modeled after the read() Unix system call. You must provide a pointer to a character buffer that has enough allocated space for your potential read. You can also specify the maximum number of bytes allowed for this particular read. The actual number of bytes read is returned. You are responsible to ensure that the size of buf is large enough to accomodate your input message

Parameters
bufa char pointer to your input buffer
lengthmax number of bytes to read
Returns
number of bytes read

Reimplemented from SGIOChannel.

Definition at line 97 of file sg_file.cxx.

Referenced by readline().

int SGFile::readline ( char *  buf,
int  length 
)
virtual

The readline() method is similar to read() except that it will stop at the first end of line encountered in the input buffer.

Parameters
bufa char pointer to your input buffer
lengthmax number of bytes to read
Returns
number of bytes read

Reimplemented from SGIOChannel.

Definition at line 121 of file sg_file.cxx.

void SGIOChannel::set_dir ( const SGProtocolDir  d)
inlineinherited

Definition at line 157 of file iochannel.hxx.

Referenced by open(), SGSerial::open(), SGSocketUDP::open(), and SGSocket::open().

void SGIOChannel::set_type ( SGChannelType  t)
inlineinherited

Definition at line 154 of file iochannel.hxx.

Referenced by SGFile(), SGSerial::SGSerial(), and SGSocket::SGSocket().

void SGIOChannel::set_valid ( const bool  v)
inlineinherited

Definition at line 160 of file iochannel.hxx.

Referenced by SGSocketUDP::open(), and SGSocketUDP::SGSocketUDP().

int SGFile::write ( const char *  buf,
const int  length 
)
virtual

The write() method is modeled after the write() Unix system call and is analogous to the read() method. You provide a pointer to a buffer of data, and then length of that data to be written out. The number of bytes written is returned.

Parameters
bufa char pointer to your output buffer
lengthnumber of bytes to write
Returns
number of bytes written

Reimplemented from SGIOChannel.

Definition at line 155 of file sg_file.cxx.

Referenced by writestring().

int SGFile::writestring ( const char *  str)
virtual

The writestring() method is a simple wrapper that will calculate the length of a null terminated character array and write it to the output channel.

Parameters
bufa char pointer to your output buffer
Returns
number of bytes written

Reimplemented from SGIOChannel.

Definition at line 166 of file sg_file.cxx.

Member Data Documentation

bool SGFile::eof_flag
private

Definition at line 37 of file sg_file.hxx.

Referenced by close(), eof(), open(), read(), and readline().

std::string SGFile::file_name
private

Definition at line 35 of file sg_file.hxx.

Referenced by get_file_name(), open(), and write().

int SGFile::fp
private

Definition at line 36 of file sg_file.hxx.

Referenced by close(), open(), read(), readline(), and write().

int SGFile::iteration
private

Definition at line 40 of file sg_file.hxx.

Referenced by read(), and readline().

const int SGFile::repeat
private

Definition at line 39 of file sg_file.hxx.

Referenced by read(), and readline().


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