Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

BytesDisplayer Class Reference

Displays a byte size in a range of [1,1024[ with a suffix. More...

#include <bytedisp.hpp>

List of all members.

Public Types

enum  Units {
  byte = 0, kilo, mega, giga,
  tera, peta, exa, zetta,
  yotta
}
 List of the units. More...

enum  UnitsFormat { None, Short, Long }
 Units format types. More...


Public Member Functions

 BytesDisplayer (const unsigned long value)
 Constructor with a long integer type.

 BytesDisplayer (const long value)
 Constructor with a long integer type.

 BytesDisplayer (const double value)
 Constructor with a double type.

 BytesDisplayer (const BytesDisplayer &source)
 Copy constructor.

 BytesDisplayer ()
 Default constructor.

BytesDisplayeroperator+= (const BytesDisplayer &a)
 Operator +=.

BytesDisplayeroperator= (const unsigned long value)
 Assignment operator.

BytesDisplayeroperator= (const long value)
 Assignment operator.

BytesDisplayeroperator= (const double value)
 Assignment operator.

BytesDisplayeroperator= (const BytesDisplayer &source)
 Assignment operator.

double toDouble (const Units u=byte) const
 Gets the size as a double.

wxString toString (const UnitsFormat uf=Short) const
 Gets the size as a string.

wxString toString (const Units u, const UnitsFormat uf=Short) const
 Gets the size as a string.


Static Public Member Functions

void initStatic ()
 Initializes the static part of the class.


Protected Types

typedef double bytesize_type
 Internal type of size values.


Protected Member Functions

void clone (const BytesDisplayer &source)
 Clones the source instance in this instance.

void normalize ()
 Normalizes the value.


Protected Attributes

bytesize_type size
 Value of the size.

Units unit
 Current unit.


Static Protected Attributes

wxString long_units [9]
 Name of the units (long format).

wxString short_units [9]
 Name of the units (short format).


Detailed Description

Displays a byte size in a range of [1,1024[ with a suffix.

Important: Call initStatic() (only once is needed) before using this class. It is needed for i18n.

The suffix could be:
NameAbbrFactor
kiloK210 = 1024
megaM220 = 1 048 576
gigaG230 = 1 073 741 824
teraT240 = 1 099 511 627 776
petaP250 = 1 125 899 906 842 624
exaE260 = 1 152 921 504 606 846 976
zettaZ270 = 1 180 591 620 717 411 303 424
yottaY280 = 1 208 925 819 614 629 174 706 176
Source: Wikipedia.

This class manages only positives integers and should not be used for precise work with sizes since it uses internally doubles values. Use it only for display sizes in xB.

Definition at line 67 of file bytedisp.hpp.


Member Typedef Documentation

typedef double BytesDisplayer::bytesize_type [protected]
 

Internal type of size values.

Definition at line 98 of file bytedisp.hpp.

Referenced by operator+=().


Member Enumeration Documentation

enum BytesDisplayer::Units
 

List of the units.

Definition at line 71 of file bytedisp.hpp.

Referenced by operator+=(), and toDouble().

enum BytesDisplayer::UnitsFormat
 

Units format types.

Definition at line 85 of file bytedisp.hpp.


Constructor & Destructor Documentation

BytesDisplayer::BytesDisplayer  ) 
 

Default constructor.

Definition at line 99 of file bytedisp.cpp.

References size, and unit.

BytesDisplayer::BytesDisplayer const BytesDisplayer source  ) 
 

Copy constructor.

Parameters:
source Source instance.

Definition at line 128 of file bytedisp.cpp.

References clone().

BytesDisplayer::BytesDisplayer const double  value  ) 
 

Constructor with a double type.

Parameters:
value The size.

Definition at line 202 of file bytedisp.cpp.

References normalize(), size, and unit.

BytesDisplayer::BytesDisplayer const long  value  ) 
 

Constructor with a long integer type.

Parameters:
value The size.

Definition at line 216 of file bytedisp.cpp.

References normalize(), size, and unit.

BytesDisplayer::BytesDisplayer const unsigned long  value  ) 
 

Constructor with a long integer type.

Parameters:
value The size.

Definition at line 230 of file bytedisp.cpp.

References normalize(), size, and unit.


Member Function Documentation

void BytesDisplayer::clone const BytesDisplayer source  )  [protected]
 

Clones the source instance in this instance.

Parameters:
source Source instance.

Definition at line 112 of file bytedisp.cpp.

References clone(), size, and unit.

Referenced by BytesDisplayer(), clone(), and operator=().

void BytesDisplayer::initStatic  )  [static]
 

Initializes the static part of the class.

Please call this function before the first use of this class.

Definition at line 72 of file bytedisp.cpp.

References long_units, and short_units.

Referenced by CkSumsApp::OnInit().

void BytesDisplayer::normalize  )  [protected]
 

Normalizes the value.

After calling this function:

  • If the size is < 0 then the size equals to 0.
  • If the size is bigger than 1024 then the size is bring back to the interval [1,1024[.
  • If the size is smaller than 1 then the size is bring back to the interval [1,1024[.

Definition at line 249 of file bytedisp.cpp.

References size, and unit.

Referenced by BytesDisplayer(), operator+=(), and operator=().

BytesDisplayer & BytesDisplayer::operator+= const BytesDisplayer a  ) 
 

Operator +=.

Parameters:
a The value to add.
Returns:
A reference on the instance.

Definition at line 282 of file bytedisp.cpp.

References bytesize_type, normalize(), operator+=(), size, unit, and Units.

Referenced by operator+=().

BytesDisplayer & BytesDisplayer::operator= const unsigned long  value  ) 
 

Assignment operator.

Parameters:
value The size.
Returns:
A reference on the instance.

Definition at line 187 of file bytedisp.cpp.

References normalize(), operator=(), size, and unit.

BytesDisplayer & BytesDisplayer::operator= const long  value  ) 
 

Assignment operator.

Parameters:
value The size.
Returns:
A reference on the instance.

Definition at line 171 of file bytedisp.cpp.

References normalize(), operator=(), size, and unit.

BytesDisplayer & BytesDisplayer::operator= const double  value  ) 
 

Assignment operator.

Parameters:
value The size.
Returns:
A reference on the instance.

Definition at line 155 of file bytedisp.cpp.

References normalize(), operator=(), size, and unit.

BytesDisplayer & BytesDisplayer::operator= const BytesDisplayer source  ) 
 

Assignment operator.

Parameters:
source Source instance.
Returns:
A reference on the instance.

Definition at line 141 of file bytedisp.cpp.

References clone(), and operator=().

Referenced by operator=().

double BytesDisplayer::toDouble const Units  u = byte  )  const
 

Gets the size as a double.

Parameters:
u Unit in which the size must be returned.
Returns:
The size as a double.

Definition at line 311 of file bytedisp.cpp.

References size, toDouble(), unit, and Units.

Referenced by ChecksumsListView::ChecksumProgress::ChecksumProgress(), dlgMultiCheck::setReadBytes(), dlgBatchCreation::setReadBytes(), dlgMultiCheck::setTotalBytes(), dlgBatchCreation::setTotalBytes(), toDouble(), toString(), ChecksumsListView::ChecksumProgress::update(), dlgMultiCheck::updateCurrentCheckedFile(), and dlgBatchCreation::updateCurrentProcessedFile().

wxString BytesDisplayer::toString const UnitsFormat  uf = Short  )  const
 

Gets the size as a string.

Parameters:
uf Format of the unit suffix.
Returns:
The size as a string.

Definition at line 366 of file bytedisp.cpp.

References toString(), and unit.

wxString BytesDisplayer::toString const Units  u,
const UnitsFormat  uf = Short
const
 

Gets the size as a string.

Parameters:
u Unit in which the size must be returned.
uf Format of the unit suffix.
Returns:
The size as a string.

Definition at line 338 of file bytedisp.cpp.

References long_units, short_units, toDouble(), and toString().

Referenced by ChecksumsListView::ChecksumProgress::ChecksumProgress(), toString(), and ChecksumsListView::ChecksumProgress::update().


Member Data Documentation

wxString BytesDisplayer::long_units [static, protected]
 

Name of the units (long format).

Definition at line 48 of file bytedisp.cpp.

Referenced by initStatic(), and toString().

wxString BytesDisplayer::short_units [static, protected]
 

Name of the units (short format).

Definition at line 49 of file bytedisp.cpp.

Referenced by initStatic(), and toString().

bytesize_type BytesDisplayer::size [protected]
 

Value of the size.

Definition at line 100 of file bytedisp.hpp.

Referenced by BytesDisplayer(), clone(), normalize(), operator+=(), operator=(), and toDouble().

Units BytesDisplayer::unit [protected]
 

Current unit.

Definition at line 101 of file bytedisp.hpp.

Referenced by BytesDisplayer(), clone(), normalize(), operator+=(), operator=(), toDouble(), and toString().


The documentation for this class was generated from the following files:
Generated on Sun May 30 13:38:02 2004 for wxChecksums by doxygen 1.3.7