DirectoryIterator_unix.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
25 
26 #include <dirent.h>
27 
28 namespace alvar {
29 
31 {
32 public:
34  : mHandle(NULL)
35  , mData(NULL)
36  {
37  }
38 
39  DIR *mHandle;
40  dirent *mData;
41 };
42 
45  , mDirectory(path)
46  , mEntry()
47  , mValid(false)
48 {
49  if (mDirectory.at(mDirectory.length() - 1) != '/') {
50  mDirectory.append("/");
51  }
52 }
53 
55 {
56  closedir(d->mHandle);
57  delete d;
58 }
59 
61 {
62  if (d->mHandle == NULL) {
63  d->mHandle = opendir(mDirectory.data());
64 
65  if (d->mHandle != NULL) {
66  d->mData = readdir(d->mHandle);
67 
68  if (d->mData != NULL) {
69  mValid = true;
70  skip();
71  }
72  }
73  }
74 
75  return mValid;
76 }
77 
79 {
80  if (!hasNext()) {
81  return "";
82  }
83 
84  mEntry = std::string(d->mData->d_name);
85 
86  d->mData = readdir(d->mHandle);
87  if (d->mData == NULL) {
88  mValid = false;
89  }
90  else {
91  skip();
92  }
93 
94  return mEntry;
95 }
96 
98 {
99  while (true) {
100  if (std::string(d->mData->d_name) != "." && std::string(d->mData->d_name) != "..") {
101  return;
102  }
103 
104  d->mData = readdir(d->mHandle);
105  if (d->mData == NULL) {
106  mValid = false;
107  return;
108  }
109  }
110 }
111 
112 } // namespace alvar
Main ALVAR namespace.
Definition: Alvar.h:174
DirectoryIteratorPrivateData * d
DirectoryIteratorPrivate(const std::string &path)
Drawable d[32]


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04