X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffile.h;h=05aaf9565a08653f278773e010fee4acb6361779;hp=49b596bb943077411db57b0bc66044de8de87a92;hb=b97d4e9f86e90254ab9edef7ee62a910f6333c78;hpb=c0861d1f8e3869f058bc8b152cd35a08e5b03e73 diff --git a/source/file.h b/source/file.h index 49b596b..05aaf95 100644 --- a/source/file.h +++ b/source/file.h @@ -1,14 +1,10 @@ -/* $Id$ - -This file is part of libmspio -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ #ifndef MSP_IO_FILE_H_ #define MSP_IO_FILE_H_ #include #include "base.h" +#include "buffered.h" +#include "filtered.h" #include "seek.h" namespace Msp { @@ -24,42 +20,56 @@ class File: public Base public: enum CreateMode { - C_NONE=0, - C_CREATE=1, - C_TRUNCATE=2 + C_NONE = 0, + C_CREATE = 1, + C_TRUNCATE = 2 }; - File(const std::string &, Mode=M_READ, CreateMode =CreateMode(C_CREATE+C_TRUNCATE)); +private: + Handle handle; +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)); + 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); - void enable_events(); - void sync(); +protected: + virtual unsigned do_write(const char *, unsigned); + virtual unsigned do_read(char *, unsigned); - int seek(int, SeekType); - int tell() const; +public: + virtual void sync(); - Handle get_event_handle() { return handle; } + /** 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; - ~File(); -private: - Handle handle; + virtual Handle get_event_handle() { return handle; } - void check_access(Mode) const; - unsigned do_write(const char *, unsigned); - unsigned do_read(char *, unsigned); +private: + void check_access(Mode) const; }; inline File::CreateMode operator|(File::CreateMode m, File::CreateMode n) -{ return File::CreateMode((int)m|(int)n); } +{ return File::CreateMode(static_cast(m)|static_cast(n)); } inline File::CreateMode operator&(File::CreateMode m, File::CreateMode n) -{ return File::CreateMode((int)m&(int)n); } +{ return File::CreateMode(static_cast(m)&static_cast(n)); } inline File::CreateMode operator~(File::CreateMode m) -{ return File::CreateMode(~(int)m); } +{ return File::CreateMode(~static_cast(m)); } + +typedef Filtered BufferedFile; } // namespace IO } // namespace Msp