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

Main Page | Modules | Namespace List | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Dev/src/ReclsFileSearchDirectoryNode_unix.h

Go to the documentation of this file.
00001 /* ///////////////////////////////////////////////////////////////////////////// 00002 * File: ReclsFileSearchDirectoryNode_unix.h 00003 * 00004 * Purpose: ReclsFileSearchDirectoryNode class, for UNIX. 00005 * 00006 * Created: 31st May 2004 00007 * Updated: 10th January 2005 00008 * 00009 * Home: http://recls.org/ 00010 * 00011 * Copyright 2004-2005, 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 00041 /* ///////////////////////////////////////////////////////////////////////////// 00042 * Includes 00043 */ 00044 00045 #include "recls.h" 00046 00047 #include <stlsoft.h> 00048 #ifdef USE_SEARCHSPEC_SEQ 00049 # include <stlsoft_searchspec_sequence.h> 00050 #endif /* USE_SEARCHSPEC_SEQ */ 00051 #include <stlsoft_simple_string.h> 00052 00053 #include <unixstl.h> 00054 #include <unixstl_filesystem_traits.h> 00055 #include <unixstl_glob_sequence.h> 00056 00057 /* ///////////////////////////////////////////////////////////////////////////// 00058 * Namespace 00059 */ 00060 00061 #if !defined(RECLS_NO_NAMESPACE) 00062 namespace recls 00063 { 00064 #endif /* !RECLS_NO_NAMESPACE */ 00065 00066 /* ///////////////////////////////////////////////////////////////////////////// 00067 * Classes 00068 */ 00069 00070 class ReclsFileSearchDirectoryNode 00071 // : public ReclsDNode 00072 { 00073 public: 00074 typedef recls_char_t char_type; 00075 typedef ReclsFileSearchDirectoryNode class_type; 00076 typedef unixstl_ns_qual(filesystem_traits)<recls_char_t> traits_type; 00077 private: 00078 typedef unixstl_ns_qual(basic_file_path_buffer)<recls_char_t> file_path_buffer_type; 00079 typedef stlsoft_ns_qual(basic_simple_string)<recls_char_t> string_type; 00080 typedef unixstl_ns_qual(glob_sequence) file_find_sequence_type; 00081 typedef unixstl_ns_qual(glob_sequence) directory_sequence_type; 00082 #ifdef USE_SEARCHSPEC_SEQ 00083 typedef stlsoft_ns_qual(searchspec_sequence)<file_find_sequence_type> entry_sequence_type; 00084 #else /* ? USE_SEARCHSPEC_SEQ */ 00085 typedef file_find_sequence_type entry_sequence_type; 00086 #endif /* USE_SEARCHSPEC_SEQ */ 00087 00088 // Construction 00089 #if defined(RECLS_COMPILER_IS_GCC) 00090 protected: 00091 #else /* ? compiler */ 00092 private: 00093 #endif /* compiler */ 00094 ReclsFileSearchDirectoryNode(recls_uint32_t flags, char_type const *rootDir, char_type const *pattern); 00095 public: 00096 virtual ~ReclsFileSearchDirectoryNode(); 00097 00098 static ReclsFileSearchDirectoryNode *FindAndCreate(recls_uint32_t flags, char_type const *rootDir, char_type const *pattern); 00099 static ReclsFileSearchDirectoryNode *FindAndCreate(recls_uint32_t flags, char_type const *rootDir, char_type const *subDir, char_type const *pattern); 00100 00101 // ReclsDNode methods 00102 public: 00103 /* virtual */ recls_rc_t GetNext(); 00104 /* virtual */ recls_rc_t GetDetails(recls_info_t *pinfo); 00105 /* virtual */ recls_rc_t GetNextDetails(recls_info_t *pinfo); 00106 00107 // Implementation 00108 private: 00109 recls_rc_t Initialise(); 00110 00111 recls_bool_t is_valid_() const; 00112 00113 #if defined(RECLS_COMPILER_IS_BORLAND) 00114 static directory_sequence_type::const_iterator _select_iter(int b, directory_sequence_type::const_iterator trueVal, directory_sequence_type::const_iterator falseVal) 00115 { 00116 // I can't explain it, but Borland does not like the tertiary operator and the copy-ctors of the iterators 00117 if(b) 00118 { 00119 return trueVal; 00120 } 00121 else 00122 { 00123 return falseVal; 00124 } 00125 } 00126 #endif /* !RECLS_COMPILER_IS_BORLAND */ 00127 static int _ssFlags_from_reclsFlags(recls_uint32_t flags) 00128 { 00129 #if 0 00130 recls_assert(0 == (flags & RECLS_F_LINKS)); // Doesn't work with links 00131 recls_assert(0 == (flags & RECLS_F_DEVICES)); // Doesn't work with devices 00132 #endif /* 0 */ 00133 00134 int ssFlags = 0; 00135 00136 if(0 != (flags & RECLS_F_FILES)) 00137 { 00138 #ifdef USE_SEARCHSPEC_SEQ 00139 // Because Digital Mars 8.40- has a problem, we must access the typedef separately from the enum value 00140 typedef entry_sequence_type::find_sequence_type sequence_t; 00141 00142 ssFlags |= sequence_t::files; 00143 00144 // ssFlags |= entry_sequence_type::find_sequence_type::files; 00145 #else /* ? USE_SEARCHSPEC_SEQ */ 00146 ssFlags |= entry_sequence_type::files; 00147 #endif /* USE_SEARCHSPEC_SEQ */ 00148 } 00149 if(0 != (flags & RECLS_F_DIRECTORIES)) 00150 { 00151 #ifdef USE_SEARCHSPEC_SEQ 00152 // Because Digital Mars 8.40- has a problem, we must access the typedef separately from the enum value 00153 typedef entry_sequence_type::find_sequence_type sequence_t; 00154 00155 ssFlags |= sequence_t::directories; 00156 00157 // ssFlags |= entry_sequence_type::find_sequence_type::directories; 00158 #else /* ? USE_SEARCHSPEC_SEQ */ 00159 ssFlags |= entry_sequence_type::directories; 00160 #endif /* USE_SEARCHSPEC_SEQ */ 00161 } 00162 00163 return ssFlags; 00164 } 00165 00166 // Members 00167 private: 00168 recls_info_t m_current; 00169 ReclsFileSearchDirectoryNode *m_dnode; 00170 recls_uint32_t const m_flags; 00171 entry_sequence_type m_entries; 00172 entry_sequence_type::const_iterator m_entriesBegin; 00173 directory_sequence_type m_directories; 00174 directory_sequence_type::const_iterator m_directoriesBegin; 00175 file_path_buffer_type m_rootDir; 00176 string_type m_pattern; 00177 00178 // Not to be implemented 00179 private: 00180 ReclsFileSearchDirectoryNode(class_type const &); 00181 class_type &operator =(class_type const &); 00182 }; 00183 00184 /* ///////////////////////////////////////////////////////////////////////////// 00185 * Namespace 00186 */ 00187 00188 #if !defined(RECLS_NO_NAMESPACE) 00189 } /* namespace recls */ 00190 #endif /* !RECLS_NO_NAMESPACE */ 00191 00192 /* ////////////////////////////////////////////////////////////////////////// */

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