From 25db5b2ec0e36c3f806e0629b4af5542e57938c5 Mon Sep 17 00:00:00 2001 From: Bart Hakvoort Date: Wed, 14 Dec 2005 01:58:15 +0000 Subject: [PATCH] did some cleanups added get_index_extended to get the ext_index in a * include/GParted_Core.h, src/GParted_Core.cc: did some cleanups * include/Operation.h, src/Operation.cc: added get_index_extended to get the ext_index in a uniform way instead of calculating it every time ourselves. --- ChangeLog | 8 ++++++++ include/GParted_Core.h | 2 +- include/Operation.h | 1 + src/GParted_Core.cc | 10 +++++++--- src/Operation.cc | 22 ++++++++++++++-------- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f66e8a0..c396516d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-12-14 Bart Hakvoort + + * include/GParted_Core.h, + src/GParted_Core.cc: did some cleanups + * include/Operation.h, + src/Operation.cc: added get_index_extended to get the ext_index in a + uniform way instead of calculating it every time ourselves. + 2005-12-13 Bart Hakvoort * src/GParted_Core.cc: check if file is open before using it. diff --git a/include/GParted_Core.h b/include/GParted_Core.h index 0eddd579..f9fea1e6 100644 --- a/include/GParted_Core.h +++ b/include/GParted_Core.h @@ -69,7 +69,7 @@ private: void set_device_partitions( Device & device ) ; void set_mountpoints( std::vector & partitions, bool first_time = true ) ; void set_used_sectors( std::vector & partitions ) ; - void Insert_Unallocated( const Glib::ustring & device_path, std::vector & partitions, Sector start, Sector end, bool inside_extended ) ; + void insert_unallocated( const Glib::ustring & device_path, std::vector & partitions, Sector start, Sector end, bool inside_extended ) ; Glib::ustring get_short_path( const Glib::ustring & real_path ) ; void LP_Set_Used_Sectors( Partition & partition ); Glib::ustring Get_Flags( ) ; diff --git a/include/Operation.h b/include/Operation.h index 887244a1..9aed6045 100644 --- a/include/Operation.h +++ b/include/Operation.h @@ -56,6 +56,7 @@ public: private: void Insert_Unallocated( std::vector & partitions, Sector start, Sector end, bool inside_extended ); int Get_Index_Original( std::vector & partitions ) ; + int get_index_extended( const std::vector & partitions ) ; void Apply_Delete_To_Visual( std::vector & partitions ); void Apply_Create_To_Visual( std::vector & partitions ); diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 9ab4e50c..869ec621 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -270,9 +270,13 @@ void GParted_Core::set_device_partitions( Device & device ) } if ( EXT_INDEX > -1 ) - Insert_Unallocated( device .path, device .device_partitions[ EXT_INDEX ] .logicals, device .device_partitions[ EXT_INDEX ] .sector_start, device .device_partitions[ EXT_INDEX ] .sector_end, true ) ; + insert_unallocated( device .path, + device .device_partitions[ EXT_INDEX ] .logicals, + device .device_partitions[ EXT_INDEX ] .sector_start, + device .device_partitions[ EXT_INDEX ] .sector_end, + true ) ; - Insert_Unallocated( device .path, device .device_partitions, 0, device .length -1, false ) ; + insert_unallocated( device .path, device .device_partitions, 0, device .length -1, false ) ; } void GParted_Core::set_mountpoints( std::vector & partitions, bool first_time ) @@ -367,7 +371,7 @@ void GParted_Core::set_used_sectors( std::vector & partitions ) } } -void GParted_Core::Insert_Unallocated( const Glib::ustring & device_path, std::vector & partitions, Sector start, Sector end, bool inside_extended ) +void GParted_Core::insert_unallocated( const Glib::ustring & device_path, std::vector & partitions, Sector start, Sector end, bool inside_extended ) { partition_temp .Reset( ) ; partition_temp .Set_Unallocated( device_path, 0, 0, inside_extended ) ; diff --git a/src/Operation.cc b/src/Operation.cc index aa805acd..60183071 100644 --- a/src/Operation.cc +++ b/src/Operation.cc @@ -208,6 +208,15 @@ int Operation::Get_Index_Original( std::vector & partitions ) return -1 ; } +int Operation::get_index_extended( const std::vector & partitions ) +{ + for ( unsigned int t = 0 ; t < partitions .size() ; t++ ) + if ( partitions[ t ] .type == GParted::TYPE_EXTENDED ) + return t ; + + return -1 ; +} + void Operation::Apply_Delete_To_Visual( std::vector & partitions ) { if ( ! partition_original .inside_extended ) @@ -218,12 +227,11 @@ void Operation::Apply_Delete_To_Visual( std::vector & partitions ) } else { - unsigned int ext = 0 ; - while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::TYPE_EXTENDED ) ext++ ; + unsigned int ext = get_index_extended( partitions ) ; partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) + Get_Index_Original( partitions[ ext ] .logicals ) ); - - //if deleted partition was logical we have to decrease the partitionnumbers of the logicals with higher numbers by one (only if its a real partition) + //if deleted partition was logical we have to decrease the partitionnumbers of the logicals + //with higher numbers by one (only if its a real partition) if ( partition_original .status != GParted::STAT_NEW ) for ( unsigned int t = 0 ; t < partitions[ ext ] .logicals .size( ) ; t++ ) if ( partitions[ ext ] .logicals[ t ] .partition_number > partition_original .partition_number ) @@ -244,8 +252,7 @@ void Operation::Apply_Create_To_Visual( std::vector & partitions ) } else { - unsigned int ext = 0 ; - while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::TYPE_EXTENDED ) ext++ ; + unsigned int ext = get_index_extended( partitions ) ; partitions[ ext ] .logicals[ Get_Index_Original( partitions[ ext ] .logicals ) ] = partition_new ; Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end, true ) ; @@ -270,8 +277,7 @@ void Operation::Apply_Resize_Move_Extended_To_Visual( std::vector & p Insert_Unallocated( partitions, 0, device .length -1, false ) ; //stuff INSIDE extended partition - ext = 0 ; - while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::TYPE_EXTENDED ) ext++ ; + ext = get_index_extended( partitions ) ; if ( partitions[ ext ] .logicals .size( ) && partitions[ ext ] .logicals .front( ) .type == GParted::TYPE_UNALLOCATED ) partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) ) ;