Format.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_Format_
18 #define HH_SENF_Utils_Format_ 1
19 
20 // Custom includes
21 #include <limits>
22 #include <ostream>
23 #include <boost/utility/enable_if.hpp>
24 #include <boost/type_traits/is_signed.hpp>
25 #include <boost/type_traits/is_unsigned.hpp>
26 
27 //#include "Format.mpp"
28 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 
30 namespace senf {
31 namespace format {
32 
36 #ifdef DOXYGEN
37 
114  streamable_type eng(float v, float d=NAN);
115 
116 #else
117 
118  class eng
119  {
120  public:
121  eng(float v, float d = std::numeric_limits<float>::quiet_NaN());
122 
123  eng const & setw(unsigned w = 1) const;
124  eng const & setprecision(unsigned p) const;
125  eng const & setfill(char c) const;
126 
127  eng const & showbase() const;
128  eng const & noshowbase() const;
129  eng const & showpos() const;
130  eng const & noshowpos() const;
131  eng const & showpoint() const;
132  eng const & noshowpoint() const;
133  eng const & uppercase() const;
134  eng const & nouppercase() const;
135  eng const & left() const;
136  eng const & internal() const;
137  eng const & right() const;
138 
139  private:
140  float v_;
141  float d_;
142 
143  mutable bool haveWidth_;
144  mutable unsigned width_;
145  mutable bool havePrecision_;
146  mutable unsigned precision_;
147  mutable bool haveFill_;
148  mutable char fill_;
149  mutable std::ios_base::fmtflags mask_;
150  mutable std::ios_base::fmtflags flags_;
151 
152  friend std::ostream & operator<<(std::ostream & os, eng const & v);
153 
154  };
155 
156  std::ostream & operator<<(std::ostream & os, eng const & v);
157 
158 #endif
159 
160 #ifdef DOXYGEN
161 
175  template <class T>
176  streamable_type dumpint(T const & v);
177 
178 #else
179 
180  template <class T>
181  std::string dumpint(T const & v,
182  typename boost::enable_if<boost::is_signed<T> >::type * = 0);
183 
184  template <class T>
185  std::string dumpint(T const & v,
186  typename boost::enable_if<boost::is_unsigned<T> >::type * = 0);
187 
188  template <class T>
189  std::string dumpint(T const & v,
190  typename boost::enable_if<boost::is_signed<typename T::value_type> >::type * = 0);
191 
192  template <class T>
193  std::string dumpint(T const & v,
194  typename boost::enable_if<boost::is_unsigned<typename T::value_type> >::type * = 0);
195 
196 #endif
197 
229  {
230  static unsigned int static_level;
231  unsigned int instance_level;
232  public:
233 
234  IndentHelper();
235 
236  ~IndentHelper();
237 
239  void increase();
240 
241  unsigned int level() const;
242  };
243 
247  std::ostream & operator<<(std::ostream & os, IndentHelper const & indent);
248 
249 }}
250 
251 //-/////////////////////////////////////////////////////////////////////////////////////////////////
252 #include "Format.cci"
253 //#include "Format.ct"
254 #include "Format.cti"
255 #endif
256 
257 
258 // Local Variables:
259 // mode: c++
260 // fill-column: 100
261 // comment-column: 40
262 // c-file-style: "senf"
263 // indent-tabs-mode: nil
264 // ispell-local-dictionary: "american"
265 // compile-command: "scons -u test"
266 // End:
u8 type
streamable_type dumpint(T const &v)
Dump integer value with internal representation.
streamable_type eng(float v, float d=NAN)
Format value in engineering representation.
std::ostream & operator<<(std::ostream &os, CpuStat const &cs)
Definition: CpuStat.cc:103
Helper class to easily achieve indent levels.
Definition: Format.hh:228
void format(Type const &value, std::ostream &os)