next up previous contents
Next: An Example: A memory Up: Reference of C stdio Previous: The StdioDeviceType

The StdioDevice

# include  <StdioDevice.h>

class StdioDevice {
    public:
      virtual int read(void*str, size_t cnt) =0;
      virtual void write(const void*str, size_t cnt) =0;
    protected:
      enum { INTERACTIVE, READABLE, WRITEABLE };
      unsigned flags_;
};

From the perspective of the stdio library, an instance of StdioDevice represents an opened physical device. The stdio library holds a pointer to one of these in the FILE structure, and uses that pointer to perform I/O operations on the device represented by the object.

In reality, an instance of StdioDevice can represent whatever the application chooses, including physical devices, channels of physical devices, even stretches of memory.

Depending on the implementation of the StdioDeviceType, there may be one instance of StdioDevice per call to StdioDeviceType::open, or one instance of StdioDevice, returned by many calls to StdioDeviceType::open.

By default, devices are considered readable and writeable. The stdio routines compare with the requested action with the device flags (stored in flags_) to be sure the device can perform the requested task. The derived class can change the default flags by ORing together all the flags (from the enum) that apply and assigning the result to the protected flags_ member.

The READABLE and WRITEABLE flags mean what one would expect, but the INTERACTIVE flag is curious. The C standard allows the environment to different between interactive and non-interactive files, and change the default buffering behavior accordingly. INTERACTIVE devices are expected to be connected to some form of interactive device (much like the POSIX isatty() flag) and the stdio library will by default buffer lines.


next up previous contents
Next: An Example: A memory Up: Reference of C stdio Previous: The StdioDeviceType
Stephen Williams
9/2/1997