You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

357 lines
13 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: inetstl/filesystem/ftpdir_sequence.hpp
  3. *
  4. * Purpose: Contains the basic_ftpdir_sequence template class, and ANSI
  5. * and Unicode specialisations thereof.
  6. *
  7. * Created: 18th January 2006
  8. * Updated: 10th August 2009
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2006-2009, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file inetstl/filesystem/ftpdir_sequence.hpp
  41. *
  42. * \brief [C++ only] Definition of the inetstl::ftpdir_sequence
  43. * class template
  44. * (\ref group__library__filesystem "File System" Library).
  45. */
  46. #ifndef INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE
  47. #define INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define INETSTL_VER_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE_MAJOR 2
  50. # define INETSTL_VER_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE_MINOR 1
  51. # define INETSTL_VER_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE_REVISION 3
  52. # define INETSTL_VER_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE_EDIT 27
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Compatibility
  56. */
  57. /*
  58. [Incompatibilies-start]
  59. STLSOFT_COMPILER_IS_MSVC: _MSC_VER<1100
  60. [Incompatibilies-end]
  61. */
  62. /* /////////////////////////////////////////////////////////////////////////
  63. * Includes
  64. */
  65. #ifndef INETSTL_INCL_INETSTL_H_INETSTL
  66. # include <inetstl/inetstl.h>
  67. #endif /* !INETSTL_INCL_INETSTL_H_INETSTL */
  68. #ifndef INETSTL_OS_IS_WINDOWS
  69. # error This file is currently compatible only with the Win32/Win64 API
  70. #endif /* !INETSTL_OS_IS_WINDOWS */
  71. #ifndef INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
  72. # include <inetstl/filesystem/filesystem_traits.hpp>
  73. #endif /* !INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS */
  74. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  75. # ifndef INETSTL_INCL_INETSTL_ERROR_HPP_EXCEPTIONS
  76. # include <inetstl/error/exceptions.hpp> // for throw_internet_exception_policy
  77. # endif /* !INETSTL_INCL_INETSTL_ERROR_HPP_EXCEPTIONS */
  78. #else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
  79. # ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXCEPTIONS
  80. # include <stlsoft/error/exceptions.hpp> // for stlsoft::null_exception_policy
  81. # endif /* !STLSOFT_INCL_STLSOFT_ERROR_HPP_EXCEPTIONS */
  82. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  83. #ifndef INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FINDFILE_SEQUENCE
  84. # include <inetstl/filesystem/findfile_sequence.hpp>
  85. #endif /* !INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FINDFILE_SEQUENCE */
  86. #ifndef STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS
  87. # include <stlsoft/collections/util/collections.hpp>
  88. #endif /* !STLSOFT_INCL_STLSOFT_COLLECTIONS_UTIL_HPP_COLLECTIONS */
  89. #ifndef STLSOFT_INCL_ALGORITHM
  90. # define STLSOFT_INCL_ALGORITHM
  91. # include <algorithm>
  92. #endif /* !STLSOFT_INCL_ALGORITHM */
  93. #ifndef STLSOFT_INCL_ITERATOR
  94. # define STLSOFT_INCL_ITERATOR
  95. # include <iterator>
  96. #endif /* !STLSOFT_INCL_ITERATOR */
  97. #ifndef STLSOFT_INCL_VECTOR
  98. # define STLSOFT_INCL_VECTOR
  99. # include <vector>
  100. #endif /* !STLSOFT_INCL_VECTOR */
  101. /* /////////////////////////////////////////////////////////////////////////
  102. * Namespace
  103. */
  104. #ifndef _INETSTL_NO_NAMESPACE
  105. # if defined(_STLSOFT_NO_NAMESPACE) || \
  106. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  107. /* There is no stlsoft namespace, so must define ::inetstl */
  108. namespace inetstl
  109. {
  110. # else
  111. /* Define stlsoft::inetstl_project */
  112. namespace stlsoft
  113. {
  114. namespace inetstl_project
  115. {
  116. # endif /* _STLSOFT_NO_NAMESPACE */
  117. #endif /* !_INETSTL_NO_NAMESPACE */
  118. /* /////////////////////////////////////////////////////////////////////////
  119. * Classes
  120. */
  121. /** STL collection of the files in an FTP directory matching a given pattern
  122. *
  123. * This class is described in detail in section 21.2 of
  124. * <a href="http://extendedstl.com/">Extended STL, volume 1</a>.
  125. */
  126. template< ss_typename_param_k C
  127. #ifdef STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT
  128. # ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  129. , ss_typename_param_k X = throw_internet_exception_policy
  130. # else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
  131. , ss_typename_param_k X = stlsoft_ns_qual(null_exception_policy)
  132. # endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  133. , ss_typename_param_k T = filesystem_traits<C>
  134. #else /* ? STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  135. , ss_typename_param_k X /* = throw_internet_exception_policy */
  136. , ss_typename_param_k T /* = filesystem_traits<C> */
  137. #endif /* STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_CLASS_ARGUMENT_SUPPORT */
  138. >
  139. class basic_ftpdir_sequence
  140. : public stlsoft_ns_qual(stl_collection_tag)
  141. {
  142. /// \name Member Types
  143. /// @{
  144. private:
  145. typedef basic_findfile_sequence<C, T, X> sequence_type_;
  146. public:
  147. typedef ss_typename_type_k sequence_type_::char_type char_type;
  148. typedef ss_typename_type_k sequence_type_::value_type value_type;
  149. typedef ss_typename_type_k sequence_type_::size_type size_type;
  150. typedef ss_typename_type_k sequence_type_::bool_type bool_type;
  151. typedef is_sint_t flags_type;
  152. private:
  153. typedef stlsoft_ns_qual_std(vector)<value_type> values_type_;
  154. public:
  155. typedef ss_typename_type_k values_type_::const_reference const_reference;
  156. typedef ss_typename_type_k values_type_::const_iterator const_iterator;
  157. typedef ss_typename_type_k values_type_::const_reverse_iterator const_reverse_iterator;
  158. typedef basic_ftpdir_sequence<C, X, T> class_type;
  159. /// @}
  160. /// \name Member Constants
  161. /// @{
  162. public:
  163. enum search_flags
  164. {
  165. includeDots = sequence_type_::includeDots
  166. , directories = sequence_type_::directories
  167. , files = sequence_type_::files
  168. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  169. , noSort = sequence_type_::noSort
  170. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  171. };
  172. /// @}
  173. /// \name Construction
  174. /// @{
  175. public:
  176. basic_ftpdir_sequence( HINTERNET hconn
  177. , char_type const* pattern
  178. , flags_type flags = directories | files)
  179. {
  180. sequence_type_ ffs(hconn, pattern, flags);
  181. stlsoft_ns_qual_std(copy)(ffs.begin(), ffs.end(), stlsoft_ns_qual_std(back_inserter)(m_values));
  182. }
  183. /// Commence a search according to the given search pattern and flags, relative to \c directory
  184. basic_ftpdir_sequence( HINTERNET hconn
  185. , char_type const* directory
  186. , char_type const* pattern
  187. , flags_type flags = directories | files)
  188. {
  189. sequence_type_ ffs(hconn, directory, pattern, flags);
  190. stlsoft_ns_qual_std(copy)(ffs.begin(), ffs.end(), stlsoft_ns_qual_std(back_inserter)(m_values));
  191. }
  192. /// Commence a search according to the given search pattern and flags, relative to \c directory
  193. basic_ftpdir_sequence( HINTERNET hconn
  194. , char_type const* directory
  195. , char_type const* patterns
  196. , char_type delim
  197. , flags_type flags = directories | files)
  198. {
  199. sequence_type_ ffs(hconn, directory, patterns, delim, flags);
  200. stlsoft_ns_qual_std(copy)(ffs.begin(), ffs.end(), stlsoft_ns_qual_std(back_inserter)(m_values));
  201. }
  202. #ifdef STLSOFT_DOCUMENTATION_SKIP_SECTION
  203. /// Constructs an instance of the sequence containing all the elements of the other
  204. basic_ftpdir_sequence(class_type const& rhs);
  205. /// Copies the contents of the given instance
  206. class_type& operator =(class_type const& rhs);
  207. #endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
  208. /// @}
  209. /// \name Element access
  210. /// @{
  211. public:
  212. const_reference operator [](size_type index) const
  213. {
  214. INETSTL_MESSAGE_ASSERT("Invalid index", index < size());
  215. return m_values[index];
  216. }
  217. /// @}
  218. /// \name Iteration
  219. /// @{
  220. public:
  221. const_iterator begin() const
  222. {
  223. return m_values.begin();
  224. }
  225. const_iterator end() const
  226. {
  227. return m_values.end();
  228. }
  229. const_reverse_iterator rbegin() const
  230. {
  231. return m_values.rbegin();
  232. }
  233. const_reverse_iterator rend() const
  234. {
  235. return m_values.rend();
  236. }
  237. /// @}
  238. /// \name Size
  239. /// @{
  240. public:
  241. size_type size() const
  242. {
  243. return m_values.size();
  244. }
  245. bool_type empty() const
  246. {
  247. return m_values.empty();
  248. }
  249. /// @}
  250. /// \name Members
  251. /// @{
  252. private:
  253. values_type_ m_values;
  254. /// @}
  255. };
  256. /* /////////////////////////////////////////////////////////////////////////
  257. * Typedefs for commonly encountered types
  258. */
  259. /** \brief Specialisation of the basic_findfile_sequence template for the ANSI character type \c char
  260. *
  261. *
  262. */
  263. typedef basic_ftpdir_sequence<is_char_a_t
  264. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  265. , throw_internet_exception_policy
  266. #else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
  267. , stlsoft_ns_qual(null_exception_policy)
  268. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  269. , filesystem_traits<is_char_a_t>
  270. > ftpdir_sequence_a;
  271. /** \brief Specialisation of the basic_ftpdir_sequence template for the Unicode character type \c wchar_t
  272. *
  273. * \ingroup group__library__filesystem
  274. */
  275. typedef basic_ftpdir_sequence<is_char_w_t
  276. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  277. , throw_internet_exception_policy
  278. #else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
  279. , stlsoft_ns_qual(null_exception_policy)
  280. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  281. , filesystem_traits<is_char_w_t>
  282. > ftpdir_sequence_w;
  283. /** \brief Specialisation of the basic_ftpdir_sequence template for the Win32 character type \c TCHAR
  284. *
  285. * \ingroup group__library__filesystem
  286. */
  287. typedef basic_ftpdir_sequence<TCHAR
  288. #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
  289. , throw_internet_exception_policy
  290. #else /* ? STLSOFT_CF_EXCEPTION_SUPPORT */
  291. , stlsoft_ns_qual(null_exception_policy)
  292. #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */
  293. , filesystem_traits<TCHAR>
  294. > ftpdir_sequence;
  295. ////////////////////////////////////////////////////////////////////////////
  296. // Unit-testing
  297. #ifdef STLSOFT_UNITTEST
  298. # include "./unittest/ftpdir_sequence_unittest_.h"
  299. #endif /* STLSOFT_UNITTEST */
  300. ////////////////////////////////////////////////////////////////////////////
  301. // Implementation
  302. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  303. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  304. /* ////////////////////////////////////////////////////////////////////// */
  305. #ifndef _INETSTL_NO_NAMESPACE
  306. # if defined(_STLSOFT_NO_NAMESPACE) || \
  307. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  308. } // namespace inetstl
  309. # else
  310. } // namespace inetstl_project
  311. } // namespace stlsoft
  312. # endif /* _STLSOFT_NO_NAMESPACE */
  313. #endif /* !_INETSTL_NO_NAMESPACE */
  314. /* ////////////////////////////////////////////////////////////////////// */
  315. #endif /* INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FTPDIR_SEQUENCE */
  316. /* ///////////////////////////// end of file //////////////////////////// */