format-helpers.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_TOOLS_NFDC_FORMAT_HELPERS_HPP
27 #define NFD_TOOLS_NFDC_FORMAT_HELPERS_HPP
28 
29 #include "core/common.hpp"
30 
31 namespace nfd {
32 namespace tools {
33 namespace nfdc {
34 
35 namespace xml {
36 
37 void
38 printHeader(std::ostream& os);
39 
40 void
41 printFooter(std::ostream& os);
42 
43 struct Text
44 {
45  const std::string& s;
46 };
47 
50 std::ostream&
51 operator<<(std::ostream& os, const Text& text);
52 
53 std::string
54 formatSeconds(time::seconds d);
55 
56 template<typename DURATION>
57 std::string
58 formatDuration(DURATION d)
59 {
60  return formatSeconds(time::duration_cast<time::seconds>(d));
61 }
62 
63 std::string
64 formatTimestamp(time::system_clock::TimePoint t);
65 
66 } // namespace xml
67 
68 namespace text {
69 
72 struct Spaces
73 {
74  int nSpaces;
75 };
76 
77 std::ostream&
78 operator<<(std::ostream& os, const Spaces& spaces);
79 
90 class Separator
91 {
92 public:
93  Separator(const std::string& first, const std::string& subsequent);
94 
95  explicit
96  Separator(const std::string& subsequent);
97 
98  int
99  getCount() const
100  {
101  return m_count;
102  }
103 
104 private:
105  std::string m_first;
106  std::string m_subsequent;
107  int m_count;
108 
109  friend std::ostream& operator<<(std::ostream& os, Separator& sep);
110 };
111 
112 std::ostream&
113 operator<<(std::ostream& os, Separator& sep);
114 
115 std::string
116 formatSeconds(time::seconds d, bool isLong = false);
117 
118 template<typename DURATION>
119 std::string
120 formatDuration(DURATION d, bool isLong = false)
121 {
122  return formatSeconds(time::duration_cast<time::seconds>(d), isLong);
123 }
124 
125 std::string
126 formatTimestamp(time::system_clock::TimePoint t);
127 
128 } // namespace text
129 
130 } // namespace nfdc
131 } // namespace tools
132 } // namespace nfd
133 
134 #endif // NFD_TOOLS_NFDC_FORMAT_HELPERS_HPP
std::string formatSeconds(time::seconds d, bool isLong)
std::string formatTimestamp(time::system_clock::TimePoint t)
friend std::ostream & operator<<(std::ostream &os, Separator &sep)
void printHeader(std::ostream &os)
std::string formatDuration(DURATION d)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
std::string formatTimestamp(time::system_clock::TimePoint t)
std::ostream & operator<<(std::ostream &os, const Text &text)
print XML text with special character represented as predefined entities
Separator(const std::string &first, const std::string &subsequent)
std::string formatDuration(DURATION d, bool isLong=false)
int nSpaces
number of spaces; print nothing if negative
std::ostream & operator<<(std::ostream &os, const Spaces &spaces)
std::string formatSeconds(time::seconds d)
print different string on first and subsequent usage
print a number of whitespaces
void printFooter(std::ostream &os)