Public Member Functions | List of all members
ecl::Manipulator< Derived > Class Template Reference

Parent template for c++ style stream manipulators. More...

#include <manipulator.hpp>

Public Member Functions

template<typename ODevice >
void insert (interfaces::OutputTextStream< ODevice, true > &ostream)
 The static crtp virtual parent call. More...
 
virtual ~Manipulator ()
 

Detailed Description

template<typename Derived>
class ecl::Manipulator< Derived >

Parent template for c++ style stream manipulators.

This class uses a trick embedded within the curiously recurring template method to allow static inheritance (important in this case because the manipulator function call is template based). Manipulators have an advantage over the usual c++ style manipulators in that they are themselves classes (not functions such as std::endl). This means that they can retain state from one insertion to the next.

Usage:

The manipulators defined in the ecl export a few global instantiations, namely

Using them follows the same pattern as for standard c++ style cout manipulators.

int main() {
OConsoleStream ostream;
ostream << clrscr;
ostream << "Dude" << endl;
return;
}

Creating your own Manipulators:

Any manipulator that you wish to define must inherit from this parent class in the following manner:

include <ecl/streams/manipulators.hpp>
class MyManipulator : public ecl::Manipulator<MyManipulator> {
template <typename OutputStream>
void action (OutputStream& ostream) {
// ...
}
};
Template Parameters
Derived: the child manipulator the crtp uses.
See also
Manipulator.

Definition at line 98 of file manipulator.hpp.

Constructor & Destructor Documentation

◆ ~Manipulator()

template<typename Derived >
virtual ecl::Manipulator< Derived >::~Manipulator ( )
inlinevirtual

Definition at line 122 of file manipulator.hpp.

Member Function Documentation

◆ insert()

template<typename Derived >
template<typename ODevice >
void ecl::Manipulator< Derived >::insert ( interfaces::OutputTextStream< ODevice, true > &  ostream)
inline

The static crtp virtual parent call.

This is exactly like a virtual function in a non-template c++ parent class, except it works for templates in the derived type. This function calls the derived class' action() method with the same signature.

Parameters
ostream: the stream to use for manipulation.
Template Parameters
OutputStream: the output stream type.
See also
Manipulator.

Definition at line 117 of file manipulator.hpp.


The documentation for this class was generated from the following file:
ecl::Manipulator
Parent template for c++ style stream manipulators.
Definition: manipulator.hpp:98
ecl::OConsoleStream
TextStream< OConsole > OConsoleStream
Streams to standard output.
Definition: console_streams.hpp:64
ecl::clrscr
ClearScreen clrscr
Definition: manipulators.cpp:31
main
int main(int argc, char **argv)
Definition: console_streams.cpp:36
ecl::endl
EndOfLine endl
Definition: manipulators.cpp:30
ecl


ecl_streams
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:48