X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Ffile.h;h=5fb0353211b2e99d23384afa2924e87ee78acc10;hp=cd547b37545cb23b6f0c3842c512a7cf13847905;hb=8642ac1b4478419630911a51a53fe8ef5fb46647;hpb=e4afb5edb0b7834ef4872218c99207e6b589e9ce diff --git a/source/io/file.h b/source/io/file.h index cd547b3..5fb0353 100644 --- a/source/io/file.h +++ b/source/io/file.h @@ -17,6 +17,12 @@ public: file_not_found(const std::string &fn): std::runtime_error(fn) { } }; +class file_already_exists: public std::runtime_error +{ +public: + file_already_exists(const std::string &fn): std::runtime_error(fn) { } +}; + /** A class for reading and writing files. @@ -30,7 +36,10 @@ public: { C_NONE = 0, C_CREATE = 1, - C_TRUNCATE = 2 + C_TRUNCATE = 2, + C_OVERWRITE = C_CREATE+C_TRUNCATE, + C_EXCLUSIVE = 4, + C_NEW = C_CREATE+C_EXCLUSIVE }; private: @@ -40,7 +49,7 @@ public: /** Creates a new file object and opens it. If the create flag is set and write access is requested and the file does exist, it is created. Otherwise a missing file is an error. */ - File(const std::string &, Mode = M_READ, CreateMode = CreateMode(C_CREATE+C_TRUNCATE)); + File(const std::string &, Mode = M_READ, CreateMode = C_OVERWRITE); virtual ~File(); void set_block(bool); @@ -55,8 +64,7 @@ public: virtual SeekOffset seek(SeekOffset, SeekType); virtual SeekOffset tell() const; -private: - void check_access(Mode) const; + virtual const Handle &get_handle(Mode); }; inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n)