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
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00059 #ifndef INETSTL_INCL_INETSTL_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE
00060 #define INETSTL_INCL_INETSTL_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE
00061
00062 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00063 # define STLSOFT_VER_INETSTL_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE_MAJOR 5
00064 # define STLSOFT_VER_INETSTL_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE_MINOR 1
00065 # define STLSOFT_VER_INETSTL_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE_REVISION 5
00066 # define STLSOFT_VER_INETSTL_FILESYSTEM_HPP_SEARCHSPEC_SEQUENCE_EDIT 55
00067 #endif
00068
00069
00070
00071
00072
00073 #ifndef INETSTL_INCL_INETSTL_H_INETSTL
00074 # include <inetstl/inetstl.h>
00075 #endif
00076
00077 #ifdef STLSOFT_CF_PRAGMA_MESSAGE_SUPPORT
00078 # pragma message("This file is now obsolete, and will be removed in a future release. The inetstl::basic_findfile_sequence class now supports multi-part patterns. This file will be removed from a future release.")
00079 #endif
00080 #ifndef INETSTL_OS_IS_WINDOWS
00081 # error This file is currently compatible only with the Win32/Win64 API
00082 #endif
00083
00084 #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
00085 # include <stlsoft/collections/util/collections.hpp>
00086 #endif
00087 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_SIMPLE_STRING
00088 # include <stlsoft/string/simple_string.hpp>
00089 #endif
00090 #ifndef STLSOFT_INCL_STLSOFT_SHIMS_ACCESS_HPP_STRING
00091 # include <stlsoft/shims/access/string.hpp>
00092 #endif
00093 #ifndef STLSOFT_INCL_STLSOFT_STRING_HPP_STRING_TOKENISER
00094 # include <stlsoft/string/string_tokeniser.hpp>
00095 #endif
00096
00097 #ifndef STLSOFT_COMPILER_IS_WATCOM
00098 # ifndef STLSOFT_INCL_STLSOFT_UTIL_STD_HPP_ITERATOR_HELPER
00099 # include <stlsoft/util/std/iterator_helper.hpp>
00100 # endif
00101 #endif
00102
00103
00104
00105
00106
00107 #ifndef _INETSTL_NO_NAMESPACE
00108 # if defined(_STLSOFT_NO_NAMESPACE) || \
00109 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00110
00111 namespace inetstl
00112 {
00113 # else
00114
00115
00116 namespace stlsoft
00117 {
00118
00119 namespace inetstl_project
00120 {
00121
00122 # endif
00123 #endif
00124
00125
00126
00127
00128
00129 template <ss_typename_param_k T>
00130 inline void call_set_null(T *&pt, void (T::*F)())
00131 {
00132 INETSTL_ASSERT(NULL != pt);
00133
00134 (pt->*F)();
00135
00136 pt = NULL;
00137 }
00138
00139
00140
00141
00142
00147 template <ss_typename_param_k S>
00148 class searchspec_sequence
00149 : public stlsoft_ns_qual(stl_collection_tag)
00150 {
00151 public:
00153 typedef S find_sequence_type;
00155 typedef searchspec_sequence<S> class_type;
00156 private:
00157 typedef searchspec_sequence<S> outer_class_type;
00158 typedef ss_typename_type_k find_sequence_type::traits_type traits_type;
00159 public:
00161 typedef ss_typename_type_k find_sequence_type::char_type char_type;
00163 typedef ss_typename_type_k find_sequence_type::value_type value_type;
00165 typedef ss_typename_type_k find_sequence_type::size_type size_type;
00167 typedef ss_typename_type_k find_sequence_type::const_reference const_reference;
00169 class const_iterator;
00170 private:
00171 typedef basic_simple_string<char_type> string_type;
00172 typedef string_tokeniser<string_type, char> tokeniser_type;
00173
00174 public:
00176 searchspec_sequence()
00177 : m_hconn(NULL)
00178 , m_rootDir(null_str_())
00179 , m_searchSpec(null_str_())
00180 , m_delimiter('\0')
00181 , m_flags(0)
00182 {}
00186 searchspec_sequence(HINTERNET hconn, char_type const* searchSpec, char_type delimiter)
00187 : m_hconn(hconn)
00188 , m_rootDir(dot1_str_())
00189 , m_searchSpec(searchSpec)
00190 , m_delimiter(delimiter)
00191 , m_flags(0)
00192 {}
00196 searchspec_sequence(HINTERNET hconn, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
00197 : m_hconn(hconn)
00198 , m_rootDir(dot1_str_())
00199 , m_searchSpec(searchSpec)
00200 , m_delimiter(delimiter)
00201 , m_flags(flags)
00202 {}
00204 searchspec_sequence(HINTERNET hconn, char_type const* rootDir, char_type const* searchSpec, char_type delimiter)
00205 : m_hconn(hconn)
00206 , m_rootDir(rootDir)
00207 , m_searchSpec(searchSpec)
00208 , m_delimiter(delimiter)
00209 , m_flags(0)
00210 {}
00212 searchspec_sequence(HINTERNET hconn, char_type const* rootDir, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
00213 : m_hconn(hconn)
00214 , m_rootDir(rootDir)
00215 , m_searchSpec(searchSpec)
00216 , m_delimiter(delimiter)
00217 , m_flags(flags)
00218 {}
00219
00220 private:
00221 struct search_state
00222 {
00223 HINTERNET m_hconn;
00224 string_type m_rootDir;
00225 ss_int_t m_flags;
00226 tokeniser_type m_tokens;
00227 ss_typename_type_k tokeniser_type::const_iterator m_tokensNext;
00228 ss_typename_type_k tokeniser_type::const_iterator m_tokensEnd;
00229 find_sequence_type *m_entries;
00230 ss_typename_type_k find_sequence_type::const_iterator m_entriesNext;
00231 ss_typename_type_k find_sequence_type::const_iterator m_entriesEnd;
00232 ss_sint32_t m_cRefs;
00233
00234 private:
00235 search_state(HINTERNET hconn, char_type const* rootDir, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
00236 : m_hconn(hconn)
00237 , m_rootDir(rootDir)
00238 , m_flags(flags)
00239 , m_tokens(searchSpec, delimiter)
00240 , m_tokensNext(m_tokens.begin())
00241 , m_tokensEnd(m_tokens.end())
00242 , m_entries(new find_sequence_type(hconn, ::stlsoft::c_str_ptr(m_rootDir), ::stlsoft::c_str_ptr(*m_tokensNext), m_flags))
00243 , m_entriesNext(m_entries->begin())
00244 , m_entriesEnd(m_entries->end())
00245 , m_cRefs(1)
00246 {
00247 while(m_entriesNext == m_entriesEnd)
00248 {
00249 ++m_tokensNext;
00250
00251 if(m_tokensNext == m_tokensEnd)
00252 {
00253 break;
00254 }
00255 else
00256 {
00257 INETSTL_ASSERT(NULL != m_entries);
00258
00259 stlsoft_destroy_instance_fn(m_entries);
00260 m_entries = new(m_entries) find_sequence_type(m_hconn, ::stlsoft::c_str_ptr(m_rootDir), ::stlsoft::c_str_ptr(*m_tokensNext), m_flags);
00261
00262 m_entriesEnd = m_entries->end();
00263 m_entriesNext = m_entries->begin();
00264 }
00265 }
00266 }
00267
00268 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00269 _MSC_VER < 1300
00270 friend class const_iterator;
00271 #endif
00272
00273 public:
00274 static search_state *create(HINTERNET hconn, char_type const* rootDir, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
00275 {
00276 search_state *ss = new search_state(hconn, rootDir, searchSpec, delimiter, flags);
00277
00278 if(ss->m_tokensNext == ss->m_tokensEnd)
00279 {
00280 delete ss;
00281
00282 ss = NULL;
00283 }
00284
00285 return ss;
00286 }
00287
00288 public:
00289 bool next()
00290 {
00291 if(m_tokensNext == m_tokensEnd)
00292 {
00293 return false;
00294 }
00295
00296 INETSTL_ASSERT(m_tokensNext != m_tokensEnd);
00297 INETSTL_ASSERT(NULL != m_entries || m_tokensNext == m_tokensEnd);
00298
00299
00300
00301
00302
00303
00304 ++m_entriesNext;
00305
00306 while(m_entriesNext == m_entriesEnd)
00307 {
00308 ++m_tokensNext;
00309
00310 if(m_tokensNext == m_tokensEnd)
00311 {
00312 return false;
00313 }
00314 else
00315 {
00316 INETSTL_ASSERT(NULL != m_entries);
00317
00318 stlsoft_destroy_instance_fn(m_entries);
00319 m_entries = new(m_entries) find_sequence_type(m_hconn, ::stlsoft::c_str_ptr(m_rootDir), ::stlsoft::c_str_ptr(*m_tokensNext), m_flags);
00320
00321 m_entriesEnd = m_entries->end();
00322 m_entriesNext = m_entries->begin();
00323 }
00324 }
00325
00326 return true;
00327 }
00328
00329 void Release()
00330 {
00331 if(0 == --m_cRefs)
00332 {
00333 delete this;
00334 }
00335 }
00336 #if defined(STLSOFT_CF_COMPILER_WARNS_NO_PUBLIC_DTOR)
00337 protected:
00338 #else
00339 private:
00340 #endif
00341 ~search_state() stlsoft_throw_0()
00342 {
00343 delete m_entries;
00344 }
00345 };
00346
00347 public:
00349 class const_iterator
00350 {
00351 private:
00352 typedef const_iterator class_type;
00353
00354 private:
00355 friend class searchspec_sequence<S>;
00356
00357 const_iterator(HINTERNET hconn, char_type const* rootDir, char_type const* searchSpec, char_type delimiter, ss_int_t flags)
00358 : m_searchState(search_state::create(hconn, rootDir, searchSpec, delimiter, flags))
00359 {}
00360
00361 public:
00363 const_iterator()
00364 : m_searchState(NULL)
00365 {}
00367 ~const_iterator() stlsoft_throw_0()
00368 {
00369 if(NULL != m_searchState)
00370 {
00371 m_searchState->Release();
00372 }
00373 }
00374
00376 const_iterator(class_type const& rhs)
00377 : m_searchState(rhs.m_searchState)
00378 {
00379 if(NULL != m_searchState)
00380 {
00381 ++m_searchState->m_cRefs;
00382 }
00383 }
00384
00385 class_type& operator =(class_type const& rhs)
00386 {
00387 if(NULL != m_searchState)
00388 {
00389 m_searchState->Release();
00390 }
00391
00392 m_searchState = rhs.m_searchState;
00393
00394 if(NULL != m_searchState)
00395 {
00396 ++m_searchState->m_cRefs;
00397 }
00398
00399 return *this;
00400 }
00401
00402 public:
00403 class_type& operator ++()
00404 {
00405 INETSTL_ASSERT(NULL != m_searchState);
00406
00407 if(!m_searchState->next())
00408 {
00409 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00410 _MSC_VER < 1300
00411 m_searchState->Release();
00412
00413 m_searchState = NULL;
00414 #else
00415 call_set_null(m_searchState, &search_state::Release);
00416 #endif
00417 }
00418
00419 return *this;
00420 }
00421
00422 class_type operator ++(int)
00423 {
00424 class_type ret(*this);
00425
00426 operator ++();
00427
00428 return ret;
00429 }
00430
00432 const value_type operator *() const
00433 {
00434 INETSTL_ASSERT(NULL != m_searchState);
00435
00436 return *m_searchState->m_entriesNext;
00437 }
00438
00439 ss_bool_t operator ==(class_type const& rhs) const
00440 {
00441
00442 return (NULL == m_searchState) && (NULL == rhs.m_searchState);
00443 }
00444 ss_bool_t operator !=(class_type const& rhs) const
00445 {
00446 return !operator ==(rhs);
00447 }
00448
00449 private:
00450 search_state *m_searchState;
00451 };
00452
00453 public:
00457 const_iterator begin() const
00458 {
00459 return const_iterator(m_hconn, ::stlsoft::c_str_ptr(m_rootDir), ::stlsoft::c_str_ptr(m_searchSpec), m_delimiter, m_flags);
00460 }
00464 const_iterator end() const
00465 {
00466 return const_iterator();
00467 }
00468
00469 public:
00471 ss_bool_t empty() const
00472 {
00473 return begin() == end();
00474 }
00475
00476
00477 private:
00478 static char_type const* null_str_()
00479 {
00480 static char_type s_null[1] = { '\0' };
00481
00482 return s_null;
00483 }
00484 static char_type const* dot1_str_()
00485 {
00486 static char_type s_dot1[2] = { '.', '\0' };
00487
00488 return s_dot1;
00489 }
00490
00491 private:
00492 HINTERNET m_hconn;
00493 string_type m_rootDir;
00494 string_type m_searchSpec;
00495 char_type m_delimiter;
00496 ss_int_t m_flags;
00497 };
00498
00500
00501
00502 #ifdef STLSOFT_UNITTEST
00503 # include "./unittest/searchspec_sequence_unittest_.h"
00504 #endif
00505
00507
00508
00509 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00510
00511
00512 #endif
00513
00514
00515
00516 #ifndef _INETSTL_NO_NAMESPACE
00517 # if defined(_STLSOFT_NO_NAMESPACE) || \
00518 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00519 }
00520 # else
00521 }
00522 }
00523 # endif
00524 #endif
00525
00526
00527
00528 #endif
00529
00530