Back to index

im-sdk  12.3.91
Public Member Functions | Private Member Functions | Private Attributes
DirectoryInfo Class Reference

#include <IMUtil.hh>

Inheritance diagram for DirectoryInfo:
Inheritance graph
[legend]
Collaboration diagram for DirectoryInfo:
Collaboration graph
[legend]

List of all members.

Public Member Functions

DirectoryInfoVecget_directory_info ()
bool refresh (const char *path=NULL)
 DirectoryInfo (bool include_subdir_p=false, bool include_unreable_p=false)

Private Member Functions

bool addfile (const char *filename)

Private Attributes

string path
bool subdirp
bool unreadablep
DirectoryInfoVec dirvec

Detailed Description

Definition at line 18 of file IMUtil.hh.


Constructor & Destructor Documentation

DirectoryInfo::DirectoryInfo ( bool  include_subdir_p = false,
bool  include_unreable_p = false 
)

Definition at line 153 of file IMUtil.cpp.

{
    subdirp = include_subdir_p;
    unreadablep = include_unreable_p;
}

Member Function Documentation

bool DirectoryInfo::addfile ( const char *  filename) [private]

Reimplemented in LEDirectoryInfo.

Definition at line 60 of file IMUtil.cpp.

{
    struct stat s;
    DirectoryEntry d;

    string full = filename;
    if (full.empty()) return false;

    char head = full.at(0);
    if (!IS_DIRECTORY_SEP(head)) {
       full = path;
       char tail = full.at(full.size() - 1);
       if (!IS_DIRECTORY_SEP(tail)) {
           full = full.append(DIRECTORY_SEP);
       }
       full = full.append(filename);
    }

    if (stat(full.c_str(), &s) != 0) return false;
    if (!subdirp && S_ISDIR(s.st_mode)) return false;
    if (!unreadablep && (!(s.st_mode & S_IRUSR))) return false;

    d.fullname = full;

    {
       string::size_type fpos;
#ifdef WIN32
       fpos = d.fullname.find_last_of("\\/");
#else
       fpos = d.fullname.rfind('/');
#endif
       if (fpos == string::npos) {
           d.filename = d.fullname;
           d.dirname = "";
       } else {
           d.filename = d.fullname.substr(fpos + 1);
           d.dirname = d.fullname.substr(0, fpos + 1);
       }
    }

    d.readable_p = (s.st_mode & S_IRUSR);
    d.writable_p = (s.st_mode & S_IWUSR);
    d.directory_p = S_ISDIR(s.st_mode); 
    dirvec.push_back(d);

    return true;
}

Here is the caller graph for this function:

Reimplemented in LEDirectoryInfo.

Definition at line 28 of file IMUtil.hh.

{ return &dirvec; }
bool DirectoryInfo::refresh ( const char *  path = NULL)

Reimplemented in LEDirectoryInfo.

Definition at line 111 of file IMUtil.cpp.

{
    if (x_path) path = x_path;
    if (path.empty()) return false;

    if (!dirvec.empty()) dirvec.erase(dirvec.begin(), dirvec.end());

#if defined(WIN32)
#error "TODO"
#elif defined(HAVE_READDIR_R)
    DIR *dir;
    struct dirent *entry;
    struct dirent *result;
    int ret;

    dir = opendir(path.c_str());
    if (!dir) return false;
    entry = (struct dirent*) malloc(sizeof(struct dirent) + NAME_MAX);
    if (!entry) return false;
    while (((ret = readdir_r(dir, entry, &result)) == 0)
          && result) {
       addfile(result->d_name);
    }
    free(entry);
    closedir(dir);
#else /* normal readdir */
    DIR *dir;
    struct dirent *result;

    dir = opendir(path.c_str());
    if (!dir) return false;
    while (result = readdir(dir)) {
       addfile(result->d_name);
    }
    closedir(dir);
#endif

    return true;
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented in LEDirectoryInfo.

Definition at line 23 of file IMUtil.hh.

string DirectoryInfo::path [private]

Reimplemented in LEDirectoryInfo.

Definition at line 20 of file IMUtil.hh.

bool DirectoryInfo::subdirp [private]

Definition at line 21 of file IMUtil.hh.

Definition at line 22 of file IMUtil.hh.


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