Public Member Functions | Public Attributes | Protected Attributes | Private Attributes

cmn_DirLst Class Reference
[Common, basic classes, functions and types]

DirLst class could list (return) directory entries by its name. More...

#include <cmn_dir.h>

Collaboration diagram for cmn_DirLst:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 cmn_DirLst (const cmn_Path &a_path, const string &a_end)
 Default constructor.
 cmn_DirLst (const cmn_Path &a_path, const string &a_end, const string &a_prefix)
 ~cmn_DirLst ()
string GetNextName ()
 this method return the name of next file that match to filter When all file are returned return empty string.
string GetNextName (ivd_GenInode_t &a_Inode)
 this method return the name and inode of next file that match to filter When all file are returned return empty string.
void Reset ()
 Reset the search to start of directory.

Public Attributes

 log_CLASSID_m

Protected Attributes

ivd_DirHandle_t m_findHnd
 Find handler.

Private Attributes

const cmn_Path m_path
 The path where directory list is perform.
const string m_end
 The file extension, for filtering.
const string m_prefix
 the file name prefix for filtering
string m_name
 the next name that have to be returned by GetNextName method.

Detailed Description

DirLst class could list (return) directory entries by its name.

End of file could be use as parameter for file name filtering.

Author:
Dejan Volk Lupo, HERMES SoftLab
See also:
<reference>

Example:

    cmn_DirLst dirList("./", ".tst" ); // find all files that name finish with ".tst" 
    
    string name = dirList.GetNextName();
    while  (name.length() > 0) {
        // TODO  some operation with name    
        name = dirList.GetNextName();
    } 

Definition at line 59 of file cmn_dir.h.


Constructor & Destructor Documentation

cmn_DirLst::cmn_DirLst ( const cmn_Path a_path,
const string &  a_end 
)

Default constructor.

Definition at line 52 of file cmn_Dir_LNX.cpp.

References log_FUNC_A_m, and Reset().

        : 
        m_path(a_path), 
        m_end(a_end),
        m_findHnd(NULL)
{ 
    log_FUNC_A_m(cmn_DirLst, "path: " << a_path << " pfix: " << a_end);
    Reset(); 
}

Here is the call graph for this function:

cmn_DirLst::cmn_DirLst ( const cmn_Path a_path,
const string &  a_end,
const string &  a_prefix 
)

Definition at line 66 of file cmn_Dir_LNX.cpp.

References log_FUNC_A_m, and Reset().

        : 
        m_path(a_path), 
        m_end(a_end),
        m_prefix(a_prefix),
        m_findHnd(NULL)
{ 
    log_FUNC_A_m(cmn_DirLst,
        "path: " << a_path << " pfix: " << a_end << " prefix: " << a_prefix);
    Reset(); 
}

Here is the call graph for this function:

cmn_DirLst::~cmn_DirLst (  ) 

Definition at line 83 of file cmn_Dir_LNX.cpp.

References log_ERR_m, log_FUNC_m, m_findHnd, m_path, and NULL.

                        {
    log_FUNC_m(~cmn_DirLst);
    if (m_findHnd != NULL) {
        if (closedir(m_findHnd) == -1) { 
            log_ERR_m("Can't close opendir handle: " << m_path);
        }
    }
}


Member Function Documentation

string cmn_DirLst::GetNextName (  ) 

this method return the name of next file that match to filter When all file are returned return empty string.

Definition at line 101 of file cmn_Dir_LNX.cpp.

References cmn_EmptyCStr(), dbg_DETAIL, dirent, log_DBG_m, log_FUNC_m, m_end, m_findHnd, m_prefix, and NULL.

Referenced by fio_JourMgr::fio_JourMgr(), fsc_MedVolReader::fsc_MedVolReader(), GetPDBI(), GetRelFiles(), JournalDump(), main(), bea_DiskMedium::Refresh(), fio_JourMgr::RemoveArhivedJourFile(), RemoveJournalFiles(), bea_DiskVolume::ReparseFiles(), and ShowRelFiles().

                               {
    log_FUNC_m(GetNextName);
    if (m_findHnd == NULL) {
        return cmn_EmptyCStr();
    }

    struct dirent *dirp;
    unsigned int extLen    = m_end.length();
    unsigned int prefixLen = m_prefix.length();
    unsigned int dirNameLen;
    int checkPoint;

    while ((dirp=readdir(m_findHnd))!=NULL) {
        dirNameLen = strlen(dirp->d_name);
        checkPoint = dirNameLen - extLen;
        if (  (checkPoint >= 0)
           && (strncmp(&dirp->d_name[checkPoint], m_end.data(), extLen) == 0) 
           && ((prefixLen == 0)
              || strncmp(dirp->d_name, m_prefix.data(), prefixLen) == 0)) {
            log_DBG_m(dbg_DETAIL,
                "got next name \'" << dirp->d_name << "\'.");
            return string(dirp->d_name);
        }
    }
    return cmn_EmptyCStr();
}

Here is the call graph for this function:

Here is the caller graph for this function:

string cmn_DirLst::GetNextName ( ivd_GenInode_t a_Inode  ) 

this method return the name and inode of next file that match to filter When all file are returned return empty string.

Definition at line 130 of file cmn_Dir_LNX.cpp.

References cmn_EmptyCStr(), dirent, m_end, m_findHnd, m_prefix, and NULL.

                                                      {
//    log_FUNC_m(GetNextName);
    a_Inode = 0;
    if (m_findHnd == NULL) {
        return cmn_EmptyCStr();
    }

    struct dirent *dirp;
    unsigned int extLen    = m_end.length();
    unsigned int prefixLen = m_prefix.length();
    unsigned int dirNameLen;
    int checkPoint;

    while ((dirp=readdir(m_findHnd))!=NULL) {
        dirNameLen = strlen(dirp->d_name);
        checkPoint = dirNameLen - extLen;
        if (  (checkPoint >= 0)
           && (strncmp(&dirp->d_name[checkPoint], m_end.data(), extLen) == 0)
           && ((prefixLen == 0)
              || strncmp(dirp->d_name, m_prefix.data(), prefixLen) == 0)) {
            a_Inode = dirp->d_ino;
            return string(dirp->d_name);
        }
    }
    return cmn_EmptyCStr();
}

Here is the call graph for this function:

void cmn_DirLst::Reset (  ) 

Reset the search to start of directory.

Definition at line 159 of file cmn_Dir_LNX.cpp.

References errno, log_FUNC_m, m_findHnd, m_path, and NULL.

Referenced by cmn_DirLst().

                       { 
    log_FUNC_m(Reset);
    if (m_findHnd != NULL) {
        if (closedir(m_findHnd) == -1) { 
            throw ivd_SysError(errno, "Can't close opendir handle.", true);
        }
    }
    m_findHnd = opendir(m_path.c_str());
    
    if (m_findHnd == NULL) {
        ostringstream sstr;
        sstr << "Failed opendir(: " << m_path << ")";
        throw ivd_SysError(errno, sstr.str(), true);
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 110 of file cmn_dir.h.

const string cmn_DirLst::m_end [private]

The file extension, for filtering.

List of name that finish with m_end string. NOTE!

Definition at line 85 of file cmn_dir.h.

Referenced by GetNextName().

Find handler.

Definition at line 106 of file cmn_dir.h.

Referenced by GetNextName(), Reset(), and ~cmn_DirLst().

string cmn_DirLst::m_name [private]

the next name that have to be returned by GetNextName method.

Definition at line 95 of file cmn_dir.h.

const cmn_Path cmn_DirLst::m_path [private]

The path where directory list is perform.

Definition at line 78 of file cmn_dir.h.

Referenced by Reset(), and ~cmn_DirLst().

const string cmn_DirLst::m_prefix [private]

the file name prefix for filtering

Definition at line 90 of file cmn_dir.h.

Referenced by GetNextName().


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