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
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef WINSTL_INCL_H_WINSTL
00061 # include "winstl.h"
00062 #endif
00063 #ifndef WINSTL_INCL_H_WINSTL_FILE_PATH_BUFFER
00064 # include "winstl_file_path_buffer.h"
00065 #endif
00066 #ifndef WINSTL_INCL_H_WINSTL_PROCESSHEAP_ALLOCATOR
00067 # include "winstl_processheap_allocator.h"
00068 #endif
00069 #ifndef STLSOFT_INCL_H_STLSOFT_AUTO_BUFFER
00070 # include "stlsoft_auto_buffer.h"
00071 #endif
00072 #if defined(__STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED) || \
00073 ( defined(__STLSOFT_COMPILER_IS_MSVC) && \
00074 _MSC_VER < 1200)
00075 # ifndef STLSOFT_INCL_H_STLSOFT_SIMPLE_STRING
00076 # include "stlsoft_simple_string.h"
00077 # endif
00078 #else
00079 # ifndef STLSOFT_INCL_H_STLSOFT_STATIC_STRING
00080 # include "stlsoft_static_string.h"
00081 # endif
00082 #endif
00083 #ifndef STLSOFT_INCL_H_STLSOFT_ITERATOR
00084 # include "stlsoft_iterator.h"
00085 #endif
00086
00087
00088
00089
00090
00091 #ifndef _WINSTL_NO_NAMESPACE
00092 # if defined(_STLSOFT_NO_NAMESPACE) || \
00093 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00094
00095 namespace winstl
00096 {
00097 # else
00098
00099
00100 namespace stlsoft
00101 {
00102
00103 namespace winstl_project
00104 {
00105
00106 # endif
00107 #endif
00108
00109
00110
00111
00112
00113 #ifdef __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE
00114 # undef __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE
00115 #endif
00116
00117 #if defined(__STLSOFT_CF_FRAME_STRING_SHIM_NOT_SUPPORTED) || \
00118 ( defined(__STLSOFT_COMPILER_IS_MSVC) && \
00119 _MSC_VER < 1200)
00120 # define __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) stlsoft_ns_qual(basic_simple_string)<C, stlsoft_ns_qual(char_traits)<C>, processheap_allocator<C> >
00121 #else
00122 # define __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) stlsoft_ns_qual(basic_static_string)<C, _MAX_PATH>
00123 #endif
00124
00125
00126
00127
00128
00129 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00130
00131 template <ss_typename_param_k C, ss_typename_param_k T>
00132 class basic_drophandle_sequence;
00133
00134 #endif
00135
00136
00137
00138
00139
00140 #ifdef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00147 template <ss_typename_param_k C>
00148 struct drophandle_sequence_traits
00149 {
00156 static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, C *buffer, ws_uint_t cchBuffer);
00157 };
00158
00159 #else
00160
00161 template <ss_typename_param_k C>
00162 struct drophandle_sequence_traits;
00163
00164 STLSOFT_TEMPLATE_SPECIALISATION
00165
00166 struct drophandle_sequence_traits<ws_char_a_t>
00167 {
00168 static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_a_t *buffer, ws_uint_t cchBuffer)
00169 {
00170 return DragQueryFileA(hdrop, index, buffer, cchBuffer);
00171 }
00172 };
00173
00174 STLSOFT_TEMPLATE_SPECIALISATION
00175 struct drophandle_sequence_traits<ws_char_w_t>
00176 {
00177 static ws_uint_t drag_query_file(HDROP hdrop, ws_uint_t index, ws_char_w_t *buffer, ws_uint_t cchBuffer)
00178 {
00179 return DragQueryFileW(hdrop, index, buffer, cchBuffer);
00180 }
00181 };
00182
00183 #endif
00184
00185
00186
00191
00192 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00193 , ss_typename_param_k T = drophandle_sequence_traits<C>
00194 #else
00195 , ss_typename_param_k T
00196 #endif
00197 >
00198 class basic_drophandle_sequence_const_iterator
00199 : public stlsoft_ns_qual(iterator_base)<winstl_ns_qual_std(bidirectional_iterator_tag), __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C), ws_ptrdiff_t, void, __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C)>
00200 {
00201 public:
00203 typedef C char_type;
00205 typedef T traits_type;
00207 typedef __STLSOFT_DROPHANDLE_SEQUENCE_VALUE_TYPE(C) string_type;
00209 typedef basic_drophandle_sequence_const_iterator<C, T> class_type;
00211 typedef string_type value_type;
00213 typedef ws_uint_t index_type;
00214
00215
00216 protected:
00218 ss_explicit_k basic_drophandle_sequence_const_iterator(HDROP hdrop, index_type index);
00219 public:
00220
00221 basic_drophandle_sequence_const_iterator();
00223 basic_drophandle_sequence_const_iterator(class_type const &rhs);
00224
00226 basic_drophandle_sequence_const_iterator &operator =(class_type const &rhs);
00227
00228
00229 public:
00231 class_type &operator ++();
00233 class_type &operator --();
00235 class_type operator ++(int);
00237 class_type operator --(int);
00239 const value_type operator *() const;
00241 ws_bool_t operator ==(class_type const &rhs) const;
00243 ws_bool_t operator !=(class_type const &rhs) const;
00244
00245
00246 private:
00247 static index_type sentinel_();
00248
00249
00250 private:
00251 friend class basic_drophandle_sequence<C, T>;
00252
00253 HDROP m_hdrop;
00254 index_type m_index;
00255 };
00256
00257
00258
00263
00264 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
00265 , ss_typename_param_k T = drophandle_sequence_traits<C>
00266 #else
00267 , ss_typename_param_k T
00268 #endif
00269 >
00270 class basic_drophandle_sequence
00271 {
00272 public:
00274 typedef C char_type;
00276 typedef T traits_type;
00278 typedef basic_drophandle_sequence<C, T> class_type;
00280 typedef basic_drophandle_sequence_const_iterator<C, T> const_iterator;
00282 typedef ss_typename_type_k const_iterator::value_type value_type;
00284 typedef ws_ptrdiff_t difference_type;
00285 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00286
00287 typedef stlsoft_ns_qual(const_reverse_bidirectional_iterator_base)< const_iterator,
00288 value_type,
00289 value_type,
00290 void*,
00291 difference_type> const_reverse_iterator;
00292 #endif
00293
00294
00295 public:
00297 ss_explicit_k basic_drophandle_sequence(HDROP hdrop);
00299 ~basic_drophandle_sequence() winstl_throw_0();
00300
00301
00302 public:
00304 ws_size_t size() const;
00306 ws_bool_t empty() const;
00307
00308
00309 public:
00313 const_iterator begin() const;
00317 const_iterator end() const;
00318
00319 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00323 const_reverse_iterator rbegin() const;
00327 const_reverse_iterator rend() const;
00328 #endif
00329
00330
00331 private:
00332 HDROP m_hdrop;
00333
00334
00335 private:
00336
00337
00338 private:
00339 basic_drophandle_sequence(class_type const &);
00340 const basic_drophandle_sequence &operator =(class_type const &);
00341 };
00342
00343
00345 typedef basic_drophandle_sequence<ws_char_a_t, drophandle_sequence_traits<ws_char_a_t> > drophandle_sequence_a;
00347 typedef basic_drophandle_sequence<ws_char_w_t, drophandle_sequence_traits<ws_char_w_t> > drophandle_sequence_w;
00348
00350
00351
00352
00353 template< ss_typename_param_k C
00354 , ss_typename_param_k T
00355 >
00356 inline ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::index_type basic_drophandle_sequence_const_iterator<C, T>::sentinel_()
00357 {
00358 return 0x7fffffff;
00359 }
00360
00361 template< ss_typename_param_k C
00362 , ss_typename_param_k T
00363 >
00364 inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator(HDROP hdrop, ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::index_type index)
00365 : m_hdrop(hdrop)
00366 , m_index(index)
00367 {}
00368
00369 template< ss_typename_param_k C
00370 , ss_typename_param_k T
00371 >
00372 inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator()
00373 : m_hdrop(0)
00374 , m_index(sentinel_())
00375 {}
00376
00377 template< ss_typename_param_k C
00378 , ss_typename_param_k T
00379 >
00380 inline basic_drophandle_sequence_const_iterator<C, T>::basic_drophandle_sequence_const_iterator(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const &rhs)
00381 : m_hdrop(rhs.m_hdrop)
00382 , m_index(rhs.m_index)
00383 {}
00384
00385 template< ss_typename_param_k C
00386 , ss_typename_param_k T
00387 >
00388 inline ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type &basic_drophandle_sequence_const_iterator<C, T>::operator =(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const &rhs)
00389 {
00390 m_hdrop = rhs.m_hdrop;
00391 m_index = rhs.m_index;
00392
00393 return *this;
00394 }
00395
00396 template< ss_typename_param_k C
00397 , ss_typename_param_k T
00398 >
00399 inline ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type &basic_drophandle_sequence_const_iterator<C, T>::operator ++()
00400 {
00401 stlsoft_message_assert("Incrementing the end iterator", m_index != sentinel_());
00402
00403 char_type ch;
00404 ws_uint_t res = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index + 1), &ch, 1);
00405
00406 if(res == 0)
00407 {
00408
00409 m_index = sentinel_();
00410 }
00411 else
00412 {
00413
00414 ++m_index;
00415 }
00416
00417 return *this;
00418 }
00419
00420 template< ss_typename_param_k C
00421 , ss_typename_param_k T
00422 >
00423 inline ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type &basic_drophandle_sequence_const_iterator<C, T>::operator --()
00424 {
00425
00426 if(m_index == sentinel_())
00427 {
00428
00429 m_index = static_cast<index_type>(traits_type::drag_query_file(m_hdrop, 0xFFFFFFFF, NULL, 0));
00430
00431 if(m_index == 0xFFFFFFFF)
00432 {
00433
00434 m_index = sentinel_();
00435 }
00436 else
00437 {
00438
00439 --m_index;
00440 }
00441 }
00442 else
00443 {
00444
00445 --m_index;
00446 }
00447
00448 return *this;
00449 }
00450
00451 template< ss_typename_param_k C
00452 , ss_typename_param_k T
00453 >
00454 inline ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type basic_drophandle_sequence_const_iterator<C, T>::operator ++(int)
00455 {
00456 class_type ret(*this);
00457
00458 operator ++();
00459
00460 return ret;
00461 }
00462
00463 template< ss_typename_param_k C
00464 , ss_typename_param_k T
00465 >
00466 inline ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type basic_drophandle_sequence_const_iterator<C, T>::operator --(int)
00467 {
00468 class_type ret(*this);
00469
00470 operator --();
00471
00472 return ret;
00473 }
00474
00475 template< ss_typename_param_k C
00476 , ss_typename_param_k T
00477 >
00478 inline const ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::value_type basic_drophandle_sequence_const_iterator<C, T>::operator *() const
00479 {
00480 stlsoft_message_assert("Dereferencing the end iterator", m_index != sentinel_());
00481
00482 basic_file_path_buffer<char_type> sz;
00483 ws_uint_t res = traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(m_index), &sz[0], sz.size());
00484
00485 if(res == 0xFFFFFFFF)
00486 {
00487 sz[0] = '\0';
00488 }
00489
00490 return value_type(stlsoft_ns_qual(c_str_ptr)(sz));
00491 }
00492
00493 template< ss_typename_param_k C
00494 , ss_typename_param_k T
00495 >
00496 inline ws_bool_t basic_drophandle_sequence_const_iterator<C, T>::operator ==(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const &rhs) const
00497 {
00498 stlsoft_message_assert("Comparing iterators from different sequences", m_hdrop == NULL || rhs.m_hdrop == NULL || rhs.m_hdrop);
00499
00500 return m_index == rhs.m_index;
00501 }
00502
00503 template< ss_typename_param_k C
00504 , ss_typename_param_k T
00505 >
00506 inline ws_bool_t basic_drophandle_sequence_const_iterator<C, T>::operator !=(ss_typename_type_k basic_drophandle_sequence_const_iterator<C, T>::class_type const &rhs) const
00507 {
00508 return !operator ==(rhs);
00509 }
00510
00511
00512
00513 template <ss_typename_param_k C, ss_typename_param_k T>
00514 inline basic_drophandle_sequence<C, T>::basic_drophandle_sequence(HDROP hdrop)
00515 : m_hdrop(hdrop)
00516 {}
00517
00518 template <ss_typename_param_k C, ss_typename_param_k T>
00519 inline basic_drophandle_sequence<C, T>::~basic_drophandle_sequence() winstl_throw_0()
00520 {
00521 ::DragFinish(m_hdrop);
00522 }
00523
00524 template <ss_typename_param_k C, ss_typename_param_k T>
00525 inline ws_size_t basic_drophandle_sequence<C, T>::size() const
00526 {
00527 return traits_type::drag_query_file(m_hdrop, static_cast<ws_uint_t>(-1), 0, 0);
00528 }
00529
00530 template <ss_typename_param_k C, ss_typename_param_k T>
00531 inline ws_bool_t basic_drophandle_sequence<C, T>::empty() const
00532 {
00533 return size() == 0;
00534 }
00535
00536 template <ss_typename_param_k C, ss_typename_param_k T>
00537 inline ss_typename_type_k basic_drophandle_sequence<C, T>::const_iterator basic_drophandle_sequence<C, T>::begin() const
00538 {
00539 char_type ch;
00540 ws_uint_t res = traits_type::drag_query_file(m_hdrop, 0, &ch, 1);
00541
00542 return const_iterator(m_hdrop, (res == 0) ? const_iterator::sentinel_() : 0);
00543 }
00544
00545 template <ss_typename_param_k C, ss_typename_param_k T>
00546 inline ss_typename_type_k basic_drophandle_sequence<C, T>::const_iterator basic_drophandle_sequence<C, T>::end() const
00547 {
00548 return const_iterator(m_hdrop, const_iterator::sentinel_());
00549 }
00550
00551 #if defined(__STLSOFT_CF_BIDIRECTIONAL_ITERATOR_SUPPORT)
00552 template <ss_typename_param_k C, ss_typename_param_k T>
00553 inline ss_typename_type_k basic_drophandle_sequence<C, T>::const_reverse_iterator basic_drophandle_sequence<C, T>::rbegin() const
00554 {
00555 return const_reverse_iterator(end());
00556 }
00557
00558 template <ss_typename_param_k C, ss_typename_param_k T>
00559 inline ss_typename_type_k basic_drophandle_sequence<C, T>::const_reverse_iterator basic_drophandle_sequence<C, T>::rend() const
00560 {
00561 return const_reverse_iterator(begin());
00562 }
00563 #endif
00564
00565
00567
00568
00569 #ifdef STLSOFT_UNITTEST
00570
00571 namespace unittest
00572 {
00573 ss_bool_t test_winstl_drophandle_sequence(unittest_reporter *r)
00574 {
00575 using stlsoft::unittest::unittest_initialiser;
00576
00577 ss_bool_t bSuccess = true;
00578
00579 unittest_initialiser init(r, "WinSTL", "drophandle_sequence", __FILE__);
00580
00581 #if 0
00582 if(<<TODO>>)
00583 {
00584 r->report("<<TODO>> failed ", __LINE__);
00585 bSuccess = false;
00586 }
00587 #endif
00588
00589 return bSuccess;
00590 }
00591
00592 unittest_registrar unittest_winstl_drophandle_sequence(test_winstl_drophandle_sequence);
00593
00594 }
00595
00596 #endif
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608 #endif
00609
00610
00611
00612
00613
00614