gparted/src/OperationResizeMove.cc

257 lines
8.4 KiB
C++
Raw Normal View History

/* Copyright (C) 2004 Bart 'plors' Hakvoort
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "OperationResizeMove.h"
#include "Partition.h"
#include "PartitionVector.h"
namespace GParted
{
OperationResizeMove::OperationResizeMove( const Device & device,
const Partition & partition_orig,
const Partition & partition_new )
{
type = OPERATION_RESIZE_MOVE ;
this->device = device.get_copy_without_partitions();
this->partition_original = partition_orig.clone();
this->partition_new = partition_new.clone();
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
}
OperationResizeMove::~OperationResizeMove()
{
delete partition_original;
delete partition_new;
partition_original = nullptr;
partition_new = nullptr;
}
void OperationResizeMove::apply_to_visual( PartitionVector & partitions )
{
g_assert(partition_original != nullptr); // Bug: Not initialised by constructor or reset later
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_original->type == TYPE_EXTENDED )
apply_extended_to_visual( partitions ) ;
else
apply_normal_to_visual( partitions ) ;
}
void OperationResizeMove::create_description()
{
g_assert(partition_original != nullptr); // Bug: Not initialised by constructor or reset later
g_assert(partition_new != nullptr); // Bug: Not initialised by constructor or reset later
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
//i'm not too happy with this, but i think it is the correct way from a i18n POV
enum Action
{
NONE = 0,
MOVE_RIGHT = 1,
MOVE_LEFT = 2,
GROW = 3,
SHRINK = 4,
MOVE_RIGHT_GROW = 5,
MOVE_RIGHT_SHRINK = 6,
MOVE_LEFT_GROW = 7,
MOVE_LEFT_SHRINK = 8
} ;
Action action = NONE ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->get_sector_length() > partition_original->get_sector_length() )
{
//Grow partition
action = GROW ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->sector_start > partition_original->sector_start )
action = MOVE_RIGHT_GROW ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->sector_start < partition_original->sector_start )
action = MOVE_LEFT_GROW ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
}
else if ( partition_new->get_sector_length() < partition_original->get_sector_length() )
{
//Shrink partition
action = SHRINK ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->sector_start > partition_original->sector_start )
action = MOVE_RIGHT_SHRINK ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->sector_start < partition_original->sector_start )
action = MOVE_LEFT_SHRINK ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
}
else
{
//No change in partition size
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->sector_start > partition_original->sector_start )
action = MOVE_RIGHT ;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_new->sector_start < partition_original->sector_start )
action = MOVE_LEFT ;
}
switch ( action )
{
case NONE :
description = Glib::ustring::compose( _("resize/move %1"), partition_original->get_path() );
description += " (" ;
description += _("new and old partition have the same size and position. Hence continuing anyway") ;
description += ")" ;
break ;
case MOVE_RIGHT :
description = Glib::ustring::compose( _("Move %1 to the right"), partition_original->get_path() );
break ;
case MOVE_LEFT :
description = Glib::ustring::compose( _("Move %1 to the left"), partition_original->get_path() );
break ;
case GROW :
description = _("Grow %1 from %2 to %3") ;
break ;
case SHRINK :
description = _("Shrink %1 from %2 to %3") ;
break ;
case MOVE_RIGHT_GROW :
description = _("Move %1 to the right and grow it from %2 to %3") ;
break ;
case MOVE_RIGHT_SHRINK :
description = _("Move %1 to the right and shrink it from %2 to %3") ;
break ;
case MOVE_LEFT_GROW :
description = _("Move %1 to the left and grow it from %2 to %3") ;
break ;
case MOVE_LEFT_SHRINK :
description = _("Move %1 to the left and shrink it from %2 to %3") ;
break ;
}
if ( ! description .empty() && action != NONE && action != MOVE_LEFT && action != MOVE_RIGHT )
description = Glib::ustring::compose( description,
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
partition_original->get_path(),
Utils::format_size( partition_original->get_sector_length(),
partition_original->sector_size ),
Utils::format_size( partition_new->get_sector_length(),
partition_new->sector_size ) );
}
void OperationResizeMove::apply_normal_to_visual( PartitionVector & partitions )
{
g_assert(partition_original != nullptr); // Bug: Not initialised by constructor or reset later
g_assert(partition_new != nullptr); // Bug: Not initialised by constructor or reset later
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
int index_extended;
int index;
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( partition_original->inside_extended )
{
index_extended = find_extended_partition( partitions );
if ( index_extended >= 0 )
{
index = find_index_original( partitions[ index_extended ] .logicals ) ;
if ( index >= 0 )
{
partitions[index_extended].logicals.replace_at( index, partition_new );
remove_adjacent_unallocated( partitions[index_extended].logicals, index );
insert_unallocated( partitions[index_extended].logicals,
partitions[index_extended].sector_start,
partitions[index_extended].sector_end,
device.sector_size,
true );
}
}
}
else
{
index = find_index_original( partitions ) ;
if ( index >= 0 )
{
partitions.replace_at( index, partition_new );
remove_adjacent_unallocated( partitions, index ) ;
insert_unallocated( partitions, 0, device .length -1, device .sector_size, false ) ;
}
}
}
void OperationResizeMove::apply_extended_to_visual( PartitionVector & partitions )
{
g_assert(partition_new != nullptr); // Bug: Not initialised by constructor or reset later
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
int index_extended;
//stuff OUTSIDE extended partition
index_extended = find_extended_partition( partitions );
if ( index_extended >= 0 )
{
remove_adjacent_unallocated( partitions, index_extended ) ;
index_extended = find_extended_partition( partitions );
if ( index_extended >= 0 )
{
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
partitions[index_extended].sector_start = partition_new->sector_start;
partitions[index_extended].sector_end = partition_new->sector_end;
}
insert_unallocated( partitions, 0, device .length -1, device .sector_size, false ) ;
}
//stuff INSIDE extended partition
index_extended = find_extended_partition( partitions );
if ( index_extended >= 0 )
{
if ( partitions[ index_extended ] .logicals .size() > 0 &&
partitions[index_extended].logicals.front().type == TYPE_UNALLOCATED )
partitions[ index_extended ] .logicals .erase( partitions[ index_extended ] .logicals .begin() ) ;
if ( partitions[ index_extended ] .logicals .size() &&
partitions[index_extended].logicals.back().type == TYPE_UNALLOCATED )
partitions[ index_extended ] .logicals .pop_back() ;
insert_unallocated( partitions[ index_extended ] .logicals,
partitions[ index_extended ] .sector_start,
partitions[ index_extended ] .sector_end,
device .sector_size,
true ) ;
}
}
void OperationResizeMove::remove_adjacent_unallocated( PartitionVector & partitions, int index_orig )
{
//remove unallocated space following the original partition
if ( index_orig +1 < static_cast<int>( partitions .size() ) &&
partitions[index_orig+1].type == TYPE_UNALLOCATED )
partitions .erase( partitions .begin() + index_orig +1 );
//remove unallocated space preceding the original partition
if (index_orig-1 >= 0 && partitions[index_orig-1].type == TYPE_UNALLOCATED)
partitions .erase( partitions .begin() + ( index_orig -1 ) ) ;
}
bool OperationResizeMove::merge_operations( const Operation & candidate )
{
g_assert(partition_new != nullptr); // Bug: Not initialised by constructor or reset later
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
if ( candidate.type == OPERATION_RESIZE_MOVE &&
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
*partition_new == candidate.get_partition_original() )
{
Use pointers to Partitions in Operation classes (#759726) Operation classes now internally use pointers to Partition objects and take on management of their lifetimes. As before, with the PartitionVector class, when storing pointers in a class the Big 3 of destructor, copy constructor and copy assignment operator also have to be considered. First, all the Partition objects are allocated in the derived Operation* class parameterised constructors and freed in the associated destructors. However the Operation classes are never copy constructed or copy assigned; they are only ever created and destroyed. Only pointers to the derived Operations are copied into the vector of pending operations. Therefore the copy construtor and copy assignment operator aren't needed. To enforce this provide inaccessible private declarations without any implementation so that the compiler will enforce this [1][2]. This example code fragment: 1 OperationCheck o1( device, partition ); 2 OperationCheck o2 = o1; 3 o2 = o1; Does these OperationCheck calls: 1 Implemented parameterised construtor, 2 Disallowed copy constructor, 3 Disallowed copy assignment Trying to compile the above code would fail with errors like these: ../include/OperationCheck.h: In member function 'void GParted::Win_GParted::activate_check()': ../include/OperationCheck.h:36:2: error: 'GParted::OperationCheck::OperationCheck(const GParted::OperationCheck&)' is private OperationCheck( const OperationCheck & src ); // Not implemented copy constructor ^ test.cc:2:21: error: within this context OperationCheck o2 = o1; ^ ../include/OperationCheck.h:37:19: error: 'GParted::OperationCheck& GParted::OperationCheck::operator=(const GParted::OperationCheck&)' is private OperationCheck & operator=( const OperationCheck & rhs ); // Not implemented copy assignment operator ^ test.cc:3:4: error: within this context o2 = o1; ^ [1] Disable copy constructor http://stackoverflow.com/questions/6077143/disable-copy-constructor [2] Disable compiler-generated copy-assignment operator [duplicate] http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator Bug 759726 - Implement Partition object polymorphism
2015-09-20 03:50:57 -06:00
delete partition_new;
partition_new = candidate.get_partition_new().clone();
create_description();
return true;
}
return false;
}
} //GParted