svMultiPhysics
Loading...
Searching...
No Matches
DebugMsg.h
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef DEBUG_MSG_H
5#define DEBUG_MSG_H
6
7#include <iostream>
8
9/// @brief The DebugMsg is class is used to print debugging messages.
11{
12 public:
13 DebugMsg() = delete;
14 DebugMsg(const char* function, const int task_id, bool add_endl=true)
15 {
16 function_name_ = function;
17 task_id_ = task_id;
18 prefix_ = "[" + function_name_ + ":" + std::to_string(task_id) + "] ";
19 banner_ = prefix_ + "=============== " + function_name_ + " ===============";
20 add_endl_ = add_endl;
21 }
22
23 void banner() { std::cout << banner_ << std::endl; };
24 std::string prefix() { return prefix_; };
25
26 template <class T> DebugMsg& operator<< (const T& x)
27 {
28 if (start_) {
29 std::cout << prefix_;
30 }
31
32 std::cout << x;
33 count_ += 1;
34
35 if (add_endl_ && count_ == 2) {
36 std::cout << std::endl;
37 start_ = true;
38 count_ = 0;
39 } else {
40 start_ = false;
41 }
42
43 return *this;
44 };
45
46 DebugMsg& operator<<(std::ostream& (*f)(std::ostream& o))
47 {
48 std::cout << f;
49 start_ = true;
50 count_ = 0;
51 return *this;
52 };
53
54 private:
55 bool add_endl_ = true;
56 std::string banner_;
57 int count_ = 0;
58 std::string function_name_;
59 std::string prefix_;
60 bool start_ = true;
61 int task_id_;
62};
63
64#endif
65
The DebugMsg is class is used to print debugging messages.
Definition DebugMsg.h:11