[gparted] Simplify calc_usage_triple() interface and rename
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Simplify calc_usage_triple() interface and rename
- Date: Tue, 26 Jun 2012 20:15:30 +0000 (UTC)
commit 6c96ab34b39eb23a906d6161a3d3b873025f4ec3
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Thu Jun 21 21:47:11 2012 +0100
Simplify calc_usage_triple() interface and rename
Now that every call to calc_usage_triple() just passes usage figures
returned by get_sectors_*(), remove those parameters, call
get_sectors_*() internally and rename to get_usage_triple().
include/Partition.h | 5 +--
src/Dialog_Partition_Info.cc | 9 +------
src/DrawingAreaVisualDisk.cc | 5 +---
src/Partition.cc | 47 ++++++++++++++++++++++++-----------------
4 files changed, 32 insertions(+), 34 deletions(-)
---
diff --git a/include/Partition.h b/include/Partition.h
index dc53d88..7081286 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -78,6 +78,7 @@ public:
Sector get_sectors_used() const ;
Sector get_sectors_unused() const ;
Sector get_sectors_unallocated() const ;
+ void get_usage_triple( int imax, int & i1, int & i2, int & i3 ) const ;
void Set_Unallocated( const Glib::ustring & device_path,
Sector sector_start,
@@ -133,10 +134,8 @@ public:
Byte_Value sector_size ; //Sector size of the disk device needed for converting to/from sectors and bytes.
- static void calc_usage_triple( double d1, double d2, double d3, int imax, int & i1, int & i2, int & i3 ) ;
-
private:
- static void calc_usage_triple_helper( double dtot, double d1, double d2, double d3, int imax, int & i1, int & i2, int & i3 ) ;
+ static void get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & i1, int & i2, int & i3 ) ;
void sort_paths_and_remove_duplicates() ;
Sector calc_significant_unallocated_sectors() const ;
diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc
index 9d2c003..c7641a2 100644
--- a/src/Dialog_Partition_Info.cc
+++ b/src/Dialog_Partition_Info.cc
@@ -136,11 +136,7 @@ void Dialog_Partition_Info::init_drawingarea()
}
else if ( partition .sector_usage_known() )
{
- Partition::calc_usage_triple( partition .get_sectors_used(),
- partition .get_sectors_unused(),
- partition .get_sectors_unallocated(),
- ( 400 - BORDER *2 ),
- used, unused, unallocated ) ;
+ partition .get_usage_triple( 400 - BORDER *2, used, unused, unallocated ) ;
}
else
{
@@ -209,8 +205,7 @@ void Dialog_Partition_Info::Display_Info()
Sector unallocated = partition .get_sectors_unallocated() ;
//calculate relative diskusage
int percent_used, percent_unused, percent_unallocated ;
- Partition::calc_usage_triple( used, unused, unallocated, 100,
- percent_used, percent_unused, percent_unallocated ) ;
+ partition .get_usage_triple( 100, percent_used, percent_unused, percent_unallocated ) ;
//Used
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Used:") ) + "</b>" ),
diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc
index 81d2a04..1ec500b 100644
--- a/src/DrawingAreaVisualDisk.cc
+++ b/src/DrawingAreaVisualDisk.cc
@@ -158,10 +158,7 @@ void DrawingAreaVisualDisk::calc_usage( std::vector<visual_partition> & visual_p
{
if ( visual_partitions[ t ] .partition .sector_usage_known() )
{
- Partition::calc_usage_triple(
- visual_partitions[ t ] .partition .get_sectors_used(),
- visual_partitions[ t ] .partition .get_sectors_unused(),
- visual_partitions[ t ] .partition .get_sectors_unallocated(),
+ visual_partitions[ t ] .partition .get_usage_triple(
visual_partitions[ t ] .length - BORDER *2,
visual_partitions[ t ] .used_length,
visual_partitions[ t ] .unused_length,
diff --git a/src/Partition.cc b/src/Partition.cc
index 6b36c2e..bbae802 100644
--- a/src/Partition.cc
+++ b/src/Partition.cc
@@ -262,32 +262,39 @@ bool Partition::operator!=( const Partition & partition ) const
return ! ( *this == partition ) ;
}
-//Calculate the "best" display integers (pixels or percentages) from
-// partition usage figures. Rounds the smaller two figures and then
-// subtracts them from the desired total for the largest figure.
-void Partition::calc_usage_triple( double d1, double d2, double d3, int imax, int & i1, int & i2, int & i3 )
-{
- if ( d1 < 0.0 ) d1 = 0.0 ;
- if ( d2 < 0.0 ) d2 = 0.0 ;
- if ( d3 < 0.0 ) d3 = 0.0 ;
- double dtot = d1 + d2 + d3 ;
- if ( d1 <= d2 && d1 <= d3 )
- calc_usage_triple_helper( dtot, d1, d2, d3, imax, i1, i2, i3 ) ;
- else if ( d2 < d1 && d2 <= d3 )
- calc_usage_triple_helper( dtot, d2, d1, d3, imax, i2, i1, i3 ) ;
- else if ( d3 < d1 && d3 < d2 )
- calc_usage_triple_helper( dtot, d3, d1, d2, imax, i3, i1, i2 ) ;
-}
-
-//Calculate the "best" display integers when d1 <= d2 and d1 <= d3.
+//Get the "best" display integers (pixels or percentages) from partition
+// usage figures. Rounds the smaller two figures and then subtracts
+// them from the desired total for the largest figure.
+void Partition::get_usage_triple( int imax, int & i1, int & i2, int & i3 ) const
+{
+ Sector s1 = get_sectors_used() ;
+ Sector s2 = get_sectors_unused() ;
+ Sector s3 = get_sectors_unallocated() ;
+ if ( ! sector_usage_known() )
+ {
+ //Set to all unused
+ i1 = i3 = 0 ;
+ i2 = imax ;
+ return ;
+ }
+ Sector stot = s1 + s2 + s3 ;
+ if ( s1 <= s2 && s1 <= s3 )
+ get_usage_triple_helper( stot, s1, s2, s3, imax, i1, i2, i3 ) ;
+ else if ( s2 < s1 && s2 <= s3 )
+ get_usage_triple_helper( stot, s2, s1, s3, imax, i2, i1, i3 ) ;
+ else if ( s3 < s1 && s3 < s2 )
+ get_usage_triple_helper( stot, s3, s1, s2, imax, i3, i1, i2 ) ;
+}
+
+//Calculate the "best" display integers when s1 <= s2 and s1 <= s3.
// Ensure i1 <= i2 and i1 <= i3.
-void Partition::calc_usage_triple_helper( double dtot, double d1, double d2, double d3, int imax, int & i1, int & i2, int & i3 )
+void Partition::get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & i1, int & i2, int & i3 )
{
int t ;
- i1 = Utils::round( d1 / dtot * imax ) ;
- if ( d2 <= d3 )
+ i1 = Utils::round( static_cast<double>( s1 ) / stot * imax ) ;
+ if ( s2 <= s3 )
{
- i2 = Utils::round( d2 / dtot * imax ) ;
+ i2 = Utils::round( static_cast<double>( s2 ) / stot * imax ) ;
i3 = imax - i1 - i2 ;
if ( i1 > i3 )
{
@@ -299,7 +306,7 @@ void Partition::calc_usage_triple_helper( double dtot, double d1, double d2, dou
}
else
{
- i3 = Utils::round( d3 / dtot * imax ) ;
+ i3 = Utils::round( static_cast<double>( s3 ) / stot * imax ) ;
i2 = imax - i1 - i3 ;
if ( i1 > i2 )
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]