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 : noncopyable
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 
131 class ItemAttributes : noncopyable
132 {
133 public:
138  explicit
139  ItemAttributes(bool wantMultiLine = false, int maxAttributeWidth = 0);
140 
141  struct Attribute
142  {
144  std::string attribute;
145  };
146 
150  Attribute
151  operator()(const std::string& attribute);
152 
153  std::string
154  end() const;
155 
156 private:
157  bool m_wantMultiLine;
158  int m_maxAttributeWidth;
159  int m_count;
160 
161  friend std::ostream& operator<<(std::ostream& os, const ItemAttributes::Attribute& attr);
162 };
163 
164 std::ostream&
165 operator<<(std::ostream& os, const ItemAttributes::Attribute& attr);
166 
167 std::string
168 formatSeconds(time::seconds d, bool isLong = false);
169 
170 template<typename DURATION>
171 std::string
172 formatDuration(DURATION d, bool isLong = false)
173 {
174  return formatSeconds(time::duration_cast<time::seconds>(d), isLong);
175 }
176 
177 std::string
178 formatTimestamp(time::system_clock::TimePoint t);
179 
180 } // namespace text
181 
182 } // namespace nfdc
183 } // namespace tools
184 } // namespace nfd
185 
186 #endif // NFD_TOOLS_NFDC_FORMAT_HELPERS_HPP
std::string formatTimestamp(time::system_clock::TimePoint t)
void printHeader(std::ostream &os)
std::string formatDuration(DURATION d)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
std::ostream & operator<<(std::ostream &os, const Text &text)
print XML text with special character represented as predefined entities
print attributes of an item
int nSpaces
number of spaces; print nothing if negative
std::string formatSeconds(time::seconds d)
print different string on first and subsequent usage
print a number of whitespaces
void printFooter(std::ostream &os)