]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/file.h
Add no-throw destructors to exception classes that were lacking one
[libs/core.git] / source / io / file.h
index 05aaf9565a08653f278773e010fee4acb6361779..90a1041ccda6520db5386b724f43fe6e936bfe85 100644 (file)
@@ -1,28 +1,47 @@
 #ifndef MSP_IO_FILE_H_
 #define MSP_IO_FILE_H_
 
+#include <stdexcept>
 #include <string>
-#include "base.h"
 #include "buffered.h"
 #include "filtered.h"
-#include "seek.h"
+#include "handle.h"
+#include "seekable.h"
 
 namespace Msp {
 namespace IO {
 
+class file_not_found: public std::runtime_error
+{
+public:
+       file_not_found(const std::string &fn): std::runtime_error(fn) { }
+       ~file_not_found() throw() { }
+};
+
+class file_already_exists: public std::runtime_error
+{
+public:
+       file_already_exists(const std::string &fn): std::runtime_error(fn) { }
+       ~file_already_exists() throw() { }
+};
+
+
 /**
 A class for reading and writing files.
 
 Non-blocking mode is not supported on Win32.
 */
-class File: public Base
+class File: public Seekable
 {
 public:
        enum CreateMode
        {
                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:
@@ -32,13 +51,9 @@ 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();
 
-       /** 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:
@@ -48,16 +63,10 @@ protected:
 public:
        virtual void sync();
 
-       /** Changes the read/write offset of the file.  Returns the new offset. */
-       virtual int seek(int, SeekType);
-       
-       /** Returns the current read/write offset of the file. */
-       virtual int 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)