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 
80 class Separator
81 {
82 public:
83  Separator(const std::string& first, const std::string& subsequent);
84 
85  explicit
86  Separator(const std::string& subsequent);
87 
88  int
89  getCount() const
90  {
91  return m_count;
92  }
93 
94 private:
95  std::string m_first;
96  std::string m_subsequent;
97  int m_count;
98 
99  friend std::ostream& operator<<(std::ostream& os, Separator& sep);
100 };
101 
102 std::ostream&
103 operator<<(std::ostream& os, Separator& sep);
104 
105 std::string
106 formatSeconds(time::seconds d, bool isLong = false);
107 
108 template<typename DURATION>
109 std::string
110 formatDuration(DURATION d, bool isLong = false)
111 {
112  return formatSeconds(time::duration_cast<time::seconds>(d), isLong);
113 }
114 
115 std::string
116 formatTimestamp(time::system_clock::TimePoint t);
117 
118 } // namespace text
119 
120 } // namespace nfdc
121 } // namespace tools
122 } // namespace nfd
123 
124 #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)
std::ostream & operator<<(std::ostream &os, Separator &sep)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
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)
std::string formatSeconds(time::seconds d)
print different string on first and subsequent usage
void printFooter(std::ostream &os)