3 #ifndef INCLUDE_NN_NLIB_TESTING_PRINTER_H_
4 #define INCLUDE_NN_NLIB_TESTING_PRINTER_H_
12 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
13 #undef NLIB_VIS_PUBLIC
14 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
20 namespace detail_func {
24 DummyStream() : m_Str() {}
25 void swap(std::string& rhs) { m_Str.swap(rhs); }
26 const std::string& str()
const {
return m_Str; }
27 std::string& str() {
return m_Str; }
30 DummyStream& operator<<(int32_t value);
31 DummyStream& operator<<(uint32_t value);
32 DummyStream& operator<<(int64_t value);
33 DummyStream& operator<<(uint64_t value);
34 DummyStream& operator<<(
float value);
35 DummyStream& operator<<(
double value);
36 DummyStream& operator<<(
bool value);
37 DummyStream& operator<<(
const char* str);
38 DummyStream& operator<<(
const wchar_t* str);
39 DummyStream& operator<<(
const std::string& str);
40 DummyStream& operator<<(
const std::wstring& str);
41 DummyStream& operator<<(
char c);
42 DummyStream& operator<<(
wchar_t c);
43 DummyStream& operator<<(
unsigned char c);
44 DummyStream& operator<<(
signed char c);
46 DummyStream& operator<<(
const T& rhs) {
47 return Op(*
this, rhs);
67 inline void PrintTo(
const std::string& str, DummyStream* ostr) { PrintTo(str.c_str(), ostr); }
69 inline void PrintTo(
const std::wstring& str, DummyStream* ostr) { PrintTo(str.c_str(), ostr); }
71 inline void PrintTo(
signed char c, DummyStream* ostr) { PrintTo(static_cast<char>(c), ostr); }
73 inline void PrintTo(
unsigned char c, DummyStream* ostr) { PrintTo(static_cast<char>(c), ostr); }
76 void PrintToArray(
const T* a,
size_t n, DummyStream* ostr) {
82 size_t nn = (n > 8) ? 8 : n;
83 for (
size_t i = 1; i < nn; ++i) {
87 PrintTo((nn == n) ?
"}" :
", ...}", ostr);
91 template <
class T,
size_t N>
92 inline void PrintTo(
const T (&a)[N], DummyStream* ostr) {
93 PrintToArray(&a[0], N, ostr);
96 template <
class T,
class Alloc>
97 inline void PrintTo(
const std::vector<T, Alloc>& value, DummyStream* ostr) {
98 PrintToArray(&value[0], value.size(), ostr);
101 template <
class T1,
class T2>
102 void PrintTo(
const std::pair<T1, T2>& value, DummyStream* ostr) {
104 PrintTo(value.first, ostr);
106 PrintTo(value.second, ostr);
113 #define NLIB_DEF_DSOP_(tp) \
114 inline DummyStream& DummyStream::operator<<(tp x) { \
119 NLIB_DEF_DSOP_(int32_t)
120 NLIB_DEF_DSOP_(uint32_t)
121 NLIB_DEF_DSOP_(int64_t)
122 NLIB_DEF_DSOP_(uint64_t)
123 NLIB_DEF_DSOP_(
float)
124 NLIB_DEF_DSOP_(
double)
126 NLIB_DEF_DSOP_(const
char*)
127 NLIB_DEF_DSOP_(const
wchar_t*)
128 NLIB_DEF_DSOP_(const
std::
string&)
129 NLIB_DEF_DSOP_(const
std::wstring&)
131 NLIB_DEF_DSOP_(
wchar_t)
132 NLIB_DEF_DSOP_(
signed char)
133 NLIB_DEF_DSOP_(
unsigned char)
135 #undef NLIB_DEF_DSOP_
137 #define NLIB_DEF_FUNCOP_(tp, coerce_tp) \
138 inline DummyStream& Op(DummyStream& os, tp x) { \
139 PrintTo(static_cast<coerce_tp>(x), &os); \
142 NLIB_DEF_FUNCOP_(
int, int32_t)
143 NLIB_DEF_FUNCOP_(
unsigned int, uint32_t)
144 NLIB_DEF_FUNCOP_(
short, int32_t)
145 NLIB_DEF_FUNCOP_(
unsigned short, uint32_t)
146 NLIB_DEF_FUNCOP_(
long, int32_t)
147 NLIB_DEF_FUNCOP_(
unsigned long, uint32_t)
148 NLIB_DEF_FUNCOP_(
long long, int32_t)
149 NLIB_DEF_FUNCOP_(
unsigned long long, uint32_t)
150 #undef NLIB_DEF_FUNCOP_
153 inline DummyStream& Op(DummyStream& ostr,
const T& x) {
157 ostr.str().append(
"?????");
161 template <
class T,
class DUMMY>
162 inline void PrintTo(
const T& value, DUMMY* ostr) {
180 ::nlib_ns::testing::detail_func::DummyStream str;
185 using ::nlib_ns::testing::detail_func::PrintTo;
186 PrintTo(value, &str);
193 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
194 #undef NLIB_VIS_PUBLIC
195 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
198 #endif // INCLUDE_NN_NLIB_TESTING_PRINTER_H_
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。