Return reference from Get_New_Partition() (#757671)

Return newly constructed partition object by reference rather than by
copy from the Copy, Resize/Move and New dialog classes.  This is another
case of stopping copying partition objects in preparation for using
polymorphic Partition objects.  In C++ polymorphism has to use pass by
pointer and reference and not pass by value, copying, to avoid object
slicing.

The returned reference to the partition is only valid until the dialog
object containing the new_partition member is destroyed.  This is okay
because in all three cases the returned referenced partition is copied
into a context with new lifetime expectations before the dialog object
is destroyed.

Case 1: GParted_Core::activate_paste()
    Referenced new_partition is copied in the OperationCopy constructor
    before the dialog object goes out of scope.

    Operation * operation = new OperationCopy( ...,
                                               dialog.Get_New_Partition( ... ),
                                               ... );

Case 2: GParted_Core::activate_new()
    Referenced new_partition is copied in the OperationCreate
    constructor before the dialog object goes out of scope.

    Operation * operation = new OperationCreate( ...,
                                                 dialog.Get_New_Partition( ... ) );

Case 3: GParted_Core::activate_resize()
    Temporary partition object is copied from the referenced
    new_partition before the dialog object goes out of scope.

    Partition part_temp = dialog.Get_New_Partition( ... );

Bug 757671 - Rework Dialog_Partition_New::Get_New_Partition() a bit
This commit is contained in:
Mike Fleetwood 2015-11-05 09:00:09 +00:00 committed by Curtis Gedak
parent 762cd1094a
commit 2c4df87a2c
6 changed files with 6 additions and 6 deletions

View File

@ -41,7 +41,7 @@ public:
~Dialog_Base_Partition( ) ;
void Set_Resizer( bool extended ) ;
Partition Get_New_Partition( Byte_Value sector_size ) ;
const Partition & Get_New_Partition( Byte_Value sector_size );
protected:
enum SPINBUTTON {

View File

@ -29,7 +29,7 @@ public:
Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
const Partition & copied_partition );
Partition Get_New_Partition( Byte_Value sector_size ) ;
const Partition & Get_New_Partition( Byte_Value sector_size );
private:
void set_data( const Partition & selected_partition, const Partition & copied_partition );

View File

@ -34,7 +34,7 @@ public:
bool any_extended,
unsigned short new_count,
const std::vector<FS> & FILESYSTEMS );
Partition Get_New_Partition( Byte_Value sector_size ) ;//overridden function
const Partition & Get_New_Partition( Byte_Value sector_size );
private:
void set_data( const Device & device,

View File

@ -136,7 +136,7 @@ void Dialog_Base_Partition::Set_Resizer( bool extended )
this ->show_all_children() ;
}
Partition Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
const Partition & Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
{
prepare_new_partition( sector_size );
return new_partition;

View File

@ -117,7 +117,7 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
this ->show_all_children() ;
}
Partition Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
const Partition & Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
{
//first call baseclass to get the correct new partition
Dialog_Base_Partition::prepare_new_partition( sector_size );

View File

@ -177,7 +177,7 @@ void Dialog_Partition_New::set_data( const Device & device,
this ->show_all_children() ;
}
Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
{
PartitionType part_type ;
Sector new_start, new_end;