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().
This commit is contained in:
Mike Fleetwood 2012-06-21 21:47:11 +01:00 committed by Curtis Gedak
parent ac3ce5ec2b
commit 6c96ab34b3
4 changed files with 32 additions and 34 deletions

View File

@ -78,6 +78,7 @@ public:
Sector get_sectors_used() const ; Sector get_sectors_used() const ;
Sector get_sectors_unused() const ; Sector get_sectors_unused() const ;
Sector get_sectors_unallocated() 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, void Set_Unallocated( const Glib::ustring & device_path,
Sector sector_start, 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. 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: 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() ; void sort_paths_and_remove_duplicates() ;
Sector calc_significant_unallocated_sectors() const ; Sector calc_significant_unallocated_sectors() const ;

View File

@ -136,11 +136,7 @@ void Dialog_Partition_Info::init_drawingarea()
} }
else if ( partition .sector_usage_known() ) else if ( partition .sector_usage_known() )
{ {
Partition::calc_usage_triple( partition .get_sectors_used(), partition .get_usage_triple( 400 - BORDER *2, used, unused, unallocated ) ;
partition .get_sectors_unused(),
partition .get_sectors_unallocated(),
( 400 - BORDER *2 ),
used, unused, unallocated ) ;
} }
else else
{ {
@ -209,8 +205,7 @@ void Dialog_Partition_Info::Display_Info()
Sector unallocated = partition .get_sectors_unallocated() ; Sector unallocated = partition .get_sectors_unallocated() ;
//calculate relative diskusage //calculate relative diskusage
int percent_used, percent_unused, percent_unallocated ; int percent_used, percent_unused, percent_unallocated ;
Partition::calc_usage_triple( used, unused, unallocated, 100, partition .get_usage_triple( 100, percent_used, percent_unused, percent_unallocated ) ;
percent_used, percent_unused, percent_unallocated ) ;
//Used //Used
table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Used:") ) + "</b>" ), table ->attach( * Utils::mk_label( "<b>" + Glib::ustring( _("Used:") ) + "</b>" ),

View File

@ -158,10 +158,7 @@ void DrawingAreaVisualDisk::calc_usage( std::vector<visual_partition> & visual_p
{ {
if ( visual_partitions[ t ] .partition .sector_usage_known() ) if ( visual_partitions[ t ] .partition .sector_usage_known() )
{ {
Partition::calc_usage_triple( visual_partitions[ t ] .partition .get_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 ] .length - BORDER *2, visual_partitions[ t ] .length - BORDER *2,
visual_partitions[ t ] .used_length, visual_partitions[ t ] .used_length,
visual_partitions[ t ] .unused_length, visual_partitions[ t ] .unused_length,

View File

@ -262,32 +262,39 @@ bool Partition::operator!=( const Partition & partition ) const
return ! ( *this == partition ) ; return ! ( *this == partition ) ;
} }
//Calculate the "best" display integers (pixels or percentages) from //Get the "best" display integers (pixels or percentages) from partition
// partition usage figures. Rounds the smaller two figures and then // usage figures. Rounds the smaller two figures and then subtracts
// subtracts them from the desired total for the largest figure. // 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 ) void Partition::get_usage_triple( int imax, int & i1, int & i2, int & i3 ) const
{ {
if ( d1 < 0.0 ) d1 = 0.0 ; Sector s1 = get_sectors_used() ;
if ( d2 < 0.0 ) d2 = 0.0 ; Sector s2 = get_sectors_unused() ;
if ( d3 < 0.0 ) d3 = 0.0 ; Sector s3 = get_sectors_unallocated() ;
double dtot = d1 + d2 + d3 ; if ( ! sector_usage_known() )
if ( d1 <= d2 && d1 <= d3 ) {
calc_usage_triple_helper( dtot, d1, d2, d3, imax, i1, i2, i3 ) ; //Set to all unused
else if ( d2 < d1 && d2 <= d3 ) i1 = i3 = 0 ;
calc_usage_triple_helper( dtot, d2, d1, d3, imax, i2, i1, i3 ) ; i2 = imax ;
else if ( d3 < d1 && d3 < d2 ) return ;
calc_usage_triple_helper( dtot, d3, d1, d2, imax, i3, i1, i2 ) ; }
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 d1 <= d2 and d1 <= d3. //Calculate the "best" display integers when s1 <= s2 and s1 <= s3.
// Ensure i1 <= i2 and i1 <= i3. // 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 ; int t ;
i1 = Utils::round( d1 / dtot * imax ) ; i1 = Utils::round( static_cast<double>( s1 ) / stot * imax ) ;
if ( d2 <= d3 ) if ( s2 <= s3 )
{ {
i2 = Utils::round( d2 / dtot * imax ) ; i2 = Utils::round( static_cast<double>( s2 ) / stot * imax ) ;
i3 = imax - i1 - i2 ; i3 = imax - i1 - i2 ;
if ( i1 > i3 ) if ( i1 > i3 )
{ {
@ -299,7 +306,7 @@ void Partition::calc_usage_triple_helper( double dtot, double d1, double d2, dou
} }
else else
{ {
i3 = Utils::round( d3 / dtot * imax ) ; i3 = Utils::round( static_cast<double>( s3 ) / stot * imax ) ;
i2 = imax - i1 - i3 ; i2 = imax - i1 - i3 ;
if ( i1 > i2 ) if ( i1 > i2 )
{ {