cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
io.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_LOG_IO_H
4#define pRC_CORE_LOG_IO_H
5
6#include <cstdio>
7
8#include <prc/config.hpp>
11
12namespace pRC::Logging
13{
14 static inline Mutex Mutex;
15
16 template<LogLevel L = LogLevel::Error, Bool E = false, class X, class... Xs>
17 static inline void log(X &&arg, Xs &&...args)
18 {
19 if constexpr(cLogLevel >= L)
20 {
21 auto stream = []()
22 {
23 if constexpr(E)
24 {
25 return stderr;
26 }
27 else
28 {
29 return stdout;
30 }
31 }();
32
33 Lock const lock(Mutex);
34
35 print(forward<X>(arg), stream);
36
37 ((print(' ', stream), print(forward<Xs>(args), stream)), ...);
38
39 print('\n', stream);
40
41 std::fflush(stream);
42 }
43 }
44}
45#endif // pRC_CORE_LOG_IO_H
Definition lock.hpp:14
Definition io.hpp:13
static void log(X &&arg, Xs &&...args)
Definition io.hpp:17
static Mutex Mutex
Definition io.hpp:14
static constexpr auto arg(Complex< T > const &a)
Definition arg.hpp:12
bool Bool
Definition type_traits.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static auto print(String< N > const &string, std::FILE *stream)
Definition print.hpp:18
LogLevel
Definition config.hpp:21
std::mutex Mutex
Definition lock.hpp:10
constexpr auto cLogLevel
Definition config.hpp:32