13 class file_not_found: public std::runtime_error
16 file_not_found(const std::string &fn): std::runtime_error(fn) { }
17 virtual ~file_not_found() throw() = default;
20 class file_already_exists: public std::runtime_error
23 file_already_exists(const std::string &fn): std::runtime_error(fn) { }
24 virtual ~file_already_exists() throw() = default;
29 A class for reading and writing files.
31 Non-blocking mode is not supported on Win32.
33 class File: public Seekable
41 C_OVERWRITE = C_CREATE+C_TRUNCATE,
43 C_NEW = C_CREATE+C_EXCLUSIVE
50 /** Creates a new file object and opens it. If the create flag is set and
51 write access is requested and the file does exist, it is created. Otherwise
52 a missing file is an error. */
53 File(const std::string &, Mode = M_READ, CreateMode = C_OVERWRITE);
55 void platform_init(const std::string &, CreateMode);
59 virtual void set_block(bool);
60 virtual void set_inherit(bool);
63 virtual std::size_t do_write(const char *, std::size_t);
64 virtual std::size_t do_read(char *, std::size_t);
69 virtual SeekOffset seek(SeekOffset, SeekType);
70 virtual SeekOffset tell() const;
72 virtual const Handle &get_handle(Mode);
75 inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n)
76 { return File::CreateMode(static_cast<int>(m)|static_cast<int>(n)); }
78 inline File::CreateMode operator&(File::CreateMode m, File::CreateMode n)
79 { return File::CreateMode(static_cast<int>(m)&static_cast<int>(n)); }
81 inline File::CreateMode operator~(File::CreateMode m)
82 { return File::CreateMode(~static_cast<int>(m)); }
85 class BufferedFile: public Seekable
93 BufferedFile(const std::string &, Mode = M_READ, File::CreateMode = File::C_OVERWRITE);
95 virtual void set_block(bool);
96 virtual void set_inherit(bool);
99 virtual std::size_t do_write(const char *, std::size_t);
100 virtual std::size_t do_read(char *, std::size_t);
102 virtual std::size_t put(char);
104 virtual bool getline(std::string &);
107 virtual const Handle &get_handle(Mode);
109 virtual SeekOffset seek(SeekOffset, SeekType);
110 virtual SeekOffset tell() const { return position; }