Directory.h
Go to the documentation of this file.
1 /****
2  * Directory.h
3  *
4  * Created: May 2019
5  *
6  * Copyright 2019 mikee47 <mike@sillyhouse.net>
7  *
8  * This file is part of the IFS Library
9  *
10  * This library is free software: you can redistribute it and/or modify it under the terms of the
11  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  * See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with this library.
18  * If not, see <https://www.gnu.org/licenses/>.
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "FsBase.h"
25 
26 namespace IFS
27 {
31 class Directory : public FsBase
32 {
33 public:
34  using FsBase::FsBase;
35 
37  {
38  close();
39  }
40 
47  bool open(const String& dirName = nullptr);
48 
52  void close();
53 
59  bool rewind();
60 
65  const String& getDirName() const
66  {
67  return name;
68  }
69 
74  bool dirExist() const
75  {
76  return dir != nullptr;
77  }
78 
82  String getPath() const;
83 
88  String getParent() const;
89 
90  int index() const
91  {
92  return currentIndex;
93  }
94 
95  uint32_t count() const
96  {
97  return uint32_t(maxIndex + 1);
98  }
99 
100  bool isValid() const
101  {
102  return currentIndex >= 0;
103  }
104 
106  {
107  return totalSize;
108  }
109 
110  const Stat& stat() const
111  {
112  return dirStat;
113  }
114 
115  bool next();
116 
117 private:
118  String name;
119  DirHandle dir{};
120  NameStat dirStat;
121  int currentIndex{-1};
122  int maxIndex{-1};
123  file_size_t totalSize{0};
124 };
125 
126 } // namespace IFS
uint32_t file_size_t
Definition: Components/IFS/src/include/IFS/Types.h:50
Wrapper class for enumerating a directory.
Definition: Directory.h:32
bool isValid() const
Definition: Directory.h:100
bool rewind()
Rewind directory stream to start so it can be re-enumerated.
file_size_t size() const
Definition: Directory.h:105
~Directory()
Definition: Directory.h:36
void close()
Close directory.
bool dirExist() const
Determine if directory exists.
Definition: Directory.h:74
int index() const
Definition: Directory.h:90
const Stat & stat() const
Definition: Directory.h:110
const String & getDirName() const
Name of directory stream is attached to.
Definition: Directory.h:65
String getPath() const
Get path with leading separator /path/to/dir.
String getParent() const
Get parent directory.
bool open(const String &dirName=nullptr)
Open a directory and attach this stream object to it.
uint32_t count() const
Definition: Directory.h:95
Definition: FsBase.h:34
FsBase(IFileSystem *filesys=nullptr)
Definition: FsBase.h:36
The String class.
Definition: WString.h:137
Definition: DirectoryTemplate.h:37
struct ImplFileDir * DirHandle
Definition: IFileSystem.h:72
version of Stat with integrated name buffer
Definition: Stat.h:103
File Status structure.
Definition: Stat.h:52