DirectoryIterator_win.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 <windows.h>
27 
28 namespace alvar {
29 
30 class DirectoryIteratorPrivateData
31 {
32 public:
34  : mHandle(INVALID_HANDLE_VALUE)
35  , mData()
36  {
37  }
38 
39  HANDLE mHandle;
40  WIN32_FIND_DATA 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  FindClose(d->mHandle);
57  delete d;
58 }
59 
61 {
62  if (d->mHandle == INVALID_HANDLE_VALUE) {
63  std::string search = mDirectory + "*";
64  d->mHandle = FindFirstFile(search.data(), &d->mData);
65 
66  if (d->mHandle != INVALID_HANDLE_VALUE) {
67  mValid = true;
68  skip();
69  }
70  }
71 
72  return mValid;
73 }
74 
76 {
77  if (!hasNext()) {
78  return "";
79  }
80 
81  mEntry = std::string(d->mData.cFileName);
82 
83  if (!FindNextFile(d->mHandle, &d->mData)) {
84  mValid = false;
85  }
86  else {
87  skip();
88  }
89 
90  return mEntry;
91 }
92 
94 {
95  while (true) {
96  if (std::string(d->mData.cFileName) != "." && std::string(d->mData.cFileName) != "..") {
97  return;
98  }
99 
100  if (!FindNextFile(d->mHandle, &d->mData)) {
101  mValid = false;
102  return;
103  }
104  }
105 }
106 
107 } // namespace alvar
Main ALVAR namespace.
Definition: Alvar.h:174
DirectoryIteratorPrivate(const std::string &path)
Drawable d[32]
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)


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