Iterator.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Iterator.h
8  *
9  ****/
10 #pragma once
11 
12 #include "Partition.h"
13 
14 namespace Storage
15 {
16 class Device;
17 
18 class Iterator : public std::iterator<std::forward_iterator_tag, Partition>
19 {
20 public:
21  Iterator(Device& device) : mSearch{&device, Partition::Type::any, Partition::SubType::any}, mDevice(&device)
22  {
23  next();
24  }
25 
26  Iterator(Device& device, Partition::Type type, uint8_t subtype) : mSearch{&device, type, subtype}, mDevice(&device)
27  {
28  next();
29  }
30 
31  Iterator(Partition::Type type, uint8_t subtype);
32 
33  explicit operator bool() const
34  {
35  return mDevice && mInfo;
36  }
37 
39  {
40  auto result = *this;
41  next();
42  return result;
43  }
44 
46  {
47  next();
48  return *this;
49  }
50 
51  bool operator==(const Iterator& other) const
52  {
53  return mInfo == other.mInfo;
54  }
55 
56  bool operator!=(const Iterator& other) const
57  {
58  return !operator==(other);
59  }
60 
62  {
63  return mDevice && mInfo ? Partition(*mDevice, *mInfo) : Partition{};
64  }
65 
67  {
68  return mSearch.device ? Iterator(*mSearch.device) : Iterator(mSearch.type, mSearch.subType);
69  }
70 
72  {
73  return Iterator();
74  }
75 
76 private:
77  Iterator()
78  {
79  }
80 
81  void next();
82 
83  struct Search {
84  Device* device;
85  Partition::Type type;
86  uint8_t subType;
87  };
88  Search mSearch{};
89  Device* mDevice{nullptr};
90  const Partition::Info* mInfo{nullptr};
91 };
92 
93 } // namespace Storage
Iterator end()
Definition: Iterator.h:71
Iterator(Device &device, Partition::Type type, uint8_t subtype)
Definition: Iterator.h:26
Partition operator*() const
Definition: Iterator.h:61
Iterator begin()
Definition: Iterator.h:66
Definition: Iterator.h:18
bool operator!=(const Iterator &other) const
Definition: Iterator.h:56
static constexpr uint8_t any
Definition: Partition.h:99
Iterator operator++(int)
Definition: Iterator.h:38
Type
Definition: Partition.h:88
Represents a storage device (e.g. flash memory)
Definition: Components/Storage/src/include/Storage/Device.h:33
bool operator==(const Iterator &other) const
Definition: Iterator.h:51
Represents a flash partition.
Definition: Partition.h:85
Definition: FileDevice.h:25
Partition information.
Definition: Partition.h:181
Iterator & operator++()
Definition: Iterator.h:45
Iterator(Device &device)
Definition: Iterator.h:21