CPN
Computational Process Networks
Main Page
Namespaces
Classes
Files
File List
File Members
lib
utils
Directory.cc
Go to the documentation of this file.
1
//=============================================================================
2
// Computational Process Networks class library
3
// Copyright (C) 1997-2006 Gregory E. Allen and The University of Texas
4
//
5
// This library is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Library General Public License as published
7
// by the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Library General Public License for more details.
14
//
15
// The GNU Public License is available in the file LICENSE, or you
16
// can write to the Free Software Foundation, Inc., 59 Temple Place -
17
// Suite 330, Boston, MA 02111-1307, USA, or you can find it on the
18
// World Wide Web at http://www.fsf.org.
19
//=============================================================================
23
#include "common_priv.h"
24
#include <
cpn/utils/Directory.h
>
25
#include <
cpn/utils/ErrnoException.h
>
26
27
Directory::Directory
(
const
std::string &dirname_)
28
: dir(0),dirname(dirname_), entry(0), stated(false)
29
{
30
dir
= opendir(
dirname
.c_str());
31
if
(!
dir
) {
32
throw
ErrnoException
();
33
}
34
Next
();
35
}
36
37
Directory::~Directory
() {
38
closedir(
dir
);
39
}
40
41
void
Directory::Rewind
() {
42
rewinddir(
dir
);
43
}
44
45
void
Directory::Next
() {
46
entry
= readdir(
dir
);
47
stated
=
false
;
48
}
49
50
std::string
Directory::BaseName
()
const
{
51
return
std::string(
entry
->d_name);
52
}
53
54
bool
Directory::IsDirectory
()
const
{
55
Stat
();
56
return
S_ISDIR(
status
.st_mode);
57
}
58
59
bool
Directory::IsRegularFile
()
const
{
60
Stat
();
61
return
S_ISREG(
status
.st_mode);
62
}
63
64
std::size_t
Directory::Size
()
const
{
65
Stat
();
66
return
status
.st_size;
67
}
68
69
void
Directory::Stat
()
const
{
70
if
(!
stated
) {
71
std::string fpath =
dirname
+
"/"
+
entry
->d_name;
72
if
(stat(fpath.c_str(), &
status
) != 0) {
73
throw
ErrnoException
();
74
}
75
stated
=
true
;
76
}
77
}
78
Directory::dirname
std::string dirname
Definition:
Directory.h:68
Directory::Size
std::size_t Size() const
Definition:
Directory.cc:64
Directory::Next
void Next()
Definition:
Directory.cc:45
Directory::status
struct stat status
Definition:
Directory.h:70
ErrnoException
Definition:
ErrnoException.h:37
Directory::Stat
void Stat() const
Definition:
Directory.cc:69
Directory::BaseName
std::string BaseName() const
Definition:
Directory.cc:50
Directory::IsDirectory
bool IsDirectory() const
Definition:
Directory.cc:54
Directory::entry
dirent * entry
Definition:
Directory.h:69
Directory::stated
bool stated
Definition:
Directory.h:71
Directory::dir
DIR * dir
Definition:
Directory.h:67
Directory::Rewind
void Rewind()
Definition:
Directory.cc:41
Directory.h
Directory::Directory
Directory(const std::string &dirname_)
Definition:
Directory.cc:27
ErrnoException.h
Directory::~Directory
~Directory()
Definition:
Directory.cc:37
Directory::IsRegularFile
bool IsRegularFile() const
Definition:
Directory.cc:59
Generated by
1.8.5