Add the option of using PartitionIterator on a PartitionTable.

This commit is contained in:
Teo Mrnjavac 2015-04-24 16:51:34 +02:00
parent 6c62d6f6d2
commit 5ab7896fca
2 changed files with 29 additions and 8 deletions

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Aurélien Gâteau <agateau@kde.org> * Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -23,8 +24,8 @@
#include <core/partition.h> #include <core/partition.h>
#include <core/partitiontable.h> #include <core/partitiontable.h>
PartitionIterator::PartitionIterator( Device* device ) PartitionIterator::PartitionIterator( PartitionTable* table )
: m_device( device ) : m_table( table )
{} {}
Partition* Partition*
@ -70,7 +71,7 @@ PartitionIterator::operator++()
bool bool
PartitionIterator::operator==( const PartitionIterator& other ) const PartitionIterator::operator==( const PartitionIterator& other ) const
{ {
return m_device == other.m_device && m_current == other.m_current; return m_table == other.m_table && m_current == other.m_current;
} }
bool bool
@ -82,10 +83,16 @@ PartitionIterator::operator!=( const PartitionIterator& other ) const
PartitionIterator PartitionIterator
PartitionIterator::begin( Device* device ) PartitionIterator::begin( Device* device )
{ {
auto it = PartitionIterator( device );
PartitionTable* table = device->partitionTable(); PartitionTable* table = device->partitionTable();
if ( !table ) if ( !table )
return it; return PartitionIterator( nullptr );
return PartitionIterator::begin( table );
}
PartitionIterator
PartitionIterator::begin( PartitionTable* table )
{
auto it = PartitionIterator( table );
QList< Partition* > children = table->children(); QList< Partition* > children = table->children();
// Does not usually happen, but it did happen on a 10MB disk with an MBR // Does not usually happen, but it did happen on a 10MB disk with an MBR
// partition table. // partition table.
@ -98,5 +105,15 @@ PartitionIterator::begin( Device* device )
PartitionIterator PartitionIterator
PartitionIterator::end( Device* device ) PartitionIterator::end( Device* device )
{ {
return PartitionIterator( device ); PartitionTable* table = device->partitionTable();
if ( !table )
return PartitionIterator( nullptr );
return PartitionIterator::end( table );
}
PartitionIterator
PartitionIterator::end( PartitionTable* table )
{
return PartitionIterator( table );
} }

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === This file is part of Calamares - <http://github.com/calamares> ===
* *
* Copyright 2014, Aurélien Gâteau <agateau@kde.org> * Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,6 +22,7 @@
class Device; class Device;
class Partition; class Partition;
class PartitionTable;
/** /**
* A forward-only iterator to go through the partitions of a device, * A forward-only iterator to go through the partitions of a device,
@ -37,12 +39,14 @@ public:
bool operator!=( const PartitionIterator& other ) const; bool operator!=( const PartitionIterator& other ) const;
static PartitionIterator begin( Device* device ); static PartitionIterator begin( Device* device );
static PartitionIterator begin( PartitionTable* table );
static PartitionIterator end( Device* device ); static PartitionIterator end( Device* device );
static PartitionIterator end( PartitionTable* table );
private: private:
PartitionIterator( Device* device ); PartitionIterator( PartitionTable* table );
Device* m_device; PartitionTable* m_table;
Partition* m_current = nullptr; Partition* m_current = nullptr;
}; };