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:     23rd September 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    0
00067 # define RECLS_VER_H_RECLSPP_FILEENTRY_REVISION 8
00068 # define RECLS_VER_H_RECLSPP_FILEENTRY_EDIT     8
00069 #endif /* !RECLS_DOCUMENTATION_SKIP_SECTION */
00070 
00073 /* 
00074  * Includes
00075  */
00076 
00077 #include "reclspp.h"
00078 #include "recls_assert.h"
00079 
00080 /* 
00081  * Namespace
00082  */
00083 
00084 #if !defined(RECLS_NO_NAMESPACE)
00085 namespace recls
00086 {
00087 
00088 namespace cpp
00089 {
00090 #endif /* !RECLS_NO_NAMESPACE */
00091 
00092 /* 
00093  * Forward declarations
00094  */
00095 
00096 class FileEntry;
00097 class FileSearch;
00098 
00099 /* 
00100  * Classes
00101  */
00102 
00106 class DirectoryParts
00107 {
00108 // Construction
00109 private:
00110     friend class FileEntry;
00111     DirectoryParts(recls_info_t info);
00112 
00115 public:
00117     DirectoryParts();
00119     DirectoryParts(DirectoryParts const &rhs);
00121     ~DirectoryParts();
00122 
00124     DirectoryParts &operator =(DirectoryParts const &rhs);
00125 
00127 
00130 public:
00132     size_t      size() const;
00138     string_t    operator [](size_t index) const;
00139 
00141 
00142 // Implementation
00143 private:
00144     static recls_info_t _copy_info(recls_info_t info);
00145 
00146 // Members
00147 private:
00148     recls_info_t    m_info;
00149 };
00150 
00154 class FileEntry
00155 {
00156 // Construction
00157 private:
00158     friend class FileSearch;
00159     FileEntry(recls_info_t info);
00160 
00163 public:
00165     FileEntry();
00167     FileEntry(FileEntry const &rhs);
00169     ~FileEntry();
00170 
00172     FileEntry &operator =(FileEntry const &rhs);
00173 
00175 
00178 public:
00180     struct boolean
00181     {};
00182 
00184     operator boolean *() const;
00185 
00187 
00190 public:
00192     char const          *c_str() const;
00193 
00195     string_t            GetPath() const;
00196 #ifdef RECLS_PLATFORM_API_WIN32
00197 
00198     char                GetDrive() const;
00199 #endif /* RECLS_PLATFORM_API_WIN32 */
00200 
00201     string_t            GetDirectory() const;
00203     DirectoryParts      GetDirectoryParts() const;
00205     string_t            GetFile() const;
00209     string_t            GetShortFile() const;
00211     string_t            GetFileName() const;
00213     string_t            GetFileExt() const;
00214 
00218     recls_time_t        GetCreationTime() const;
00220     recls_time_t        GetModificationTime() const;
00222     recls_time_t        GetLastAccessTime() const;
00226     recls_time_t        GetLastStatusChangeTime() const;
00227 
00229     recls_filesize_t    GetSize() const;
00230 
00232     recls_bool_t        IsReadOnly() const;
00234     recls_bool_t        IsDirectory() const;
00236     recls_bool_t        IsLink() const;
00237 
00239 
00240 // Implementation
00241 private:
00242     static recls_info_t _copy_info(recls_info_t info);
00243 
00244 // Members
00245 private:
00246     recls_info_t    m_info;
00247 };
00248 
00249 /* 
00250  * Shims
00251  */
00252 
00261 inline char const *c_str_ptr(FileEntry const &fe)
00262 {
00263     return fe.c_str();
00264 }
00265 
00266 /* 
00267  * Implementation
00268  */
00269 
00270 inline /* static */ recls_info_t DirectoryParts::_copy_info(recls_info_t info)
00271 {
00272     recls_info_t    newInfo;
00273 
00274     if( NULL == info ||
00275         RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00276     {
00277         newInfo = NULL;
00278     }
00279 
00280     return newInfo;
00281 }
00282 
00283 inline DirectoryParts::DirectoryParts(recls_info_t info)
00284     : m_info(_copy_info(info))
00285 {}
00286 
00287 inline DirectoryParts::DirectoryParts()
00288     : m_info(NULL)
00289 {}
00290 
00291 inline DirectoryParts::DirectoryParts(DirectoryParts const &rhs)
00292     : m_info(_copy_info(rhs.m_info))
00293 {}
00294 
00295 inline DirectoryParts::~DirectoryParts()
00296 {
00297     Recls_CloseDetails(m_info);
00298 }
00299 
00300 inline DirectoryParts &DirectoryParts::operator =(DirectoryParts const &rhs)
00301 {
00302     Recls_CloseDetails(m_info);
00303 
00304     m_info = _copy_info(rhs.m_info);
00305 
00306     return *this;
00307 }
00308 
00309 inline size_t DirectoryParts::size() const
00310 {
00311     return Recls_GetDirectoryPartProperty(m_info, -1, NULL, 0);
00312 }
00313 
00314 inline string_t DirectoryParts::operator [](size_t index) const
00315 {
00316     char    dirPart[RECLS_PATH_MAX];
00317 
00318     recls_assert(NULL != m_info);
00319     recls_assert(index < size());
00320 
00321     return RECLS_SUCCEEDED(Recls_GetDirectoryPartProperty(m_info, index, dirPart, RECLS_PATH_MAX)) ? string_t(dirPart) : string_t();
00322 }
00323 
00324 inline /* static */ recls_info_t FileEntry::_copy_info(recls_info_t info)
00325 {
00326     recls_info_t    newInfo;
00327 
00328     if( NULL == info ||
00329         RECLS_FAILED(Recls_CopyDetails(info, &newInfo)))
00330     {
00331         newInfo = NULL;
00332     }
00333 
00334     return newInfo;
00335 }
00336 
00337 inline FileEntry::FileEntry(recls_info_t info)
00338     : m_info(info)
00339 {}
00340 
00341 inline FileEntry::FileEntry()
00342     : m_info(NULL)
00343 {}
00344 
00345 inline FileEntry::FileEntry(FileEntry const &rhs)
00346     : m_info(_copy_info(rhs.m_info))
00347 {}
00348 
00349 inline FileEntry::~FileEntry()
00350 {
00351     Recls_CloseDetails(m_info);
00352 }
00353 
00354 inline FileEntry &FileEntry::operator =(FileEntry const &rhs)
00355 {
00356     Recls_CloseDetails(m_info);
00357 
00358     m_info = _copy_info(rhs.m_info);
00359 
00360     return *this;
00361 }
00362 
00363 inline FileEntry::operator FileEntry::boolean *() const
00364 {
00365     return static_cast<boolean*>(0) + (NULL != m_info);
00366 }
00367 
00368 inline char const *FileEntry::c_str() const
00369 {
00370     return (NULL != m_info) ? m_info->path.begin : "";
00371 }
00372 
00373 inline string_t FileEntry::GetPath() const
00374 {
00375     recls_assert(NULL != m_info);
00376 
00377     return string_t(m_info->path.begin, m_info->path.end);
00378 }
00379 
00380 #ifdef RECLS_PLATFORM_API_WIN32
00381 inline char FileEntry::GetDrive() const
00382 {
00383     char    chDrive;
00384 
00385     return (Recls_GetDriveProperty(m_info, &chDrive), chDrive);
00386 }
00387 #endif /* RECLS_PLATFORM_API_WIN32 */
00388 
00389 inline string_t FileEntry::GetDirectory() const
00390 {
00391     recls_assert(NULL != m_info);
00392 
00393     return string_t(m_info->directory.begin, m_info->directory.end);
00394 }
00395 
00396 inline DirectoryParts FileEntry::GetDirectoryParts() const
00397 {
00398     recls_assert(NULL != m_info);
00399 
00400     return DirectoryParts(m_info);
00401 }
00402 
00403 inline string_t FileEntry::GetFile() const
00404 {
00405     recls_assert(NULL != m_info);
00406 
00407     return string_t(m_info->fileName.begin, m_info->fileExt.end);
00408 }
00409 
00410 inline string_t FileEntry::GetShortFile() const
00411 {
00412 #ifdef RECLS_PLATFORM_API_WIN32
00413     recls_assert(NULL != m_info);
00414 
00415     return string_t(m_info->shortFile.begin, m_info->shortFile.end);
00416 #else
00417     return GetFile();
00418 #endif /* RECLS_PLATFORM_API_WIN32 */
00419 }
00420 
00421 inline string_t FileEntry::GetFileName() const
00422 {
00423     recls_assert(NULL != m_info);
00424 
00425     return string_t(m_info->fileName.begin, m_info->fileName.end);
00426 }
00427 
00428 inline string_t FileEntry::GetFileExt() const
00429 {
00430     recls_assert(NULL != m_info);
00431 
00432     return string_t(m_info->fileExt.begin, m_info->fileExt.end);
00433 }
00434 
00435 inline recls_time_t FileEntry::GetCreationTime() const
00436 {
00437     recls_assert(NULL != m_info);
00438 
00439     return Recls_GetCreationTime(m_info);
00440 }
00441 
00442 inline recls_time_t FileEntry::GetModificationTime() const
00443 {
00444     recls_assert(NULL != m_info);
00445 
00446     return Recls_GetModificationTime(m_info);
00447 }
00448 
00449 inline recls_time_t FileEntry::GetLastAccessTime() const
00450 {
00451     recls_assert(NULL != m_info);
00452 
00453     return Recls_GetLastAccessTime(m_info);
00454 }
00455 
00456 inline recls_time_t FileEntry::GetLastStatusChangeTime() const
00457 {
00458     recls_assert(NULL != m_info);
00459 
00460     return Recls_GetLastStatusChangeTime(m_info);
00461 }
00462 
00463 inline recls_filesize_t FileEntry::GetSize() const
00464 {
00465     recls_assert(NULL != m_info);
00466 
00467     return m_info->size;
00468 }
00469 
00470 inline recls_bool_t FileEntry::IsReadOnly() const
00471 {
00472     recls_assert(NULL != m_info);
00473 
00474     return Recls_IsFileReadOnly(m_info);
00475 }
00476 
00477 inline recls_bool_t FileEntry::IsDirectory() const
00478 {
00479     recls_assert(NULL != m_info);
00480 
00481     return Recls_IsFileDirectory(m_info);
00482 }
00483 
00484 inline recls_bool_t FileEntry::IsLink() const
00485 {
00486     recls_assert(NULL != m_info);
00487 
00488     return Recls_IsFileLink(m_info);
00489 }
00490 
00491 /* 
00492  * Namespace
00493  */
00494 
00495 #if !defined(RECLS_NO_NAMESPACE)
00496 } /* namespace cpp */
00497 } /* namespace recls */
00498 #endif /* !RECLS_NO_NAMESPACE */
00499 
00500 /* 
00501 
00502 #endif /* !RECLS_INCL_H_RECLSPP_FILEENTRY */
00503 
00504 /* 

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