1 // convert_destination.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_convert_destination_HPP_DEFINED
18 #define JT28092007_convert_destination_HPP_DEFINED
19 
20 #include <hpx/util/logging/detail/fwd.hpp>
21 #include <ostream>
22 #include <string>
23 
24 namespace hpx { namespace util { namespace logging { namespace destination {
25 
26 template<class t> struct into {};
27 
28 /**
29 @brief Allows writing messages to destinations
30 
31 It has 2 function overloads:
32 - write(message, output) - writes the given message, to the given output
33 - do_convert(message, into<other_type>() );
34 
35 FIXME
36 */
37 namespace convert {
write(const obj & m,std::ostream & out)38     template<class obj> inline void write(const obj & m,
39         std::ostream & out) {
40         out << m;
41     }
42 
write(const char * m,std::ostream & out)43     inline void write(const char* m,
44         std::ostream & out) {
45         out << m;
46     }
47 
do_convert(const char * c,const into<const char * > &)48     inline const char * do_convert(const char * c,
49         const into<const char*> &) { return c; }
do_convert(const std::string & s,const into<const char * > &)50     inline const char * do_convert(const std::string & s,
51         const into<const char* > &) { return s.c_str(); }
52 
53     inline const std::string &
do_convert(const std::string & s,const into<std::string> &)54         do_convert(const std::string & s,
55             const into< std::string > &) {
56         return s;
57     }
58 }
59 
60 struct do_convert_destination {
writehpx::util::logging::destination::do_convert_destination61     template<class msg, class dest> static void write(const msg & m, dest & d) {
62         convert::write(m, d);
63     }
64 
do_converthpx::util::logging::destination::do_convert_destination65     template<class msg, class dest> static dest do_convert(const msg & m,
66         const into<dest> &) {
67         return convert::do_convert(m, into<dest>() );
68     }
69 
70 };
71 
72 }}}}
73 
74 #endif
75