tlx
Loading...
Searching...
No Matches
unordered_map.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/logger/unordered_map.hpp
3 *
4 * Part of tlx - http://panthema.net/tlx
5 *
6 * Copyright (C) 2018 Timo Bingmann <tb@panthema.net>
7 *
8 * All rights reserved. Published under the Boost Software License, Version 1.0
9 ******************************************************************************/
10
11#ifndef TLX_LOGGER_UNORDERED_MAP_HEADER
12#define TLX_LOGGER_UNORDERED_MAP_HEADER
13
14#include <tlx/logger/core.hpp>
15
16#include <unordered_map>
17
18namespace tlx {
19
20template <typename K, typename V, typename H, typename E, typename A>
21class LoggerFormatter<std::unordered_map<K, V, H, E, A> >
22{
23public:
24 static void print(std::ostream& os,
25 const std::unordered_map<K, V, H, E, A>& data) {
26 os << '{';
27 for (typename std::unordered_map<K, V, H, E, A>::const_iterator
28 it = data.begin(); it != data.end(); ++it)
29 {
30 if (it != data.begin()) os << ',';
31 LoggerFormatter<K>::print(os, it->first);
32 os << '=';
33 LoggerFormatter<V>::print(os, it->second);
34 }
35 os << '}';
36 }
37};
38
39template <typename K, typename V, typename H, typename E, typename A>
40class LoggerFormatter<std::unordered_multimap<K, V, H, E, A> >
41{
42public:
43 static void print(std::ostream& os,
44 const std::unordered_multimap<K, V, H, E, A>& data) {
45 os << '{';
46 for (typename std::unordered_multimap<K, V, H, E, A>::const_iterator
47 it = data.begin(); it != data.end(); ++it)
48 {
49 if (it != data.begin()) os << ',';
50 LoggerFormatter<K>::print(os, it->first);
51 os << '=';
52 LoggerFormatter<V>::print(os, it->second);
53 }
54 os << '}';
55 }
56};
57
58} // namespace tlx
59
60#endif // !TLX_LOGGER_UNORDERED_MAP_HEADER
61
62/******************************************************************************/
static void print(std::ostream &os, const std::unordered_map< K, V, H, E, A > &data)
static void print(std::ostream &os, const std::unordered_multimap< K, V, H, E, A > &data)
template class for formatting. contains a print() method.
Definition: core.hpp:25
STL namespace.