13 class file_not_found: public std::runtime_error
16 file_not_found(const std::string &fn): std::runtime_error(fn) { }
19 class file_already_exists: public std::runtime_error
22 file_already_exists(const std::string &fn): std::runtime_error(fn) { }
27 A class for reading and writing files.
29 Non-blocking mode is not supported on Win32.
31 class File: public Seekable
39 C_OVERWRITE = C_CREATE+C_TRUNCATE,
41 C_NEW = C_CREATE+C_EXCLUSIVE
48 /** Creates a new file object and opens it. If the create flag is set and
49 write access is requested and the file does exist, it is created. Otherwise
50 a missing file is an error. */
51 File(const std::string &, Mode = M_READ, CreateMode = C_OVERWRITE);
53 void platform_init(const std::string &, CreateMode);
57 void set_block(bool) override;
58 void set_inherit(bool) override;
61 std::size_t do_write(const char *, std::size_t) override;
62 std::size_t do_read(char *, std::size_t) override;
67 SeekOffset seek(SeekOffset, SeekType) override;
68 SeekOffset tell() const override;
70 const Handle &get_handle(Mode) override;
73 inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n)
74 { return File::CreateMode(static_cast<int>(m)|static_cast<int>(n)); }
76 inline File::CreateMode operator&(File::CreateMode m, File::CreateMode n)
77 { return File::CreateMode(static_cast<int>(m)&static_cast<int>(n)); }
79 inline File::CreateMode operator~(File::CreateMode m)
80 { return File::CreateMode(~static_cast<int>(m)); }
83 class BufferedFile: public Seekable
91 BufferedFile(const std::string &, Mode = M_READ, File::CreateMode = File::C_OVERWRITE);
93 void set_block(bool) override;
94 void set_inherit(bool) override;
97 std::size_t do_write(const char *, std::size_t) override;
98 std::size_t do_read(char *, std::size_t) override;
100 std::size_t put(char) override;
102 bool getline(std::string &) override;
105 const Handle &get_handle(Mode) override;
107 SeekOffset seek(SeekOffset, SeekType) override;
108 SeekOffset tell() const override { return position; }