00001 #ifndef QPID_LOG_HELPERS_H
00002 #define QPID_LOG_HELPERS_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <boost/range.hpp>
00025
00026 #include <ostream>
00027
00028 namespace qpid {
00029 namespace log {
00030
00033
00034 template <class Range>
00035 struct ListFormatter {
00036 typedef typename boost::range_const_iterator<Range>::type Iterator;
00037 boost::iterator_range<Iterator> range;
00038 const char* separator;
00039
00040 ListFormatter(const Range& r, const char* s=", ") : range(r), separator(s) {}
00041 };
00042
00044 template <class Range>
00045 std::ostream& operator<<(std::ostream& out, const ListFormatter<Range>& sl) {
00046 typename ListFormatter<Range>::Iterator i = sl.range.begin();
00047 if (i != sl.range.end()) out << *(i++);
00048 while (i != sl.range.end()) out << sl.separator << *(i++);
00049 return out;
00050 }
00051
00058 template <class Range>
00059 ListFormatter<Range> formatList(const Range& range, const char* separator=", ") {
00060 return ListFormatter<Range>(range, separator);
00061 }
00062
00069 template <class U, class V>
00070 ListFormatter<std::pair<U,V> > formatList(U begin, V end, const char* separator=", ") {
00071 return formatList(std::make_pair(begin,end), separator);
00072 }
00073
00074
00075 }}
00076
00077
00078
00079 #endif