4 #ifndef DUNE_DEBUGSTREAM_HH 5 #define DUNE_DEBUGSTREAM_HH 127 template <DebugLevel current, DebugLevel threshold>
129 static const bool value = (current >= threshold);
139 template <DebugLevel current, DebugLevel mask>
141 enum {
value = ((current & mask)!=0) };
186 template <DebugLevel thislevel = 1,
187 DebugLevel dlevel = 1,
188 DebugLevel alevel = 1,
203 _active = activator<thislevel,alevel>::value;
218 std::ostream& fallback = std::cerr)
225 _active = activator<thislevel,alevel>::value;
244 tiedstate->_tied_streams--;
247 if (_tied_streams != 0)
249 "There are streams still tied to this stream!");
253 while (current != 0) {
255 current = current->
next;
264 if (activator<thislevel, dlevel>::value) {
267 current->out << data;
269 if (_active && tiedstate->_active)
286 if (activator<thislevel, dlevel>::value) {
289 current->out << data;
291 if (_active && tiedstate->_active)
301 if (activator<thislevel, dlevel>::value) {
306 if (_active && tiedstate->_active)
307 f(tiedstate->current->out);
316 if (activator<thislevel, dlevel>::value) {
319 current->out.
flush();
321 if (_active && tiedstate->_active)
332 if (activator<thislevel,alevel>::value) {
333 _actstack.push(_active);
337 _actstack.push(
false);
343 if (_actstack.empty())
344 DUNE_THROW(DebugStreamError,
"No previous activation setting!");
346 _active = _actstack.top();
357 return activator<thislevel, dlevel>::value && _active;
369 newcurr->
next = current;
375 if (current->next == 0)
376 DUNE_THROW(DebugStreamError,
"Cannot detach initial stream!");
378 DUNE_THROW(DebugStreamError,
"Cannot detach a tied stream!");
381 current = current->
next;
396 tiedstate->_tied_streams++;
402 DUNE_THROW(DebugStreamError,
"Cannot untie, stream is not tied!");
404 tiedstate->_tied_streams--;
417 std::stack<bool> _actstack;
DebugStream & flush()
pass on flush to underlying output stream
Definition: debugstream.hh:315
unsigned int _tied_streams
how many streams are tied to this state
Definition: debugstream.hh:169
DebugStream(std::ostream &out=std::cerr)
Create a DebugStream and set initial output stream.
Definition: debugstream.hh:197
void detach()
detach current output stream and restore to previous stream
Definition: debugstream.hh:374
void tie(DebugStreamState &to)
Definition: debugstream.hh:386
StreamWrap(std::ostream &_out)
Definition: debugstream.hh:150
void pop()
restore previously set activation flag
Definition: debugstream.hh:342
StreamWrap * current
current output stream and link to possibly pushed old output streams
Definition: debugstream.hh:160
Definition: debugstream.hh:148
Greater or equal template test.
Definition: debugstream.hh:128
bool _active
flag to switch output during runtime
Definition: debugstream.hh:163
unsigned int DebugLevel
Type for debug levels.
Definition: debugstream.hh:116
Generic class to implement debug output streams.
Definition: debugstream.hh:190
DebugStream & operator<<(std::ostream &(*f)(std::ostream &))
pass on manipulators to underlying output stream
Definition: debugstream.hh:300
static const bool value
Definition: debugstream.hh:129
~DebugStream() noexcept(false)
Destroy stream.
Definition: debugstream.hh:240
Dune namespace.
Definition: alignment.hh:10
Default exception class for I/O errors.
Definition: exceptions.hh:229
StreamWrap * next
Definition: debugstream.hh:152
A few common exception classes.
DebugStream & operator<<(const int data)
explicit specialization so that enums can be printed
Definition: debugstream.hh:284
standard exception for the debugstream
Definition: debugstream.hh:146
bool active() const
reports if this stream will produce output
Definition: debugstream.hh:356
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Intermediate class to implement tie-operation of DebugStream.
Definition: debugstream.hh:156
void push(bool b)
set activation flag and store old value
Definition: debugstream.hh:330
void untie()
Untie stream.
Definition: debugstream.hh:400
activate if current and mask have common bits switched on.
Definition: debugstream.hh:140
DebugStream(DebugStreamState &master, std::ostream &fallback=std::cerr)
Create a DebugStream and directly tie to another DebugStream.
Definition: debugstream.hh:217
std::ostream & out
Definition: debugstream.hh:151
DebugStream & operator<<(const T data)
Generic types are passed on to current output stream.
Definition: debugstream.hh:262
void attach(std::ostream &stream)
set output to a different stream.
Definition: debugstream.hh:364
bool _tied
are we tied to another DebugStream?
Definition: debugstream.hh:166