SimpleGlobBase< SOCHAR > Struct Template Reference

Unix glob implementation. More...

#include <SimpleGlob.h>

Inheritance diagram for SimpleGlobBase< SOCHAR >:

[legend]
Collaboration diagram for SimpleGlobBase< SOCHAR >:
[legend]

Public Member Functions

 SimpleGlobBase ()
 ~SimpleGlobBase ()
void FilePrep ()
int FindFirstFileS (const char *a_pszFileSpec, unsigned int a_uiFlags)
bool FindNextFileS (char)
void FindDone ()
const char * GetFileNameS (char) const
bool IsDirS (char) const
SG_FileType GetFileTypeS (const char *a_pszPath) const

Private Attributes

glob_t m_glob
size_t m_uiCurr
bool m_bIsDir

Detailed Description

template<class SOCHAR>
struct SimpleGlobBase< SOCHAR >

Unix glob implementation.

Definition at line 342 of file SimpleGlob.h.


Constructor & Destructor Documentation

template<class SOCHAR>
SimpleGlobBase< SOCHAR >::SimpleGlobBase (  )  [inline]

Definition at line 343 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::m_glob, and SimpleGlobBase< SOCHAR >::m_uiCurr.

00343                          {
00344                 memset(&m_glob, 0, sizeof(m_glob));
00345                 m_uiCurr = (size_t) -1;
00346         }             ~SimpleGlobBase() {

template<class SOCHAR>
SimpleGlobBase< SOCHAR >::~SimpleGlobBase (  )  [inline]

Definition at line 346 of file SimpleGlob.h.

00346                                         {
00347                 globfree(&m_glob);
00348         }


Member Function Documentation

template<class SOCHAR>
void SimpleGlobBase< SOCHAR >::FilePrep (  )  [inline]

Definition at line 350 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::m_bIsDir, SimpleGlobBase< SOCHAR >::m_glob, and SimpleGlobBase< SOCHAR >::m_uiCurr.

Referenced by SimpleGlobBase< SOCHAR >::FindFirstFileS(), and SimpleGlobBase< SOCHAR >::FindNextFileS().

00350                         {
00351                 m_bIsDir = false;
00352                 size_t len = strlen(m_glob.gl_pathv[m_uiCurr]);
00353                 if (m_glob.gl_pathv[m_uiCurr][len - 1] == '/') {
00354                         m_bIsDir = true;
00355                         m_glob.gl_pathv[m_uiCurr][len - 1] = 0;
00356                 }
00357         }

template<class SOCHAR>
void SimpleGlobBase< SOCHAR >::FindDone (  )  [inline]

Definition at line 388 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::m_glob, and SimpleGlobBase< SOCHAR >::m_uiCurr.

00388                         {
00389                 globfree(&m_glob);
00390                 memset(&m_glob, 0, sizeof(m_glob));
00391                 m_uiCurr = (size_t) -1;
00392         }

template<class SOCHAR>
int SimpleGlobBase< SOCHAR >::FindFirstFileS ( const char *  a_pszFileSpec,
unsigned int  a_uiFlags 
) [inline]

Definition at line 359 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::FilePrep(), SimpleGlobBase< SOCHAR >::m_glob, SimpleGlobBase< SOCHAR >::m_uiCurr, SG_ERR_FAILURE, SG_ERR_MEMORY, SG_ERR_NOMATCH, SG_GLOB_ERR, SG_GLOB_TILDE, and SG_SUCCESS.

00359                                                                               {
00360                 int nFlags = GLOB_MARK | GLOB_NOSORT;
00361                 if (a_uiFlags & SG_GLOB_ERR)
00362                         nFlags |= GLOB_ERR;
00363 #ifdef GLOB_TILDE
00364                 if (a_uiFlags & SG_GLOB_TILDE)
00365                         nFlags |= GLOB_TILDE;
00366 #endif
00367                 int rc = glob(a_pszFileSpec, nFlags, NULL, &m_glob);
00368                 if (rc == GLOB_NOSPACE)
00369                         return SG_ERR_MEMORY;
00370                 if (rc == GLOB_ABORTED)
00371                         return SG_ERR_FAILURE;
00372                 if (rc == GLOB_NOMATCH)
00373                         return SG_ERR_NOMATCH;
00374                 m_uiCurr = 0;
00375                 FilePrep();
00376                 return SG_SUCCESS;
00377         }

template<class SOCHAR>
bool SimpleGlobBase< SOCHAR >::FindNextFileS ( char   )  [inline]

Definition at line 379 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::FilePrep(), SimpleGlobBase< SOCHAR >::m_glob, SimpleGlobBase< SOCHAR >::m_uiCurr, and SG_ASSERT.

00379                                  {
00380                 SG_ASSERT(m_uiCurr != (size_t) -1);
00381                 if (++m_uiCurr >= m_glob.gl_pathc) {
00382                         return false;
00383                 }
00384                 FilePrep();
00385                 return true;
00386         }

template<class SOCHAR>
const char* SimpleGlobBase< SOCHAR >::GetFileNameS ( char   )  const [inline]

Definition at line 394 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::m_glob, SimpleGlobBase< SOCHAR >::m_uiCurr, and SG_ASSERT.

00394                                              {
00395                 SG_ASSERT(m_uiCurr != (size_t) -1);
00396                 return m_glob.gl_pathv[m_uiCurr];
00397         }

template<class SOCHAR>
SG_FileType SimpleGlobBase< SOCHAR >::GetFileTypeS ( const char *  a_pszPath  )  const [inline]

Definition at line 402 of file SimpleGlob.h.

References SG_FILETYPE_DIR, SG_FILETYPE_FILE, and SG_FILETYPE_INVALID.

00402                                                               {
00403                 struct stat sb;
00404                 if   (0 != stat(a_pszPath, &sb)) {
00405                         return SG_FILETYPE_INVALID;
00406                 }
00407                 if    (S_ISDIR(sb.st_mode)) {
00408                         return SG_FILETYPE_DIR;
00409                 }
00410                 if (S_ISREG(sb.st_mode)) {
00411                         return SG_FILETYPE_FILE;
00412                 }
00413                 return SG_FILETYPE_INVALID;
00414         }

template<class SOCHAR>
bool SimpleGlobBase< SOCHAR >::IsDirS ( char   )  const [inline]

Definition at line 398 of file SimpleGlob.h.

References SimpleGlobBase< SOCHAR >::m_bIsDir, SimpleGlobBase< SOCHAR >::m_uiCurr, and SG_ASSERT.

00398                                 {
00399                 SG_ASSERT(m_uiCurr != (size_t) -1);
00400                 return m_bIsDir;
00401         }


Field Documentation

template<class SOCHAR>
bool SimpleGlobBase< SOCHAR >::m_bIsDir [private]

Definition at line 419 of file SimpleGlob.h.

Referenced by SimpleGlobBase< SOCHAR >::FilePrep(), and SimpleGlobBase< SOCHAR >::IsDirS().

template<class SOCHAR>
glob_t SimpleGlobBase< SOCHAR >::m_glob [private]

Definition at line 417 of file SimpleGlob.h.

Referenced by SimpleGlobBase< SOCHAR >::FilePrep(), SimpleGlobBase< SOCHAR >::FindDone(), SimpleGlobBase< SOCHAR >::FindFirstFileS(), SimpleGlobBase< SOCHAR >::FindNextFileS(), SimpleGlobBase< SOCHAR >::GetFileNameS(), and SimpleGlobBase< SOCHAR >::SimpleGlobBase().

template<class SOCHAR>
size_t SimpleGlobBase< SOCHAR >::m_uiCurr [private]

Definition at line 418 of file SimpleGlob.h.

Referenced by SimpleGlobBase< SOCHAR >::FilePrep(), SimpleGlobBase< SOCHAR >::FindDone(), SimpleGlobBase< SOCHAR >::FindFirstFileS(), SimpleGlobBase< SOCHAR >::FindNextFileS(), SimpleGlobBase< SOCHAR >::GetFileNameS(), SimpleGlobBase< SOCHAR >::IsDirS(), and SimpleGlobBase< SOCHAR >::SimpleGlobBase().


The documentation for this struct was generated from the following file:
Generated on Wed May 16 04:00:24 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7