mirror of
https://gitlab.gnome.org/GNOME/gparted
synced 2024-08-27 11:40:03 +00:00
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
This commit is contained in:
parent
4a6cbcd0f1
commit
656e1709ff
|
@ -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() ;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 ) ;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue