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
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #ifndef WINSTL_INCL_H_WINSTL
00066 # include "winstl.h"
00067 #endif
00068 #ifndef WINSTL_INCL_H_WINSTL_FILESYSTEM_TRAITS
00069 # include "winstl_filesystem_traits.h"
00070 #endif
00071 #ifndef STLSOFT_INCL_H_STLSOFT_ITERATOR
00072 # include "stlsoft_iterator.h"
00073 #endif
00074
00075
00076
00077
00078
00079 #ifndef _WINSTL_NO_NAMESPACE
00080 # if defined(_STLSOFT_NO_NAMESPACE) || \
00081 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00082
00083 namespace winstl
00084 {
00085 # else
00086
00087
00088 namespace stlsoft
00089 {
00090
00091 namespace winstl_project
00092 {
00093
00094 # endif
00095 #endif
00096
00097
00098
00101
00105
00110
00111
00112
00113
00114
00115
00116
00117 enum
00118 {
00119 MAX_VOL_NAME = _MAX_PATH
00120 };
00121
00122
00123
00124
00125
00126 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00127
00128 template <ss_typename_param_k C, ss_typename_param_k T>
00129 class basic_findvolume_sequence_value_type;
00130
00131 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00132 class basic_findvolume_sequence_const_iterator;
00133
00134 #endif
00135
00136
00137
00138
00139
00140
00147
00148 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00149 , ss_typename_param_k T = filesystem_traits<C>
00150 #else
00151 , ss_typename_param_k T
00152 #endif
00153 >
00154 class basic_findvolume_sequence
00155 {
00156 public:
00158 typedef C char_type;
00160 typedef T traits_type;
00162 typedef basic_findvolume_sequence<C, T> class_type;
00164 typedef basic_findvolume_sequence_value_type<C, T> value_type;
00166 typedef basic_findvolume_sequence_const_iterator<C, T, value_type> const_iterator;
00168 typedef value_type &reference;
00170 typedef const value_type &const_reference;
00171
00172
00173 public:
00177 const_iterator begin() const;
00181 const_iterator end() const;
00182
00183
00184 public:
00186 ws_bool_t empty() const;
00187 };
00188
00189
00190
00191
00192
00194 typedef basic_findvolume_sequence<ws_char_a_t, filesystem_traits<ws_char_a_t> > findvolume_sequence_a;
00196 typedef basic_findvolume_sequence<ws_char_w_t, filesystem_traits<ws_char_w_t> > findvolume_sequence_w;
00198 typedef basic_findvolume_sequence<TCHAR, filesystem_traits<TCHAR> > findvolume_sequence;
00199
00200
00201
00202
00204
00205
00206
00207
00208
00209
00211
00213
00215
00216
00217
00219
00221
00222
00223
00224
00225
00227
00228
00229
00230
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00245
00246
00247
00248
00249
00250
00251
00252
00254
00256
00258
00260
00261
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 private:
00297 #endif
00298 ~shared_handle()
00299 {
00300 winstl_message_assert("Shared search handle being destroyed with outstanding references!", 0 == cRefs);
00301
00302 if(hSrch != INVALID_HANDLE_VALUE)
00303 {
00304 traits_type::find_volume_close(hSrch);
00305 }
00306 }
00307
00308 private:
00309 shared_handle(class_type const &);
00310 class_type &operator =(class_type const &);
00311 };
00312 #endif
00313
00314
00317 private:
00318 basic_findvolume_sequence_const_iterator(basic_findvolume_sequence<C, T> const &l, HANDLE hSrch, char_type const *vol_name)
00319 : m_list(&l)
00320 , m_handle(new shared_handle(hSrch))
00321 {
00322 traits_type::str_copy(m_name, vol_name);
00323
00324 winstl_assert(INVALID_HANDLE_VALUE != hSrch);
00325 }
00326 basic_findvolume_sequence_const_iterator(basic_findvolume_sequence<C, T> const &l);
00327 public:
00329 basic_findvolume_sequence_const_iterator();
00331 basic_findvolume_sequence_const_iterator(const class_type &rhs);
00333 ~basic_findvolume_sequence_const_iterator() winstl_throw_0();
00334
00336 basic_findvolume_sequence_const_iterator &operator =(const class_type &rhs);
00337
00338 public:
00340 class_type &operator ++();
00342 class_type operator ++(int);
00344 const value_type operator *() const;
00346 ws_bool_t operator ==(const class_type &rhs) const;
00348 ws_bool_t operator !=(const class_type &rhs) const;
00349
00350
00351 private:
00352 friend class basic_findvolume_sequence<C, T>;
00353
00354 typedef basic_findvolume_sequence<C, T> list_type;
00355
00356 list_type const *m_list;
00357 shared_handle *m_handle;
00358 char_type m_name[MAX_VOL_NAME + 1];
00359 };
00360
00362
00363
00364 #ifdef STLSOFT_UNITTEST
00365
00366 namespace unittest
00367 {
00368 ss_bool_t test_winstl_findvolume_sequence(unittest_reporter *r)
00369 {
00370 using stlsoft::unittest::unittest_initialiser;
00371
00372 ss_bool_t bSuccess = true;
00373
00374 unittest_initialiser init(r, "WinSTL", "findvolume_sequence", __FILE__);
00375
00376 findvolume_sequence_a fvsa;
00377 findvolume_sequence_w fvsw;
00378
00379 if(fvsa.empty() != fvsw.empty())
00380 {
00381 r->report("findvolume_sequence(ANSI)::empty() != findvolume_sequence(Unicode)::empty()", __LINE__);
00382 bSuccess = false;
00383 }
00384
00385 return bSuccess;
00386 }
00387
00388 unittest_registrar unittest_winstl_findvolume_sequence(test_winstl_findvolume_sequence);
00389
00390 }
00391
00392 #endif
00393
00395
00396
00397 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00398
00399
00400
00401 template <ss_typename_param_k C, ss_typename_param_k T>
00402 inline ss_typename_type_k basic_findvolume_sequence<C, T>::const_iterator basic_findvolume_sequence<C, T>::begin() const
00403 {
00404 char_type vol_name[MAX_VOL_NAME + 1];
00405 HANDLE hSrch = traits_type::find_first_volume(vol_name, winstl_num_elements(vol_name));
00406
00407 if(hSrch == INVALID_HANDLE_VALUE)
00408 {
00409 return const_iterator(*this);
00410 }
00411 else
00412 {
00413 return const_iterator(*this, hSrch, vol_name);
00414 }
00415 }
00416
00417 template <ss_typename_param_k C, ss_typename_param_k T>
00418 inline ss_typename_type_k basic_findvolume_sequence<C, T>::const_iterator basic_findvolume_sequence<C, T>::end() const
00419 {
00420 return const_iterator(*this);
00421 }
00422
00423 template <ss_typename_param_k C, ss_typename_param_k T>
00424 inline ws_bool_t basic_findvolume_sequence<C, T>::empty() const
00425 {
00426 return begin() == end();
00427 }
00428
00429
00430
00431 template <ss_typename_param_k C, ss_typename_param_k T>
00432 inline basic_findvolume_sequence_value_type<C, T>::basic_findvolume_sequence_value_type()
00433 {
00434 m_name[0] = '\0';
00435 }
00436
00437 template <ss_typename_param_k C, ss_typename_param_k T>
00438 inline basic_findvolume_sequence_value_type<C, T>::basic_findvolume_sequence_value_type(const class_type &rhs)
00439 {
00440 traits_type::str_copy(m_name, rhs.m_name);
00441 }
00442
00443 template <ss_typename_param_k C, ss_typename_param_k T>
00444 inline basic_findvolume_sequence_value_type<C, T>::basic_findvolume_sequence_value_type(char_type const *vol_name)
00445 {
00446 traits_type::str_copy(m_name, vol_name);
00447 }
00448
00449 template <ss_typename_param_k C, ss_typename_param_k T>
00450 inline ss_typename_type_k basic_findvolume_sequence_value_type<C, T>::class_type &basic_findvolume_sequence_value_type<C, T>::operator =(const class_type &rhs)
00451 {
00452 traits_type::str_copy(m_name, rhs.m_name);
00453
00454 return *this;
00455 }
00456
00457
00458 #if 0
00459 template <ss_typename_param_k C, ss_typename_param_k T>
00460 #ifdef __STLSOFT_CF_FUNCTION_SIGNATURE_FULL_ARG_QUALIFICATION_REQUIRED
00461 inline basic_findvolume_sequence_value_type<C, T>::operator basic_findvolume_sequence<C, T>::char_type const *() const
00462 #else
00463 inline basic_findvolume_sequence_value_type<C, T>::operator char_type const *() const
00464 #endif
00465 {
00466 return m_name;
00467 }
00468 #endif
00469
00470
00471
00472
00473 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00474 inline basic_findvolume_sequence_const_iterator<C, T, V>::basic_findvolume_sequence_const_iterator()
00475 : m_list(NULL)
00476 , m_handle(NULL)
00477 {
00478 m_name[0] = '\0';
00479 }
00480
00481 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00482 inline basic_findvolume_sequence_const_iterator<C, T, V>::basic_findvolume_sequence_const_iterator(basic_findvolume_sequence<C, T> const &l)
00483 : m_list(&l)
00484 , m_handle(NULL)
00485 {
00486 m_name[0] = '\0';
00487 }
00488
00489 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00490 inline basic_findvolume_sequence_const_iterator<C, T, V>::basic_findvolume_sequence_const_iterator(const class_type &rhs)
00491 : m_list(rhs.m_list)
00492 , m_handle(rhs.m_handle)
00493 {
00494 if(NULL != m_handle)
00495 {
00496 m_handle->AddRef();
00497 }
00498 }
00499
00500 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00501
00502 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00503 inline ss_typename_type_k basic_findvolume_sequence_const_iterator<C, T, V>::class_type &basic_findvolume_sequence_const_iterator<C, T, V>::operator =(ss_typename_type_k basic_findvolume_sequence_const_iterator<C, T, V>::class_type const &rhs)
00504 {
00505 if(NULL != m_handle)
00506 {
00507 m_handle->Release();
00508 }
00509
00510 m_list = rhs.m_list;
00511 m_handle = rhs.m_handle;
00512
00513 if(NULL != m_handle)
00514 {
00515 m_handle->AddRef();
00516 }
00517
00518 return *this;
00519 }
00520
00521 #endif
00522
00523 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00524 inline basic_findvolume_sequence_const_iterator<C, T, V>::~basic_findvolume_sequence_const_iterator() winstl_throw_0()
00525 {
00526 if(NULL != m_handle)
00527 {
00528 m_handle->Release();
00529 }
00530 }
00531
00532 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00533 inline ss_typename_type_k basic_findvolume_sequence_const_iterator<C, T, V>::class_type &basic_findvolume_sequence_const_iterator<C, T, V>::operator ++()
00534 {
00535 winstl_message_assert("Attempting to increment an invalid iterator!", NULL != m_handle);
00536
00537 if(!traits_type::find_next_volume(m_handle->hSrch, m_name, winstl_num_elements(m_name)))
00538 {
00539 m_handle->Release();
00540
00541 m_handle = NULL;
00542 }
00543
00544 return *this;
00545 }
00546
00547 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00548 inline ss_typename_type_k basic_findvolume_sequence_const_iterator<C, T, V>::class_type basic_findvolume_sequence_const_iterator<C, T, V>::operator ++(int)
00549 {
00550 class_type ret(*this);
00551
00552 operator ++();
00553
00554 return ret;
00555 }
00556
00557 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00558 inline const ss_typename_type_k basic_findvolume_sequence_const_iterator<C, T, V>::value_type basic_findvolume_sequence_const_iterator<C, T, V>::operator *() const
00559 {
00560 if(NULL != m_handle)
00561 {
00562 return value_type(m_name);
00563 }
00564 else
00565 {
00566 return value_type();
00567 }
00568 }
00569
00570 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00571 inline ws_bool_t basic_findvolume_sequence_const_iterator<C, T, V>::operator ==(class_type const &rhs) const
00572 {
00573 ws_bool_t eq;
00574
00575 winstl_assert(m_list == rhs.m_list);
00576
00577
00578
00579 if( m_list != rhs.m_list ||
00580 (NULL == m_handle) != (NULL == m_handle) ||
00581 ( NULL != m_handle &&
00582 traits_type::str_compare(m_name, rhs.m_name) != 0))
00583 {
00584 eq = ws_false_v;
00585 }
00586 else
00587 {
00588 eq = ws_true_v;
00589 }
00590
00591 return eq;
00592 }
00593
00594 template <ss_typename_param_k C, ss_typename_param_k T, ss_typename_param_k V>
00595 inline ws_bool_t basic_findvolume_sequence_const_iterator<C, T, V>::operator !=(class_type const &rhs) const
00596 {
00597 return ! operator ==(rhs);
00598 }
00599
00600 #endif
00601
00602
00603
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 #endif
00617
00618
00619
00620
00621
00622