C/C++ User's Journal STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - where the Standard Template Library meets the Active Template Library COMSTL - where the Standard Template Library meets the Component Object Model
Synesis Software InetSTL - where the Standard Template Library meets the Internet UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/include/recls/cpp/fileentry.hpp

Go to the documentation of this file.
00001 /* 
00002  * File:        recls/cpp/fileentry.hpp
00003  *
00004  * Purpose:     recls C++ mapping - FileEntry class.
00005  *
00006  * Created:     18th August 2003
00007  * Updated:     15th March 2005
00008  *
00009  * Home:        http://recls.org/
00010  *
00011  * Copyright 2003-2005, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without 
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer. 
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00041 #ifndef RECLS_INCL_RECLS_CPP_HPP_FILEENTRY
00042 #define RECLS_INCL_RECLS_CPP_HPP_FILEENTRY
00043 
00044 /* File version */
00045 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00046 # define RECLS_VER_RECLS_CPP_HPP_FILEENTRY_MAJOR    2
00047 # define RECLS_VER_RECLS_CPP_HPP_FILEENTRY_MINOR    2
00048 # define RECLS_VER_RECLS_CPP_HPP_FILEENTRY_REVISION 1
00049 # define RECLS_VER_RECLS_CPP_HPP_FILEENTRY_EDIT     27
00050 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00051 
00056 /* 
00057  * Includes
00058  */
00059 
00060 #include <recls/cpp/recls.hpp>      // reclspp root header
00061 #include <recls_assert.h>
00062 #include <stlsoft.h>
00063 #include <stlsoft_operator_bool.h>  // For operator bool() stuff
00064 #if defined(RECLS_PLATFORM_IS_WIN32)
00065 # include <winstl_file_path_buffer.h>
00066 #elif defined(RECLS_PLATFORM_IS_UNIX)
00067 # include <unixstl_file_path_buffer.h>
00068 #else
00069 # error Platform not (yet) recognised
00070 #endif /* platform */
00071 
00072 /* 
00073  * Namespace
00074  */
00075 
00076 #if !defined(RECLS_NO_NAMESPACE)
00077 namespace recls
00078 {
00079 
00080 namespace cpp
00081 {
00082 #endif /* !RECLS_NO_NAMESPACE */
00083 
00084 #if defined(RECLS_PLATFORM_IS_WIN32)
00085 typedef winstl::basic_file_path_buffer<recls_char_t>    file_path_buffer;
00086 #elif defined(RECLS_PLATFORM_IS_UNIX)
00087 typedef unixstl::basic_file_path_buffer<recls_char_t>   file_path_buffer;
00088 #else
00089 # error Platform not (yet) recognised
00090 #endif /* platform */
00091 
00092 /* 
00093  * Forward declarations
00094  */
00095 
00096 class FileEntry;
00097 class FileSearch;
00098 
00099 /* 
00100  * Classes
00101  */
00102 
00106 class DirectoryParts
00107 {
00108 public:
00109     typedef recls_char_t    char_type;
00110     typedef DirectoryParts  class_type;
00111 
00112 // Construction
00113 private:
00114     friend class FileEntry;
00115     DirectoryParts(recls_info_t info);
00116 
00119 public:
00121     DirectoryParts();
00123     DirectoryParts(DirectoryParts const &rhs);
00125     ~DirectoryParts();
00126 
00128     DirectoryParts &operator =(DirectoryParts const &rhs);
00129 
00131 
00134 public:
00136     size_t      size() const;
00142     string_t    operator [](size_t index) const;
00143 
00145 
00146 // Implementation
00147 private:
00148     static recls_info_t copy_info_(recls_info_t info);
00149 
00150 // Members
00151 private:
00152     recls_info_t    m_info;
00153 };
00154 
00158 class FileEntry
00159 {
00160 public:
00161     typedef recls_char_t    char_type;
00162     typedef FileEntry       class_type;
00163 
00164 // Construction
00165 private:
00166     friend class Search;
00167     FileEntry(recls_info_t info);
00168 
00171 public:
00173     FileEntry();
00175     FileEntry(FileEntry const &rhs);
00177     ~FileEntry();
00178 
00180     FileEntry &operator =(FileEntry const &rhs);
00182 
00185 private:
00186     STLSOFT_DEFINE_OPERATOR_BOOL_TYPES(class_type, boolean_generator_type, boolean_type);
00187 public:
00189     operator boolean_type() const
00190     {
00191         return boolean_generator_type::translate(NULL != m_info);
00192     }
00193 
00194 #ifndef STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT
00195 
00196     bool operator !() const;
00197 #endif /* !STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT */
00198 
00200 
00203 public:
00204 #ifndef RECLS_PURE_API
00205 
00206     char_type const     *c_str() const;
00207 #endif /* !RECLS_PURE_API */
00208 
00210     string_t            GetPath() const;
00211 #ifdef RECLS_PLATFORM_API_WIN32
00212 
00213     char_type           GetDrive() const;
00214 #endif /* RECLS_PLATFORM_API_WIN32 */
00215 
00216     string_t            GetDirectory() const;
00218     string_t            GetDirectoryPath() const;
00219 #if defined(RECLS_DOCUMENTATION_SKIP_SECTION) || \
00220     (   RECLS_VER_MAJOR > 1 || \
00221         RECLS_VER_MINOR >= 6)
00222 
00223     string_t            GetUNCDrive() const;
00224 #endif /* recls 1.6.x */
00225 
00226     DirectoryParts      GetDirectoryParts() const;
00228     string_t            GetFile() const;
00232     string_t            GetShortFile() const;
00234     string_t            GetFileName() const;
00236     string_t            GetFileExt() const;
00237 
00241     recls_time_t        GetCreationTime() const;
00243     recls_time_t        GetModificationTime() const;
00245     recls_time_t        GetLastAccessTime() const;
00249     recls_time_t        GetLastStatusChangeTime() const;
00250 
00252     recls_filesize_t    GetSize() const;
00253 
00255     recls_bool_t        IsReadOnly() const;
00257     recls_bool_t        IsDirectory() const;
00259     recls_bool_t        IsLink() const;
00260 #if defined(RECLS_DOCUMENTATION_SKIP_SECTION) || \
00261     (   RECLS_VER_MAJOR > 1 || \
00262         RECLS_VER_MINOR >= 6)
00263 
00264     recls_bool_t        IsUNC() const;
00265 #endif /* recls 1.6.x */
00266 
00267 
00268 // Implementation
00269 private:
00270     static recls_info_t copy_info_(recls_info_t info);
00271 #ifdef RECLS_PURE_API
00272     // Note: this has to be inside the class because GCC is a real dummy n this regard.
00273     static string_t     get_string_(size_t (RECLS_CALLCONV_DEFAULT *pfn)(recls_info_t, recls_char_t *, size_t), recls_info_t info);
00274     {
00275         file_path_buffer    buffer;
00276         size_t              cch =   pfn(info, &buffer[0], buffer.size());
00277 
00278         return string_t(&buffer[0], cch);
00279     }
00280 #endif /* RECLS_PURE_API */
00281 
00282 // Members
00283 private:
00284     recls_info_t    m_info;
00285 };
00286 
00287 /* 
00288  * Shims
00289  */
00290 
00291 #ifndef RECLS_PURE_API
00302 inline FileEntry::char_type const *c_str_ptr(FileEntry const &fe)
00303 {
00304     return fe.c_str();
00305 }
00306 #endif /* !RECLS_PURE_API */
00307 
00308 /* 
00309  * Implementation
00310  */
00311 
00312 inline /* static */ recls_info_t DirectoryParts::copy_info_(recls_info_t info)
00313 {
00314     recls_info_t    newInfo;
00315 
00316     if( NULL == info ||
00317         RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00318     {
00319         newInfo = NULL;
00320     }
00321 
00322     return newInfo;
00323 }
00324 
00325 inline DirectoryParts::DirectoryParts(recls_info_t info)
00326     : m_info(copy_info_(info))
00327 {}
00328 
00329 inline DirectoryParts::DirectoryParts()
00330     : m_info(NULL)
00331 {}
00332 
00333 inline DirectoryParts::DirectoryParts(DirectoryParts const &rhs)
00334     : m_info(copy_info_(rhs.m_info))
00335 {}
00336 
00337 inline DirectoryParts::~DirectoryParts()
00338 {
00339     Recls_CloseDetails(m_info);
00340 }
00341 
00342 inline DirectoryParts &DirectoryParts::operator =(DirectoryParts const &rhs)
00343 {
00344     Recls_CloseDetails(m_info);
00345 
00346     m_info = copy_info_(rhs.m_info);
00347 
00348     return *this;
00349 }
00350 
00351 inline size_t DirectoryParts::size() const
00352 {
00353     return Recls_GetDirectoryPartProperty(m_info, -1, NULL, 0);
00354 }
00355 
00356 inline string_t DirectoryParts::operator [](size_t index) const
00357 {
00358     file_path_buffer    dirPart;
00359 
00360     recls_assert(NULL != m_info);
00361     recls_assert(index < size());
00362 
00363     return RECLS_SUCCEEDED(Recls_GetDirectoryPartProperty(m_info, index, &dirPart[0], dirPart.size())) ? string_t(dirPart.c_str()) : string_t();
00364 }
00365 
00366 inline /* static */ recls_info_t FileEntry::copy_info_(recls_info_t info)
00367 {
00368     recls_info_t    newInfo;
00369 
00370     if( NULL == info ||
00371         RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00372     {
00373         newInfo = NULL;
00374     }
00375 
00376     return newInfo;
00377 }
00378 
00379 inline FileEntry::FileEntry(recls_info_t info)
00380     : m_info(info)
00381 {}
00382 
00383 inline FileEntry::FileEntry()
00384     : m_info(NULL)
00385 {}
00386 
00387 inline FileEntry::FileEntry(FileEntry const &rhs)
00388     : m_info(copy_info_(rhs.m_info))
00389 {}
00390 
00391 inline FileEntry::~FileEntry()
00392 {
00393     if(NULL != m_info)
00394     {
00395         Recls_CloseDetails(m_info);
00396     }
00397 }
00398 
00399 inline FileEntry &FileEntry::operator =(FileEntry const &rhs)
00400 {
00401     Recls_CloseDetails(m_info);
00402 
00403     m_info = copy_info_(rhs.m_info);
00404 
00405     return *this;
00406 }
00407 
00408 #ifndef STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT
00409 inline bool FileEntry::operator !() const
00410 {
00411     return (*this) ? false : true;
00412 }
00413 #endif /* !STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT */
00414 
00415 
00416 #ifndef RECLS_PURE_API
00417 inline FileEntry::char_type const *FileEntry::c_str() const
00418 {
00419     return (NULL != m_info) ? m_info->path.begin : "";
00420 }
00421 #endif /* !RECLS_PURE_API */
00422 
00423 inline string_t FileEntry::GetPath() const
00424 {
00425     recls_assert(NULL != m_info);
00426 
00427 #ifdef RECLS_PURE_API
00428     return get_string_(Recls_GetPathProperty, m_info);
00429 #else /* ? RECLS_PURE_API */
00430     return string_t(m_info->path.begin, m_info->path.end);
00431 #endif /* RECLS_PURE_API */
00432 }
00433 
00434 #ifdef RECLS_PLATFORM_API_WIN32
00435 inline FileEntry::char_type FileEntry::GetDrive() const
00436 {
00437     char_type chDrive;
00438 
00439     return (Recls_GetDriveProperty(m_info, &chDrive), chDrive);
00440 }
00441 #endif /* RECLS_PLATFORM_API_WIN32 */
00442 
00443 inline string_t FileEntry::GetDirectory() const
00444 {
00445     recls_assert(NULL != m_info);
00446 
00447 #ifdef RECLS_PURE_API
00448     return get_string_(Recls_GetDirectoryProperty, m_info);
00449 #else /* ? RECLS_PURE_API */
00450     return string_t(m_info->directory.begin, m_info->directory.end);
00451 #endif /* RECLS_PURE_API */
00452 }
00453 
00454 inline string_t FileEntry::GetDirectoryPath() const
00455 {
00456     recls_assert(NULL != m_info);
00457 
00458 #ifdef RECLS_PURE_API
00459     return get_string_(Recls_GetDirectoryPathProperty, m_info);
00460 #else /* ? RECLS_PURE_API */
00461     return string_t(m_info->path.begin, m_info->directory.end);
00462 #endif /* RECLS_PURE_API */
00463 }
00464 
00465 #if defined(RECLS_DOCUMENTATION_SKIP_SECTION) || \
00466     (   RECLS_VER_MAJOR > 1 || \
00467         RECLS_VER_MINOR >= 6)
00468 inline string_t FileEntry::GetUNCDrive() const
00469 {
00470     recls_assert(NULL != m_info);
00471 
00472 #if 0
00473     if(!IsUNC())
00474     {
00475         return string_t();
00476     }
00477     else
00478     {
00479 #ifdef RECLS_PURE_API
00480         string_t    directoryPath   =   GetDirectoryPath();
00481         size_t      directoryLen    =   Recls_GetDirectoryProperty(m_info, NULL, 0);
00482 
00483         return string_t(directoryPath, 0, directoryPath.length() - directoryLen);
00484 #else /* ? RECLS_PURE_API */
00485         return string_t(m_info->path.begin, m_info->directory.begin);
00486 #endif /* RECLS_PURE_API */
00487     }
00488 #else /* ? 0 */
00489 # ifdef RECLS_PURE_API
00490     return get_string_(Recls_GetUNCDriveProperty, m_info);
00491 # else /* ? RECLS_PURE_API */
00492     return string_t(m_info->path.begin, m_info->directory.begin);
00493 # endif /* RECLS_PURE_API */
00494 #endif /* 0 */
00495 }
00496 #endif /* recls 1.6.x */
00497 
00498 inline DirectoryParts FileEntry::GetDirectoryParts() const
00499 {
00500     recls_assert(NULL != m_info);
00501 
00502     return DirectoryParts(m_info);
00503 }
00504 
00505 inline string_t FileEntry::GetFile() const
00506 {
00507     recls_assert(NULL != m_info);
00508 
00509 #ifdef RECLS_PURE_API
00510     return get_string_(Recls_GetFileProperty, m_info);
00511 #else /* ? RECLS_PURE_API */
00512     recls_assert(m_info->fileName.begin <= m_info->fileExt.end);
00513     return string_t(m_info->fileName.begin, m_info->fileExt.end);
00514 #endif /* RECLS_PURE_API */
00515 }
00516 
00517 inline string_t FileEntry::GetShortFile() const
00518 {
00519 #ifdef RECLS_PLATFORM_API_WIN32
00520     recls_assert(NULL != m_info);
00521 
00522     return string_t(m_info->shortFile.begin, m_info->shortFile.end);
00523 #else
00524     return GetFile();
00525 #endif /* RECLS_PLATFORM_API_WIN32 */
00526 }
00527 
00528 inline string_t FileEntry::GetFileName() const
00529 {
00530     recls_assert(NULL != m_info);
00531 
00532 #ifdef RECLS_PURE_API
00533     return get_string_(Recls_GetFileNameProperty, m_info);
00534 #else /* ? RECLS_PURE_API */
00535     return string_t(m_info->fileName.begin, m_info->fileName.end);
00536 #endif /* RECLS_PURE_API */
00537 }
00538 
00539 inline string_t FileEntry::GetFileExt() const
00540 {
00541     recls_assert(NULL != m_info);
00542 
00543 #ifdef RECLS_PURE_API
00544     return get_string_(Recls_GetFileExtProperty, m_info);
00545 #else /* ? RECLS_PURE_API */
00546     return string_t(m_info->fileExt.begin, m_info->fileExt.end);
00547 #endif /* RECLS_PURE_API */
00548 }
00549 
00550 inline recls_time_t FileEntry::GetCreationTime() const
00551 {
00552     recls_assert(NULL != m_info);
00553 
00554     return Recls_GetCreationTime(m_info);
00555 }
00556 
00557 inline recls_time_t FileEntry::GetModificationTime() const
00558 {
00559     recls_assert(NULL != m_info);
00560 
00561     return Recls_GetModificationTime(m_info);
00562 }
00563 
00564 inline recls_time_t FileEntry::GetLastAccessTime() const
00565 {
00566     recls_assert(NULL != m_info);
00567 
00568     return Recls_GetLastAccessTime(m_info);
00569 }
00570 
00571 inline recls_time_t FileEntry::GetLastStatusChangeTime() const
00572 {
00573     recls_assert(NULL != m_info);
00574 
00575     return Recls_GetLastStatusChangeTime(m_info);
00576 }
00577 
00578 inline recls_filesize_t FileEntry::GetSize() const
00579 {
00580     recls_assert(NULL != m_info);
00581 
00582 #ifdef RECLS_PURE_API
00583     recls_filesize_t    size;
00584 
00585     return (Recls_GetSizeProperty(m_info, &size), size);
00586 #else /* ? RECLS_PURE_API */
00587     return m_info->size;
00588 #endif /* RECLS_PURE_API */
00589 }
00590 
00591 inline recls_bool_t FileEntry::IsReadOnly() const
00592 {
00593     recls_assert(NULL != m_info);
00594 
00595     return Recls_IsFileReadOnly(m_info);
00596 }
00597 
00598 inline recls_bool_t FileEntry::IsDirectory() const
00599 {
00600     recls_assert(NULL != m_info);
00601 
00602     return Recls_IsFileDirectory(m_info);
00603 }
00604 
00605 inline recls_bool_t FileEntry::IsLink() const
00606 {
00607     recls_assert(NULL != m_info);
00608 
00609     return Recls_IsFileLink(m_info);
00610 }
00611 
00612 #if defined(RECLS_DOCUMENTATION_SKIP_SECTION) || \
00613     (   RECLS_VER_MAJOR > 1 || \
00614         RECLS_VER_MINOR >= 6)
00615 inline recls_bool_t FileEntry::IsUNC() const
00616 {
00617     recls_assert(NULL != m_info);
00618 
00619     return Recls_IsFileUNC(m_info);
00620 }
00621 #endif /* recls 1.6.x */
00622 
00623 /* 
00624  * Namespace
00625  */
00626 
00627 #if !defined(RECLS_NO_NAMESPACE)
00628 } /* namespace cpp */
00629 } /* namespace recls */
00630 #endif /* !RECLS_NO_NAMESPACE */
00631 
00632 /* 
00633 
00634 #endif /* !RECLS_INCL_RECLS_CPP_HPP_FILEENTRY */
00635 
00636 /* 

recls Library documentation © Synesis Software Pty Ltd, 2001-2005