~ubuntu-branches/ubuntu/oneiric/partitionmanager/oneiric

« back to all changes in this revision

Viewing changes to src/util/capacity.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-01-23 17:57:36 UTC
  • Revision ID: james.westby@ubuntu.com-20090123175736-2ltrhgg3m55dokbm
Tags: upstream-1.0.0~beta1a
ImportĀ upstreamĀ versionĀ 1.0.0~beta1a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2008 by Volker Lanz <vl@fidra.de>                       *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
#if !defined(CAPACITY__H)
 
21
 
 
22
#define CAPACITY__H
 
23
 
 
24
class Partition;
 
25
class Device;
 
26
 
 
27
#include <qglobal.h>
 
28
 
 
29
/** @brief Represent any kind of capacity.
 
30
 
 
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.
 
33
 
 
34
        @author vl@fidra.de
 
35
*/
 
36
class Capacity
 
37
{
 
38
        public:
 
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)
 
46
 
 
47
        public:
 
48
                explicit Capacity(qint64 size);
 
49
                explicit Capacity(const Partition& p, Type t = Total);
 
50
                Capacity(const Device& d);
 
51
 
 
52
        public:
 
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; }
 
59
 
 
60
                QString toString(Flags f = AppendUnit) const;
 
61
                QString toString(Unit u, Flags f) const;
 
62
                qint64 toInt() const;
 
63
                qint64 toInt(Unit u) const;
 
64
 
 
65
                QString unitName() const;
 
66
                Unit bestUnit() const;
 
67
 
 
68
                bool isValid() const;
 
69
 
 
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);
 
73
 
 
74
        protected:
 
75
                QString toStringInternal(qint64 unitSize) const;
 
76
 
 
77
        private:
 
78
                qint64 m_Size;
 
79
                static const QString m_InvalidString;
 
80
};
 
81
 
 
82
Q_DECLARE_OPERATORS_FOR_FLAGS(Capacity::Flags)
 
83
 
 
84
#endif