aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Directory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Directory.cc')
-rw-r--r--src/FbTk/Directory.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/FbTk/Directory.cc b/src/FbTk/Directory.cc
new file mode 100644
index 0000000..8d327dd
--- /dev/null
+++ b/src/FbTk/Directory.cc
@@ -0,0 +1,86 @@
1// Directory.cc
2// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: Directory.cc,v 1.1 2003/05/18 22:06:59 fluxgen Exp $
23
24#include "Directory.hh"
25
26namespace FbTk {
27
28Directory::Directory(const char *dir):m_dir(0),
29m_num_entries(0) {
30 if (dir != 0)
31 open(dir);
32}
33
34Directory::~Directory() {
35 close();
36}
37
38void Directory::rewind() {
39 if (m_dir != 0)
40 rewinddir(m_dir);
41}
42
43struct dirent *Directory::read() {
44 if (m_dir == 0)
45 return 0;
46
47 return readdir(m_dir);
48}
49
50std::string Directory::readFilename() {
51 dirent *ent = read();
52 if (ent == 0)
53 return "";
54 return (ent->d_name ? ent->d_name : "");
55}
56
57void Directory::close() {
58 if (m_dir != 0) {
59 closedir(m_dir);
60 m_dir = 0;
61 m_num_entries = 0;
62 }
63}
64
65
66bool Directory::open(const char *dir) {
67 if (dir == 0)
68 return false;
69
70 if (m_dir != 0)
71 close();
72
73 m_dir = opendir(dir);
74 if (m_dir == 0) // successfull loading?
75 return false;
76
77 // get number of entries
78 while (read())
79 m_num_entries++;
80
81 rewind(); // go back to start
82
83 return true;
84}
85
86}; // end namespace FbTk