C/C++ User's Journal Synesis Software 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 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  

/Mappings/Cpp/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:     8th June 2004
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-2004, 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    4
00067 # define RECLS_VER_H_RECLSPP_FILEENTRY_REVISION 3
00068 # define RECLS_VER_H_RECLSPP_FILEENTRY_EDIT     21
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 #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 /* platform */
00089 
00090 /* 
00091  * Namespace
00092  */
00093 
00094 #if !defined(RECLS_NO_NAMESPACE)
00095 namespace recls
00096 {
00097 
00098 namespace cpp
00099 {
00100 #endif /* !RECLS_NO_NAMESPACE */
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 /* platform */
00109 
00110 /* 
00111  * Forward declarations
00112  */
00113 
00114 class FileEntry;
00115 class FileSearch;
00116 
00117 /* 
00118  * Classes
00119  */
00120 
00124 class DirectoryParts
00125 {
00126 public:
00127     typedef recls_char_t    char_type;
00128     typedef DirectoryParts  class_type;
00129 
00130 // Construction
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 // Implementation
00165 private:
00166     static recls_info_t _copy_info(recls_info_t info);
00167 
00168 // Members
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 // Construction
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 /* !STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT */
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 /* RECLS_PLATFORM_API_WIN32 */
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 // Implementation
00275 private:
00276     static recls_info_t _copy_info(recls_info_t info);
00277 
00278 // Members
00279 private:
00280     recls_info_t    m_info;
00281 };
00282 
00283 /* 
00284  * Shims
00285  */
00286 
00297 inline FileEntry::char_type const *c_str_ptr(FileEntry const &fe)
00298 {
00299     return fe.c_str();
00300 }
00301 
00302 /* 
00303  * Implementation
00304  */
00305 
00306 inline /* static */ 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 /* static */ 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 /* !STLSOFT_CF_OPERATOR_NOT_VIA_OPERATOR_POINTER_TO_MEMBER_SUPPORT */
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 /* RECLS_PLATFORM_API_WIN32 */
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 /* RECLS_PLATFORM_API_WIN32 */
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  * Namespace
00543  */
00544 
00545 #if !defined(RECLS_NO_NAMESPACE)
00546 } /* namespace cpp */
00547 } /* namespace recls */
00548 #endif /* !RECLS_NO_NAMESPACE */
00549 
00550 /* 
00551 
00552 #endif /* !RECLS_INCL_H_RECLSPP_FILEENTRY */
00553 
00554 /* 

recls Library documentation Synesis Software Pty Ltd, 2001-2004