TPIE

2362a60
pretty_print.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2014, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
25 
26 #ifndef __TPIE_PRETTY_PRINT_H__
27 #define __TPIE_PRETTY_PRINT_H__
28 
29 #include <algorithm>
30 #include <sstream>
31 
32 namespace tpie {
33 
34 namespace bits {
35 
36  class pretty_print {
37  public:
38  static std::string size_type(stream_size_type size) {
39  static std::string units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"};
40  stream_size_type i = 0;
41  while(size > 1024 && i < 8) {
42  size /= 1024;
43  ++i;
44  }
45 
46  std::stringstream ss;
47  ss << size << units[i];
48  return ss.str();
49  }
50  };
51 
52 };
53 
54 };
55 
56 #endif //__TPIE_PRETTY_PRINT_H__