conexus logo

Conexus::File Class Reference
[Conexus I/O Endpoints]

This class encapsulates a file. More...

#include <file.h>

Inheritance diagram for Conexus::File:

Inheritance graph
[legend]

List of all members.

Public Types

typedef ConexusPointer< Filepointer

Public Member Functions

 CONEXUS_ENDPOINT_GENERIC_CREATE ()
virtual ~File ()
virtual void open (const std::string name, long unsigned mode=FILE_UNCHANGED) throw ( open_exception)
 Opens the named file in the specified mode.
virtual void open () throw ( open_exception )
 Will attempt to open the file if a filename has been specified.
std::string filename ()
 Will return the filename.
long unsigned mode ()
 Returns the POSIX file mode of the endpoint.
bool eof ()
 True if file has encountered an EOF condition, false otherwise.
void set_eof (bool state=true)
 Forces the eof state to a specific value.
bool is_throw_eof_set ()
 If true, file endpoint will throw an eof exception when an EOF condition is encountered.
void set_throw_eof (bool teof=true)
 Sets the endpoint behavior when an EOF condition is encountered.
void set_filename (std::string d, long unsigned mode=FILE_UNCHANGED) throw ( open_exception )
 Sets the filename.
sigc::signal< void > signal_filename_changed ()

Static Public Member Functions

static File::pointer create (const std::string &filename=std::string(), long unsigned mode=0)

Protected Member Functions

 File (const std::string &filename, long unsigned mode)
virtual Data read_data (size_t size, Timeout timeout) throw ( read_exception )
 Reimplements Endpoint::read_data() using FileDescriptor::read_data() to catch the exception where data read size is zero indicating EOF.

Protected Attributes

std::string m_filename
long unsigned m_mode
bool m_eof
bool m_throw_eof
sigc::signal< void > m_signal_filename_changed

Related Functions

(Note that these are not member functions.)

enum  FileMode {
  FILE_READ = 1<<0, FILE_WRITE = 1<<1, FILE_APPEND = 1<<2, FILE_CREATE = 1<<3,
  FILE_DIRECT = 1<<4, FILE_LARGE_FILE = 1<<5, FILE_NO_ACCESS_TIME = 1<<6, FILE_NO_FOLLOW = 1<<7,
  FILE_TRUNCATE = 1<<8, FILE_EXCLUSIVE_CREATE = 1<<9, FILE_UNCHANGED = 1<<10, FILE_LAST_STATE = FILE_UNCHANGED
}


Detailed Description

This class encapsulates a file.

TODO add support for stat(2)

Author:
Rick L Vinyard Jr

Member Typedef Documentation

typedef ConexusPointer<File> Conexus::File::pointer


Constructor & Destructor Documentation

Conexus::File::File ( const std::string &  filename,
long unsigned  mode 
) [protected]

Conexus::File::~File (  )  [virtual]


Member Function Documentation

Conexus::File::CONEXUS_ENDPOINT_GENERIC_CREATE (  ) 

File::pointer Conexus::File::create ( const std::string &  filename = std::string(),
long unsigned  mode = 0 
) [static]

bool Conexus::File::eof (  ) 

True if file has encountered an EOF condition, false otherwise.

References m_eof.

std::string Conexus::File::filename (  ) 

Will return the filename.

References m_filename.

bool Conexus::File::is_throw_eof_set (  ) 

If true, file endpoint will throw an eof exception when an EOF condition is encountered.

The default setting for any endpoint is to not throw an EOF exception

References m_throw_eof.

long unsigned Conexus::File::mode (  ) 

Returns the POSIX file mode of the endpoint.

References m_mode.

void Conexus::File::open (  )  throw ( open_exception ) [virtual]

Will attempt to open the file if a filename has been specified.

Otherwise an exception will be thrown.

Implements Conexus::Endpoint.

References m_filename.

void Conexus::File::open ( const std::string  name,
long unsigned  mode = FILE_UNCHANGED 
) throw ( open_exception) [virtual]

Data Conexus::File::read_data ( size_t  size,
Timeout  timeout 
) throw ( read_exception ) [protected, virtual]

Reimplements Endpoint::read_data() using FileDescriptor::read_data() to catch the exception where data read size is zero indicating EOF.

When encountered throws eof exception.

Exceptions:
Conexus::exception::read::eof When file EOF is encounter on a zero length read

Reimplemented from Conexus::FileDescriptor.

References Conexus::FileDescriptor::read_data().

void Conexus::File::set_eof ( bool  state = true  ) 

Forces the eof state to a specific value.

Setting this to false sets the internal eof state to false, even if an EOF condition has been encountered. This effectively resets the internal state of the endpoint but has no actual effect on the file. If the file is truly EOF it will remain EOF.

References m_eof.

void Conexus::File::set_filename ( std::string  d,
long unsigned  mode = FILE_UNCHANGED 
) throw ( open_exception )

Sets the filename.

If the file is currently open and d is not equal to the current filename, the current file will be closed.

Also, if auto_open is set, the new file will be immediately opened.

Additionally, this method checks whether the parameter d is the same as the current filename, and parameter mode is the same as the current mode. If both are equal, the file will not be closed and reopened unless force=true.

References Conexus::FILE_UNCHANGED.

Referenced by File().

void Conexus::File::set_throw_eof ( bool  teof = true  ) 

Sets the endpoint behavior when an EOF condition is encountered.

Parameters:
teof If set to true, endpoint will throw an exception when an EOF is encountered

References m_throw_eof.

sigc::signal< void > Conexus::File::signal_filename_changed (  ) 


Friends And Related Function Documentation

enum FileMode [related]

Enumerator:
FILE_READ 
FILE_WRITE 
FILE_APPEND 
FILE_CREATE 
FILE_DIRECT 
FILE_LARGE_FILE 
FILE_NO_ACCESS_TIME 
FILE_NO_FOLLOW 
FILE_TRUNCATE 
FILE_EXCLUSIVE_CREATE 
FILE_UNCHANGED 
FILE_LAST_STATE 


Member Data Documentation

bool Conexus::File::m_eof [protected]

Referenced by eof(), and set_eof().

std::string Conexus::File::m_filename [protected]

Referenced by filename(), and open().

long unsigned Conexus::File::m_mode [protected]

Referenced by mode().

sigc::signal<void> Conexus::File::m_signal_filename_changed [protected]

Referenced by signal_filename_changed().

bool Conexus::File::m_throw_eof [protected]

Referenced by is_throw_eof_set(), and set_throw_eof().


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

Generated on Wed Jul 8 15:51:20 2009 for conexus by doxygen 1.5.8