Sierra Toolkit
Version of the Day
FormatMemorySize.cpp
1
/*------------------------------------------------------------------------*/
2
/* Copyright 2010, 2011 Sandia Corporation. */
3
/* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4
/* license for use of this work by or on behalf of the U.S. Government. */
5
/* Export of this program may require a license from the */
6
/* United States Government. */
7
/*------------------------------------------------------------------------*/
8
9
#include <sstream>
10
#include <iomanip>
11
#include <cmath>
12
13
#include <boost/lexical_cast.hpp>
14
15
#include <stk_util/environment/FormatMemorySize.hpp>
16
17
namespace
stk_classic
{
18
19
std::string
20
formatMemorySize(
21
double
size)
22
{
23
std::string result;
24
25
static
const
double
kb = 1024.0;
26
// static const double mb = kb * kb;
27
// static const double gb = kb * kb * kb;
28
29
if
(size < 0.0) {
30
result =
"-"
;
31
size = -size;
32
}
33
34
// output size in kilo bytes
35
result += boost::lexical_cast<std::string>(
static_cast<
unsigned
long
>
(size / kb));
36
result +=
" KB"
;
37
// if (size < kb) {
38
// // output size in bytes
39
// result += boost::lexical_cast<std::string>(static_cast<unsigned long>(size));
40
// result += " B";
41
// }
42
// else if (size < mb) {
43
// // output size in kilo bytes
44
// result += boost::lexical_cast<std::string>(static_cast<unsigned long>(size / kb));
45
// result += " KB";
46
// }
47
// else if (size < gb) {
48
// // output size in mega bytes
49
// result += boost::lexical_cast<std::string>(static_cast<unsigned long>(size / mb));
50
// result += " MB";
51
// }
52
// else {
53
// // everything else output in giga bytes
54
// result += boost::lexical_cast<std::string>(static_cast<unsigned long>(size / gb));
55
// result += " GB";
56
// }
57
58
return
result;
59
}
60
61
62
std::string
63
formatMemorySize(
64
MemorySize size)
65
{
66
std::string result;
67
68
static
const
MemorySize kb = 1024;
69
// static const MemorySize mb = kb * kb;
70
// static const MemorySize gb = kb * kb * kb;
71
72
// output size in kilo bytes
73
result = boost::lexical_cast<std::string>(size / kb);
74
result +=
" KB"
;
75
76
// if (size < kb) {
77
// // output size in bytes
78
// result = boost::lexical_cast<std::string>(size);
79
// result += " B";
80
// }
81
// else if (size < mb) {
82
// // output size in kilo bytes
83
// result = boost::lexical_cast<std::string>(size / kb);
84
// result += " KB";
85
// }
86
// else if (size < gb) {
87
// // output size in mega bytes
88
// result = boost::lexical_cast<std::string>(size / mb);
89
// result += " MB";
90
// }
91
// else {
92
// // everything else output in giga bytes
93
// result = boost::lexical_cast<std::string>(size / gb);
94
// result += " GB";
95
// }
96
97
return
result;
98
}
99
100
}
// namespace stk_classic
stk_classic
Sierra Toolkit.
Definition:
AlgorithmRunner.cpp:16
stk_util
stk_util
environment
FormatMemorySize.cpp
Generated by
1.8.14