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
00048 #ifndef PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_READDIR_SEQUENCE
00049 #define PLATFORMSTL_INCL_PLATFORMSTL_FILESYSTEM_HPP_READDIR_SEQUENCE
00050
00051
00052 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00053 # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_READDIR_SEQUENCE_MAJOR 2
00054 # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_READDIR_SEQUENCE_MINOR 2
00055 # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_READDIR_SEQUENCE_REVISION 2
00056 # define PLATFORMSTL_VER_PLATFORMSTL_FILESYSTEM_HPP_READDIR_SEQUENCE_EDIT 18
00057 #endif
00058
00059
00060
00061
00062
00063 #ifndef PLATFORMSTL_INCL_PLATFORMSTL_HPP_PLATFORMSTL
00064 # include <platformstl/platformstl.hpp>
00065 #endif
00066
00067 #if defined(PLATFORMSTL_OS_IS_UNIX)
00068 # ifndef UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_READDIR_SEQUENCE
00069 # include <unixstl/filesystem/readdir_sequence.hpp>
00070 # endif
00071 #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
00072 # ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FINDFILE_SEQUENCE
00073 # include <winstl/filesystem/findfile_sequence.hpp>
00074 # endif
00075 # ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
00076 # include <winstl/filesystem/filesystem_traits.hpp>
00077 # endif
00078 #else
00079 # error Operating system not discriminated
00080 #endif
00081
00082
00083
00084
00085
00086 #if defined(_STLSOFT_NO_NAMESPACE) || \
00087 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00088
00089 namespace platformstl
00090 {
00091 #else
00092
00093
00094 namespace stlsoft
00095 {
00096
00097 namespace platformstl_project
00098 {
00099 #endif
00100
00101
00102
00103 #if defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00104
00117 class readdir_sequence
00118 {};
00119
00120 #elif defined(PLATFORMSTL_OS_IS_UNIX)
00121
00122 # ifdef _UNIXSTL_NO_NAMESPACE
00123 using ::readdir_sequence;
00124 # else
00125 using ::unixstl::readdir_sequence;
00126 # endif
00127
00128 #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
00129
00130 class readdir_sequence
00131 {
00134 public:
00135
00136 typedef readdir_sequence class_type;
00137 private:
00138 typedef winstl_ns_qual(ws_char_a_t) char_type;
00139 typedef winstl_ns_qual(basic_findfile_sequence)<char_type> underlying_sequence_type;
00140 typedef winstl_ns_qual(filesystem_traits)<char_type> traits_type;
00141 public:
00142 typedef underlying_sequence_type::const_iterator underlying_sequence_const_iterator_type;
00143 typedef underlying_sequence_type::value_type underlying_sequence_value_type;
00144 public:
00145
00146 typedef winstl_ns_qual(ws_size_t) size_type;
00147
00148 class const_iterator;
00149
00150 typedef char_type const* value_type;
00152 typedef winstl_ns_qual(ws_int_t) flags_type;
00154 typedef winstl_ns_qual(ws_bool_t) bool_type;
00155
00156 public:
00158
00161 public:
00162 enum search_flags
00163 {
00164 includeDots = 0x0008
00165 , directories = 0x0010
00166 , files = 0x0020
00167 , fullPath = 0x0100
00168 , absolutePath = 0x0200
00169 };
00171
00174 public:
00186 template <ss_typename_param_k S>
00187 ss_explicit_k readdir_sequence(S const& directory)
00188 : m_ffs(stlsoft_ns_qual(c_str_ptr)(directory), "*.*", translate_flags_(directories | files))
00189 , m_flags(validate_flags_(directories | files))
00190 {}
00191
00192 template <ss_typename_param_k S>
00193 readdir_sequence(S const& directory, flags_type flags)
00194 : m_ffs(stlsoft_ns_qual(c_str_ptr)(directory), "*.*", translate_flags_(flags))
00195 , m_flags(validate_flags_(flags))
00196 {}
00197
00198 template <ss_typename_param_k S>
00199 readdir_sequence(S const& directory, search_flags flags)
00200 : m_ffs(stlsoft_ns_qual(c_str_ptr)(directory), "*.*", translate_flags_(flags))
00201 , m_flags(validate_flags_(flags))
00202 {}
00204
00207 public:
00211 const_iterator begin() const;
00215 const_iterator end() const;
00217
00220 public:
00222 bool_type empty() const;
00223
00229 char_type const *get_directory() const;
00230
00237 flags_type get_flags() const;
00239
00242 private:
00244 static flags_type validate_flags_(flags_type flags);
00245
00247 static flags_type translate_flags_(flags_type flags);
00249
00252 private:
00253 const underlying_sequence_type m_ffs;
00254 const flags_type m_flags;
00256
00259 private:
00260 readdir_sequence(class_type const&);
00261 class_type& operator =(class_type const&);
00263 };
00264
00269
00270 class readdir_sequence::const_iterator
00271 : public stlsoft_ns_qual(iterator_base)<platformstl_ns_qual_std(input_iterator_tag)
00272 , readdir_sequence::value_type
00273 , ss_ptrdiff_t
00274 , void
00275 , readdir_sequence::value_type
00276 >
00277 {
00280 public:
00282 typedef const_iterator class_type;
00284 typedef readdir_sequence::value_type value_type;
00286 typedef readdir_sequence::flags_type flags_type;
00288
00291 private:
00292 friend class readdir_sequence;
00293
00295 const_iterator(underlying_sequence_const_iterator_type it, flags_type flags)
00296 : m_it(it)
00297 , m_flags(flags)
00298 {}
00299 public:
00301 const_iterator()
00302 : m_it()
00303 , m_flags(0)
00304 {}
00306 const_iterator(class_type const& rhs)
00307 : m_it(rhs.m_it)
00308 , m_flags(rhs.m_flags)
00309 {}
00311 ~const_iterator() stlsoft_throw_0()
00312 {}
00313
00315 class_type const& operator =(class_type const& rhs)
00316 {
00317 m_it = rhs.m_it;
00318 m_flags = rhs.m_flags;
00319
00320 return *this;
00321 }
00323
00326 public:
00328 value_type operator *() const
00329 {
00330 remove_const(m_value) = *m_it;
00331
00332 return (fullPath & m_flags) ? m_value.get_path() : m_value.get_filename();
00333 }
00334
00337 class_type& operator ++()
00338 {
00339 ++m_it;
00340
00341 return *this;
00342 }
00343
00349 class_type operator ++(int)
00350 {
00351 class_type r(*this);
00352
00353 operator ++();
00354
00355 return r;
00356 }
00357
00363 bool equal(class_type const& rhs) const
00364 {
00365 return m_it == rhs.m_it;
00366 }
00368
00371 private:
00372 underlying_sequence_const_iterator_type m_it;
00373 underlying_sequence_value_type m_value;
00374 flags_type m_flags;
00376 };
00377
00378 inline readdir_sequence::flags_type readdir_sequence::validate_flags_(readdir_sequence::flags_type flags)
00379 {
00380 const flags_type validFlags = 0
00381 | includeDots
00382 | directories
00383 | files
00384 | fullPath
00385 | absolutePath
00386 | 0;
00387
00388 WINSTL_MESSAGE_ASSERT("Specification of unrecognised/unsupported flags", flags == (flags & validFlags));
00389 STLSOFT_SUPPRESS_UNUSED(validFlags);
00390
00391 if(0 == (flags & (directories | files)))
00392 {
00393 flags |= (directories | files);
00394 }
00395
00396 return flags;
00397 }
00398
00399 inline readdir_sequence::flags_type readdir_sequence::translate_flags_(readdir_sequence::flags_type flags)
00400 {
00401 flags_type translatedFlags = 0;
00402
00403 if(underlying_sequence_type::includeDots & flags)
00404 {
00405 translatedFlags |= underlying_sequence_type::includeDots;
00406 }
00407
00408 if(directories & flags)
00409 {
00410 translatedFlags |= underlying_sequence_type::directories;
00411 }
00412
00413 if(files & flags)
00414 {
00415 translatedFlags |= underlying_sequence_type::files;
00416 }
00417
00418 if(fullPath == ((fullPath | absolutePath) & flags))
00419 {
00420 translatedFlags |= underlying_sequence_type::relativePath;
00421 }
00422
00423 return translatedFlags;
00424 }
00425
00426
00427 inline readdir_sequence::const_iterator readdir_sequence::begin() const
00428 {
00429 return const_iterator(m_ffs.begin(), m_flags);
00430 }
00431
00432 inline readdir_sequence::const_iterator readdir_sequence::end() const
00433 {
00434 return const_iterator(m_ffs.end(), m_flags);
00435 }
00436
00437 inline readdir_sequence::bool_type readdir_sequence::empty() const
00438 {
00439 return m_ffs.empty();
00440 }
00441
00442 inline readdir_sequence::char_type const* readdir_sequence::get_directory() const
00443 {
00444 return m_ffs.get_directory();
00445 }
00446
00447 inline readdir_sequence::flags_type readdir_sequence::get_flags() const
00448 {
00449 return m_flags;
00450 }
00451
00452 inline ss_bool_t operator ==( readdir_sequence::const_iterator const& lhs
00453 , readdir_sequence::const_iterator const& rhs)
00454 {
00455 return lhs.equal(rhs);
00456 }
00457
00458 inline ss_bool_t operator !=( readdir_sequence::const_iterator const& lhs
00459 , readdir_sequence::const_iterator const& rhs)
00460 {
00461 return !lhs.equal(rhs);
00462 }
00463
00464 #else
00465 # error Operating system not discriminated
00466 #endif
00467
00468
00469
00470 #if defined(_STLSOFT_NO_NAMESPACE) || \
00471 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00472 }
00473 #else
00474 }
00475 }
00476 #endif
00477
00478 #if defined(PLATFORMSTL_OS_IS_WINDOWS) && \
00479 ( defined(STLSOFT_COMPILER_IS_BORLAND) || \
00480 defined(STLSOFT_COMPILER_IS_DMC))
00481
00482 inline int operator ==( platformstl::readdir_sequence::const_iterator const& lhs
00483 , platformstl::readdir_sequence::const_iterator const& rhs)
00484 {
00485 return lhs.equal(rhs);
00486 }
00487
00488 inline int operator !=( platformstl::readdir_sequence::const_iterator const& lhs
00489 , platformstl::readdir_sequence::const_iterator const& rhs)
00490 {
00491 return !lhs.equal(rhs);
00492 }
00493
00494 #endif
00495
00496
00497
00498 #endif
00499
00500