summaryrefslogtreecommitdiff
path: root/zen/file_io_base.h
blob: f26cd8c2d93e5576759bca3d1d043b6f118b1692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved        *
// **************************************************************************

#ifndef FILEIO_BASE_H_INCLUDED_23432431789615314
#define FILEIO_BASE_H_INCLUDED_23432431789615314

#include "zstring.h"

namespace zen
{
class FileBase
{
public:
    const Zstring& getFilename() const { return filename_; }

protected:
    FileBase(const Zstring& filename) : filename_(filename)  {}
    ~FileBase() {}

private:
    FileBase(const FileBase&);
    FileBase& operator=(const FileBase&);

    const Zstring filename_;
};


class FileInputBase : public FileBase
{
public:
    virtual size_t read(void* buffer, size_t bytesToRead) = 0; //throw FileError; returns actual number of bytes read
    bool eof() const { return eofReached; } //end of file reached

protected:
    FileInputBase(const Zstring& filename) : FileBase(filename), eofReached(false) {}
    ~FileInputBase() {}
    void setEof() { eofReached = true; }

private:
    bool eofReached;
};


class FileOutputBase : public FileBase
{
public:
    enum AccessFlag
    {
        ACC_OVERWRITE,
        ACC_CREATE_NEW
    };
    virtual void write(const void* buffer, size_t bytesToWrite) = 0; //throw FileError

protected:
    FileOutputBase(const Zstring& filename) : FileBase(filename) {}
    ~FileOutputBase() {}
};

}

#endif //FILEIO_BASE_H_INCLUDED_23432431789615314
bgstack15