]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/file.h
Add an exclusive create flag to IO::File
[libs/core.git] / source / io / file.h
index d59cd577fc0f33e1acbcbb62bcaa9fa0bb31c141..4f8e5ddf8612b559f82ce5bfc7c2623ba5860cc9 100644 (file)
@@ -5,6 +5,7 @@
 #include <string>
 #include "buffered.h"
 #include "filtered.h"
+#include "handle.h"
 #include "seekable.h"
 
 namespace Msp {
@@ -16,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.
@@ -29,7 +36,8 @@ public:
        {
                C_NONE = 0,
                C_CREATE = 1,
-               C_TRUNCATE = 2
+               C_TRUNCATE = 2,
+               C_EXCLUSIVE = 4
        };
 
 private:
@@ -42,10 +50,6 @@ public:
        File(const std::string &, Mode = M_READ, CreateMode = CreateMode(C_CREATE+C_TRUNCATE));
        virtual ~File();
 
-       /** Closes the file.  Any attempt to access the file after this will cause
-       an exception to be thrown. */
-       void close();
-
        void set_block(bool);
 
 protected:
@@ -55,13 +59,10 @@ protected:
 public:
        virtual void sync();
 
-       virtual unsigned seek(int, SeekType);
-       virtual unsigned tell() const;
-
-       virtual Handle get_event_handle() { return handle; }
+       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)