forked from objectcomputing/mFAST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_stream.h
More file actions
53 lines (44 loc) · 1.24 KB
/
debug_stream.h
File metadata and controls
53 lines (44 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2016, Huang-Ming Huang, Object Computing, Inc.
// All rights reserved.
//
// This file is part of mFAST.
// See the file license.txt for licensing information.
#pragma once
#include <iostream>
#ifdef NDEBUG
struct debug_stream {
debug_stream() {}
void set(std::ostream *) {}
template <class T> const debug_stream &operator<<(const T &) const {
return *this;
}
typedef std::ostream &(*ostream_manipulator)(std::ostream &);
// define an operator<< to take in std::endl
const debug_stream &operator<<(ostream_manipulator) const {
// call the function, but we cannot return it's value
return *this;
}
};
#else
#include "../../output.h"
class debug_stream {
private:
std::ostream *os_;
public:
debug_stream() : os_(nullptr) {}
void set(std::ostream *os) { os_ = os; }
template <class T> const debug_stream &operator<<(const T &t) const {
if (os_ != nullptr)
*os_ << t;
return *this;
}
typedef std::ostream &(*ostream_manipulator)(std::ostream &);
// define an operator<< to take in std::endl
const debug_stream &operator<<(ostream_manipulator manip) const {
// call the function, but we cannot return it's value
if (os_ != nullptr)
*os_ << manip;
return *this;
}
};
#endif