-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcppcut-message.h
More file actions
94 lines (80 loc) · 2.45 KB
/
Copy pathcppcut-message.h
File metadata and controls
94 lines (80 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Copyright (C) 2009-2010 Kouhei Sutou <[email protected]>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __CPPCUT_MESSAGE_H__
#define __CPPCUT_MESSAGE_H__
#include <sstream>
/**
* SECTION: cppcut-message
* @title: Optional assertion message in C++
* @short_description: Supports optional assertion message
* in C++.
*
*/
namespace cut
{
template <typename Type> inline void
delegate_shift_operator(std::ostream& stream, const Type& value) {
stream << value;
}
class Message
{
public:
CUT_EXPORT Message();
CUT_EXPORT Message(const char *format, ...);
CUT_EXPORT Message(const char *format, va_list args);
CUT_EXPORT ~Message();
template <typename Type> inline Message&
operator <<(const Type& value)
{
delegate_shift_operator(buffer_, value);
return *this;
}
template <typename Type> inline Message&
operator <<(const Type *value)
{
if (value == NULL) {
buffer_ << "(null)";
} else {
delegate_shift_operator(buffer_, value);
}
return *this;
}
CUT_EXPORT inline Message&
operator <<(bool value)
{
return *this << (value ? "true" : "false");
}
CUT_EXPORT void printf(const char *format=NULL, ...);
CUT_EXPORT inline const std::string
string() const
{
return buffer_.str();
}
private:
std::ostringstream buffer_;
};
inline std::ostream&
operator <<(std::ostream& stream, const Message& message) {
return stream << message.string();
}
}
#endif /* __CPPCUT_MESSAGE_H__ */
/*
vi:ts=4:nowrap:ai:expandtab:sw=4
*/