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_RECLS_ASSERT
00085 # include <recls_assert.h>
00086 #endif
00087 #ifndef _STLSOFT_INCL_H_STLSOFT_ITERATOR
00088 # include <stlsoft_iterator.h>
00089 #endif
00090
00091 #ifndef _STLSOFT_INCL_H_STLSOFT_PROXY_SEQUENCE
00092 # include <inprogress/stlsoft_proxy_sequence.h>
00093 #endif
00094
00095
00096
00097
00098
00099 #if !defined(RECLS_NO_NAMESPACE)
00100 namespace recls
00101 {
00102
00103 namespace stl
00104 {
00105 #endif
00106
00107
00108
00109
00110
00111 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00112
00113 template< typename C
00114 , typename T
00115 >
00116 class basic_search_sequence_value_type;
00117
00118 template< typename C
00119 , typename T
00120 , typename V
00121 >
00122 class basic_search_sequence_const_iterator;
00123
00124 #endif
00125
00126
00127
00128
00129
00133 template <typename C>
00134 struct reclstl_traits
00135 {
00136 public:
00141 typedef void char_type;
00146 typedef void *entry_type;
00147
00148 public:
00150 static hrecls_t Search(char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags);
00151
00153 static recls_rc_t GetDetails(hrecls_t hSrch, entry_type *pinfo);
00155 static recls_rc_t GetNextDetails(hrecls_t hSrch, entry_type *pinfo);
00156
00158 static void CloseDetails(entry_type fileInfo);
00160 static entry_type CopyDetails(entry_type fileInfo);
00161
00163 static char_type *str_copy(char_type *, char_type const *);
00164 };
00165
00166 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00167 template <>
00168 struct reclstl_traits<char>
00169 {
00170 public:
00171 typedef reclstl_traits<char> traits_type;
00172 typedef char char_type;
00173 typedef recls_info_t entry_type;
00174 typedef recls_strptrs_t strptrs_type;
00175 typedef recls_strptrsptrs_t strptrsptrs_type;
00176
00178 typedef stlsoft::proxy_sequence< const strptrs_type
00179 , string_t
00180 , traits_type
00181 > directory_parts_type;
00182
00186 static string_t make_value(strptrs_type const &ptrs)
00187 {
00188 return string_t(ptrs.begin, ptrs.end);
00189 }
00190
00191 public:
00192 static hrecls_t Search(char_type const *searchRoot, char_type const *pattern, recls_uint32_t flags)
00193 {
00194 hrecls_t hSrch;
00195 recls_rc_t rc = Recls_Search(searchRoot, pattern, flags, &hSrch);
00196
00197 return RECLS_SUCCEEDED(rc) ? hSrch : static_cast<hrecls_t>(NULL);
00198 }
00199
00200 static recls_rc_t GetDetails(hrecls_t hSrch, entry_type *pinfo)
00201 {
00202 return Recls_GetDetails(hSrch, pinfo);
00203 }
00204
00205 static recls_rc_t GetNextDetails(hrecls_t hSrch, entry_type *pinfo)
00206 {
00207 return Recls_GetNextDetails(hSrch, pinfo);
00208 }
00209
00210 static void CloseDetails(entry_type fileInfo)
00211 {
00212 Recls_CloseDetails(fileInfo);
00213 }
00214 static entry_type CopyDetails(entry_type fileInfo)
00215 {
00216 entry_type infoCopy;
00217
00218 return RECLS_SUCCEEDED(Recls_CopyDetails(fileInfo, &infoCopy)) ? infoCopy : static_cast<entry_type>(NULL);
00219 }
00220
00221 static char_type *str_copy(char_type *dest, char_type const *src)
00222 {
00223 return strcpy(dest, src);
00224 }
00225 };
00226 #endif
00227
00228
00235
00236 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00237 , typename T = reclstl_traits<C>
00238 #else
00239 , typename T
00240 #endif
00241 >
00242 class basic_search_sequence
00243 {
00246 public:
00248 typedef C char_type;
00250 typedef T traits_type;
00252 typedef basic_search_sequence<C, T> class_type;
00254 typedef basic_search_sequence_value_type<C, T> value_type;
00256 typedef basic_search_sequence_const_iterator<C, T, value_type> const_iterator;
00258 typedef value_type &reference;
00260 typedef value_type const &const_reference;
00262 typedef ss_typename_type_k traits_type::entry_type entry_type;
00264 typedef size_t size_type;
00265
00267
00270 public:
00272 basic_search_sequence(char_type const *searchSpec, recls_uint32_t flags);
00274 basic_search_sequence(char_type const *directory, char_type const *searchSpec, recls_uint32_t flags);
00275
00277
00280 public:
00284 const_iterator begin() const;
00288 const_iterator end() const;
00289
00291
00294 public:
00296 size_type size() const;
00298 recls_bool_t empty() const;
00300 static size_type max_size();
00301
00303
00306 private:
00307 friend class basic_search_sequence_value_type<C, T>;
00308 friend class basic_search_sequence_const_iterator<C, T, value_type>;
00309
00310 char_type m_directory[_MAX_DIR + 1];
00311 char_type m_search[_MAX_PATH + 1];
00312 recls_uint32_t m_flags;
00313
00315
00316
00317 private:
00318 basic_search_sequence(class_type const &);
00319 basic_search_sequence const &operator =(class_type const &);
00320 };
00321
00322
00323
00324
00325
00327 typedef basic_search_sequence<char, reclstl_traits<char> > search_sequence_a;
00329 typedef basic_search_sequence<wchar_t, reclstl_traits<wchar_t> > search_sequence_w;
00330
00331
00332
00333
00337
00338
00339
00340
00341
00344
00346
00348
00350
00352
00354
00355
00357
00360
00362
00363
00364
00365
00366
00367
00368
00370
00371
00373
00374
00376
00379
00381
00382
00383
00384
00386 string_t get_directory() const;
00388 string_t get_directory_path() const;
00390 directory_parts_type get_directory_parts() const;
00392 string_t get_file() const;
00394 string_t get_short_file() const;
00396 string_t get_filename() const;
00398 string_t get_fileext() const;
00399
00400 recls_time_t get_creation_time() const;
00401 recls_time_t get_modification_time() const;
00402 recls_time_t get_last_access_time() const;
00403 recls_time_t get_last_status_change_time() const;
00404
00405 recls_filesize_t get_size() const;
00406
00407 recls_bool_t is_readonly() const;
00408 recls_bool_t is_directory() const;
00409 recls_bool_t is_link() const;
00410
00412 char_type const *c_str() const;
00413
00415 entry_type const &get_entry() const;
00416
00418
00419
00420 private:
00421 friend class basic_search_sequence_const_iterator<C, T, class_type>;
00422
00423 entry_type m_info;
00424 };
00425
00426
00430
00431 , typename T
00432 , typename V
00433 >
00434 class basic_search_sequence_const_iterator
00435 : public stlsoft_ns_qual(iterator_base)<stlsoft_ns_qual_std(input_iterator_tag), V, ptrdiff_t, void, V>
00436 {
00437 public:
00439 typedef C char_type;
00441 typedef T traits_type;
00443 typedef V value_type;
00445 typedef basic_search_sequence_const_iterator<C, T, V> class_type;
00446 typedef stlsoft_define_move_rhs_type(class_type) rhs_type;
00448 typedef ss_typename_type_k traits_type::entry_type entry_type;
00449 private:
00450 typedef basic_search_sequence<C, T> sequence_type;
00451
00452 private:
00453 explicit basic_search_sequence_const_iterator(hrecls_t hSrch)
00454 : m_hSrch(hSrch)
00455 {}
00456 public:
00458 basic_search_sequence_const_iterator();
00460 basic_search_sequence_const_iterator(rhs_type rhs);
00462 ~basic_search_sequence_const_iterator();
00463
00464 public:
00466 class_type &operator ++();
00468 void operator ++(int);
00470 const value_type operator *() const;
00472 recls_bool_t operator ==(class_type const &rhs) const;
00474 recls_bool_t operator !=(class_type const &rhs) const;
00475
00476
00477 private:
00478 friend class basic_search_sequence<C, T>;
00479
00480 hrecls_t m_hSrch;
00481
00482
00483 private:
00484 basic_search_sequence_const_iterator &operator =(class_type const &rhs);
00485 };
00486
00488
00489
00500 template <typename C, typename T>
00501 inline recls_bool_t is_empty(basic_search_sequence<C, T> const &s)
00502 {
00503 return s.empty();
00504 }
00505
00516 template <typename C, typename T>
00517 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00518 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)
00519 #else
00520 inline C const *c_str_ptr(basic_search_sequence_value_type<C, T> const &v)
00521 #endif
00522 {
00523 return v.c_str();
00524 }
00525
00527
00528
00529 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00530
00531
00532
00533
00534 template <typename C, typename T>
00535 inline basic_search_sequence<C, T>::basic_search_sequence(char_type const *searchSpec, recls_uint32_t flags)
00536 : m_flags(flags)
00537 {
00538 m_directory[0] = '\0';
00539 traits_type::str_copy(m_search, searchSpec);
00540 }
00541
00542 template <typename C, typename T>
00543 inline basic_search_sequence<C, T>::basic_search_sequence(char_type const *directory, char_type const * searchSpec, recls_uint32_t flags)
00544 : m_flags(flags)
00545 {
00546 traits_type::str_copy(m_directory, directory);
00547 traits_type::str_copy(m_search, searchSpec);
00548 }
00549
00550
00551 template <typename C, typename T>
00552 inline ss_typename_type_k basic_search_sequence<C, T>::const_iterator basic_search_sequence<C, T>::begin() const
00553 {
00554 return const_iterator(traits_type::Search(m_directory, m_search, m_flags));
00555 }
00556
00557 template <typename C, typename T>
00558 inline ss_typename_type_k basic_search_sequence<C, T>::const_iterator basic_search_sequence<C, T>::end() const
00559 {
00560 return const_iterator();
00561 }
00562
00563
00564 template <typename C, typename T>
00565 inline ss_typename_type_k basic_search_sequence<C, T>::size_type basic_search_sequence<C, T>::size() const
00566 {
00567 const_iterator b = begin();
00568 const_iterator e = end();
00569 size_type c = 0;
00570
00571 for(; b != e; ++b)
00572 {
00573 ++c;
00574 }
00575
00576 return c;
00577 }
00578
00579 template <typename C, typename T>
00580 inline recls_bool_t basic_search_sequence<C, T>::empty() const
00581 {
00582 return begin() == end();
00583 }
00584
00585 template <typename C, typename T>
00586 inline ss_typename_type_k basic_search_sequence<C, T>::size_type basic_search_sequence<C, T>::max_size()
00587 {
00588 return static_cast<size_type>(-1);
00589 }
00590
00591
00592
00593 template <typename C, typename T>
00594 inline basic_search_sequence_value_type<C, T>::basic_search_sequence_value_type()
00595 : m_info(NULL)
00596 {}
00597
00598 template <typename C, typename T>
00599 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)
00600 : m_info(traits_type::CopyDetails(rhs.m_info))
00601 {}
00602
00603 template <typename C, typename T>
00604 inline basic_search_sequence_value_type<C, T>::~basic_search_sequence_value_type()
00605 {
00606 if(NULL != m_info)
00607 {
00608 traits_type::CloseDetails(m_info);
00609 }
00610 }
00611
00612 template <typename C, typename T>
00613 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)
00614 {
00615 if(NULL != m_info)
00616 {
00617 traits_type::CloseDetails(m_info);
00618 }
00619
00620 m_info = traits_type::CopyDetails(rhs.m_info);
00621
00622 return *this;
00623 }
00624
00625 template <typename C, typename T>
00626 inline string_t basic_search_sequence_value_type<C, T>::get_path() const
00627 {
00628 recls_assert(NULL != m_info);
00629
00630 return string_t(m_info->path.begin, m_info->path.end);
00631 }
00632
00633 #ifdef RECLS_PLATFORM_API_WIN32
00634 template <typename C, typename T>
00635 inline ss_typename_type_k basic_search_sequence_value_type<C, T>::char_type basic_search_sequence_value_type<C, T>::get_drive() const
00636 {
00637 char chDrive;
00638
00639 return (Recls_GetDriveProperty(m_info, &chDrive), chDrive);
00640 }
00641 #endif
00642
00643 template <typename C, typename T>
00644 inline string_t basic_search_sequence_value_type<C, T>::get_directory() const
00645 {
00646 recls_assert(NULL != m_info);
00647
00648 return string_t(m_info->directory.begin, m_info->directory.end);
00649 }
00650
00651 template <typename C, typename T>
00652 inline string_t basic_search_sequence_value_type<C, T>::get_directory_path() const
00653 {
00654 recls_assert(NULL != m_info);
00655
00656 return string_t(m_info->path.begin, m_info->directory.end);
00657 }
00658
00659 template <typename C, typename T>
00660 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
00661 {
00662 recls_assert(NULL != m_info);
00663
00664 return directory_parts_type(m_info->directoryParts.begin, m_info->directoryParts.end);
00665 }
00666
00667 template <typename C, typename T>
00668 inline string_t basic_search_sequence_value_type<C, T>::get_file() const
00669 {
00670 recls_assert(NULL != m_info);
00671
00672 return string_t(m_info->fileName.begin, m_info->fileExt.end);
00673 }
00674
00675 #if 0
00676 template <typename C, typename T>
00677 inline string_t basic_search_sequence_value_type<C, T>::get_short_file() const
00678 {
00679 return m_info.cAlternateFileName[0] != '\0' ? m_info.cAlternateFileName : m_info.cFileName;
00680 }
00681 #endif
00682
00683 template <typename C, typename T>
00684 inline string_t basic_search_sequence_value_type<C, T>::get_filename() const
00685 {
00686 recls_assert(NULL != m_info);
00687
00688 return string_t(m_info->fileName.begin, m_info->fileName.end);
00689 }
00690
00691 template <typename C, typename T>
00692 inline string_t basic_search_sequence_value_type<C, T>::get_fileext() const
00693 {
00694 recls_assert(NULL != m_info);
00695
00696 return string_t(m_info->fileExt.begin, m_info->fileExt.end);
00697 }
00698
00699 template <typename C, typename T>
00700 inline recls_time_t basic_search_sequence_value_type<C, T>::get_creation_time() const
00701 {
00702 recls_assert(NULL != m_info);
00703
00704 return Recls_GetCreationTime(m_info);
00705 }
00706
00707 template <typename C, typename T>
00708 inline recls_time_t basic_search_sequence_value_type<C, T>::get_modification_time() const
00709 {
00710 recls_assert(NULL != m_info);
00711
00712 return Recls_GetModificationTime(m_info);
00713 }
00714
00715 template <typename C, typename T>
00716 inline recls_time_t basic_search_sequence_value_type<C, T>::get_last_access_time() const
00717 {
00718 recls_assert(NULL != m_info);
00719
00720 return Recls_GetLastAccessTime(m_info);
00721 }
00722
00723 template <typename C, typename T>
00724 inline recls_time_t basic_search_sequence_value_type<C, T>::get_last_status_change_time() const
00725 {
00726 recls_assert(NULL != m_info);
00727
00728 return Recls_GetLastStatusChangeTime(m_info);
00729 }
00730
00731 template <typename C, typename T>
00732 inline recls_filesize_t basic_search_sequence_value_type<C, T>::get_size() const
00733 {
00734 recls_assert(NULL != m_info);
00735
00736 return m_info->size;
00737 }
00738
00739 template <typename C, typename T>
00740 inline recls_bool_t basic_search_sequence_value_type<C, T>::is_readonly() const
00741 {
00742 recls_assert(NULL != m_info);
00743
00744 return Recls_IsFileReadOnly(m_info);
00745 }
00746
00747 template <typename C, typename T>
00748 inline recls_bool_t basic_search_sequence_value_type<C, T>::is_directory() const
00749 {
00750 recls_assert(NULL != m_info);
00751
00752 return Recls_IsFileDirectory(m_info);
00753 }
00754
00755 template <typename C, typename T>
00756 inline recls_bool_t basic_search_sequence_value_type<C, T>::is_link() const
00757 {
00758 recls_assert(NULL != m_info);
00759
00760 return Recls_IsFileLink(m_info);
00761 }
00762
00763 template <typename C, typename T>
00764 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
00765 {
00766 recls_assert(NULL != m_info);
00767
00768 return m_info->path.begin;
00769 }
00770
00771 template <typename C, typename T>
00772 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
00773 {
00774 return m_info;
00775 }
00776
00777
00778
00779 template <typename C, typename T, typename V>
00780 inline basic_search_sequence_const_iterator<C, T, V>::basic_search_sequence_const_iterator()
00781 : m_hSrch(NULL)
00782 {}
00783
00784 template <typename C, typename T, typename V>
00785 inline basic_search_sequence_const_iterator<C, T, V>::basic_search_sequence_const_iterator(rhs_type rhs)
00786 : m_hSrch(rhs.m_hSrch)
00787 {
00788 move_lhs_from_rhs(rhs).m_hSrch = NULL;
00789 }
00790
00791 template <typename C, typename T, typename V>
00792 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)
00793 {
00794 m_hSrch = rhs.m_hSrch;
00795
00796 return *this;
00797 }
00798
00799 template <typename C, typename T, typename V>
00800 inline basic_search_sequence_const_iterator<C, T, V>::~basic_search_sequence_const_iterator()
00801 {
00802 if(NULL != m_hSrch)
00803 {
00804 Recls_SearchClose(m_hSrch);
00805 }
00806 }
00807
00808 template <typename C, typename T, typename V>
00809 inline ss_typename_type_k basic_search_sequence_const_iterator<C, T, V>::class_type &basic_search_sequence_const_iterator<C, T, V>::operator ++()
00810 {
00811 recls_message_assert("Attempting to increment invalid iterator", NULL != m_hSrch);
00812
00813 if(RECLS_FAILED(Recls_GetNext(m_hSrch)))
00814 {
00815 Recls_SearchClose(m_hSrch);
00816 m_hSrch = NULL;
00817 }
00818
00819 return *this;
00820 }
00821
00822 template <typename C, typename T, typename V>
00823 inline void basic_search_sequence_const_iterator<C, T, V>::operator ++(int)
00824 {
00825 operator ++();
00826 }
00827
00828 template <typename C, typename T, typename V>
00829 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
00830 {
00831 entry_type info;
00832
00833 if( m_hSrch != NULL &&
00834 RECLS_SUCCEEDED(traits_type::GetDetails(m_hSrch, &info)))
00835 {
00836 return value_type(info);
00837 }
00838 else
00839 {
00840 recls_message_assert("Dereferencing end()-valued iterator", 0);
00841
00842 return value_type();
00843 }
00844 }
00845
00846 template <typename C, typename T, typename V>
00847 inline recls_bool_t basic_search_sequence_const_iterator<C, T, V>::operator ==(class_type const &rhs) const
00848 {
00849 return (m_hSrch == NULL) && (rhs.m_hSrch == NULL);
00850 }
00851
00852 template <typename C, typename T, typename V>
00853 inline recls_bool_t basic_search_sequence_const_iterator<C, T, V>::operator !=(class_type const &rhs) const
00854 {
00855 return ! operator ==(rhs);
00856 }
00857
00858 #endif
00859
00860
00861
00862
00863
00864 }
00865 #endif
00866
00867
00868
00869
00870
00871