PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: FileStdStream.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_STDSTREAM_H__ 00024 #define __PLCORE_FILE_STDSTREAM_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/File/StdIo.h" 00032 #include "PLCore/File/FileImpl.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * Standard OS file stream implementation of 'FileImpl' 00047 * 00048 * @remarks 00049 * This implementation works either on a FILE* or on an OS file handle 00050 * (HANDLE on Windows, int on Linux). This can be used to access files 00051 * that have been returned by other functions/libraries. 00052 */ 00053 class FileStdStream : public FileImpl { 00054 00055 00056 //[-------------------------------------------------------] 00057 //[ Friends ] 00058 //[-------------------------------------------------------] 00059 friend class FileObject; 00060 00061 00062 //[-------------------------------------------------------] 00063 //[ Private functions ] 00064 //[-------------------------------------------------------] 00065 private: 00066 /** 00067 * @brief 00068 * Constructor 00069 * 00070 * @param[in] pFile 00071 * Standard stream pointer 00072 * @param[in] nAccess 00073 * Access flags that were used to open the stream 00074 */ 00075 FileStdStream(FILE *pFile, uint32 nAccess); 00076 00077 /** 00078 * @brief 00079 * Constructor 00080 * 00081 * @param[in] hFile 00082 * System file handle 00083 * 00084 * @note 00085 * - On Linux, the handle is a file handle of type int. 00086 * - On Windows, the handle is a file handle of type HANDLE. 00087 * Do not expect an int (fileno) here! If you need it to work with 00088 * low level io functions, you need to convert the HANDLE to a 00089 * file handle by yourself (see _open_osfhandle). 00090 */ 00091 FileStdStream(handle hFile); 00092 00093 /** 00094 * @brief 00095 * Destructor 00096 */ 00097 virtual ~FileStdStream(); 00098 00099 00100 //[-------------------------------------------------------] 00101 //[ Private virtual FileImpl functions ] 00102 //[-------------------------------------------------------] 00103 private: 00104 virtual bool Exists() const override; 00105 virtual bool IsFile() const override; 00106 virtual bool IsDirectory() const override; 00107 virtual bool CopyTo(const String &sDest, bool bOverwrite) const override; 00108 virtual bool MoveTo(const String &sDest) override; 00109 virtual bool Rename(const String &sName) override; 00110 virtual bool CreateNewFile(bool bAlways) override; 00111 virtual bool CreateNewDirectory() override; 00112 virtual bool Delete() override; 00113 virtual bool DeleteDirectory() override; 00114 virtual void Close() override; 00115 virtual bool Open(uint32 nAccess, String::EFormat nStringFormat = String::ASCII) override; 00116 virtual bool IsOpen() const override; 00117 virtual bool IsReadable() const override; 00118 virtual bool IsWritable() const override; 00119 virtual String::EFormat GetStringFormat() const override; 00120 virtual bool IsEof() const override; 00121 virtual int GetC() override; 00122 virtual bool PutC(int nChar) override; 00123 virtual String GetS() override; 00124 virtual int PutS(const String &sString) override; 00125 virtual uint32 Read(void *pBuffer, uint32 nSize, uint32 nCount) override; 00126 virtual uint32 Write(const void *pBuffer, uint32 nSize, uint32 nCount) override; 00127 virtual bool Flush() override; 00128 virtual bool Seek(int32 nOffset, uint32 nLocation) override; 00129 virtual int32 Tell() const override; 00130 virtual uint32 GetSize() const override; 00131 virtual FileSearchImpl *CreateSearch() override; 00132 00133 00134 //[-------------------------------------------------------] 00135 //[ Private data ] 00136 //[-------------------------------------------------------] 00137 private: 00138 bool m_bStream; /**< If 'true', m_pFile is used, otherwise m_hFile */ 00139 FILE *m_pFile; /**< Pointer to file stream, can be a null pointer */ 00140 handle m_hFile; /**< System file handle */ 00141 uint32 m_nAccess; /**< File access modes (see EAccess) */ 00142 String::EFormat m_nStringFormat; /**< String encoding format to use when dealing with string functions */ 00143 00144 00145 }; 00146 00147 00148 //[-------------------------------------------------------] 00149 //[ Namespace ] 00150 //[-------------------------------------------------------] 00151 } // PLCore 00152 00153 00154 #endif // __PLCORE_FILE_STDSTREAM_H__
|