C/C++ User's Journal Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/mappings/C++/reclspp_filesearch.h

Go to the documentation of this file.
00001 /* 
00002  * File:        reclspp_filesearch.h
00003  *
00004  * Purpose:     recls C++ mapping - FileSearch class.
00005  *
00006  * Created:     18th August 2003
00007  * Updated:     23rd September 2003
00008  *
00009  * Author:      Matthew Wilson, Synesis Software Pty Ltd.
00010  *
00011  * License:     (Licensed under the Synesis Software Standard Source License)
00012  *
00013  *              Copyright (C) 2002-2003, Synesis Software Pty Ltd.
00014  *
00015  *              All rights reserved.
00016  *
00017  *              www:        http://www.synesis.com.au/software
00018  *                          http://www.recls.org/
00019  *
00020  *              email:      submissions@recls.org  for submissions
00021  *                          admin@recls.org        for other enquiries
00022  *
00023  *              Redistribution and use in source and binary forms, with or
00024  *              without modification, are permitted provided that the following
00025  *              conditions are met:
00026  *
00027  *              (i) Redistributions of source code must retain the above
00028  *              copyright notice and contact information, this list of
00029  *              conditions and the following disclaimer.
00030  *
00031  *              (ii) Any derived versions of this software (howsoever modified)
00032  *              remain the sole property of Synesis Software.
00033  *
00034  *              (iii) Any derived versions of this software (howsoever modified)
00035  *              remain subject to all these conditions.
00036  *
00037  *              (iv) Neither the name of Synesis Software nor the names of any
00038  *              subdivisions, employees or agents of Synesis Software, nor the
00039  *              names of any other contributors to this software may be used to
00040  *              endorse or promote products derived from this software without
00041  *              specific prior written permission.
00042  *
00043  *              This source code is provided by Synesis Software "as is" and any
00044  *              warranties, whether expressed or implied, including, but not
00045  *              limited to, the implied warranties of merchantability and
00046  *              fitness for a particular purpose are disclaimed. In no event
00047  *              shall the Synesis Software be liable for any direct, indirect,
00048  *              incidental, special, exemplary, or consequential damages
00049  *              (including, but not limited to, procurement of substitute goods
00050  *              or services; loss of use, data, or profits; or business
00051  *              interruption) however caused and on any theory of liability,
00052  *              whether in contract, strict liability, or tort (including
00053  *              negligence or otherwise) arising in any way out of the use of
00054  *              this software, even if advised of the possibility of such
00055  *              damage.
00056  *
00057  * 
00058 
00059 
00060 #ifndef RECLS_INCL_H_RECLSPP_FILESEARCH
00061 #define RECLS_INCL_H_RECLSPP_FILESEARCH
00062 
00063 /* File version */
00064 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00065 # define RECLS_VER_H_RECLSPP_FILESEARCH_MAJOR       1
00066 # define RECLS_VER_H_RECLSPP_FILESEARCH_MINOR       0
00067 # define RECLS_VER_H_RECLSPP_FILESEARCH_REVISION    7
00068 # define RECLS_VER_H_RECLSPP_FILESEARCH_EDIT        7
00069 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00070 
00073 /* 
00074  * Includes
00075  */
00076 
00077 #include "reclspp.h"
00078 #include "reclspp_fileentry.h"
00079 
00080 /* 
00081  * Namespace
00082  */
00083 
00084 #if !defined(RECLS_NO_NAMESPACE)
00085 namespace recls
00086 {
00087 
00088 namespace cpp
00089 {
00090 #endif /* !RECLS_NO_NAMESPACE */
00091 
00092 /* 
00093  * Classes
00094  */
00095 
00099 class FileSearch
00100 {
00101 public:
00102 
00105 public:
00111     FileSearch(char const *rootDir, char const *pattern, recls_uint32_t flags);
00113     ~FileSearch();
00114 
00116 
00119 public:
00121     recls_rc_t      GetNext();
00122 
00124 
00127 public:
00129     recls_bool_t    HasMoreElements() const;
00133     FileEntry       GetCurrentEntry() const;
00134 
00136     recls_rc_t      GetLastError() const;
00137 
00139     recls_uint32_t  GetNumOutstandingDetails() const;
00140 
00142 
00143 // Implementation
00144 private:
00145 
00146 // Members
00147 private:
00148     hrecls_t /* const */    m_hSrch;
00149     mutable recls_rc_t      m_lastError;
00150 
00151 // Not to be implemented
00152 private:
00153     FileSearch(FileSearch const &rhs);
00154     FileSearch &operator =(FileSearch const &rhs);
00155 };
00156 
00157 /* 
00158  * Implementation
00159  */
00160 
00161 inline FileSearch::FileSearch(char const *rootDir, char const *pattern, recls_uint32_t flags)
00162     : /* m_hSrch(NULL) // This must not be initialised in the constructor
00163     , */ m_lastError((m_hSrch = NULL, Recls_Search(rootDir, pattern, flags, &const_cast<hrecls_t&>(m_hSrch))))
00164 {}
00165 
00166 inline FileSearch::~FileSearch()
00167 {
00168     if(NULL != m_hSrch)
00169     {
00170         Recls_SearchClose(m_hSrch);
00171     }
00172 }
00173 
00174 inline recls_rc_t FileSearch::GetNext()
00175 {
00176     recls_assert(NULL != m_hSrch);
00177 
00178     recls_rc_t  rc  =   Recls_GetNext(m_hSrch);
00179 
00180     if(RECLS_FAILED(rc))
00181     {
00182         Recls_SearchClose(m_hSrch);
00183         m_hSrch = NULL;
00184     }
00185 
00186     m_lastError = rc;
00187 
00188     return rc;
00189 }
00190 
00191 inline recls_bool_t FileSearch::HasMoreElements() const
00192 {
00193     return RECLS_SUCCEEDED(m_lastError);
00194 }
00195 
00196 inline FileEntry FileSearch::GetCurrentEntry() const
00197 {
00198     recls_info_t    info;
00199     recls_rc_t      rc  =   Recls_GetDetails(m_hSrch, &info);
00200 
00201     return RECLS_SUCCEEDED(m_lastError = rc) ? FileEntry(info) : FileEntry();
00202 }
00203 
00204 inline recls_rc_t FileSearch::GetLastError() const
00205 {
00206     return m_lastError;
00207 }
00208 
00209 inline recls_uint32_t FileSearch::GetNumOutstandingDetails() const
00210 {
00211     recls_uint32_t  cDetails;
00212     recls_rc_t      rc  =   Recls_OutstandingDetails(m_hSrch, &cDetails);
00213 
00214     if(RECLS_FAILED(m_lastError = rc))
00215     {
00216         cDetails = 0;
00217     }
00218 
00219     return cDetails;
00220 }
00221 
00222 /* 
00223  * Namespace
00224  */
00225 
00226 #if !defined(RECLS_NO_NAMESPACE)
00227 } /* namespace cpp */
00228 } /* namespace recls */
00229 #endif /* !RECLS_NO_NAMESPACE */
00230 
00231 /* 
00232 
00233 #endif /* !RECLS_INCL_H_RECLSPP_FILESEARCH */
00234 
00235 /* 

recls Library documentation © Synesis Software Pty Ltd, 2001-2003