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:
parent
762cd1094a
commit
2c4df87a2c
|
@ -41,7 +41,7 @@ public:
|
||||||
~Dialog_Base_Partition( ) ;
|
~Dialog_Base_Partition( ) ;
|
||||||
|
|
||||||
void Set_Resizer( bool extended ) ;
|
void Set_Resizer( bool extended ) ;
|
||||||
Partition Get_New_Partition( Byte_Value sector_size ) ;
|
const Partition & Get_New_Partition( Byte_Value sector_size );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum SPINBUTTON {
|
enum SPINBUTTON {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public:
|
||||||
Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
|
Dialog_Partition_Copy( const FS & fs, const Partition & selected_partition,
|
||||||
const Partition & copied_partition );
|
const Partition & copied_partition );
|
||||||
|
|
||||||
Partition Get_New_Partition( Byte_Value sector_size ) ;
|
const Partition & Get_New_Partition( Byte_Value sector_size );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set_data( const Partition & selected_partition, const Partition & copied_partition );
|
void set_data( const Partition & selected_partition, const Partition & copied_partition );
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
bool any_extended,
|
bool any_extended,
|
||||||
unsigned short new_count,
|
unsigned short new_count,
|
||||||
const std::vector<FS> & FILESYSTEMS );
|
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:
|
private:
|
||||||
void set_data( const Device & device,
|
void set_data( const Device & device,
|
||||||
|
|
|
@ -136,7 +136,7 @@ void Dialog_Base_Partition::Set_Resizer( bool extended )
|
||||||
this ->show_all_children() ;
|
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 );
|
prepare_new_partition( sector_size );
|
||||||
return new_partition;
|
return new_partition;
|
||||||
|
|
|
@ -117,7 +117,7 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
|
||||||
this ->show_all_children() ;
|
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
|
//first call baseclass to get the correct new partition
|
||||||
Dialog_Base_Partition::prepare_new_partition( sector_size );
|
Dialog_Base_Partition::prepare_new_partition( sector_size );
|
||||||
|
|
|
@ -177,7 +177,7 @@ void Dialog_Partition_New::set_data( const Device & device,
|
||||||
this ->show_all_children() ;
|
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 ;
|
PartitionType part_type ;
|
||||||
Sector new_start, new_end;
|
Sector new_start, new_end;
|
||||||
|
|
Loading…
Reference in New Issue