Main Page
Namespaces
Classes
Files
Examples
File List
File Members
src
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
24
#include "
ar_track_alvar/DirectoryIterator_private.h
"
25
26
#include <dirent.h>
27
28
namespace
alvar
{
29
30
class
DirectoryIteratorPrivateData
31
{
32
public
:
33
DirectoryIteratorPrivateData
()
34
:
mHandle
(NULL)
35
,
mData
(NULL)
36
{
37
}
38
39
DIR *
mHandle
;
40
dirent *
mData
;
41
};
42
43
DirectoryIteratorPrivate::DirectoryIteratorPrivate
(
const
std::string &path)
44
:
d
(new
DirectoryIteratorPrivateData
())
45
, mDirectory(path)
46
, mEntry()
47
, mValid(false)
48
{
49
if
(
mDirectory
.at(
mDirectory
.length() - 1) !=
'/'
) {
50
mDirectory
.append(
"/"
);
51
}
52
}
53
54
DirectoryIteratorPrivate::~DirectoryIteratorPrivate
()
55
{
56
closedir(
d
->
mHandle
);
57
delete
d
;
58
}
59
60
bool
DirectoryIteratorPrivate::hasNext
()
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
78
std::string
DirectoryIteratorPrivate::next
()
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
97
void
DirectoryIteratorPrivate::skip
()
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
alvar
Main ALVAR namespace.
Definition:
Alvar.h:174
alvar::DirectoryIteratorPrivateData::mHandle
DIR * mHandle
Definition:
DirectoryIterator_unix.cpp:39
alvar::DirectoryIteratorPrivate::mEntry
std::string mEntry
Definition:
DirectoryIterator_private.h:44
alvar::DirectoryIteratorPrivate::d
DirectoryIteratorPrivateData * d
Definition:
DirectoryIterator_private.h:42
alvar::DirectoryIteratorPrivate::skip
void skip()
Definition:
DirectoryIterator_unix.cpp:97
alvar::DirectoryIteratorPrivate::mValid
bool mValid
Definition:
DirectoryIterator_private.h:45
alvar::DirectoryIteratorPrivateData::mData
dirent * mData
Definition:
DirectoryIterator_unix.cpp:40
alvar::DirectoryIteratorPrivate::DirectoryIteratorPrivate
DirectoryIteratorPrivate(const std::string &path)
Definition:
DirectoryIterator_unix.cpp:43
alvar::DirectoryIteratorPrivate::next
std::string next()
Definition:
DirectoryIterator_unix.cpp:78
alvar::DirectoryIteratorPrivateData::DirectoryIteratorPrivateData
DirectoryIteratorPrivateData()
Definition:
DirectoryIterator_unix.cpp:33
d
Drawable d[32]
Definition:
SampleMarkerDetector.cpp:11
alvar::DirectoryIteratorPrivateData
Definition:
DirectoryIterator_unix.cpp:30
alvar::DirectoryIteratorPrivate::hasNext
bool hasNext()
Definition:
DirectoryIterator_unix.cpp:60
alvar::DirectoryIteratorPrivate::~DirectoryIteratorPrivate
~DirectoryIteratorPrivate()
Definition:
DirectoryIterator_unix.cpp:54
alvar::DirectoryIteratorPrivate::mDirectory
std::string mDirectory
Definition:
DirectoryIterator_private.h:43
DirectoryIterator_private.h
ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04