Devices

Overview

Rather than provide a complex inheritable family of classes with super-imposed mixins to represent the varying degrees of generic device functionalities (e.g. source, sink, seekable...) a rather more simpler (and faster) concept based method is used for the devices in ecl's input-output library. The concepts are required to validate the classes for use by higher level structures such as streams.

Compiling & Linking

Include the following at the top of any translation unit for which you are running compile time checks on your blueprint classes.

Since it only uses macros and templatised objects, no linking is required for just this feature.

Concept Definition

InputCharDevice

An input device class has to satisfy the following conditions:

  • long read(char &c) : read a single character from the device buffer.
  • long read(char *s, unsigned long n) : read a char buffer from the device buffer.

OutputCharDevice

An output device class has to satisfy the following conditions:

  • long write(char &c) : write a single character from the device buffer.
  • long write(char *s, unsigned long n) : write a char buffer from the device buffer.
  • void flush() : a method for flushing the output device buffer to the device.

InputOutputCharDevice

An input-output device class has to satisfy the conditions required by both input and output devices simultaneously.

ByteDevice

The three byte device concepts are similar except they add additional read/write capabilities for the other is_byte types (refer to ecl_mpl's type traits). Namely char, signed char and unsigned char.

Usage

Generally, you won't need to use these directly. Rather they're embedded in other ecl objects such as streams. However, a simple example of a device function definition and the concept check usage is outlined below.

using ecl::InputCharDevice;
template <typename Device>
class MyStream {
public:
MyStream(Device *device) {
compile_time_concept_check(InputCharDeviceConcept<Device>);
}
};
ecl::InputByteDeviceConcept
Validates functionality for the input byte device concept.
Definition: devices.hpp:165
ecl::InputCharDeviceConcept
Validates functionality for the input char device concept.
Definition: devices.hpp:45
devices.hpp
Defines validating functionality for the device concepts.
ecl::InputOutputByteDeviceConcept
Validates functionality for the input-output byte device concept.
Definition: devices.hpp:261
ecl::InputOutputCharDeviceConcept
Validates functionality for the input-output char device concept.
Definition: devices.hpp:122
concepts.hpp
Compile time meta-programming concepts.
ecl::OutputByteDeviceConcept
Validates functionality for the output byte device concept.
Definition: devices.hpp:211
ecl::OutputCharDeviceConcept
Validates functionality for the output char device concept.
Definition: devices.hpp:82


ecl_concepts
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:24