Streams

Overview

Many of the ecl classes are streamable, in order to provide quick visual debugging of its contents. Typically in c++ the default streaming object is the ostream object, however the io module here extends streaming functionalities to almost every device. The important caveat though, is they do not use the c++ iostream overheads (these are very costly).

In order to accomodate both (and also perhaps third party streams), the streams concept has been defined so streaming with a generalised template function is convenient.

Compiling & Linking

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

#include <ecl/concepts.hpp>
using ecl::StreamsConcept;

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

Concept Definition

A streaming class just has to satisfy the following conditions:

  • operator << : can stream characters.
  • flush() : a method which writes the stream to an underlying device or object.

Note that the object instance cout automatically satisfies these.

Usage

A simple example of a streaming function definition and the concept check usage is outlined below.

using ecl::Stream;
class MyMatrix {
public:
template <typename OutputStream>
friend OutputStream& operator << (OutputStream &ostream, MyMatrix &matrix);
};
template <typename OutputStream>
OutputStream& operator << (OutputStream &ostream, MyMatrix &matrix) {
compile_time_concept_check(StreamConcept<OutputStream>);
ostream << "Hello Dudes, this is a matrix\n";
ostream.flush();
return ostream;
}
concepts.hpp
Compile time meta-programming concepts.
streams.hpp
Defines and validates functionality for the streams concept.


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