[gparted] Replace all Partition object copy assignment (#759726)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Replace all Partition object copy assignment (#759726)
- Date: Sat, 30 Jan 2016 17:40:34 +0000 (UTC)
commit 656e1709ffdf9853495e4ac6380896a103ac8ef4
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sun Dec 20 11:28:09 2015 +0000
Replace all Partition object copy assignment (#759726)
Copy assignment of Partition objects is now only performed in a few
places in the Operation and OperationResizeMove classes when updating
the displayed PartitionVector. (From Refresh_Visual() when each
operation is visually applied to the display_partitions vector; the
new_partition from the operation is copy assigned over the top of the
relevant existing partition in the display_partitions vector).
In general polymorphic copy assignment is complicated [1], and is now
unnecessary given the above limited use. All that is needed is a way to
polymorphically replace one Partition object with another in a
PartitionVector.
First, prevent further use of Partition object copy assignment by
providing a private declaration and no implementation, so the compiler
enforces this. Second implement and use PartitionVector method
replace_at() which replaces a pointer to one Partition object with
another at the specified index in the PartitionVector.
[1] The Assignment Operator Revisited
[Section:] Virtual assignment
http://icu-project.org/docs/papers/cpp_report/the_assignment_operator_revisited.html
Bug 759726 - Implement Partition object polymorphism
include/Partition.h | 2 ++
include/PartitionVector.h | 1 +
src/Operation.cc | 8 ++++----
src/OperationResizeMove.cc | 4 ++--
src/PartitionVector.cc | 7 +++++++
5 files changed, 16 insertions(+), 6 deletions(-)
---
diff --git a/include/Partition.h b/include/Partition.h
index f2e0ebe..0f3c4e1 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -149,6 +149,8 @@ public:
Byte_Value sector_size ; //Sector size of the disk device needed for converting to/from sectors and
bytes.
private:
+ Partition & operator=( Partition & rhs ); // Not implemented copy assignment operator
+
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() ;
diff --git a/include/PartitionVector.h b/include/PartitionVector.h
index 5eb89b3..4c65e2c 100644
--- a/include/PartitionVector.h
+++ b/include/PartitionVector.h
@@ -71,6 +71,7 @@ public:
void clear();
void push_back_adopt( Partition * partition );
void insert_adopt( iterator position, Partition * partition );
+ void replace_at( size_type n, const Partition * partition );
private:
std::vector<Partition *> v;
diff --git a/src/Operation.cc b/src/Operation.cc
index 024197d..43cf895 100644
--- a/src/Operation.cc
+++ b/src/Operation.cc
@@ -115,14 +115,14 @@ void Operation::substitute_new( PartitionVector & partitions )
{
index = find_index_original( partitions[index_extended].logicals );
if ( index >= 0 )
- partitions[index_extended].logicals[index] = *partition_new;
+ partitions[index_extended].logicals.replace_at( index, partition_new );
}
}
else
{
index = find_index_original( partitions );
if ( index >= 0 )
- partitions[index] = *partition_new;
+ partitions.replace_at( index, partition_new );
}
}
@@ -152,7 +152,7 @@ void Operation::insert_new( PartitionVector & partitions )
index = find_index_new( partitions[index_extended].logicals );
if ( index >= 0 )
{
- partitions[index_extended].logicals[index] = *partition_new;
+ partitions[index_extended].logicals.replace_at( index, partition_new );
insert_unallocated( partitions[index_extended].logicals,
partitions[index_extended].sector_start,
@@ -167,7 +167,7 @@ void Operation::insert_new( PartitionVector & partitions )
index = find_index_new( partitions );
if ( index >= 0 )
{
- partitions[index] = *partition_new;
+ partitions.replace_at( index, partition_new );
insert_unallocated( partitions, 0, device.length-1, device.sector_size, false );
}
diff --git a/src/OperationResizeMove.cc b/src/OperationResizeMove.cc
index e6b6c98..aa21023 100644
--- a/src/OperationResizeMove.cc
+++ b/src/OperationResizeMove.cc
@@ -159,7 +159,7 @@ void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
if ( index >= 0 )
{
- partitions[index_extended].logicals[index] = *partition_new;
+ partitions[index_extended].logicals.replace_at( index, partition_new );
remove_adjacent_unallocated( partitions[index_extended].logicals, index );
insert_unallocated( partitions[index_extended].logicals,
@@ -176,7 +176,7 @@ void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
if ( index >= 0 )
{
- partitions[index] = *partition_new;
+ partitions.replace_at( index, partition_new );
remove_adjacent_unallocated( partitions, index ) ;
insert_unallocated( partitions, 0, device .length -1, device .sector_size, false ) ;
diff --git a/src/PartitionVector.cc b/src/PartitionVector.cc
index 2e7ee1b..630289d 100644
--- a/src/PartitionVector.cc
+++ b/src/PartitionVector.cc
@@ -83,4 +83,11 @@ void PartitionVector::insert_adopt( iterator position, Partition * partition )
v.insert( position, partition );
}
+void PartitionVector::replace_at( size_type n, const Partition * partition )
+{
+ Partition *p = new Partition( *partition );
+ delete v[n];
+ v[n] = p;
+}
+
} //GParted
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]