[gparted] Create PartitionVector class (#759726)



commit fa9827344551cf7df265d4a1b8bbc570ac266425
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri May 22 21:01:59 2015 +0100

    Create PartitionVector class (#759726)
    
    Just creates PartitionVector class and includes it in partition.h so
    that it is built and validated by the compiler.  Not used anywhere yet.
    
    Implementation strategy is to create a PartitionLUKS class derived from
    the Partition class.  This implies polymorphism of Partition objects,
    which in C++ requires using pointers and references to objects, and not
    using objects directly.  (See C++ object slicing).  Later this
    PartitionVector class will be modified to use pointers to Partition
    objects and act as the owner of the pointed to Partition objects.
    
    Bug 759726 - Implement Partition object polymorphism

 include/Makefile.am       |    1 +
 include/Partition.h       |    9 +++++
 include/PartitionVector.h |   79 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/include/Makefile.am b/include/Makefile.am
index 4c308d9..3ca02c3 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -36,6 +36,7 @@ EXTRA_DIST = \
        OperationNamePartition.h        \
        OperationResizeMove.h           \
        Partition.h                     \
+       PartitionVector.h               \
        PipeCapture.h                   \
        Proc_Partitions_Info.h          \
        SWRaid_Info.h                   \
diff --git a/include/Partition.h b/include/Partition.h
index 4419b23..a37ed08 100644
--- a/include/Partition.h
+++ b/include/Partition.h
@@ -24,6 +24,7 @@
 #define GPARTED_PARTITION_H
 
 #include "../include/Utils.h"
+#include "../include/PartitionVector.h"
 
 namespace GParted
 {
@@ -50,6 +51,14 @@ enum PartitionAlignment {
                               //  Indicator if start and end sectors must remain unchanged
 };
 
+class Partition;        // Forward declarations as Partition and PartitionVector are
+class PartitionVector;  // mutually recursive classes.
+                        // References:
+                        // *   Mutually recursive classes
+                        //     http://stackoverflow.com/questions/3410637/mutually-recursive-classes
+                        // *   recursive definition in CPP
+                        //     http://stackoverflow.com/questions/4300420/recursive-definition-in-cpp
+
 class Partition
 {
 public:
diff --git a/include/PartitionVector.h b/include/PartitionVector.h
new file mode 100644
index 0000000..3a3addf
--- /dev/null
+++ b/include/PartitionVector.h
@@ -0,0 +1,79 @@
+/* Copyright (C) 2015 Mike Fleetwood
+ *
+ *  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/>.
+ */
+
+/* Minimal implementation of a class that behaves like a std::vector<Partition> which can
+ * be used in it's place with minimal change to the existing GParted code which expects to
+ * be working with a std::vector<Partition>.
+ * Reference:
+ *     C++ Reference to std::vector
+ *     http://www.cplusplus.com/reference/vector/vector/
+ */
+
+#ifndef GPARTED_PARTITIONVECTOR_H
+#define GPARTED_PARTITIONVECTOR_H
+
+#include "../include/Partition.h"
+
+#include <cstddef>
+#include <vector>
+
+namespace GParted
+{
+
+class Partition;        // Forward declarations as Partition and PartitionVector are
+class PartitionVector;  // mutually recursive classes.
+                        // References:
+                        //     Mutually recursive classes
+                        //     http://stackoverflow.com/questions/3410637/mutually-recursive-classes
+                        //     recursive definition in CPP
+                        //     http://stackoverflow.com/questions/4300420/recursive-definition-in-cpp
+
+class PartitionVector {
+public:
+       typedef size_t size_type;
+       typedef std::vector<Partition>::iterator iterator;
+
+       PartitionVector() {};
+       ~PartitionVector() {};
+
+       // Iterators
+       iterator begin()                                   { return v.begin(); };
+
+       // Capacity
+       bool empty() const                                 { return v.empty(); };
+
+       // Element access
+       Partition & operator[]( size_type n )              { return v[n]; };
+       const Partition & operator[]( size_type n ) const  { return v[n]; };
+       size_type size() const                             { return v.size(); };
+       const Partition & front() const                    { return v.front(); };
+       const Partition & back() const                     { return v.back(); };
+
+       // Modifiers
+       void pop_back()                                    { v.pop_back(); };
+       void erase( const iterator position )              { v.erase( position ); };
+       void clear()                                       { v.clear(); };
+       void push_back( const Partition & partition )      { v.push_back( partition ); };
+       void insert( iterator position, const Partition & partition )
+                                                          { v.insert( position, partition ); };
+
+private:
+       std::vector<Partition> v;
+};
+
+} //GParted
+
+#endif /* GPARTED_PARTITIONVECTOR_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]