00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef RECLS_INCL_RECLS_CPP_HPP_FILESEARCH
00042 #define RECLS_INCL_RECLS_CPP_HPP_FILESEARCH
00043
00044
00045 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00046 # define RECLS_VER_RECLS_CPP_HPP_FILESEARCH_MAJOR 3
00047 # define RECLS_VER_RECLS_CPP_HPP_FILESEARCH_MINOR 2
00048 # define RECLS_VER_RECLS_CPP_HPP_FILESEARCH_REVISION 1
00049 # define RECLS_VER_RECLS_CPP_HPP_FILESEARCH_EDIT 24
00050 #endif
00051
00060
00061
00062
00063
00064 #include <recls/cpp/recls.hpp>
00065 #include <recls/cpp/search.hpp>
00066 #include <recls/assert.h>
00067
00068 #include <stlsoft/memory/auto_buffer.hpp>
00069 #include <stlsoft/shims/access/string.hpp>
00070
00071
00072
00073
00074
00075 #if !defined(RECLS_NO_NAMESPACE)
00076 namespace recls
00077 {
00078
00079 namespace cpp
00080 {
00081 #endif
00082
00083
00084
00085
00086
00090 class FileSearch
00091 : public Search
00092 {
00094 public:
00096 typedef recls_char_t char_type;
00097 typedef size_t size_type;
00098 typedef FileSearch class_type;
00100
00103 public:
00109 FileSearch(char_type const *rootDir, char_type const *pattern, recls_uint32_t flags);
00111 ~FileSearch();
00113
00116 public:
00123 template <typename S>
00124 static FileEntry Stat(S const &path)
00125 {
00126 return Stat_(stlsoft::c_str_ptr(path), RECLS_F_FILES | RECLS_F_DIRECTORIES | RECLS_F_DIRECTORY_PARTS);
00127 }
00128
00129 template <typename S>
00130 static FileEntry Stat( S const &path
00131 , recls_uint32_t flags )
00132 {
00133 return Stat_(stlsoft::c_str_ptr(path), flags);
00134 }
00135
00136 template< typename S1
00137 , typename S2
00138 >
00139 static string_t CombinePaths( S1 const &path1
00140 , S2 const &path2)
00141 {
00142 return CombinePaths_(stlsoft::c_str_ptr(path1), stlsoft::c_str_ptr(path2));
00143 }
00144
00145 template< typename S1
00146 , typename S2
00147 >
00148 static string_t DeriveRelativePath( S1 const &origin
00149 , S2 const &target)
00150 {
00151 return DeriveRelativePath_(stlsoft::c_str_ptr(origin), stlsoft::c_str_ptr(target));
00152 }
00153
00154 template <typename S>
00155 static string_t SqueezePath( S const &path
00156 , size_type width)
00157 {
00158 return SqueezePath_(stlsoft::c_str_ptr(path), width);
00159 }
00161
00162
00163 private:
00164 static ctor_args_type CreateSearch_(char_type const *rootDir, char_type const *pattern, recls_uint32_t flags)
00165 {
00166 hrecls_t hSrch;
00167 recls_rc_t rc = Recls_Search(rootDir, pattern, flags, &hSrch);
00168
00169 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00170 if( RECLS_FAILED(rc) &&
00171 RECLS_RC_NO_MORE_DATA != rc)
00172 {
00173 throw ReclsException(rc);
00174 }
00175 #endif
00176
00177 return Search::ctor_args_type(hSrch, rc);
00178 }
00179
00180 static FileEntry Stat_(char_type const *path, recls_uint32_t flags);
00181
00182 static string_t CombinePaths_( char_type const *path1, char_type const *path2);
00183
00184 static string_t DeriveRelativePath_(char_type const *origin, char_type const *target);
00185
00186 static string_t SqueezePath_(char_type const *path, size_type width);
00187
00188
00189 private:
00190 FileSearch(class_type const &rhs);
00191 class_type &operator =(class_type const &rhs);
00192 };
00193
00194
00195
00196
00197
00198 inline string_t FileSearch::CombinePaths_(FileSearch::char_type const *path1, FileSearch::char_type const *path2)
00199 {
00200 stlsoft::auto_buffer<char_type> buffer(Recls_CombinePaths(path1, path2, NULL, 0));
00201
00202 Recls_CombinePaths(path1, path2, &buffer[0], buffer.size());
00203
00204 return string_t(buffer.data(), buffer.size());
00205 }
00206
00207 inline string_t FileSearch::DeriveRelativePath_(FileSearch::char_type const *origin, FileSearch::char_type const *target)
00208 {
00209 stlsoft::auto_buffer<char_type> buffer(Recls_DeriveRelativePath(origin, target, NULL, 0));
00210
00211 Recls_DeriveRelativePath(origin, target, &buffer[0], buffer.size());
00212
00213 return string_t(buffer.data(), buffer.size());
00214 }
00215
00216 inline string_t FileSearch::SqueezePath_(FileSearch::char_type const *path, size_type width)
00217 {
00218 stlsoft::auto_buffer<char_type> buffer(width);
00219 size_t cch = Recls_SqueezePath(path, &buffer[0], buffer.size());
00220
00221 RECLS_ASSERT(cch <= buffer.size());
00222
00223 return string_t(buffer.data(), cch);
00224 }
00225
00226
00227 inline FileSearch::FileSearch(FileSearch::char_type const *rootDir, FileSearch::char_type const *pattern, recls_uint32_t flags)
00228 : Search(CreateSearch_(rootDir, pattern, flags))
00229 {}
00230
00231 inline FileSearch::~FileSearch()
00232 {}
00233
00234 inline FileEntry FileSearch::Stat_(FileSearch::char_type const *path, recls_uint32_t flags )
00235 {
00236 recls_info_t info;
00237 recls_rc_t rc = Recls_Stat(path, flags, &info);
00238
00239 return RECLS_SUCCEEDED(rc) ? make_entry_(info) : FileEntry();
00240 }
00241
00242 #if 0
00243 inline string_t FileSearch::CombinePaths(FileSearch::char_type const *path1, FileSearch::char_type const *path2)
00244 {
00245 return CombinePaths_(path1, path2);
00246 }
00247
00248 inline string_t FileSearch::DeriveRelativePath(FileSearch::char_type const *origin, FileSearch::char_type const *target)
00249 {
00250 return DeriveRelativePath_(origin, target);
00251 }
00252
00253 inline string_t FileSearch::SqueezePath(FileSearch::char_type const *path, size_type width)
00254 {
00255 return SqueezePath_(path, width);
00256 }
00257 #endif
00258
00259
00260
00261
00262
00263 #if !defined(RECLS_NO_NAMESPACE)
00264 }
00265 }
00266 #endif
00267
00268
00269
00270 #endif
00271
00272