1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 template<class Ch
, class Tr
, class A
>
40 typedef std::basic_ostringstream
<Ch
, Tr
, A
> stream_buffer
;
43 void operator()(const stream_buffer
&s
)
45 std::cerr
<< s
.str() << std::endl
;
49 template<class Ch
, class Tr
, class A
>
54 typedef std::basic_ostringstream
<Ch
, Tr
, A
> stream_buffer
;
57 void operator()(const stream_buffer
&s
)
59 std::cerr
<< std::endl
<< s
.str() << std::endl
;
63 template<class Ch
, class Tr
, class A
>
68 typedef std::basic_ostringstream
<Ch
, Tr
, A
> stream_buffer
;
71 void operator()(const stream_buffer
&s
)
73 std::cout
<< s
.str() << std::endl
;
77 template<class Ch
, class Tr
, class A
>
82 typedef std::basic_ostringstream
<Ch
, Tr
, A
> stream_buffer
;
85 void operator()(const stream_buffer
&s
)
87 std::cerr
<< s
.str() << std::endl
;
91 template<template <class Ch
, class Tr
, class A
> class OutputPolicy
, class Ch
= char, class Tr
= std::char_traits
<Ch
>, class A
= std::allocator
<Ch
> >
94 typedef OutputPolicy
<Ch
, Tr
, A
> output_policy
;
95 const char *_filename
;
105 void set_filename(const char *filename
, int line_number
, const char *func
)
108 _line_number
= line_number
;
114 output_policy()(arg
);
119 log
&operator<<(const T
&x
)
123 arg
<< _filename
<< ":" << _line_number
<< ": in " << _func
<< "() ";
131 typename
output_policy::stream_buffer arg
;
135 class make_cerr
: public detail::log
<detail::make_cerr
> {
137 make_cerr(const char *filename
, int line_number
, const char *func
)
139 set_filename(filename
, line_number
, func
);
143 class cerr
: public detail::log
<detail::cerr
> {
145 cerr(const char *filename
, int line_number
, const char *func
)
147 set_filename(filename
, line_number
, func
);
151 class clog
: public detail::log
<detail::clog
> {
153 clog(const char *, int, const char*)
157 class cout
: public detail::log
<detail::cout
> {
159 cout(const char *, int, const char *)
164 } // namespace stream
166 #define Error stream::cerr(__FILE__, __LINE__, __func__)
168 #define Out stream::cout(NULL, __LINE__, __func__)
170 #define Outn() stream::cout(NULL, __LINE__, __func__) << " "
172 #define Log stream::clog(NULL, __LINE__, __func__)
174 #define Logn() stream::clog(NULL, __LINE__, __func__) << " "
176 } // namespace libtest