C/C++ User's Journal STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - where the Standard Template Library meets the Active Template Library COMSTL - where the Standard Template Library meets the Component Object Model
Synesis Software InetSTL - where the Standard Template Library meets the Internet UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

H:/freelibs/recls/current/src/ReclsFileSearchDirectoryNode.hpp

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        ReclsFileSearchDirectoryNode.h
00003  *
00004  * Purpose:     ReclsFileSearchDirectoryNode class.
00005  *
00006  * Created:     31st May 2004
00007  * Updated:     13th June 2006
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright (c) 2004-2006, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without 
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer. 
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * ////////////////////////////////////////////////////////////////////////// */
00039 
00040 
00044 /* /////////////////////////////////////////////////////////////////////////////
00045  * Includes
00046  */
00047 
00048 // recls includes
00049 #include <recls/recls.h>
00050 #include "recls_string.h"
00051 #include "recls_util.h"
00052 
00053 // Platform-specific includes
00054 #include <platformstl/platformstl.h>
00055 #include <platformstl/filesystem/filesystem_traits.hpp>
00056 #include <platformstl/filesystem/file_path_buffer.hpp>
00057 
00058 #if defined(RECLS_PLATFORM_IS_UNIX)
00059 
00060 # include <unixstl/filesystem/glob_sequence.hpp>
00061 # include <unixstl/filesystem/readdir_sequence.hpp>
00062 
00063 #elif defined(RECLS_PLATFORM_IS_WIN32)
00064 
00065 # include <winstl/filesystem/findfile_sequence.hpp>
00066 
00067 #else /* unrecognised platform */
00068 
00069 # error The platform is not recognised. Only RECLS_PLATFORM_IS_UNIX or RECLS_PLATFORM_IS_WIN32 currently supported
00070 
00071 #endif /* platform */
00072 
00073 // STLSoft includes
00074 #ifdef _RECLS_SUPPORTS_MULTIPATTERN
00075 # if !defined(RECLS_PLATFORM_IS_WIN32) || \
00076      !defined(WINSTL_VER_WINSTL_HPP_FINDFILE_SEQUENCE_MAJOR) || \
00077      WINSTL_VER_WINSTL_HPP_FINDFILE_SEQUENCE_MAJOR < 3
00078 #  define _RECLS_USING_STLSOFT_SEARCHSPEC_SEQUENCE
00079 #  include <stlsoft/filesystem/searchspec_sequence.hpp>
00080 # endif /* stlsoft::findfile_sequence version */
00081 #endif /* _RECLS_SUPPORTS_MULTIPATTERN */
00082 
00083 #include "ReclsSearch.hpp"
00084 
00085 /* /////////////////////////////////////////////////////////////////////////////
00086  * Namespace
00087  */
00088 
00089 #if !defined(RECLS_NO_NAMESPACE)
00090 namespace recls
00091 {
00092 #endif /* !RECLS_NO_NAMESPACE */
00093 
00094 /* /////////////////////////////////////////////////////////////////////////////
00095  * Classes
00096  */
00097 
00098 class ReclsFileSearchDirectoryNode
00099     : public ReclsSearchDirectoryNode
00100 {
00101 public:
00102     typedef ReclsFileSearchDirectoryNode                                        class_type;
00103     typedef ::platformstl::filesystem_traits<recls_char_t>                      traits_type;
00104     typedef ::platformstl::basic_file_path_buffer<recls_char_t>                 file_path_buffer_type;
00105 private:
00107     typedef RECLS_STRING_TEMPLATE_1(recls_char_t)                               string_type;
00108 
00110 #if defined(RECLS_PLATFORM_IS_UNIX)
00111     typedef unixstl_ns_qual(glob_sequence)                                      file_find_sequence_type;
00112 #elif defined(RECLS_PLATFORM_IS_WIN32)
00113     typedef winstl_ns_qual(basic_findfile_sequence)<recls_char_t, traits_type>  file_find_sequence_type;
00114 #endif /* platform */
00115 
00117 #if defined(RECLS_PLATFORM_IS_UNIX)
00118     typedef unixstl_ns_qual(readdir_sequence)                                   directory_sequence_type;
00119 #elif defined(RECLS_PLATFORM_IS_WIN32)
00120     typedef file_find_sequence_type                                             directory_sequence_type;
00121 #endif /* platform */
00122 
00124 #ifdef _RECLS_USING_STLSOFT_SEARCHSPEC_SEQUENCE
00125     typedef stlsoft_ns_qual(searchspec_sequence)<file_find_sequence_type>       entry_sequence_type;
00126 #else /* ? _RECLS_USING_STLSOFT_SEARCHSPEC_SEQUENCE */
00127     typedef file_find_sequence_type                                             entry_sequence_type;
00128 #endif /* _RECLS_USING_STLSOFT_SEARCHSPEC_SEQUENCE */
00129 
00130 // Construction
00131 protected: // Not private, or GCC whines
00132     ReclsFileSearchDirectoryNode(   recls_uint32_t              flags
00133                                 ,   size_t                      rootDirLen
00134                                 ,   recls_char_t const          *searchDir
00135                                 ,   recls_char_t const          *pattern
00136                                 ,   hrecls_progress_fn_t        pfn
00137                                 ,   recls_process_fn_param_t    param);
00138 public:
00139     virtual ~ReclsFileSearchDirectoryNode();
00140 
00141     static class_type *FindAndCreate(recls_uint32_t             flags
00142                                 ,   size_t                      rootDirLen
00143                                 ,   recls_char_t const          *searchDir
00144                                 ,   recls_char_t const          *pattern
00145                                 ,   hrecls_progress_fn_t        pfn
00146                                 ,   recls_process_fn_param_t    param);
00147 
00148     static recls_rc_t Stat( recls_char_t const  *path
00149                         ,   recls_uint32_t      flags
00150                         ,   recls_info_t        *phEntry);
00151 
00152 // ReclsSearchDirectoryNode methods
00153 private:
00154     /* virtual */ recls_rc_t GetNext();
00155     /* virtual */ recls_rc_t GetDetails(recls_info_t *pinfo);
00156     /* virtual */ recls_rc_t GetNextDetails(recls_info_t *pinfo);
00157 
00158 // Implementation
00159 private:
00160     recls_rc_t      Initialise();
00161 
00162 #ifdef RECLS_ENFORCING_CONTRACTS
00163     recls_bool_t    is_valid() const;
00164 #endif /* RECLS_ENFORCING_CONTRACTS */
00165 
00167     static int essFlags_from_reclsFlags_(recls_uint32_t flags);
00169     static int dssFlags_from_reclsFlags_(recls_uint32_t flags);
00174     static directory_sequence_type::const_iterator select_iter_if_( unsigned long                           b
00175                                                                 ,   directory_sequence_type::const_iterator trueVal
00176                                                                 ,   directory_sequence_type::const_iterator falseVal);
00177 
00180     static size_t prepare_searchDir_(file_path_buffer_type &buff, recls_char_t const *searchDir);
00181 
00182     static recls_info_t     CreateEntryInfo(size_t                              rootDirLen
00183                                         ,   recls_char_t const                  *searchDir
00184                                         ,   size_t                              searchDirLen
00185                                         ,   recls_uint32_t                      flags
00186                                         ,   entry_sequence_type::const_iterator it);
00187 
00188 // Members
00189 private:
00190     recls_info_t                            m_current;
00191     class_type                              *m_dnode;
00192     const recls_uint32_t                    m_flags;
00193     const size_t                            m_rootDirLen;
00194     file_path_buffer_type                   m_searchDir;
00195     const size_t                            m_searchDirLen;
00196     const string_type                       m_pattern;
00197     directory_sequence_type                 m_directories;
00198     directory_sequence_type::const_iterator m_directoriesBegin;
00199     entry_sequence_type                     m_entries;
00200     entry_sequence_type::const_iterator     m_entriesBegin;
00201     const hrecls_progress_fn_t              m_pfn;
00202     const recls_process_fn_param_t          m_param;
00203 
00204 // Not to be implemented
00205 private:
00206     ReclsFileSearchDirectoryNode(class_type const &);
00207     class_type &operator =(class_type const &);
00208 };
00209 
00210 /* /////////////////////////////////////////////////////////////////////////////
00211  * Namespace
00212  */
00213 
00214 #if !defined(RECLS_NO_NAMESPACE)
00215 } /* namespace recls */
00216 #endif /* !RECLS_NO_NAMESPACE */
00217 
00218 /* ////////////////////////////////////////////////////////////////////////// */

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