some initial stream api stuff

master
Daniel Kolesa 2015-06-26 02:30:48 +01:00
parent 9a6caffefe
commit 6b32072694
1 changed files with 37 additions and 4 deletions

View File

@ -6,11 +6,44 @@
#ifndef OCTA_STREAM_H
#define OCTA_STREAM_H
#include <stdio.h>
#include <sys/types.h>
#include "octa/types.h"
#include "octa/range.h"
namespace octa {
struct stream {
stream() {}
virtual ~stream() {}
};
/* off_t is POSIX - will also work on windows with mingw/clang, but FIXME */
using StreamOffset = off_t;
enum class Seek {
cur = SEEK_CUR,
end = SEEK_END,
set = SEEK_SET
};
struct Stream {
using Offset = StreamOffset;
virtual void close() = 0;
virtual bool end() = 0;
virtual Offset size() {
Offset p = tell();
if ((p < 0) || !seek(0, Seek::end)) return -1;
Offset e = tell();
return (p == e) || (seek(p, Seek::set) ? e : -1);
}
virtual bool seek(Offset pos, Seek whence = Seek::set) { return false; }
virtual Offset tell() { return -1; }
virtual bool flush() { return true; }
};
}
#endif