[gparted] Return reference from Get_New_Partition() (#757671)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Return reference from Get_New_Partition() (#757671)
- Date: Wed, 11 Nov 2015 17:18:02 +0000 (UTC)
commit 2c4df87a2c4e6521773323a052e6f7eab8278d66
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Thu Nov 5 09:00:09 2015 +0000
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
include/Dialog_Base_Partition.h | 2 +-
include/Dialog_Partition_Copy.h | 2 +-
include/Dialog_Partition_New.h | 2 +-
src/Dialog_Base_Partition.cc | 2 +-
src/Dialog_Partition_Copy.cc | 2 +-
src/Dialog_Partition_New.cc | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/include/Dialog_Base_Partition.h b/include/Dialog_Base_Partition.h
index ea65116..5397aea 100644
--- a/include/Dialog_Base_Partition.h
+++ b/include/Dialog_Base_Partition.h
@@ -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 {
diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h
index daadbff..f91aae0 100644
--- a/include/Dialog_Partition_Copy.h
+++ b/include/Dialog_Partition_Copy.h
@@ -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 );
diff --git a/include/Dialog_Partition_New.h b/include/Dialog_Partition_New.h
index ce06dad..4ce9828 100644
--- a/include/Dialog_Partition_New.h
+++ b/include/Dialog_Partition_New.h
@@ -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,
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index 8ff1fcd..d58cee4 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -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;
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index 21963d1..92a9ed1 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -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 );
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 08c2625..570e4ae 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]