blob: 11d3d5ace232500345a9d37f2c87ca745ffd564d [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_TOOLS_NFD_STATUS_FORMAT_HELPERS_HPP
27#define NFD_TOOLS_NFD_STATUS_FORMAT_HELPERS_HPP
28
29#include "common.hpp"
30
31namespace nfd {
32namespace tools {
33namespace nfd_status {
34
35namespace xml {
36
37void
38printHeader(std::ostream& os);
39
40void
41printFooter(std::ostream& os);
42
43struct Text
44{
45 const std::string& s;
46};
47
48/** \brief print XML text with special character represented as predefined entities
49 */
50std::ostream&
51operator<<(std::ostream& os, const Text& text);
52
53std::string
54formatSeconds(time::seconds d);
55
56template<typename DURATION>
57std::string
58formatDuration(DURATION d)
59{
60 return formatSeconds(time::duration_cast<time::seconds>(d));
61}
62
63std::string
64formatTimestamp(time::system_clock::TimePoint t);
65
66} // namespace xml
67
68namespace text {
69
70/** \brief print different string on first and subsequent usage
71 *
72 * \code
73 * Separator sep(",");
74 * for (int i = 1; i <= 3; ++i) {
75 * os << sep << i;
76 * }
77 * // prints: 1,2,3
78 * \endcode
79 */
80class Separator
81{
82public:
83 Separator(const std::string& first, const std::string& subsequent);
84
85 explicit
86 Separator(const std::string& subsequent);
87
88private:
89 std::string m_first;
90 std::string m_subsequent;
91 int m_count;
92
93 friend std::ostream& operator<<(std::ostream& os, Separator& sep);
94};
95
96std::ostream&
97operator<<(std::ostream& os, Separator& sep);
98
99std::string
100formatSeconds(time::seconds d, bool isLong = false);
101
102template<typename DURATION>
103std::string
104formatDuration(DURATION d, bool isLong = false)
105{
106 return formatSeconds(time::duration_cast<time::seconds>(d), isLong);
107}
108
109std::string
110formatTimestamp(time::system_clock::TimePoint t);
111
112} // namespace text
113
114} // namespace nfd_status
115} // namespace tools
116} // namespace nfd
117
118#endif // NFD_TOOLS_NFD_STATUS_FORMAT_HELPERS_HPP