gparted/include/Operation.h

93 lines
3.1 KiB
C
Raw Normal View History

/* Copyright (C) 2004 Bart
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
2004-09-19 14:24:53 -06:00
*
* 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.
2004-09-19 14:24:53 -06:00
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
2004-09-19 14:24:53 -06:00
*/
#ifndef GPARTED_OPERATION_H
#define GPARTED_OPERATION_H
2004-09-19 14:24:53 -06:00
#include "Device.h"
#include "OperationDetail.h"
#include "Partition.h"
#include "PartitionVector.h"
2004-09-19 14:24:53 -06:00
namespace GParted
{
//FIXME: stop using GParted:: in front of our own enums.. it's not necessary and clutters the code
2004-09-19 14:24:53 -06:00
enum OperationType {
OPERATION_DELETE = 0,
OPERATION_CHECK = 1,
OPERATION_CREATE = 2,
OPERATION_RESIZE_MOVE = 3,
OPERATION_FORMAT = 4,
OPERATION_COPY = 5,
OPERATION_LABEL_FILESYSTEM = 6,
OPERATION_CHANGE_UUID = 7,
OPERATION_NAME_PARTITION = 8
2004-09-19 14:24:53 -06:00
};
class Operation
{
public:
Operation() ;
virtual ~Operation() {}
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 & get_partition_original();
const Partition & get_partition_original() const;
virtual Partition & get_partition_new();
const virtual Partition & get_partition_new() const;
virtual void apply_to_visual( PartitionVector & partitions ) = 0;
virtual void create_description() = 0 ;
virtual bool merge_operations( const Operation & candidate ) = 0;
2004-09-19 14:24:53 -06:00
//public variables
Device device ;
OperationType type ;
Glib::RefPtr<Gdk::Pixbuf> icon ;
Glib::ustring description ;
OperationDetail operation_detail ;
2004-09-19 14:24:53 -06:00
protected:
int find_index_original( const PartitionVector & partitions );
int find_index_new( const PartitionVector & partitions );
void insert_unallocated( PartitionVector & partitions,
Sector start, Sector end, Byte_Value sector_size, bool inside_extended );
void substitute_new( PartitionVector & partitions );
void insert_new( PartitionVector & partitions );
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 * partition_original;
Partition * partition_new;
private:
// Disable compiler generated copy constructor and copy assignment operator by
// providing private declarations and no definition. Code which tries to copy
// construct or copy assign this class will fail to compile.
// References:
// * Disable copy constructor
// http://stackoverflow.com/questions/6077143/disable-copy-constructor
// * Disable compiler-generated copy-assignment operator [duplicate]
// http://stackoverflow.com/questions/7823845/disable-compiler-generated-copy-assignment-operator
Operation( const Operation & src ); // Not implemented copy constructor
Operation & operator=( const Operation & rhs ); // Not implemented copy assignment operator
2004-09-19 14:24:53 -06:00
};
} //GParted
#endif /* GPARTED_OPERATION_H */