libDwm-0.6.0
DwmDirectoryEntry.hh
Go to the documentation of this file.
1
//===========================================================================
2
// @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmDirectoryEntry.hh 8401 $
3
// @(#) $Id: DwmDirectoryEntry.hh 8401 2016-04-17 06:44:31Z dwm $
4
//===========================================================================
5
// Copyright (c) Daniel W. McRobb 2011, 2016
6
// All rights reserved.
7
//
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions
10
// are met:
11
//
12
// 1. Redistributions of source code must retain the above copyright
13
// notice, this list of conditions and the following disclaimer.
14
// 2. Redistributions in binary form must reproduce the above copyright
15
// notice, this list of conditions and the following disclaimer in the
16
// documentation and/or other materials provided with the distribution.
17
// 3. The names of the authors and copyright holders may not be used to
18
// endorse or promote products derived from this software without
19
// specific prior written permission.
20
//
21
// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22
// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23
// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24
// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25
// DAMAGE.
26
//
27
// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28
// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29
// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30
// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31
// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32
// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33
// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34
// TRADEMARK OR OTHER RIGHTS.
35
//===========================================================================
36
37
//---------------------------------------------------------------------------
40
//---------------------------------------------------------------------------
41
42
#ifndef _DWMDIRECTORYENTRY_HH_
43
#define _DWMDIRECTORYENTRY_HH_
44
45
extern
"C"
{
46
#include <sys/types.h>
47
#include <sys/stat.h>
48
#include <dirent.h>
49
}
50
51
#include <string>
52
#include <vector>
53
54
namespace
Dwm
{
55
56
//--------------------------------------------------------------------------
57
// pre-declare DirectoryEntry
58
//--------------------------------------------------------------------------
59
class
DirectoryEntry;
60
61
//--------------------------------------------------------------------------
63
//--------------------------------------------------------------------------
64
class
DirectoryEntryFunctor
65
{
66
public
:
67
virtual
bool
operator () (DirectoryEntry & dirEntry)
68
{
69
return
false
;
70
}
71
};
72
73
//--------------------------------------------------------------------------
75
//--------------------------------------------------------------------------
76
class
DirectoryEntry
77
{
78
public
:
79
//------------------------------------------------------------------------
81
//------------------------------------------------------------------------
82
typedef
enum
{
83
e_typeUnknown = 0x00,
84
e_typeFifo = 0x01,
85
e_typeCharacterSpecial = 0x02,
86
e_typeDirectory = 0x04,
87
e_typeBlockSpecial = 0x08,
88
e_typeRegular = 0x10,
89
e_typeSymbolicLink = 0x20,
90
e_typeSocket = 0x40
91
}
TypeEnum
;
92
93
//------------------------------------------------------------------------
95
//------------------------------------------------------------------------
96
DirectoryEntry
(
const
std::string & path);
97
98
//------------------------------------------------------------------------
100
//------------------------------------------------------------------------
101
DirectoryEntry
(
const
std::string & path,
const
DirectoryEntry
*parent);
102
103
//------------------------------------------------------------------------
105
//------------------------------------------------------------------------
106
TypeEnum
Type()
const
;
107
108
//------------------------------------------------------------------------
110
//------------------------------------------------------------------------
111
const
std::string & Path()
const
;
112
113
std::string RelativePath()
const
;
114
115
//------------------------------------------------------------------------
117
//------------------------------------------------------------------------
118
std::string BaseName()
const
;
119
120
//------------------------------------------------------------------------
122
//------------------------------------------------------------------------
123
std::string DirName()
const
;
124
125
//------------------------------------------------------------------------
129
//------------------------------------------------------------------------
130
std::string RealPath()
const
;
131
132
//------------------------------------------------------------------------
136
//------------------------------------------------------------------------
137
std::string Extension()
const
;
138
139
//------------------------------------------------------------------------
142
//------------------------------------------------------------------------
143
const
DirectoryEntry
*Parent()
const
;
144
145
//------------------------------------------------------------------------
147
//------------------------------------------------------------------------
148
bool
Exists()
const
;
149
150
//------------------------------------------------------------------------
152
//------------------------------------------------------------------------
153
bool
IsDirectory()
const
;
154
155
//------------------------------------------------------------------------
159
//------------------------------------------------------------------------
160
bool
GetChildren(std::vector<DirectoryEntry> & children,
161
uint8_t typeMask = 0xFF)
const
;
162
163
bool
GetChildren(std::vector<DirectoryEntry> & children,
164
DirectoryEntryFunctor & dirEntryFunc)
const
;
165
166
uint32_t Recurse(DirectoryEntryFunctor & dirEntryFunc,
167
bool
depthFirst =
false
,
168
int
maxDepth = -1);
169
170
protected
:
171
std::string _path;
172
const
DirectoryEntry
*_parent;
173
TypeEnum
_type;
174
175
static
TypeEnum
GetType(
const
struct
stat & statStruct);
176
static
TypeEnum
GetType(
const
struct
dirent & dirEntry);
177
178
uint32_t Recurse(
DirectoryEntry
& de,
179
DirectoryEntryFunctor & dirEntryFunc,
180
int
depth,
bool
depthFirst,
int
maxDepth);
181
};
182
183
}
// namespace Dwm
184
185
#endif // _DWMDIRECTORYENTRY_HH_
Dwm::DirectoryEntry
Encapsulates a directory entry (file, directory, FIFO, et. al.).
Definition:
DwmDirectoryEntry.hh:76
Dwm
Definition:
DwmBZ2IO.hh:67
Dwm::DirectoryEntry::TypeEnum
TypeEnum
The types of DirectoryEntry objects.
Definition:
DwmDirectoryEntry.hh:82
include
DwmDirectoryEntry.hh
(dwmcrobb@me.com)