Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
SkOSFile::Iter Class Reference

#include <SkOSFile.h>

Public Member Functions

SK_SPI Iter ()
 
SK_SPI Iter (const char path[], const char suffix[]=nullptr)
 
SK_SPI ~Iter ()
 
SK_SPI void reset (const char path[], const char suffix[]=nullptr)
 
SK_SPI bool next (SkString *name, bool getDir=false)
 

Static Public Attributes

static const size_t kStorageSize = 40
 

Detailed Description

Definition at line 81 of file SkOSFile.h.

Constructor & Destructor Documentation

◆ Iter() [1/2]

SkOSFile::Iter::Iter ( )

Definition at line 140 of file SkOSFile_posix.cpp.

◆ Iter() [2/2]

SkOSFile::Iter::Iter ( const char  path[],
const char  suffix[] = nullptr 
)

Definition at line 142 of file SkOSFile_posix.cpp.

142 {
143 new (fSelf) SkOSFileIterData;
144 this->reset(path, suffix);
145}
m reset()

◆ ~Iter()

SkOSFile::Iter::~Iter ( )

Definition at line 147 of file SkOSFile_posix.cpp.

147 {
148 SkOSFileIterData& self = *reinterpret_cast<SkOSFileIterData*>(fSelf);
149 if (self.fDIR) {
150 ::closedir(self.fDIR);
151 }
152 self.~SkOSFileIterData();
153}

Member Function Documentation

◆ next()

bool SkOSFile::Iter::next ( SkString name,
bool  getDir = false 
)

If getDir is true, only returns directories. Results are undefined if true and false calls are interleaved on a single iterator.

Definition at line 186 of file SkOSFile_posix.cpp.

186 {
187 SkOSFileIterData& self = *reinterpret_cast<SkOSFileIterData*>(fSelf);
188 if (self.fDIR) {
189 dirent* entry;
190
191 while ((entry = ::readdir(self.fDIR)) != nullptr) {
192 struct stat s = {};
193 SkString str(self.fPath);
194
195 if (!str.endsWith("/") && !str.endsWith("\\")) {
196 str.append("/");
197 }
198 str.append(entry->d_name);
199
200 if (0 == stat(str.c_str(), &s)) {
201 if (getDir) {
202 if (s.st_mode & S_IFDIR) {
203 break;
204 }
205 } else {
206 if (!(s.st_mode & S_IFDIR) && issuffixfor(self.fSuffix, entry->d_name)) {
207 break;
208 }
209 }
210 }
211 }
212 if (entry) { // we broke out with a file
213 if (name) {
214 name->set(entry->d_name);
215 }
216 return true;
217 }
218 }
219 return false;
220}
static bool issuffixfor(const SkString &suffix, const char str[])
struct MyStruct s
const char * name
Definition fuchsia.cc:50

◆ reset()

void SkOSFile::Iter::reset ( const char  path[],
const char  suffix[] = nullptr 
)

Definition at line 155 of file SkOSFile_posix.cpp.

155 {
156 SkOSFileIterData& self = *reinterpret_cast<SkOSFileIterData*>(fSelf);
157 if (self.fDIR) {
158 ::closedir(self.fDIR);
159 self.fDIR = nullptr;
160 }
161 self.fPath.set(path);
162
163 if (path) {
164 self.fDIR = ::opendir(path);
165#ifdef SK_BUILD_FOR_IOS
166 // check bundle for directory
167 if (!self.fDIR && ios_get_path_in_bundle(path, &self.fPath)) {
168 self.fDIR = ::opendir(self.fPath.c_str());
169 }
170#endif
171 self.fSuffix.set(suffix);
172 } else {
173 self.fSuffix.reset();
174 }
175}

Member Data Documentation

◆ kStorageSize

const size_t SkOSFile::Iter::kStorageSize = 40
static

Definition at line 95 of file SkOSFile.h.


The documentation for this class was generated from the following files: