PixelLightAPI  .
FileImpl.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: FileImpl.h                                     *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLCORE_FILE_IMPL_H__
00024 #define __PLCORE_FILE_IMPL_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLCore/File/Url.h"
00032 
00033 
00034 //[-------------------------------------------------------]
00035 //[ Namespace                                             ]
00036 //[-------------------------------------------------------]
00037 namespace PLCore {
00038 
00039 
00040 //[-------------------------------------------------------]
00041 //[ Forward declarations                                  ]
00042 //[-------------------------------------------------------]
00043 class FileAccess;
00044 class FileSearchImpl;
00045 
00046 
00047 //[-------------------------------------------------------]
00048 //[ Classes                                               ]
00049 //[-------------------------------------------------------]
00050 /**
00051 *  @brief
00052 *    Abstract base class for platform specific file object implementations
00053 *
00054 *  @note
00055 *    - Implementation of the state design pattern, this class is the state of the 'FileObject'-context
00056 */
00057 class FileImpl {
00058 
00059 
00060     //[-------------------------------------------------------]
00061     //[ Friends                                               ]
00062     //[-------------------------------------------------------]
00063     friend class FileObject;
00064     friend class File;
00065     friend class Directory;
00066     friend class FileSearch;
00067 
00068 
00069     //[-------------------------------------------------------]
00070     //[ Protected functions                                   ]
00071     //[-------------------------------------------------------]
00072     protected:
00073         /**
00074         *  @brief
00075         *    Constructor
00076         *
00077         *  @param[in] cUrl
00078         *    URL of the file or directory
00079         *  @param[in] pAccess
00080         *    Additional file access information (can be a null pointer)
00081         */
00082         PLCORE_API FileImpl(const Url &cUrl, const FileAccess *pAccess);
00083 
00084         /**
00085         *  @brief
00086         *    Destructor
00087         */
00088         PLCORE_API virtual ~FileImpl();
00089 
00090 
00091     //[-------------------------------------------------------]
00092     //[ Protected virtual FileImpl functions                  ]
00093     //[-------------------------------------------------------]
00094     protected:
00095         /**
00096         *  @brief
00097         *    Check if the file or directory exists
00098         *
00099         *  @return
00100         *    'true', if the object is existing, else 'false'
00101         */
00102         virtual bool Exists() const = 0;
00103 
00104         /**
00105         *  @brief
00106         *    Check if the object is a regular file
00107         *
00108         *  @return
00109         *    'true', if the object is a file
00110         */
00111         virtual bool IsFile() const = 0;
00112 
00113         /**
00114         *  @brief
00115         *    Check if the object is a directory
00116         *
00117         *  @return
00118         *    'true', if the object is a directory
00119         */
00120         virtual bool IsDirectory() const = 0;
00121 
00122         /**
00123         *  @brief
00124         *    Copy the file or directory to a new location
00125         *
00126         *  @param[in] sDest
00127         *    URL of the destination
00128         *  @param[in] bOverwrite
00129         *    Shall the file be overwritten if it already exists?
00130         *
00131         *  @return
00132         *    'true', if all went fine, else 'false'
00133         */
00134         virtual bool CopyTo(const String &sDest, bool bOverwrite) const = 0;
00135 
00136         /**
00137         *  @brief
00138         *    Move the file or directory to a new location
00139         *
00140         *  @param[in] sDest
00141         *    URL of the destination
00142         *
00143         *  @return
00144         *    'true', if all went fine, else 'false'
00145         */
00146         virtual bool MoveTo(const String &sDest) = 0;
00147 
00148         /**
00149         *  @brief
00150         *    Rename the file or directory
00151         *
00152         *  @param[in] sName
00153         *    New filename (filename only, no path)
00154         *
00155         *  @return
00156         *    'true', if all went fine, else 'false'
00157         */
00158         virtual bool Rename(const String &sName) = 0;
00159 
00160         /**
00161         *  @brief
00162         *    Create a file
00163         *
00164         *  @param[in] bAlways
00165         *    If 'true', the file is created (and therefore overwritten) if it already exists
00166         *
00167         *  @return
00168         *    'true', if all went fine, else 'false'
00169         */
00170         virtual bool CreateNewFile(bool bAlways) = 0;
00171 
00172         /**
00173         *  @brief
00174         *    Create a directory
00175         *
00176         *  @return
00177         *    'true', if all went fine, else 'false'
00178         */
00179         virtual bool CreateNewDirectory() = 0;
00180 
00181         /**
00182         *  @brief
00183         *    Delete a file
00184         *
00185         *  @return
00186         *    'true', if all went fine, else 'false'
00187         */
00188         virtual bool Delete() = 0;
00189 
00190         /**
00191         *  @brief
00192         *    Delete a directory
00193         *
00194         *  @return
00195         *    'true', if all went fine, else 'false'
00196         */
00197         virtual bool DeleteDirectory() = 0;
00198 
00199         /**
00200         *  @brief
00201         *    Close the file or directory
00202         */
00203         virtual void Close() = 0;
00204 
00205         /**
00206         *  @brief
00207         *    Open the file for reading and/or writing
00208         *
00209         *  @param[in] nAccess
00210         *    Access mode (see EAccess)
00211         *  @param[in] nStringFormat
00212         *    String encoding format to use when dealing with string functions
00213         *
00214         *  @return
00215         *    'false' on error, else 'true'
00216         */
00217         virtual bool Open(uint32 nAccess, String::EFormat nStringFormat = String::ASCII) = 0;
00218 
00219         /**
00220         *  @brief
00221         *    Returns whether the file is open
00222         *
00223         *  @return
00224         *    'true', if the file is open, else 'false'
00225         */
00226         virtual bool IsOpen() const = 0;
00227 
00228         /**
00229         *  @brief
00230         *    Returns whether the file is readable
00231         *
00232         *  @return
00233         *    'true', if the file can be read, else 'false'
00234         */
00235         virtual bool IsReadable() const = 0;
00236 
00237         /**
00238         *  @brief
00239         *    Returns whether the file is writable
00240         *
00241         *  @return
00242         *    'true', if the file can be written, else 'false'
00243         */
00244         virtual bool IsWritable() const = 0;
00245 
00246         /**
00247         *  @brief
00248         *    Returns the string encoding format to use when dealing with string functions
00249         *
00250         *  @return
00251         *    String encoding format to use when dealing with string functions
00252         */
00253         virtual String::EFormat GetStringFormat() const = 0;
00254 
00255         /**
00256         *  @brief
00257         *    Returns whether end of file has been reached
00258         *
00259         *  @return
00260         *    'true', if the end of the file has been reached, else 'false'
00261         */
00262         virtual bool IsEof() const = 0;
00263 
00264         /**
00265         *  @brief
00266         *    Reads a character
00267         *
00268         *  @return
00269         *    A character from file, < 0 if there was an error
00270         */
00271         virtual int GetC() = 0;
00272 
00273         /**
00274         *  @brief
00275         *    Writes a character
00276         *
00277         *  @param[in] nChar
00278         *    Character to write
00279         *
00280         *  @return
00281         *    'true' if all went fine, else 'false' (maybe file is read only)
00282         */
00283         virtual bool PutC(int nChar) = 0;
00284 
00285         /**
00286         *  @brief
00287         *    Reads a string
00288         *
00289         *  @return
00290         *    Read string
00291         */
00292         virtual String GetS() = 0;
00293 
00294         /**
00295         *  @brief
00296         *    Writes a string
00297         *
00298         *  @param[in] sString
00299         *    String which should be written into the file
00300         *
00301         *  @return
00302         *    Number of bytes written, 0 if nothing was written, < 0 if there was an error
00303         */
00304         virtual int PutS(const String &sString) = 0;
00305 
00306         /**
00307         *  @brief
00308         *    Reads the given number of bytes
00309         *
00310         *  @param[out] pBuffer
00311         *    Buffer were the data should be copied in (MUST valid and large enough!)
00312         *  @param[in]  nSize
00313         *    Item size in bytes
00314         *  @param[in]  nCount
00315         *    Maximum number of items to be read
00316         *
00317         *  @return
00318         *    Number of fully read items, if != 'nCount' an error occurred
00319         */
00320         virtual uint32 Read(void *pBuffer, uint32 nSize, uint32 nCount) = 0;
00321 
00322         /**
00323         *  @brief
00324         *    Writes the given number of bytes
00325         *
00326         *  @param[in] pBuffer
00327         *    Buffer with the data which should be written into the file (MUST valid and large enough!)
00328         *  @param[in] nSize
00329         *    Item size in bytes
00330         *  @param[in] nCount
00331         *    Maximum number of items to be written
00332         *
00333         *  @return
00334         *    Number of fully written items, if != 'nCount' an error occurred
00335         */
00336         virtual uint32 Write(const void *pBuffer, uint32 nSize, uint32 nCount) = 0;
00337 
00338         /**
00339         *  @brief
00340         *    Flushes the file buffer
00341         *
00342         *  @return
00343         *    'true' if all went fine, else 'false'
00344         */
00345         virtual bool Flush() = 0;
00346 
00347         /**
00348         *  @brief
00349         *    Sets the starting position
00350         *
00351         *  @param[in] nOffset
00352         *    File offset in bytes relative to the given location
00353         *  @param[in] nLocation
00354         *    Location ("File::ESeek"-type)
00355         *
00356         *  @return
00357         *    'true' if all went fine, else 'false'
00358         */
00359         virtual bool Seek(int32 nOffset, uint32 nLocation) = 0;
00360 
00361         /**
00362         *  @brief
00363         *    Gets the current position of the file pointer
00364         *
00365         *  @return
00366         *    The current byte position of the file pointer, < 0 if there was an error
00367         */
00368         virtual int32 Tell() const = 0;
00369 
00370         /**
00371         *  @brief
00372         *    Returns the file size
00373         *
00374         *  @return
00375         *    File size in bytes
00376         */
00377         virtual uint32 GetSize() const = 0;
00378 
00379         /**
00380         *  @brief
00381         *    Create a file searcher for the directory
00382         *
00383         *  @return
00384         *    Pointer to a file searcher, or a null pointer on error
00385         */
00386         virtual FileSearchImpl *CreateSearch() = 0;
00387 
00388 
00389     //[-------------------------------------------------------]
00390     //[ Protected data                                        ]
00391     //[-------------------------------------------------------]
00392     protected:
00393         Url               m_cUrl;       /**< URL of the file or directory */
00394         const FileAccess *m_pAccess;    /**< File access information, can be a null pointer */
00395 
00396 
00397 };
00398 
00399 
00400 //[-------------------------------------------------------]
00401 //[ Namespace                                             ]
00402 //[-------------------------------------------------------]
00403 } // PLCore
00404 
00405 
00406 #endif // __PLCORE_FILE_IMPL_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:53
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported