Kurlyk
Loading...
Searching...
No Matches
print_utils.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef _KURLYK_UTILS_PRINT_UTILS_HPP_INCLUDED
3#define _KURLYK_UTILS_PRINT_UTILS_HPP_INCLUDED
4
7
8#define KURLYK_PRINT kurlyk::utils::ThreadSafePrintStream{}
9
10namespace kurlyk::utils {
11
13 class ThreadSafePrintStream : public std::ostringstream {
14 public:
16
18 get_instance().print(this->str());
19 }
20
21 private:
23 public:
24 void print(const std::string &str) {
25 std::lock_guard<std::mutex> guard(m_mutex_print);
26 std::cout << str;
27 }
28
29 private:
30 std::mutex m_mutex_print;
31 };
32
34 static PrintStream instance;
35 return instance;
36 }
37 };
38
39} // namespace kurlyk::utils
40
41#endif // _KURLYK_UTILS_PRINT_UTILS_HPP_INCLUDED
static PrintStream & get_instance()