6 #include <msp/core/mspcore_api.h>
14 class MSPCORE_API file_not_found: public std::runtime_error
17 file_not_found(const std::string &fn): std::runtime_error(fn) { }
20 class MSPCORE_API file_already_exists: public std::runtime_error
23 file_already_exists(const std::string &fn): std::runtime_error(fn) { }
28 A class for reading and writing files.
30 Non-blocking mode is not supported on Win32.
32 class MSPCORE_API File: public Seekable
40 C_OVERWRITE = C_CREATE+C_TRUNCATE,
42 C_NEW = C_CREATE+C_EXCLUSIVE
49 /** Creates a new file object and opens it. If the create flag is set and
50 write access is requested and the file does exist, it is created. Otherwise
51 a missing file is an error. */
52 File(const std::string &, Mode = M_READ, CreateMode = C_OVERWRITE);
54 void platform_init(const std::string &, CreateMode);
58 void set_block(bool) override;
59 void set_inherit(bool) override;
62 std::size_t do_write(const char *, std::size_t) override;
63 std::size_t do_read(char *, std::size_t) override;
68 SeekOffset seek(SeekOffset, SeekType) override;
69 SeekOffset tell() const override;
71 const Handle &get_handle(Mode) override;
74 inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n)
75 { return File::CreateMode(static_cast<int>(m)|static_cast<int>(n)); }
77 inline File::CreateMode operator&(File::CreateMode m, File::CreateMode n)
78 { return File::CreateMode(static_cast<int>(m)&static_cast<int>(n)); }
80 inline File::CreateMode operator~(File::CreateMode m)
81 { return File::CreateMode(~static_cast<int>(m)); }
84 class MSPCORE_API BufferedFile: public Seekable
92 BufferedFile(const std::string &, Mode = M_READ, File::CreateMode = File::C_OVERWRITE);
94 void set_block(bool) override;
95 void set_inherit(bool) override;
98 std::size_t do_write(const char *, std::size_t) override;
99 std::size_t do_read(char *, std::size_t) override;
101 std::size_t put(char) override;
103 bool getline(std::string &) override;
106 const Handle &get_handle(Mode) override;
108 SeekOffset seek(SeekOffset, SeekType) override;
109 SeekOffset tell() const override { return position; }