C/C++ User's Journal Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/mappings/C++/reclspp_fileentry.h

Go to the documentation of this file.
00001 /* 
00002  * File:        reclspp_fileentry.h
00003  *
00004  * Purpose:     recls C++ mapping - FileEntry class.
00005  *
00006  * Created:     18th August 2003
00007  * Updated:     10th November 2003
00008  *
00009  * Author:      Matthew Wilson, Synesis Software Pty Ltd.
00010  *
00011  * License:     (Licensed under the Synesis Software Standard Source License)
00012  *
00013  *              Copyright (C) 2002-2003, Synesis Software Pty Ltd.
00014  *
00015  *              All rights reserved.
00016  *
00017  *              www:        http://www.synesis.com.au/software
00018  *                          http://www.recls.org/
00019  *
00020  *              email:      submissions@recls.org  for submissions
00021  *                          admin@recls.org        for other enquiries
00022  *
00023  *              Redistribution and use in source and binary forms, with or
00024  *              without modification, are permitted provided that the following
00025  *              conditions are met:
00026  *
00027  *              (i) Redistributions of source code must retain the above
00028  *              copyright notice and contact information, this list of
00029  *              conditions and the following disclaimer.
00030  *
00031  *              (ii) Any derived versions of this software (howsoever modified)
00032  *              remain the sole property of Synesis Software.
00033  *
00034  *              (iii) Any derived versions of this software (howsoever modified)
00035  *              remain subject to all these conditions.
00036  *
00037  *              (iv) Neither the name of Synesis Software nor the names of any
00038  *              subdivisions, employees or agents of Synesis Software, nor the
00039  *              names of any other contributors to this software may be used to
00040  *              endorse or promote products derived from this software without
00041  *              specific prior written permission.
00042  *
00043  *              This source code is provided by Synesis Software "as is" and any
00044  *              warranties, whether expressed or implied, including, but not
00045  *              limited to, the implied warranties of merchantability and
00046  *              fitness for a particular purpose are disclaimed. In no event
00047  *              shall the Synesis Software be liable for any direct, indirect,
00048  *              incidental, special, exemplary, or consequential damages
00049  *              (including, but not limited to, procurement of substitute goods
00050  *              or services; loss of use, data, or profits; or business
00051  *              interruption) however caused and on any theory of liability,
00052  *              whether in contract, strict liability, or tort (including
00053  *              negligence or otherwise) arising in any way out of the use of
00054  *              this software, even if advised of the possibility of such
00055  *              damage.
00056  *
00057  * 
00058 
00059 
00060 #ifndef RECLS_INCL_H_RECLSPP_FILEENTRY
00061 #define RECLS_INCL_H_RECLSPP_FILEENTRY
00062 
00063 /* File version */
00064 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00065 # define RECLS_VER_H_RECLSPP_FILEENTRY_MAJOR    1
00066 # define RECLS_VER_H_RECLSPP_FILEENTRY_MINOR    3
00067 # define RECLS_VER_H_RECLSPP_FILEENTRY_REVISION 3
00068 # define RECLS_VER_H_RECLSPP_FILEENTRY_EDIT     16
00069 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00070 
00075 /* 
00076  * Includes
00077  */
00078 
00079 #include "reclspp.h"
00080 #include <recls_assert.h>
00081 #include <stlsoft_operator_bool.h>      // For operator bool() stuff
00082 
00083 /* 
00084  * Namespace
00085  */
00086 
00087 #if !defined(RECLS_NO_NAMESPACE)
00088 namespace recls
00089 {
00090 
00091 namespace cpp
00092 {
00093 #endif /* !RECLS_NO_NAMESPACE */
00094 
00095 /* 
00096  * Forward declarations
00097  */
00098 
00099 class FileEntry;
00100 class FileSearch;
00101 
00102 /* 
00103  * Classes
00104  */
00105 
00109 class DirectoryParts
00110 {
00111 public:
00112     typedef recls_char_t    char_type;
00113     typedef DirectoryParts  class_type;
00114 
00115 // Construction
00116 private:
00117     friend class FileEntry;
00118     DirectoryParts(recls_info_t info);
00119 
00122 public:
00124     DirectoryParts();
00126     DirectoryParts(DirectoryParts const &rhs);
00128     ~DirectoryParts();
00129 
00131     DirectoryParts &operator =(DirectoryParts const &rhs);
00132 
00134 
00137 public:
00139     size_t      size() const;
00145     string_t    operator [](size_t index) const;
00146 
00148 
00149 // Implementation
00150 private:
00151     static recls_info_t _copy_info(recls_info_t info);
00152 
00153 // Members
00154 private:
00155     recls_info_t    m_info;
00156 };
00157 
00161 class FileEntry
00162 {
00163 public:
00164     typedef recls_char_t    char_type;
00165     typedef FileEntry       class_type;
00166 
00167 // Construction
00168 private:
00169     friend class FileSearch;
00170     FileEntry(recls_info_t info);
00171 
00174 public:
00176     FileEntry();
00178     FileEntry(FileEntry const &rhs);
00180     ~FileEntry();
00181 
00183     FileEntry &operator =(FileEntry const &rhs);
00184 
00186 
00189 private:
00190         typedef stlsoft_ns_qual(operator_bool_generator)<class_type>::class_type        boolean_type;
00191 public:
00193         operator boolean_type::return_type() const
00194         {
00195                 return boolean_type::translate(NULL != m_info);
00196         }
00197 
00198 #ifndef STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT
00199 
00200     bool operator !() const;
00201 #endif /* !STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT */
00202 
00204 
00207 public:
00209     char_type const     *c_str() const;
00210 
00212     string_t            GetPath() const;
00213 #ifdef RECLS_PLATFORM_API_WIN32
00214 
00215     char_type           GetDrive() const;
00216 #endif /* RECLS_PLATFORM_API_WIN32 */
00217 
00218     string_t            GetDirectory() const;
00220     string_t            GetDirectoryPath() const;
00222     DirectoryParts      GetDirectoryParts() const;
00224     string_t            GetFile() const;
00228     string_t            GetShortFile() const;
00230     string_t            GetFileName() const;
00232     string_t            GetFileExt() const;
00233 
00237     recls_time_t        GetCreationTime() const;
00239     recls_time_t        GetModificationTime() const;
00241     recls_time_t        GetLastAccessTime() const;
00245     recls_time_t        GetLastStatusChangeTime() const;
00246 
00248     recls_filesize_t    GetSize() const;
00249 
00251     recls_bool_t        IsReadOnly() const;
00253     recls_bool_t        IsDirectory() const;
00255     recls_bool_t        IsLink() const;
00256 
00258 
00259 // Implementation
00260 private:
00261     static recls_info_t _copy_info(recls_info_t info);
00262 
00263 // Members
00264 private:
00265     recls_info_t    m_info;
00266 };
00267 
00268 /* 
00269  * Shims
00270  */
00271 
00282 inline FileEntry::char_type const *c_str_ptr(FileEntry const &fe)
00283 {
00284     return fe.c_str();
00285 }
00286 
00287 /* 
00288  * Implementation
00289  */
00290 
00291 inline /* static */ recls_info_t DirectoryParts::_copy_info(recls_info_t info)
00292 {
00293     recls_info_t    newInfo;
00294 
00295     if( NULL == info ||
00296         RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00297     {
00298         newInfo = NULL;
00299     }
00300 
00301     return newInfo;
00302 }
00303 
00304 inline DirectoryParts::DirectoryParts(recls_info_t info)
00305     : m_info(_copy_info(info))
00306 {}
00307 
00308 inline DirectoryParts::DirectoryParts()
00309     : m_info(NULL)
00310 {}
00311 
00312 inline DirectoryParts::DirectoryParts(DirectoryParts const &rhs)
00313     : m_info(_copy_info(rhs.m_info))
00314 {}
00315 
00316 inline DirectoryParts::~DirectoryParts()
00317 {
00318     Recls_CloseDetails(m_info);
00319 }
00320 
00321 inline DirectoryParts &DirectoryParts::operator =(DirectoryParts const &rhs)
00322 {
00323     Recls_CloseDetails(m_info);
00324 
00325     m_info = _copy_info(rhs.m_info);
00326 
00327     return *this;
00328 }
00329 
00330 inline size_t DirectoryParts::size() const
00331 {
00332     return Recls_GetDirectoryPartProperty(m_info, -1, NULL, 0);
00333 }
00334 
00335 inline string_t DirectoryParts::operator [](size_t index) const
00336 {
00337     char_type dirPart[RECLS_PATH_MAX];
00338 
00339     recls_assert(NULL != m_info);
00340     recls_assert(index < size());
00341 
00342     return RECLS_SUCCEEDED(Recls_GetDirectoryPartProperty(m_info, index, dirPart, RECLS_PATH_MAX)) ? string_t(dirPart) : string_t();
00343 }
00344 
00345 inline /* static */ recls_info_t FileEntry::_copy_info(recls_info_t info)
00346 {
00347     recls_info_t    newInfo;
00348 
00349     if( NULL == info ||
00350         RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00351     {
00352         newInfo = NULL;
00353     }
00354 
00355     return newInfo;
00356 }
00357 
00358 inline FileEntry::FileEntry(recls_info_t info)
00359     : m_info(info)
00360 {}
00361 
00362 inline FileEntry::FileEntry()
00363     : m_info(NULL)
00364 {}
00365 
00366 inline FileEntry::FileEntry(FileEntry const &rhs)
00367     : m_info(_copy_info(rhs.m_info))
00368 {}
00369 
00370 inline FileEntry::~FileEntry()
00371 {
00372         if(NULL != m_info)
00373         {
00374                 Recls_CloseDetails(m_info);
00375         }
00376 }
00377 
00378 inline FileEntry &FileEntry::operator =(FileEntry const &rhs)
00379 {
00380     Recls_CloseDetails(m_info);
00381 
00382     m_info = _copy_info(rhs.m_info);
00383 
00384     return *this;
00385 }
00386 
00387 #ifndef STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT
00388 inline bool FileEntry::operator !() const
00389 {
00390     return (*this) ? false : true;
00391 }
00392 #endif /* !STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT */
00393 
00394 
00395 inline FileEntry::char_type const *FileEntry::c_str() const
00396 {
00397     return (NULL != m_info) ? m_info->path.begin : "";
00398 }
00399 
00400 inline string_t FileEntry::GetPath() const
00401 {
00402     recls_assert(NULL != m_info);
00403 
00404     return string_t(m_info->path.begin, m_info->path.end);
00405 }
00406 
00407 #ifdef RECLS_PLATFORM_API_WIN32
00408 inline FileEntry::char_type FileEntry::GetDrive() const
00409 {
00410     char_type chDrive;
00411 
00412     return (Recls_GetDriveProperty(m_info, &chDrive), chDrive);
00413 }
00414 #endif /* RECLS_PLATFORM_API_WIN32 */
00415 
00416 inline string_t FileEntry::GetDirectory() const
00417 {
00418     recls_assert(NULL != m_info);
00419 
00420     return string_t(m_info->directory.begin, m_info->directory.end);
00421 }
00422 
00423 inline string_t FileEntry::GetDirectoryPath() const
00424 {
00425     recls_assert(NULL != m_info);
00426 
00427     return string_t(m_info->path.begin, m_info->directory.end);
00428 }
00429 
00430 inline DirectoryParts FileEntry::GetDirectoryParts() const
00431 {
00432     recls_assert(NULL != m_info);
00433 
00434     return DirectoryParts(m_info);
00435 }
00436 
00437 inline string_t FileEntry::GetFile() const
00438 {
00439     recls_assert(NULL != m_info);
00440     recls_assert(m_info->fileName.begin <= m_info->fileExt.end);
00441 
00442     return string_t(m_info->fileName.begin, m_info->fileExt.end);
00443 }
00444 
00445 inline string_t FileEntry::GetShortFile() const
00446 {
00447 #ifdef RECLS_PLATFORM_API_WIN32
00448     recls_assert(NULL != m_info);
00449 
00450     return string_t(m_info->shortFile.begin, m_info->shortFile.end);
00451 #else
00452     return GetFile();
00453 #endif /* RECLS_PLATFORM_API_WIN32 */
00454 }
00455 
00456 inline string_t FileEntry::GetFileName() const
00457 {
00458     recls_assert(NULL != m_info);
00459 
00460     return string_t(m_info->fileName.begin, m_info->fileName.end);
00461 }
00462 
00463 inline string_t FileEntry::GetFileExt() const
00464 {
00465     recls_assert(NULL != m_info);
00466 
00467     return string_t(m_info->fileExt.begin, m_info->fileExt.end);
00468 }
00469 
00470 inline recls_time_t FileEntry::GetCreationTime() const
00471 {
00472     recls_assert(NULL != m_info);
00473 
00474     return Recls_GetCreationTime(m_info);
00475 }
00476 
00477 inline recls_time_t FileEntry::GetModificationTime() const
00478 {
00479     recls_assert(NULL != m_info);
00480 
00481     return Recls_GetModificationTime(m_info);
00482 }
00483 
00484 inline recls_time_t FileEntry::GetLastAccessTime() const
00485 {
00486     recls_assert(NULL != m_info);
00487 
00488     return Recls_GetLastAccessTime(m_info);
00489 }
00490 
00491 inline recls_time_t FileEntry::GetLastStatusChangeTime() const
00492 {
00493     recls_assert(NULL != m_info);
00494 
00495     return Recls_GetLastStatusChangeTime(m_info);
00496 }
00497 
00498 inline recls_filesize_t FileEntry::GetSize() const
00499 {
00500     recls_assert(NULL != m_info);
00501 
00502     return m_info->size;
00503 }
00504 
00505 inline recls_bool_t FileEntry::IsReadOnly() const
00506 {
00507     recls_assert(NULL != m_info);
00508 
00509     return Recls_IsFileReadOnly(m_info);
00510 }
00511 
00512 inline recls_bool_t FileEntry::IsDirectory() const
00513 {
00514     recls_assert(NULL != m_info);
00515 
00516     return Recls_IsFileDirectory(m_info);
00517 }
00518 
00519 inline recls_bool_t FileEntry::IsLink() const
00520 {
00521     recls_assert(NULL != m_info);
00522 
00523     return Recls_IsFileLink(m_info);
00524 }
00525 
00526 /* 
00527  * Namespace
00528  */
00529 
00530 #if !defined(RECLS_NO_NAMESPACE)
00531 } /* namespace cpp */
00532 } /* namespace recls */
00533 #endif /* !RECLS_NO_NAMESPACE */
00534 
00535 /* 
00536 
00537 #endif /* !RECLS_INCL_H_RECLSPP_FILEENTRY */
00538 
00539 /* 

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