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 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00065 # define RECLS_VER_H_RECLSPP_FILEENTRY_MAJOR 1
00066 # define RECLS_VER_H_RECLSPP_FILEENTRY_MINOR 4
00067 # define RECLS_VER_H_RECLSPP_FILEENTRY_REVISION 3
00068 # define RECLS_VER_H_RECLSPP_FILEENTRY_EDIT 21
00069 #endif
00070
00075
00076
00077
00078
00079 #include "reclspp.h"
00080 #include <recls_assert.h>
00081 #include <stlsoft_operator_bool.h>
00082 #if defined(RECLS_PLATFORM_IS_WIN32)
00083 # include <winstl_file_path_buffer.h>
00084 #elif defined(RECLS_PLATFORM_IS_UNIX)
00085 # include <unixstl_file_path_buffer.h>
00086 #else
00087 # error Platform not (yet) recognised
00088 #endif
00089
00090
00091
00092
00093
00094 #if !defined(RECLS_NO_NAMESPACE)
00095 namespace recls
00096 {
00097
00098 namespace cpp
00099 {
00100 #endif
00101
00102 #if defined(RECLS_PLATFORM_IS_WIN32)
00103 typedef winstl::basic_file_path_buffer<recls_char_t> file_path_buffer;
00104 #elif defined(RECLS_PLATFORM_IS_UNIX)
00105 typedef unixstl::basic_file_path_buffer<recls_char_t> file_path_buffer;
00106 #else
00107 # error Platform not (yet) recognised
00108 #endif
00109
00110
00111
00112
00113
00114 class FileEntry;
00115 class FileSearch;
00116
00117
00118
00119
00120
00124 class DirectoryParts
00125 {
00126 public:
00127 typedef recls_char_t char_type;
00128 typedef DirectoryParts class_type;
00129
00130
00131 private:
00132 friend class FileEntry;
00133 DirectoryParts(recls_info_t info);
00134
00137 public:
00139 DirectoryParts();
00141 DirectoryParts(DirectoryParts const &rhs);
00143 ~DirectoryParts();
00144
00146 DirectoryParts &operator =(DirectoryParts const &rhs);
00147
00149
00152 public:
00154 size_t size() const;
00160 string_t operator [](size_t index) const;
00161
00163
00164
00165 private:
00166 static recls_info_t _copy_info(recls_info_t info);
00167
00168
00169 private:
00170 recls_info_t m_info;
00171 };
00172
00176 class FileEntry
00177 {
00178 public:
00179 typedef recls_char_t char_type;
00180 typedef FileEntry class_type;
00181
00182
00183 private:
00184 friend class Search;
00185 FileEntry(recls_info_t info);
00186
00189 public:
00191 FileEntry();
00193 FileEntry(FileEntry const &rhs);
00195 ~FileEntry();
00196
00198 FileEntry &operator =(FileEntry const &rhs);
00199
00201
00204 private:
00205 STLSOFT_DEFINE_OPERATOR_BOOL_TYPES(class_type, boolean_generator_type, boolean_type);
00206 public:
00208 operator boolean_type() const
00209 {
00210 return boolean_generator_type::translate(NULL != m_info);
00211 }
00212
00213 #ifndef STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT
00214
00215 bool operator !() const;
00216 #endif
00217
00219
00222 public:
00224 char_type const *c_str() const;
00225
00227 string_t GetPath() const;
00228 #ifdef RECLS_PLATFORM_API_WIN32
00229
00230 char_type GetDrive() const;
00231 #endif
00232
00233 string_t GetDirectory() const;
00235 string_t GetDirectoryPath() const;
00237 DirectoryParts GetDirectoryParts() const;
00239 string_t GetFile() const;
00243 string_t GetShortFile() const;
00245 string_t GetFileName() const;
00247 string_t GetFileExt() const;
00248
00252 recls_time_t GetCreationTime() const;
00254 recls_time_t GetModificationTime() const;
00256 recls_time_t GetLastAccessTime() const;
00260 recls_time_t GetLastStatusChangeTime() const;
00261
00263 recls_filesize_t GetSize() const;
00264
00266 recls_bool_t IsReadOnly() const;
00268 recls_bool_t IsDirectory() const;
00270 recls_bool_t IsLink() const;
00271
00273
00274
00275 private:
00276 static recls_info_t _copy_info(recls_info_t info);
00277
00278
00279 private:
00280 recls_info_t m_info;
00281 };
00282
00283
00284
00285
00286
00297 inline FileEntry::char_type const *c_str_ptr(FileEntry const &fe)
00298 {
00299 return fe.c_str();
00300 }
00301
00302
00303
00304
00305
00306 inline recls_info_t DirectoryParts::_copy_info(recls_info_t info)
00307 {
00308 recls_info_t newInfo;
00309
00310 if( NULL == info ||
00311 RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00312 {
00313 newInfo = NULL;
00314 }
00315
00316 return newInfo;
00317 }
00318
00319 inline DirectoryParts::DirectoryParts(recls_info_t info)
00320 : m_info(_copy_info(info))
00321 {}
00322
00323 inline DirectoryParts::DirectoryParts()
00324 : m_info(NULL)
00325 {}
00326
00327 inline DirectoryParts::DirectoryParts(DirectoryParts const &rhs)
00328 : m_info(_copy_info(rhs.m_info))
00329 {}
00330
00331 inline DirectoryParts::~DirectoryParts()
00332 {
00333 Recls_CloseDetails(m_info);
00334 }
00335
00336 inline DirectoryParts &DirectoryParts::operator =(DirectoryParts const &rhs)
00337 {
00338 Recls_CloseDetails(m_info);
00339
00340 m_info = _copy_info(rhs.m_info);
00341
00342 return *this;
00343 }
00344
00345 inline size_t DirectoryParts::size() const
00346 {
00347 return Recls_GetDirectoryPartProperty(m_info, -1, NULL, 0);
00348 }
00349
00350 inline string_t DirectoryParts::operator [](size_t index) const
00351 {
00352 file_path_buffer dirPart;
00353
00354 recls_assert(NULL != m_info);
00355 recls_assert(index < size());
00356
00357 return RECLS_SUCCEEDED(Recls_GetDirectoryPartProperty(m_info, index, &dirPart[0], dirPart.size())) ? string_t(dirPart.c_str()) : string_t();
00358 }
00359
00360 inline recls_info_t FileEntry::_copy_info(recls_info_t info)
00361 {
00362 recls_info_t newInfo;
00363
00364 if( NULL == info ||
00365 RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00366 {
00367 newInfo = NULL;
00368 }
00369
00370 return newInfo;
00371 }
00372
00373 inline FileEntry::FileEntry(recls_info_t info)
00374 : m_info(info)
00375 {}
00376
00377 inline FileEntry::FileEntry()
00378 : m_info(NULL)
00379 {}
00380
00381 inline FileEntry::FileEntry(FileEntry const &rhs)
00382 : m_info(_copy_info(rhs.m_info))
00383 {}
00384
00385 inline FileEntry::~FileEntry()
00386 {
00387 if(NULL != m_info)
00388 {
00389 Recls_CloseDetails(m_info);
00390 }
00391 }
00392
00393 inline FileEntry &FileEntry::operator =(FileEntry const &rhs)
00394 {
00395 Recls_CloseDetails(m_info);
00396
00397 m_info = _copy_info(rhs.m_info);
00398
00399 return *this;
00400 }
00401
00402 #ifndef STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT
00403 inline bool FileEntry::operator !() const
00404 {
00405 return (*this) ? false : true;
00406 }
00407 #endif
00408
00409
00410 inline FileEntry::char_type const *FileEntry::c_str() const
00411 {
00412 return (NULL != m_info) ? m_info->path.begin : "";
00413 }
00414
00415 inline string_t FileEntry::GetPath() const
00416 {
00417 recls_assert(NULL != m_info);
00418
00419 return string_t(m_info->path.begin, m_info->path.end);
00420 }
00421
00422 #ifdef RECLS_PLATFORM_API_WIN32
00423 inline FileEntry::char_type FileEntry::GetDrive() const
00424 {
00425 char_type chDrive;
00426
00427 return (Recls_GetDriveProperty(m_info, &chDrive), chDrive);
00428 }
00429 #endif
00430
00431 inline string_t FileEntry::GetDirectory() const
00432 {
00433 recls_assert(NULL != m_info);
00434
00435 return string_t(m_info->directory.begin, m_info->directory.end);
00436 }
00437
00438 inline string_t FileEntry::GetDirectoryPath() const
00439 {
00440 recls_assert(NULL != m_info);
00441
00442 return string_t(m_info->path.begin, m_info->directory.end);
00443 }
00444
00445 inline DirectoryParts FileEntry::GetDirectoryParts() const
00446 {
00447 recls_assert(NULL != m_info);
00448
00449 return DirectoryParts(m_info);
00450 }
00451
00452 inline string_t FileEntry::GetFile() const
00453 {
00454 recls_assert(NULL != m_info);
00455 recls_assert(m_info->fileName.begin <= m_info->fileExt.end);
00456
00457 return string_t(m_info->fileName.begin, m_info->fileExt.end);
00458 }
00459
00460 inline string_t FileEntry::GetShortFile() const
00461 {
00462 #ifdef RECLS_PLATFORM_API_WIN32
00463 recls_assert(NULL != m_info);
00464
00465 return string_t(m_info->shortFile.begin, m_info->shortFile.end);
00466 #else
00467 return GetFile();
00468 #endif
00469 }
00470
00471 inline string_t FileEntry::GetFileName() const
00472 {
00473 recls_assert(NULL != m_info);
00474
00475 return string_t(m_info->fileName.begin, m_info->fileName.end);
00476 }
00477
00478 inline string_t FileEntry::GetFileExt() const
00479 {
00480 recls_assert(NULL != m_info);
00481
00482 return string_t(m_info->fileExt.begin, m_info->fileExt.end);
00483 }
00484
00485 inline recls_time_t FileEntry::GetCreationTime() const
00486 {
00487 recls_assert(NULL != m_info);
00488
00489 return Recls_GetCreationTime(m_info);
00490 }
00491
00492 inline recls_time_t FileEntry::GetModificationTime() const
00493 {
00494 recls_assert(NULL != m_info);
00495
00496 return Recls_GetModificationTime(m_info);
00497 }
00498
00499 inline recls_time_t FileEntry::GetLastAccessTime() const
00500 {
00501 recls_assert(NULL != m_info);
00502
00503 return Recls_GetLastAccessTime(m_info);
00504 }
00505
00506 inline recls_time_t FileEntry::GetLastStatusChangeTime() const
00507 {
00508 recls_assert(NULL != m_info);
00509
00510 return Recls_GetLastStatusChangeTime(m_info);
00511 }
00512
00513 inline recls_filesize_t FileEntry::GetSize() const
00514 {
00515 recls_assert(NULL != m_info);
00516
00517 return m_info->size;
00518 }
00519
00520 inline recls_bool_t FileEntry::IsReadOnly() const
00521 {
00522 recls_assert(NULL != m_info);
00523
00524 return Recls_IsFileReadOnly(m_info);
00525 }
00526
00527 inline recls_bool_t FileEntry::IsDirectory() const
00528 {
00529 recls_assert(NULL != m_info);
00530
00531 return Recls_IsFileDirectory(m_info);
00532 }
00533
00534 inline recls_bool_t FileEntry::IsLink() const
00535 {
00536 recls_assert(NULL != m_info);
00537
00538 return Recls_IsFileLink(m_info);
00539 }
00540
00541
00542
00543
00544
00545 #if !defined(RECLS_NO_NAMESPACE)
00546 }
00547 }
00548 #endif
00549
00550
00551
00552
00553
00554