
/*---------------------------------------------------------------------------*/
/* file.h																     */
/* copyright (c) innovaphone 2016                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/


class FileWrite : public IFileWrite {
    class IInstanceLog * const log;
    FILE * fp;

public:
    FileWrite(class IInstanceLog * const log, const char * filenamePath, bool append = false);
    ~FileWrite();

    bool IsOpen() const override;
    bool Write(const void * buffer, size_t len) override;
    void Flush() override;
    bool Close() override;
};

class FileRead : public IFileRead {
    class IInstanceLog * const log;
    FILE * fp;

public:
    FileRead(class IInstanceLog * const log, const char * filenamePath);
    ~FileRead();

    virtual bool IsOpen() const override;
    virtual size_t Read(void * buffer, size_t len) override;
    virtual bool Close() override;
    virtual bool Seek(size_t offset, Origin origin = Origin::CURRENT) override;
    virtual size_t Pos() override;
    virtual bool EoF() override;
};

class Directory : public IDirectory {
    class IInstanceLog * const log;
    IDirectoryEntry * entry;
    DIR * dir;

public:
    Directory(class IInstanceLog * const log, const char * directoryPath);
    ~Directory();
    
    bool IsOpen() const override;
    class IDirectoryEntry * ReadNext() override;
    bool Close() override;
};

class DirectoryEntry : public IDirectoryEntry {
    char * entryName;
    bool isFile;

public:
    DirectoryEntry(char * entryName, bool isFile);
    virtual ~DirectoryEntry();
    
    const char * GetName() const override;
    bool IsFile() const override;
};
