1
/***************************************************************************
2
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18
***************************************************************************/
20
#if !defined(CAPACITY__H)
29
/** @brief Represent any kind of capacity.
31
Any kind of capacity that can be expressed in units of Byte, KiB, MiB and so on. Also prints
32
capacities in nicely formatted ways.
39
/** Units we can deal with */
40
enum Unit { Byte, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, YiB };
41
/** Type of capacity to print */
42
enum Type { Used, Available, Total };
43
/** Flags for printing */
44
enum Flag { NoFlags = 0, AppendUnit = 1, AppendBytes = 2 };
45
Q_DECLARE_FLAGS(Flags, Flag)
48
explicit Capacity(qint64 size);
49
explicit Capacity(const Partition& p, Type t = Total);
50
Capacity(const Device& d);
53
bool operator==(const Capacity& other) const { return other.m_Size == m_Size; }
54
bool operator!=(const Capacity& other) const { return other.m_Size != m_Size; }
55
bool operator>(const Capacity& other) const { return other.m_Size > m_Size; }
56
bool operator<(const Capacity& other) const { return other.m_Size < m_Size; }
57
bool operator>=(const Capacity& other) const { return other.m_Size >= m_Size; }
58
bool operator<=(const Capacity& other) const { return other.m_Size <= m_Size; }
60
QString toString(Flags f = AppendUnit) const;
61
QString toString(Unit u, Flags f) const;
63
qint64 toInt(Unit u) const;
65
QString unitName() const;
66
Unit bestUnit() const;
70
static const QString& invalidString() { return m_InvalidString; } /**< @return string representing an invalid capacity */
71
static QString unitName(Unit u);
72
static qint64 unitFactor(Unit from, Unit to);
75
QString toStringInternal(qint64 unitSize) const;
79
static const QString m_InvalidString;
82
Q_DECLARE_OPERATORS_FOR_FLAGS(Capacity::Flags)