#endif
}
-int File::seek(int off, SeekType st)
+unsigned File::seek(int off, SeekType st)
{
check_access(M_NONE);
if(ret==INVALID_SET_FILE_POINTER)
throw system_error("SetFilePointer");
#else
- int ret = lseek(handle, off, type);
- if(ret==-1)
+ off_t ret = lseek(handle, off, type);
+ if(ret==(off_t)-1)
throw system_error("lseek");
#endif
return ret;
}
-int File::tell() const
+unsigned File::tell() const
{
check_access(M_NONE);
if(ret==INVALID_SET_FILE_POINTER)
throw system_error("SetFilePointer");
#else
- int ret = lseek(handle, 0, SEEK_CUR);
- if(ret==-1)
+ off_t ret = lseek(handle, 0, SEEK_CUR);
+ if(ret==(off_t)-1)
throw system_error("lseek");
#endif
#include <stdexcept>
#include <string>
-#include "base.h"
#include "buffered.h"
#include "filtered.h"
-#include "seek.h"
+#include "seekable.h"
namespace Msp {
namespace IO {
Non-blocking mode is not supported on Win32.
*/
-class File: public Base
+class File: public Seekable
{
public:
enum CreateMode
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 unsigned seek(int, SeekType);
+ virtual unsigned tell() const;
virtual Handle get_event_handle() { return handle; }
#ifndef MSP_IO_MEMORY_H_
#define MSP_IO_MEMORY_H_
-#include "base.h"
-#include "seek.h"
+#include "seekable.h"
namespace Msp {
namespace IO {
-class Memory: public Base
+class Memory: public Seekable
{
private:
char *begin;
virtual bool getline(std::string &);
virtual int get();
- unsigned seek(int, SeekType);
- unsigned tell() const { return pos-begin; }
+ virtual unsigned seek(int, SeekType);
+ virtual unsigned tell() const { return pos-begin; }
virtual Handle get_event_handle();
+++ /dev/null
-#ifdef WIN32
-#include <windows.h>
-#endif
-#include <stdexcept>
-#include "seek.h"
-
-using namespace std;
-
-namespace Msp {
-namespace IO {
-
-int sys_seek_type(SeekType st)
-{
-#ifdef WIN32
- if(st==S_BEG)
- return FILE_BEGIN;
- else if(st==S_CUR)
- return FILE_CURRENT;
- else if(st==S_END)
- return FILE_END;
-#else
- if(st==S_BEG)
- return SEEK_SET;
- else if(st==S_CUR)
- return SEEK_CUR;
- else if(st==S_END)
- return SEEK_END;
-#endif
-
- throw invalid_argument("Invalid seek type");
-}
-
-} // namespace IO
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_IO_SEEK_H_
-#define MSP_IO_SEEK_H_
-
-namespace Msp {
-namespace IO {
-
-enum SeekType
-{
- S_BEG,
- S_CUR,
- S_END
-};
-
-extern int sys_seek_type(SeekType);
-
-} // namespace IO
-} // namespace Msp
-
-#endif
--- /dev/null
+#ifdef WIN32
+#include <windows.h>
+#endif
+#include <stdexcept>
+#include "seekable.h"
+
+using namespace std;
+
+namespace Msp {
+namespace IO {
+
+int sys_seek_type(SeekType st)
+{
+#ifdef WIN32
+ if(st==S_BEG)
+ return FILE_BEGIN;
+ else if(st==S_CUR)
+ return FILE_CURRENT;
+ else if(st==S_END)
+ return FILE_END;
+#else
+ if(st==S_BEG)
+ return SEEK_SET;
+ else if(st==S_CUR)
+ return SEEK_CUR;
+ else if(st==S_END)
+ return SEEK_END;
+#endif
+
+ throw invalid_argument("sys_seek_type");
+}
+
+} // namespace IO
+} // namespace Msp
--- /dev/null
+#ifndef MSP_IO_SEEKABLE_H_
+#define MSP_IO_SEEKABLE_H_
+
+#include "base.h"
+
+namespace Msp {
+namespace IO {
+
+enum SeekType
+{
+ S_BEG,
+ S_CUR,
+ S_END
+};
+
+int sys_seek_type(SeekType);
+
+
+class Seekable: public Base
+{
+protected:
+ Seekable() { }
+
+public:
+ /** Changes the read/write offset. Returns the new offset. */
+ virtual unsigned seek(int, SeekType) = 0;
+
+ /** Returns the current read/write offset. */
+ virtual unsigned tell() const = 0;
+};
+
+} // namespace IO
+} // namespace Msp
+
+#endif