14 class file_not_found: public std::runtime_error
17 file_not_found(const std::string &fn): std::runtime_error(fn) { }
18 virtual ~file_not_found() throw() = default;
21 class file_already_exists: public std::runtime_error
24 file_already_exists(const std::string &fn): std::runtime_error(fn) { }
25 virtual ~file_already_exists() throw() = default;
30 A class for reading and writing files.
32 Non-blocking mode is not supported on Win32.
34 class File: public Seekable
42 C_OVERWRITE = C_CREATE+C_TRUNCATE,
44 C_NEW = C_CREATE+C_EXCLUSIVE
51 /** Creates a new file object and opens it. If the create flag is set and
52 write access is requested and the file does exist, it is created. Otherwise
53 a missing file is an error. */
54 File(const std::string &, Mode = M_READ, CreateMode = C_OVERWRITE);
56 void platform_init(const std::string &, CreateMode);
60 virtual void set_block(bool);
61 virtual void set_inherit(bool);
64 virtual std::size_t do_write(const char *, std::size_t);
65 virtual std::size_t do_read(char *, std::size_t);
70 virtual SeekOffset seek(SeekOffset, SeekType);
71 virtual SeekOffset tell() const;
73 virtual const Handle &get_handle(Mode);
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, File::CreateMode n)
80 { return File::CreateMode(static_cast<int>(m)&static_cast<int>(n)); }
82 inline File::CreateMode operator~(File::CreateMode m)
83 { return File::CreateMode(~static_cast<int>(m)); }
86 class BufferedFile: public Seekable
94 BufferedFile(const std::string &, Mode = M_READ, File::CreateMode = File::C_OVERWRITE);
96 virtual void set_block(bool);
97 virtual void set_inherit(bool);
100 virtual std::size_t do_write(const char *, std::size_t);
101 virtual std::size_t do_read(char *, std::size_t);
103 virtual std::size_t put(char);
105 virtual bool getline(std::string &);
108 virtual const Handle &get_handle(Mode);
110 virtual SeekOffset seek(SeekOffset, SeekType);
111 virtual SeekOffset tell() const { return position; }