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

recls Library documentation Synesis Software Pty Ltd, 2001-2003