📄 unixfile.hpp
字号:
//// This file is part of the "More for C++" library//// Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)//// The "More for C++" library is free software; you can redistribute it and/or// modify it under the terms of the license that comes with this package.//// Read "license.txt" for more details.//// THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES// OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#ifndef UNIXFILE_HPP#define UNIXFILE_HPP////////////////////////////////////////////////////////////////////////////////#include <more/core/finalizable.hpp>#include <more/os/file.hpp>#include <dirent.h>////////////////////////////////////////////////////////////////////////////////namespace more{ namespace os { namespace unix_ { class UnixDirectory: public Directory, public more::core::Finalizable { public: class UnixEntry: public Directory::Entry { public: UnixEntry( const p<Entry>& pParent, const String& sName ); UnixEntry( const String& sFullName ); virtual String getName( ) throw( more::io::IOException ); virtual String getFullName( ) throw( more::io::IOException ); virtual String getExtension( ) throw( more::io::IOException ); virtual p<Entry> getParent( ) throw( more::io::IOException ); virtual bool isDirectory( ) throw( more::io::IOException ); virtual bool isReadOnly( ) throw( more::io::IOException ); virtual size_t getSize( ) throw( more::io::IOException ); protected: void throwIfInvalid( ) const; private: p<Entry> m_pParent; String m_sName; String m_sFullName; }; UnixDirectory( const p<Directory>& pParent, const String& sName ); UnixDirectory( const p<Directory::Entry>& pDescriptor ); UnixDirectory( const String& sFullName ); virtual void finalize( ); virtual bool exists( ) throw( more::io::IOException ); virtual p<Directory::Entry> getDescriptor( ) throw( more::io::IOException ); virtual p<Directory> getParent( ) throw( more::io::IOException ); virtual p<Directory::Entry> getFirstEntry( ) throw( more::io::IOException ); virtual p<Directory::Entry> getNextEntry( ) throw( more::io::IOException ); private: String m_sFullName; p<Directory::Entry> m_pDescriptor; p<Directory::Entry> m_pCurrentEntry; DIR* m_pDirHandle; }; //////////////////////////////////////////////////////////////////////// class UnixFile: public File, public more::core::Finalizable { public: UnixFile( const p<Directory>& pParent, const String& sName ); UnixFile( const p<Directory::Entry>& pDescriptor ); UnixFile( const String& sFullName ); virtual void finalize( ); virtual bool exists( ) throw( more::io::IOException ); virtual p<Directory::Entry> getDescriptor( ) throw( more::io::IOException ); virtual p<Directory> getParent( ) throw( more::io::IOException ); virtual void open( AccessMode ) throw( more::io::IOException ); virtual void close( ) throw( more::io::IOException ); virtual p<more::io::InputStream> getInputStream( ) throw( more::io::IOException ); virtual p<more::io::OutputStream> getOutputStream( ) throw( more::io::IOException ); protected: int convertAccessMode( File::AccessMode ) const; void throwIfNotOpen( ) throw( more::io::IOException ); private: String m_sFullName; p<Directory::Entry> m_pDescriptor; int m_nFileReadHandle; int m_nFileWriteHandle; File::AccessMode m_eAccessMode; p<more::io::InputStream> m_pInputStream; p<more::io::OutputStream> m_pOutputStream; // For UnixFileInputStream/UnixFileOutputStream: public: virtual size_t available( ) throw( more::io::IOException ); virtual bool hasBeenClosed( ) throw( more::io::IOException ); virtual size_t skip( size_t nNoOfBytes ) throw( more::io::IOException ); virtual size_t read( void* pBuffer, size_t nMaxNoOfBytes ) throw( more::io::IOException ); virtual void write( const void* pBuffer, size_t nNoOfBytes ) throw( more::io::IOException ); virtual size_t rewind( size_t nNoOfBytes ) throw( more::io::IOException ); virtual void flush( ) throw( more::io::IOException ); }; //////////////////////////////////////////////////////////////////////// class UnixFileInputStream: public more::io::InputStream { public: UnixFileInputStream( const p<UnixFile>& ); virtual size_t available( ) throw( more::io::IOException ); virtual bool hasBeenClosed( ) throw( more::io::IOException ); virtual size_t skip( size_t nNoOfBytes ) throw( more::io::IOException ); virtual size_t read( void* pBuffer, size_t nMaxNoOfBytes ) throw( more::io::IOException ); private: p<UnixFile> m_pUnixFile; }; //////////////////////////////////////////////////////////////////////// class UnixFileOutputStream: public more::io::OutputStream { public: UnixFileOutputStream( const p<UnixFile>& ); virtual void write( const void* pBuffer, size_t nNoOfBytes ) throw( more::io::IOException ); virtual size_t rewind( size_t nNoOfBytes ) throw( more::io::IOException ); virtual bool hasBeenClosed( ) throw( more::io::IOException ); virtual void flush( ) throw( more::io::IOException ); private: p<UnixFile> m_pUnixFile; }; } }}////////////////////////////////////////////////////////////////////////////////#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -