1 // destination_defaults.hpp
2 
3 // Boost Logging library
4 //
5 // Author: John Torjo, www.torjo.com
6 //
7 // Copyright (C) 2007 John Torjo (see www.torjo.com for email)
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 //    (See accompanying file LICENSE_1_0.txt or copy at
11 //          http://www.boost.org/LICENSE_1_0.txt)
12 //
13 // See http://www.boost.org for updates, documentation, and revision history.
14 // See http://www.torjo.com/log2/ for more details
15 
16 
17 #ifndef JT28092007_destination_defaults_HPP_DEFINED
18 #define JT28092007_destination_defaults_HPP_DEFINED
19 
20 #include <hpx/config.hpp>
21 #include <hpx/util/logging/detail/fwd.hpp>
22 #include <hpx/util/logging/detail/manipulator.hpp>
23 #include <hpx/util/logging/format/destination/convert_destination.hpp>
24 #include <hpx/util/logging/format/destination/file.hpp>
25 #include <iostream>
26 
27 namespace hpx { namespace util { namespace logging { namespace destination {
28 
29 
30 /**
31     @brief Writes the string to console
32 */
33 template<class convert_dest = do_convert_destination > struct cout_t : is_generic,
34 hpx::util::logging::op_equal::always_equal {
operator ()hpx::util::logging::destination::cout_t35     void operator()(const msg_type & msg) const {
36         convert_dest::write(msg, std::cout);
37     }
38 };
39 
40 
41 /**
42     @brief Writes the string to cerr
43 */
44 template<class convert_dest = do_convert_destination > struct cerr_t : is_generic,
45 hpx::util::logging::op_equal::always_equal {
operator ()hpx::util::logging::destination::cerr_t46     void operator()(const msg_type & msg) const {
47         convert_dest::write(msg, std::cerr);
48     }
49 };
50 
51 
52 
53 /**
54     @brief writes to stream.
55 
56     @note:
57     The stream must outlive this object! Or, clear() the stream,
58     before the stream is deleted.
59 */
60 template<class convert_dest = do_convert_destination > struct stream_t : is_generic,
61 non_const_context< std::ostream * > {
62     typedef std::ostream stream_type;
63     typedef non_const_context< stream_type* > non_const_context_base;
64 
stream_thpx::util::logging::destination::stream_t65     stream_t(stream_type * s) : non_const_context_base(s) {
66     }
stream_thpx::util::logging::destination::stream_t67     stream_t(stream_type & s) : non_const_context_base(&s) {
68     }
69 
operator ()hpx::util::logging::destination::stream_t70     void operator()(const msg_type & msg) const {
71         if ( non_const_context_base::context() )
72             convert_dest::write(msg, *non_const_context_base::context());
73     }
74 
operator ==hpx::util::logging::destination::stream_t75     bool operator==(const stream_t & other) const {
76         return non_const_context_base::context() !=
77             other.non_const_context_base::context();
78     }
79 
80     /**
81         @brief resets the stream. Further output will be written to this stream
82     */
streamhpx::util::logging::destination::stream_t83     void stream(stream_type * p) { non_const_context_base::context() = p; }
84 
85     /**
86         @brief clears the stream. Further output will be ignored
87     */
clearhpx::util::logging::destination::stream_t88     void clear() { stream(0); }
89 };
90 
91 
92 
93 
94 /**
95     @brief Writes the string to output debug window
96 
97     For non-Windows systems, this is the console.
98 */
99 template<class convert_dest = do_convert_destination > struct dbg_window_t : is_generic,
100 hpx::util::logging::op_equal::always_equal {
operator ()hpx::util::logging::destination::dbg_window_t101     void operator()(const msg_type & msg) const {
102 #ifdef HPX_WINDOWS
103     ::OutputDebugStringA( convert_dest::do_convert(msg, into<const char*>() ) );
104 #else
105         // non windows - dump to console
106         std::cout << msg;
107 #endif
108     }
109 };
110 
111 
112 /** @brief cout_t with default values. See cout_t
113 
114 @copydoc cout_t
115 */
116 typedef cout_t<> cout;
117 
118 /** @brief cerr_t with default values. See cerr_t
119 
120 @copydoc cerr_t
121 */
122 typedef cerr_t<> cerr;
123 
124 /** @brief stream_t with default values. See stream_t
125 
126 @copydoc stream_t
127 */
128 typedef stream_t<> stream;
129 
130 /** @brief dbg_window_t with default values. See dbg_window_t
131 
132 @copydoc dbg_window_t
133 */
134 typedef dbg_window_t<> dbg_window;
135 
136 
137 }}}}
138 
139 #endif
140