⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warfile.h

📁 ftpserver very good sample
💻 H
字号:
/** */#ifndef WAR_FILE_H#define WAR_FILE_H/* SYSTEM INCLUDES *//* PROJECT INCLUDES */#ifndef WAR_TYPES_H#   include "WarTypes.h"#endif#ifndef WAR_EXCEPTION_H#   include "WarException.h"#endif#ifndef WAR_SMART_POINTER_H#   include "WarSmartPointer.h"#endif#ifndef WAR_PTR_WRAPPER_H#   include "WarPtrWrapper.h"#endif#ifndef WAR_PATH_H#   include "WarPath.h"#endif#ifndef WAR_FILE_ENUMS#   include "WarFileEnums.h"#endif#ifndef WAR_URL_H#   include "WarUrl.h"#endif#ifndef WAR_FILE_ENGINE_H#   include "WarFileEngine.h"#endif#ifndef WAR_FIFO_BUFFER_H#   include "WarFifoBuffer.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */class WarFileDriverFile;#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarFile :    public WarFileEnums,    public WarSmartPointer{public:    typedef WarPtrWrapper<WarFile> warfile_ref_t;    // LIFECYCLE    // OPERATORS    // OPERATIONS                 /** Creates a WarFile object for the native file system        @param Path to create for. This assumes a system        path (equals a "file://" URL )    */    static warfile_ref_t Create(const war_syspath_t& filePath)        throw(WarException);    /** Creates a WarFile object according to it's protocol.        @param URL URL to create for.    */    static warfile_ref_t CreateForURL(const WarUrl& fileUrl)        throw(WarException);        /** Open a file        \begin{itemize}        \item F_CALLBACK - Open in non-blocking (async) mode        \item F_READ - Open for read. If neither raed or write is specified,           the file is opened for query.        \item F_WRITE - Open for write.         \item F_APPEND - Combine with write. Adds new data to the end of the file.        \item F_SHREAD - Allow other processes to open the file for read.        \item F_SHWRITE - Alow other processes to open the file for write        \item F_TEXT - Open in ASCII mode. This will map CR to           CRLF on input, and CR to the system default (CRLF           under DOS/Windows and CR under UNIX) end-of-line marker           for textfiles on output.        \item F_CREATE - Allows the file to be created. Combine with write.        \item F_TRUNCATE - Truncate the file if it exist. Combine with create.        \item F_NOTEXIST - The file must not exist        \item F_MUSTEXIST - The file must exist        \item F_SEQUENTIAL - Caching hint: The file will be accessed           secquentally        \item F_TEMPORARY - Temporay file. The file is automatically deleted           when it is closed.        \item F_RATIO - Used by overrides to check download-ratio before          the file is opened for read.        \end{itemize}                @param Flags        @exception WarException on error    */    virtual void Open(war_uint32_t Flags) throw (WarException);    virtual void Close() throw(WarException);    /** If the file is opened in ASCII mode (text flag),        the bytes read can be larger than the physical file-size,        as CR will be mapped to CRLF. This will not affect        DOS/Windows text files, but unix text files and binary        files.        @param Buf buffer to read from        @param Bytes Bytes to read        @return Bytes read        @exception WarException on error    */    virtual war_uint32_t Read(war_cptr_t Buf, war_uint32_t Bytes)        throw(WarException);    /** Read one line of text. Handles both UNIX and DOS files        The trailing newline character(s) is removed.        @param Str buffer to write to        @Return true if data was read        @exception WarException on error    */    virtual bool ReadLine(std::string& Str)        throw(WarException);    /** If the file is opened in ASCII mode (text flag),        the bytes written can differ from the physical file-size,        as CR will be mapped to CRLF, and LF stripped out from the         output-stream. This will not affect        DOS/Windows text files, but unix text files and binary        files.        @param Buf buffer to write to        @param Bytes Bytes to write        @exception WarException on error    */    virtual void Write(war_ccptr_t Buf,         war_uint32_t Bytes)        throw(WarException);    /** High performance Write function. OnWritten() is       * called when the operation has completed.      *      * Multiple buffers can be queued, something that      * should boost performance on systems that       * supports native I/O callbacks (like Windows NT)      *      * Make no assumptions about threads! The      * OnSent() function can be called by the same      * thread that issued the call, or by any other      * thread. This depends on the IO model used, and      * is handled by the low-level framework      */    virtual void WriteWithCallback(war_transfer_buffer_ptr_t& outBuffer)        throw(WarException);     /** High performance Read function.       *      * Calls OnRead() when completed      * @see WriteWithCallback      */    virtual void ReadWithCallback(war_transfer_buffer_ptr_t& inBuffer)        throw(WarException);    /** Flush caced data to the file. This function does not        guarantee to flush all cached data to the disk before        returning.        Note that the file must be opened for write in order to use        this function.        @exception WarException on error    */    virtual void Flush()        throw(WarException);    /** Seek to a position whithin a file                If the file is opened in ASCII (text flag) mode, the position        will be mapped to the logical text-size in the file. The        relative text-size is the size where all CR's is mappped to         CRLF, and LF's stripped from the stream. This means that the        file is read and parsed, something that makes seeking on        ASCII files a costly operation!        In ASCII mode, the offset must be larger than 2.        @param Offset to seek to        @param Mode - Where to seek from (default is start-of-file).        @return Current offset in the file        @exception WarException on error     */    virtual war_flen_t Seek(war_flen_t Offset,         SeekModes Mode = WAR_SEEK_BEGIN)        throw(WarException);    /** Returns he length of the file. If the file is opened in ASCII mode,        the returned length wil be the relative size of the file, when it        is mapped to ASCII.        @return The Length of the file        @exception WarException on error        @see Flush    */    // ACCESS    WarFileDriverFile& GetFileDriverFile()        throw(WarException)    {        return *mpFile;    }    void AddFrom(const char * from);    void AddFrom(const std::string& from);    void AddFrom(const std::wstring& from);    void AddFrom(const int from);    void AddFrom(const unsigned int from);        template <class slashT>    void AddFrom(const WarPath<char,slashT> from)    {        to.AddFrom(from.GetPath());    }    template <class slashT>    void AddFrom(const WarPath<wchar_t,slashT> from)    {        WarUtf8 conv = from.GetPath();        AddFrom(conv.GetUtf8().c_str());    }    // INQUIRY     virtual war_flen_t GetLength()         throw(WarException);    /** Returns he current position of the file. If the       file is opened in ASCII mode, the returned position       be the relative position of the file, when it       is mapped to ASCII.       @return The current position of the file       @exception WarException on error       @see Flush    */    virtual war_flen_t GetPosition()        throw(WarException);    /// Returns true if the current position is at the end of the file.    virtual bool IsEof() throw(WarException);    /// Test for read access    virtual bool CanRead() throw(WarException);    /// Test for write access    virtual bool CanWrite() throw(WarException);    /// Test if the file is open    virtual bool IsOpen() throw(WarException);    /** Get the current flags/modes of the file, as set when the file        was opened.    */    const war_uint32_t GetFlags() const         throw(WarException);    /** Get the file name        This function can return the file name, pathname        URL, type etc.    */    template <class charT, class slashT>    void GetFileName(WarPath<charT, slashT>& rPath,        NameModes nameMode = NAME_LOGICAL_NAME_ONLY)    {        WarThrow(WarError(WAR_ERR_NOT_IMPLEMENTED), NULL);    };    // Get the default character compare mode for a filesystem    //static PathCmpTypeE GetCmpMode(const <charT, slashT>& rPath)    //{    //}    /* Get a handle to the system handle for the     * file. Only guaranteed to work on native     * files */    virtual war_filehandle_t GetHandle() throw(WarException);    virtual std::string ExplainFags(war_uint32_t fileFlags) const;        /// Get the default character compare mode for a filesystem    PathCmpTypeE GetCmpMode();     /** Returns true if the driver supports       * ReadWithCallback and WriteWithCallback      */    virtual bool CanDoCallback() const;    virtual const WarUrl& GetUrl() const    {        return mUrl;    }protected:    virtual void OnRead(const WarError& status,         war_transfer_buffer_ptr_t& buffer);    virtual void OnWritten(const WarError& status,        war_transfer_buffer_ptr_t& buffer);    virtual void CreateDriverForUrl(const WarUrl& fileUrl)        throw(WarException);    friend class WarFileDriverFile;    WarFileDriver::driver_ptr_t mDriver;    WarUrl mUrl;    WarFileDriverFile *mpFile;    WarFifoBuffer<char> mBuffer;    WarFile();    ~WarFile();    void SyncBufferedIo();    private:};/* INLINE METHODS */template <class fromT>inline WarFile& operator << (WarFile& to, const fromT& from){    to.AddFrom(from);    return to;}/* EXTERNAL REFERENCES */typedef WarPtrWrapper<WarFile> war_file_ptr_t;#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif  /* WAR_FILE_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -