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
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00077
00078
00079
00080
00081 #ifndef RECLS_INCL_H_RECLSTL
00082 # include "reclstl.h"
00083 #endif
00084 #ifndef RECLS_INCL_H_RECLSTL_TRAITS
00085 # include "reclstl_traits.h"
00086 #endif
00087
00088
00089
00090
00091
00092 #if !defined(RECLS_NO_NAMESPACE)
00093 namespace recls
00094 {
00095
00096 namespace stl
00097 {
00098 #endif
00099
00100
00101
00102
00103
00104 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00105
00106 template< typename C
00107 , typename T
00108 >
00109 class basic_search_sequence_value_type;
00110
00111 template< typename C
00112 , typename T
00113 , typename V
00114 >
00115 class basic_search_sequence_const_iterator;
00116
00117 #endif
00118
00119
00120
00121
00122
00123 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00124 struct rss_shared_handle
00125 {
00126 hrecls_t hSrch;
00127 recls_sint32_t cRefs;
00128
00129 public:
00130 explicit rss_shared_handle(hrecls_t h)
00131 : hSrch(h)
00132 , cRefs(1)
00133 {}
00134 void Release()
00135 {
00136 if(--cRefs == 0)
00137 {
00138 delete this;
00139 }
00140 }
00141 #if defined(__STLSOFT_COMPILER_IS_GCC)
00142 protected:
00143 #else
00144 private:
00145 #endif
00146 ~rss_shared_handle()
00147 {
00148 recls_message_assert("Shared search handle being destroyed with outstanding references!", 0 == cRefs);
00149
00150 if(NULL != hSrch)
00151 {
00152 Recls_SearchClose(hSrch);
00153 }
00154 }
00155 };
00156 #endif
00157
00158
00159
00160
00161
00162
00169
00170 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00171 , typename T = reclstl_traits<C>
00172 #else
00173 , typename T
00174 #endif
00175 >
00176 class basic_search_sequence
00177 {
00180 public:
00182 typedef C char_type;
00184 typedef T traits_type;
00186 typedef basic_search_sequence<C, T> class_type;
00188 typedef basic_search_sequence_value_type<C, T> value_type;
00190 typedef basic_search_sequence_const_iterator<C, T, value_type> const_iterator;
00192 typedef value_type &reference;
00194 typedef value_type const &const_reference;
00196 typedef ss_typename_type_k traits_type::entry_type entry_type;
00198 typedef size_t size_type;
00200
00203 public:
00205 basic_search_sequence(char_type const *pattern, recls_uint32_t flags);
00207 basic_search_sequence(char_type const *directory, char_type const *pattern, recls_uint32_t flags);
00209
00212 public:
00216 const_iterator begin() const;
00220 const_iterator end() const;
00222
00225 public:
00227 size_type size() const;
00229 recls_bool_t empty() const;
00231 static size_type max_size();
00233
00236 private:
00237 friend class basic_search_sequence_value_type<C, T>;
00238 friend class basic_search_sequence_const_iterator<C, T, value_type>;
00239
00240 static char_type const *copy_or_null_(char_type *dest, char_type const *src);
00241
00242 char_type const *const m_directory;
00243 char_type const *const m_pattern;
00244
00245 char_type m_directory_[RECLS_PATH_MAX + 1];
00246 char_type m_pattern_[RECLS_PATH_MAX + 1];
00247 recls_uint32_t m_flags;
00249
00250
00251 private:
00252 basic_search_sequence(class_type const &);
00253 basic_search_sequence const &operator =(class_type const &);
00254 };
00255
00256
00257
00258
00259
00261 typedef basic_search_sequence<recls_char_a_t, reclstl_traits<recls_char_a_t> > search_sequence_a;
00263 typedef basic_search_sequence<recls_char_w_t, reclstl_traits<recls_char_w_t> > search_sequence_w;
00264
00265
00266
00267
00271
00272
00273
00274
00275
00278
00280
00282
00284
00286
00288
00290
00293
00295
00296
00297
00298
00299
00300
00301
00303
00304
00306
00308
00311
00313
00314
00315
00316
00318 string_t get_directory() const;
00320 string_t get_directory_path() const;
00322 directory_parts_type get_directory_parts() const;
00324 string_t get_file() const;
00326 string_t get_short_file() const;
00328 string_t get_filename() const;
00330 string_t get_fileext() const;
00331
00332 recls_time_t get_creation_time() const;
00333 recls_time_t get_modification_time() const;
00334 recls_time_t get_last_access_time() const;
00335 recls_time_t get_last_status_change_time() const;
00336
00337 recls_filesize_t get_size() const;
00338
00339 recls_bool_t is_readonly() const;
00340 recls_bool_t is_directory() const;
00341 recls_bool_t is_link() const;
00342
00344 char_type const *c_str() const;
00345
00347 entry_type const &get_entry() const;
00349
00350
00351 private:
00352 friend class basic_search_sequence_const_iterator<C, T, class_type>;
00353
00354 entry_type m_info;
00355 };
00356
00357
00361
00362 , typename T
00363 , typename V
00364 >
00365 class basic_search_sequence_const_iterator
00366 : public stlsoft_ns_qual(iterator_base)<stlsoft_ns_qual_std(input_iterator_tag), V, ptrdiff_t, void, V>
00367 {
00368 public:
00370 typedef C char_type;
00372 typedef T traits_type;
00374 typedef V value_type;
00376 typedef basic_search_sequence_const_iterator<C, T, V> class_type;
00378 typedef ss_typename_type_k traits_type::entry_type entry_type;
00379 private:
00380 typedef basic_search_sequence<C, T> sequence_type;
00381
00382 private:
00383 explicit basic_search_sequence_const_iterator(hrecls_t hSrch)
00384 : m_handle(make_handle_(hSrch))
00385 {}
00386 public:
00388 basic_search_sequence_const_iterator();
00390 basic_search_sequence_const_iterator(class_type const &rhs);
00392 ~basic_search_sequence_const_iterator();
00393
00394 public:
00396 class_type &operator ++();
00398 void operator ++(int);
00400 const value_type operator *() const;
00402 recls_bool_t operator ==(class_type const &rhs) const;
00404 recls_bool_t operator !=(class_type const &rhs) const;
00405
00406
00407 private:
00408 rss_shared_handle *make_handle_(hrecls_t hSrch);
00409
00410
00411 private:
00412 friend class basic_search_sequence<C, T>;
00413
00414 rss_shared_handle *m_handle;
00415
00416
00417 private:
00418 basic_search_sequence_const_iterator &operator =(class_type const &rhs);
00419 };
00420
00422
00423
00434 template <typename C, typename T>
00435 inline recls_bool_t is_empty(basic_search_sequence<C, T> const &s)
00436 {
00437 return s.empty();
00438 }
00439
00450 template <typename C, typename T>
00451 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00452 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::char_type const *c_str_ptr(basic_search_sequence_value_type<C, T> const &v)
00453 #else
00454 inline C const *c_str_ptr(basic_search_sequence_value_type<C, T> const &v)
00455 #endif
00456 {
00457 return v.c_str();
00458 }
00459
00461
00462
00463 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00464
00465
00466
00467 template <typename C, typename T>
00468 inline typename basic_search_sequence<C, T>::char_type const *basic_search_sequence<C, T>::copy_or_null_(typename basic_search_sequence<C, T>::char_type *dest, typename basic_search_sequence<C, T>::char_type const *src)
00469 {
00470 return (NULL == src) ? static_cast<char_type const*>(NULL) : traits_type::str_copy(dest, src);
00471 }
00472
00473
00474
00475 template <typename C, typename T>
00476 inline basic_search_sequence<C, T>::basic_search_sequence(char_type const *pattern, recls_uint32_t flags)
00477 : m_flags(flags)
00478 , m_directory(copy_or_null_(m_directory_, ""))
00479 , m_pattern(copy_or_null_(m_pattern_, pattern))
00480 {}
00481
00482 template <typename C, typename T>
00483 inline basic_search_sequence<C, T>::basic_search_sequence(char_type const *directory, char_type const *pattern, recls_uint32_t flags)
00484 : m_flags(flags)
00485 , m_directory(copy_or_null_(m_directory_, directory))
00486 , m_pattern(copy_or_null_(m_pattern_, pattern))
00487 {}
00488
00489
00490 template <typename C, typename T>
00491 inline ss_typename_type_k basic_search_sequence<C, T>::const_iterator basic_search_sequence<C, T>::begin() const
00492 {
00493 return const_iterator(traits_type::Search(m_directory, m_pattern, m_flags));
00494 }
00495
00496 template <typename C, typename T>
00497 inline ss_typename_type_k basic_search_sequence<C, T>::const_iterator basic_search_sequence<C, T>::end() const
00498 {
00499 return const_iterator();
00500 }
00501
00502
00503 template <typename C, typename T>
00504 inline ss_typename_type_k basic_search_sequence<C, T>::size_type basic_search_sequence<C, T>::size() const
00505 {
00506 const_iterator b = begin();
00507 const_iterator e = end();
00508 size_type c = 0;
00509
00510 for(; b != e; ++b)
00511 {
00512 ++c;
00513 }
00514
00515 return c;
00516 }
00517
00518 template <typename C, typename T>
00519 inline recls_bool_t basic_search_sequence<C, T>::empty() const
00520 {
00521 return begin() == end();
00522 }
00523
00524 template <typename C, typename T>
00525 inline ss_typename_type_k basic_search_sequence<C, T>::size_type basic_search_sequence<C, T>::max_size()
00526 {
00527 return static_cast<size_type>(-1);
00528 }
00529
00530
00531
00532 template <typename C, typename T>
00533 inline basic_search_sequence_value_type<C, T>::basic_search_sequence_value_type()
00534 : m_info(NULL)
00535 {}
00536
00537 template <typename C, typename T>
00538 inline basic_search_sequence_value_type<C, T>::basic_search_sequence_value_type(ss_typename_type_k basic_search_sequence_value_type<C, T>::class_type const &rhs)
00539 : m_info(traits_type::CopyDetails(rhs.m_info))
00540 {}
00541
00542 template <typename C, typename T>
00543 inline basic_search_sequence_value_type<C, T>::~basic_search_sequence_value_type()
00544 {
00545 if(NULL != m_info)
00546 {
00547 traits_type::CloseDetails(m_info);
00548 }
00549 }
00550
00551 template <typename C, typename T>
00552 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::class_type &basic_search_sequence_value_type<C, T>::operator =(ss_typename_type_k basic_search_sequence_value_type<C, T>::class_type const &rhs)
00553 {
00554 if(NULL != m_info)
00555 {
00556 traits_type::CloseDetails(m_info);
00557 }
00558
00559 m_info = traits_type::CopyDetails(rhs.m_info);
00560
00561 return *this;
00562 }
00563
00564 template <typename C, typename T>
00565 inline string_t basic_search_sequence_value_type<C, T>::get_path() const
00566 {
00567 recls_assert(NULL != m_info);
00568
00569 return string_t(m_info->path.begin, m_info->path.end);
00570 }
00571
00572 #ifdef RECLS_PLATFORM_API_WIN32
00573 template <typename C, typename T>
00574 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::char_type basic_search_sequence_value_type<C, T>::get_drive() const
00575 {
00576 char_type chDrive;
00577
00578 return (Recls_GetDriveProperty(m_info, &chDrive), chDrive);
00579 }
00580 #endif
00581
00582 template <typename C, typename T>
00583 inline string_t basic_search_sequence_value_type<C, T>::get_directory() const
00584 {
00585 recls_assert(NULL != m_info);
00586
00587 return string_t(m_info->directory.begin, m_info->directory.end);
00588 }
00589
00590 template <typename C, typename T>
00591 inline string_t basic_search_sequence_value_type<C, T>::get_directory_path() const
00592 {
00593 recls_assert(NULL != m_info);
00594
00595 return string_t(m_info->path.begin, m_info->directory.end);
00596 }
00597
00598 template <typename C, typename T>
00599 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::directory_parts_type basic_search_sequence_value_type<C, T>::get_directory_parts() const
00600 {
00601 recls_assert(NULL != m_info);
00602
00603 return directory_parts_type(m_info->directoryParts.begin, m_info->directoryParts.end);
00604 }
00605
00606 template <typename C, typename T>
00607 inline string_t basic_search_sequence_value_type<C, T>::get_file() const
00608 {
00609 recls_assert(NULL != m_info);
00610
00611 return string_t(m_info->fileName.begin, m_info->fileExt.end);
00612 }
00613
00614 #if 0
00615 template <typename C, typename T>
00616 inline string_t basic_search_sequence_value_type<C, T>::get_short_file() const
00617 {
00618 return m_info.cAlternateFileName[0] != '\0' ? m_info.cAlternateFileName : m_info.cFileName;
00619 }
00620 #endif
00621
00622 template <typename C, typename T>
00623 inline string_t basic_search_sequence_value_type<C, T>::get_filename() const
00624 {
00625 recls_assert(NULL != m_info);
00626
00627 return string_t(m_info->fileName.begin, m_info->fileName.end);
00628 }
00629
00630 template <typename C, typename T>
00631 inline string_t basic_search_sequence_value_type<C, T>::get_fileext() const
00632 {
00633 recls_assert(NULL != m_info);
00634
00635 return string_t(m_info->fileExt.begin, m_info->fileExt.end);
00636 }
00637
00638 template <typename C, typename T>
00639 inline recls_time_t basic_search_sequence_value_type<C, T>::get_creation_time() const
00640 {
00641 recls_assert(NULL != m_info);
00642
00643 return Recls_GetCreationTime(m_info);
00644 }
00645
00646 template <typename C, typename T>
00647 inline recls_time_t basic_search_sequence_value_type<C, T>::get_modification_time() const
00648 {
00649 recls_assert(NULL != m_info);
00650
00651 return Recls_GetModificationTime(m_info);
00652 }
00653
00654 template <typename C, typename T>
00655 inline recls_time_t basic_search_sequence_value_type<C, T>::get_last_access_time() const
00656 {
00657 recls_assert(NULL != m_info);
00658
00659 return Recls_GetLastAccessTime(m_info);
00660 }
00661
00662 template <typename C, typename T>
00663 inline recls_time_t basic_search_sequence_value_type<C, T>::get_last_status_change_time() const
00664 {
00665 recls_assert(NULL != m_info);
00666
00667 return Recls_GetLastStatusChangeTime(m_info);
00668 }
00669
00670 template <typename C, typename T>
00671 inline recls_filesize_t basic_search_sequence_value_type<C, T>::get_size() const
00672 {
00673 recls_assert(NULL != m_info);
00674
00675 return m_info->size;
00676 }
00677
00678 template <typename C, typename T>
00679 inline recls_bool_t basic_search_sequence_value_type<C, T>::is_readonly() const
00680 {
00681 recls_assert(NULL != m_info);
00682
00683 return Recls_IsFileReadOnly(m_info);
00684 }
00685
00686 template <typename C, typename T>
00687 inline recls_bool_t basic_search_sequence_value_type<C, T>::is_directory() const
00688 {
00689 recls_assert(NULL != m_info);
00690
00691 return Recls_IsFileDirectory(m_info);
00692 }
00693
00694 template <typename C, typename T>
00695 inline recls_bool_t basic_search_sequence_value_type<C, T>::is_link() const
00696 {
00697 recls_assert(NULL != m_info);
00698
00699 return Recls_IsFileLink(m_info);
00700 }
00701
00702 template <typename C, typename T>
00703 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::char_type const * basic_search_sequence_value_type<C, T>::c_str() const
00704 {
00705 recls_assert(NULL != m_info);
00706
00707 return m_info->path.begin;
00708 }
00709
00710 template <typename C, typename T>
00711 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::entry_type const &basic_search_sequence_value_type<C, T>::get_entry() const
00712 {
00713 return m_info;
00714 }
00715
00716
00717
00718 template <typename C, typename T, typename V>
00719 inline rss_shared_handle *basic_search_sequence_const_iterator<C, T, V>::make_handle_(hrecls_t hSrch)
00720 {
00721 return (NULL != hSrch) ? new rss_shared_handle(hSrch) : static_cast<rss_shared_handle*>(NULL);
00722 }
00723
00724 template <typename C, typename T, typename V>
00725 inline basic_search_sequence_const_iterator<C, T, V>::basic_search_sequence_const_iterator()
00726 : m_handle(NULL)
00727 {}
00728
00729 template <typename C, typename T, typename V>
00730 inline basic_search_sequence_const_iterator<C, T, V>::basic_search_sequence_const_iterator(class_type const &rhs)
00731 : m_handle(rhs.m_handle)
00732 {
00733 if(NULL != m_handle)
00734 {
00735 ++m_handle->cRefs;
00736 }
00737 }
00738
00739 template <typename C, typename T, typename V>
00740 inline ss_typename_type_k basic_search_sequence_const_iterator<C, T, V>::class_type &basic_search_sequence_const_iterator<C, T, V>::operator =(typename basic_search_sequence_const_iterator<C, T, V>::class_type const &rhs)
00741 {
00742 if(NULL != m_handle)
00743 {
00744 m_handle->Release();
00745 }
00746
00747 m_handle = rhs.m_handle;
00748
00749 if(NULL != m_handle)
00750 {
00751 ++m_handle->cRefs;
00752 }
00753
00754 return *this;
00755 }
00756
00757 template <typename C, typename T, typename V>
00758 inline basic_search_sequence_const_iterator<C, T, V>::~basic_search_sequence_const_iterator()
00759 {
00760 if(NULL != m_handle)
00761 {
00762 m_handle->Release();
00763 }
00764 }
00765
00766 template <typename C, typename T, typename V>
00767 inline ss_typename_type_k basic_search_sequence_const_iterator<C, T, V>::class_type &basic_search_sequence_const_iterator<C, T, V>::operator ++()
00768 {
00769 recls_message_assert("Attempting to increment invalid iterator", NULL != m_handle);
00770
00771 if(RECLS_FAILED(Recls_GetNext(m_handle->hSrch)))
00772 {
00773 m_handle->Release();
00774
00775 m_handle = NULL;
00776 }
00777
00778 return *this;
00779 }
00780
00781 template <typename C, typename T, typename V>
00782 inline void basic_search_sequence_const_iterator<C, T, V>::operator ++(int)
00783 {
00784 operator ++();
00785 }
00786
00787 template <typename C, typename T, typename V>
00788 inline const ss_typename_type_k basic_search_sequence_const_iterator<C, T, V>::value_type basic_search_sequence_const_iterator<C, T, V>::operator *() const
00789 {
00790 entry_type info;
00791
00792 recls_message_assert("Attempting to dereference invalid iterator", NULL != m_handle);
00793
00794 if( m_handle->hSrch != NULL &&
00795 RECLS_SUCCEEDED(traits_type::GetDetails(m_handle->hSrch, &info)))
00796 {
00797 return value_type(info);
00798 }
00799 else
00800 {
00801 recls_message_assert("Dereferencing end()-valued iterator", 0);
00802
00803 return value_type();
00804 }
00805 }
00806
00807 template <typename C, typename T, typename V>
00808 inline recls_bool_t basic_search_sequence_const_iterator<C, T, V>::operator ==(class_type const &rhs) const
00809 {
00810 return (m_handle == NULL) && (rhs.m_handle == NULL);
00811 }
00812
00813 template <typename C, typename T, typename V>
00814 inline recls_bool_t basic_search_sequence_const_iterator<C, T, V>::operator !=(class_type const &rhs) const
00815 {
00816 return ! operator ==(rhs);
00817 }
00818
00819 #endif
00820
00821
00822
00823
00824
00825 }
00826
00827
00828 namespace stlsoft
00829 {
00830 using recls::stl::is_empty;
00831 using recls::stl::c_str_ptr;
00832
00833 }
00834 #endif
00835
00836
00837
00838
00839
00840