cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
print.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_LOG_PRINT_H
4#define pRC_CORE_LOG_PRINT_H
5
6#include <cstdio>
7#include <string>
8
10
11namespace pRC
12{
13 template<class T>
14 static inline constexpr auto name();
15
16 template<auto T>
17 static inline constexpr auto name();
18
19 template<class T, T V, class S>
20 static inline auto print(Constant<T, V> const, S &&stream)
21 {
22 print("pRC::Constant<" + name<T>() + ", " + name<V>() + ">", stream);
23 }
24
25 static inline auto print(Bool const value, std::FILE *stream)
26 {
27 if(value)
28 {
29 std::fprintf(stream, "True");
30 }
31 else
32 {
33 std::fprintf(stream, "False");
34 }
35 }
36
37 template<IsIntegral T>
38 static inline auto print(T const value, std::FILE *stream)
39 {
40 if constexpr(IsSame<T, int>)
41 {
42 std::fprintf(stream, "% d", value);
43 }
44 else if constexpr(IsSame<T, short>)
45 {
46 std::fprintf(stream, "% hd", value);
47 }
48 else if constexpr(IsSame<T, long>)
49 {
50 std::fprintf(stream, "% ld", value);
51 }
52 else if constexpr(IsSame<T, long long>)
53 {
54 std::fprintf(stream, "% lld", value);
55 }
56 else if constexpr(IsSame<T, unsigned>)
57 {
58 std::fprintf(stream, "%u", value);
59 }
60 else if constexpr(IsSame<T, unsigned short>)
61 {
62 std::fprintf(stream, "%hu", value);
63 }
64 else if constexpr(IsSame<T, unsigned long>)
65 {
66 std::fprintf(stream, "%lu", value);
67 }
68 else if constexpr(IsSame<T, unsigned long long>)
69 {
70 std::fprintf(stream, "%llu", value);
71 }
72 else if constexpr(IsSame<T, char> || IsSame<T, unsigned char> ||
74 {
75 std::fputc(value, stream);
76 }
77 }
78
79 static inline auto print(char const *const string, std::FILE *stream)
80 {
81 std::fputs(string, stream);
82 }
83
84 static inline auto print(std::string const &string, std::FILE *stream)
85 {
86 print(string.c_str(), stream);
87 }
88}
89#endif // pRC_CORE_LOG_PRINT_H
Definition value.hpp:12
Definition concepts.hpp:28
TN::Subscripts S
Definition externs_nonTT.hpp:9
int value
Definition gmock-actions_test.cc:1714
Definition cholesky.hpp:10
static auto print(String< N > const &string, std::FILE *stream)
Definition print.hpp:18
static constexpr auto name()
Definition type_name.hpp:11
std::integral_constant< T, V > Constant
Definition basics.hpp:38
Definition gtest_pred_impl_unittest.cc:54