CPN
Computational Process Networks
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Directory Class Reference

#include <Directory.h>

+ Collaboration diagram for Directory:

Public Member Functions

 Directory (const std::string &dirname_)
 
 ~Directory ()
 
void Rewind ()
 
bool End () const
 
std::string BaseName () const
 
std::string FullName () const
 
std::string DirName () const
 
void Next ()
 
bool IsDirectory () const
 
bool IsRegularFile () const
 
std::size_t Size () const
 

Private Member Functions

void Stat () const
 

Private Attributes

DIR * dir
 
std::string dirname
 
dirent * entry
 
struct stat status
 
bool stated
 

Detailed Description

Definition at line 33 of file Directory.h.

Constructor & Destructor Documentation

Directory::Directory ( const std::string &  dirname_)

Definition at line 27 of file Directory.cc.

References dir, dirname, and Next().

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 }
std::string dirname
Definition: Directory.h:68
void Next()
Definition: Directory.cc:45
dirent * entry
Definition: Directory.h:69
bool stated
Definition: Directory.h:71
DIR * dir
Definition: Directory.h:67

+ Here is the call graph for this function:

Directory::~Directory ( )

Definition at line 37 of file Directory.cc.

References dir.

37  {
38  closedir(dir);
39 }
DIR * dir
Definition: Directory.h:67

Member Function Documentation

std::string Directory::BaseName ( ) const

Get the name of the current file in the directory

Definition at line 50 of file Directory.cc.

References entry.

Referenced by FullName().

50  {
51  return std::string(entry->d_name);
52 }
dirent * entry
Definition: Directory.h:69

+ Here is the caller graph for this function:

std::string Directory::DirName ( ) const
inline

Definition at line 55 of file Directory.h.

References dirname.

Referenced by FullName().

55 { return dirname; }
std::string dirname
Definition: Directory.h:68

+ Here is the caller graph for this function:

bool Directory::End ( ) const
inline
Returns
true if we are at the end of the directory.

Definition at line 48 of file Directory.h.

References entry.

Referenced by CPN::NodeLoader::SearchDirectory().

48 { return entry == 0; }
dirent * entry
Definition: Directory.h:69

+ Here is the caller graph for this function:

std::string Directory::FullName ( ) const
inline

Definition at line 54 of file Directory.h.

References BaseName(), and DirName().

54 { return DirName() + "/" + BaseName(); }
std::string BaseName() const
Definition: Directory.cc:50
std::string DirName() const
Definition: Directory.h:55

+ Here is the call graph for this function:

bool Directory::IsDirectory ( ) const

Definition at line 54 of file Directory.cc.

References Stat(), and status.

54  {
55  Stat();
56  return S_ISDIR(status.st_mode);
57 }
struct stat status
Definition: Directory.h:70
void Stat() const
Definition: Directory.cc:69

+ Here is the call graph for this function:

bool Directory::IsRegularFile ( ) const

Definition at line 59 of file Directory.cc.

References Stat(), and status.

59  {
60  Stat();
61  return S_ISREG(status.st_mode);
62 }
struct stat status
Definition: Directory.h:70
void Stat() const
Definition: Directory.cc:69

+ Here is the call graph for this function:

void Directory::Next ( )

Move to the next file in the directory.

Definition at line 45 of file Directory.cc.

References dir, entry, and stated.

Referenced by Directory().

45  {
46  entry = readdir(dir);
47  stated = false;
48 }
dirent * entry
Definition: Directory.h:69
bool stated
Definition: Directory.h:71
DIR * dir
Definition: Directory.h:67

+ Here is the caller graph for this function:

void Directory::Rewind ( )

Rewind to the beginning of the directory.

Definition at line 41 of file Directory.cc.

References dir.

41  {
42  rewinddir(dir);
43 }
DIR * dir
Definition: Directory.h:67
std::size_t Directory::Size ( ) const

Definition at line 64 of file Directory.cc.

References Stat(), and status.

64  {
65  Stat();
66  return status.st_size;
67 }
struct stat status
Definition: Directory.h:70
void Stat() const
Definition: Directory.cc:69

+ Here is the call graph for this function:

void Directory::Stat ( ) const
private

Definition at line 69 of file Directory.cc.

References dirname, entry, stated, and status.

Referenced by IsDirectory(), IsRegularFile(), and Size().

69  {
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 }
std::string dirname
Definition: Directory.h:68
struct stat status
Definition: Directory.h:70
dirent * entry
Definition: Directory.h:69
bool stated
Definition: Directory.h:71

+ Here is the caller graph for this function:

Member Data Documentation

DIR* Directory::dir
private

Definition at line 67 of file Directory.h.

Referenced by Directory(), Next(), Rewind(), and ~Directory().

std::string Directory::dirname
private

Definition at line 68 of file Directory.h.

Referenced by Directory(), DirName(), and Stat().

dirent* Directory::entry
private

Definition at line 69 of file Directory.h.

Referenced by BaseName(), End(), Next(), and Stat().

bool Directory::stated
mutableprivate

Definition at line 71 of file Directory.h.

Referenced by Next(), and Stat().

struct stat Directory::status
private

Definition at line 70 of file Directory.h.

Referenced by IsDirectory(), IsRegularFile(), Size(), and Stat().


The documentation for this class was generated from the following files: