Wheefun I/O Library  0.0.5
Useful I/O Primitives.
Classes | Public Types | Public Member Functions | List of all members
wfio::Device Class Reference

A C++ wrapper for a wfio_device_t. More...

#include <device.h>

Inheritance diagram for wfio::Device:
Inheritance graph
[legend]

Classes

class  CXXStrategy
 A strategy for a device. More...
 

Public Types

typedef ::wfio_device_tCType
 The C type from which a Device is derived.
 

Public Member Functions

 Device ()
 Construct the default Device. More...
 
 Device (CType dev, bool acquire=true)
 Wrap a wfio_device_t. More...
 
 Device (CType dev, IOShare ioshare)
 Wrap a wfio:device_t using an IOShare. More...
 
WFIO_CXX_DLL Device (CXXStrategy *strategy)
 Create a new Device from a CXXStrategy. More...
 
 Device (const Device &dev)
 Copy-construct a device. More...
 
 ~Device ()
 Release this Device. More...
 
size_t read (void *buf, size_t sz, size_t elem)
 Write elements to this Device. More...
 
size_t read (void *buf, size_t len)
 Write a vector of bytes to this Device. More...
 
int read ()
 Read a single byte from this Device. More...
 
size_t write (const void *buf, size_t sz, size_t elem)
 Write a vector of elements to this Device. More...
 
size_t write (const void *buf, size_t len)
 Write a vector of bytes to this Device. More...
 
bool write (char c)
 Write a single byte to this Device. More...
 
bool seek (wfio_off_t offset, wfio_whence_t whence)
 Seek to a position in this Device. More...
 
wfio_off_t tell () const
 Determine the current stream position of this Device. More...
 
Device dup ()
 Duplicate this Device. More...
 
bool flush ()
 Attempt to flush this Device. More...
 
size_t bufsz (size_t len)
 Set the buffer size for this Device. More...
 
size_t bufsz () const
 Obtain the buffer size for this Device. More...
 
bool buffered () const
 Determine whether or not the device is buffered. More...
 
int dcntl (::wfio_dcntl_t cmd,...)
 Perform device-independent I/O control on this Device. More...
 
int ioctl (int cmd,...)
 Perform device-dependent I/O control on this Device. More...
 
int flags () const throw ()
 Obtain the flags vector associated with this Device.
 
int ecode () const throw ()
 Obtain the error code associated with this Device.
 
void ecode (int ecode) throw ()
 Set the error code associated with this Device. More...
 
bool valid () const throw ()
 Determine if this Device is valid. More...
 
 operator bool () const throw ()
 Synonymous with this->valid(). More...
 
 operator::wfio_device_t * () throw ()
 Implicitly convert this Device into it's C equivalent.
 
WFIO_CXX_DLL Deviceoperator= (const Device &rhs)
 Perform assignment on this Device. More...
 

Detailed Description

A C++ wrapper for a wfio_device_t.

Constructor & Destructor Documentation

◆ Device() [1/5]

wfio::Device::Device ( )
inline

Construct the default Device.

This constructor creates an invalid Device.

◆ Device() [2/5]

wfio::Device::Device ( CType  dev,
bool  acquire = true 
)
inline

Wrap a wfio_device_t.

Parameters
devThe device to wrap.
acquireWhether or not the device should be acquired as a consequence of constructing this object.
Note
If you want to disown the previous ownership of dev from the context in which it is called, then acquire should be false.

◆ Device() [3/5]

wfio::Device::Device ( CType  dev,
IOShare  ioshare 
)
inline

Wrap a wfio:device_t using an IOShare.

Parameters
devThe device to wrap.
ioshareThe sharing mode to use.
Note
This is similar to initializing the device using wfio_device_ioshare().

◆ Device() [4/5]

WFIO_CXX_DLL wfio::Device::Device ( CXXStrategy strategy)

Create a new Device from a CXXStrategy.

Parameters
strategyThe CXXStrategy used to implement this device.

This constructor accepts a CXXStrategy and wraps it around an appropriate CType, which takes direct ownership of the CType. This device therefore indirectly owns strategy.

◆ Device() [5/5]

wfio::Device::Device ( const Device dev)
inline

Copy-construct a device.

Thie constructor acquires the underlying CType and sets it as this Device's underyling CType.

◆ ~Device()

wfio::Device::~Device ( )
inline

Release this Device.

This destructor releases this Device's underylying CType.

Member Function Documentation

◆ buffered()

bool wfio::Device::buffered ( ) const
inline

Determine whether or not the device is buffered.

Returns
True iff the device is buffered.
Note
When the buffer size if WFIO_NPOS, this function will claim that the device is buffered. This is done because flushing does not adversely affect the operation of the stream if the

◆ bufsz() [1/2]

size_t wfio::Device::bufsz ( size_t  len)
inline

Set the buffer size for this Device.

Parameters
szThe requested size to set.
Returns
The size of the buffer after this operation; otherwise, WFIO_NPOS. A return value of zero shall indicate that device is unbuffered.
Note
When the buffer size is immutable or the device cannot be buffered, but is otherwise known, then the size of the buffer is returned.

◆ bufsz() [2/2]

size_t wfio::Device::bufsz ( ) const
inline

Obtain the buffer size for this Device.

Returns
The size of the buffer associated with this device on success; otherwise, WFIO_NPOS. A return value of zero shall indicate that the device is unbuffered.

◆ dcntl()

int wfio::Device::dcntl ( ::wfio_dcntl_t  cmd,
  ... 
)
inline

Perform device-independent I/O control on this Device.

Parameters
cmdThe command to send to the device.
...Additional arguments to the dcntl.
Returns
A return value peculiar to the command invoked.
Note
It is not sufficient to look at the return value from this function to determine failure because the return value is dependent on the dcntl command. Instead, check he value of ecode; if the value is WFIO_E_SUCCESS, then no error has occurred.
If NULL is passed, zero shall be returned.

◆ dup()

Device wfio::Device::dup ( )
inline

Duplicate this Device.

Returns
A new Device; on failure, the Device is invalid.

◆ ecode()

void wfio::Device::ecode ( int  ecode)
throw (
)
inline

Set the error code associated with this Device.

Parameters
ecodethe new error code to set.

◆ flush()

bool wfio::Device::flush ( )
inline

Attempt to flush this Device.

Returns
True iff the flush operation is successful.

◆ ioctl()

int wfio::Device::ioctl ( int  cmd,
  ... 
)
inline

Perform device-dependent I/O control on this Device.

Parameters
devThe device to ioctl.
cmdThe command to send to the device.
...Additional arguments to the ioctl.
Returns
A return value peculiar to the command invoked.
Note
It is not sufficient to look at the return value from this function to determine failure because the return value is dependent on the dcntl command. Instead, check he value of ecode; if the value is WFIO_E_SUCCESS, then no error has occurred.

◆ operator bool()

wfio::Device::operator bool ( ) const
throw (
)
inline

Synonymous with this->valid().

Returns
True if this object is valid.

◆ operator=()

WFIO_CXX_DLL Device& wfio::Device::operator= ( const Device rhs)

Perform assignment on this Device.

Parameters
rhsThe device to assign to this one.

If rhs does not refer to the same CType as this one, then the current CType is released, rhs's CType is acquired. Thereafter, this Device shall refer to the same instance as rhs,

Returns
This device.

◆ read() [1/3]

size_t wfio::Device::read ( void *  buf,
size_t  sz,
size_t  elem 
)
inline

Write elements to this Device.

Parameters
bufThe buffer to write from.
szThe size of each elements.
szThe maximum number of elements to write.
Returns
The number of elements actually written on success; otherwise, WFIO_NPOS.
Note
This method may set ecode.

◆ read() [2/3]

size_t wfio::Device::read ( void *  buf,
size_t  len 
)
inline

Write a vector of bytes to this Device.

Parameters
bufThe buffer to write from.
lenThe maximum number of bytes to write.
Returns
The number of bytes actually written on success; otherwise, WFIO_NPOS.

◆ read() [3/3]

int wfio::Device::read ( )
inline

Read a single byte from this Device.

Returns
The value of the byte read on success; otherwise, WFIO_NPOS.

◆ seek()

bool wfio::Device::seek ( wfio_off_t  offset,
wfio_whence_t  whence 
)
inline

Seek to a position in this Device.

Parameters
offsetThe offset relative to whence to seek to.
whenceThe origin added to whence to seek to.
Returns
True iff the seek was successful.

◆ tell()

wfio_off_t wfio::Device::tell ( ) const
inline

Determine the current stream position of this Device.

Returns
The current stream position of the device on success; otherwise, WFIO_NPOS.

◆ valid()

bool wfio::Device::valid ( ) const
throw (
)
inline

Determine if this Device is valid.

This function determines whether or not this Device can be operated on. It is valid iff its underlying pointer is not null.

Returns
True if this object is valid.

◆ write() [1/3]

size_t wfio::Device::write ( const void *  buf,
size_t  sz,
size_t  elem 
)
inline

Write a vector of elements to this Device.

Parameters
bufThe buffer to write from.
szThe size of each elements.
elemThe maximum number of elements to write.
Returns
The number of elements actually written on success; otherwise, WFIO_NPOS.
Note
This method may set ecode.

◆ write() [2/3]

size_t wfio::Device::write ( const void *  buf,
size_t  len 
)
inline

Write a vector of bytes to this Device.

Parameters
bufThe buffer to write from.
lenThe maximum number of bytes to write.
Returns
The number of bytes actually written on success; otherwise, WFIO_NPOS.
Note
This method may set ecode.

◆ write() [3/3]

bool wfio::Device::write ( char  c)
inline

Write a single byte to this Device.

Parameters
cThe byte to write.
Returns
True iff the byte was written.
Note
This method may set ecode.

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