jbm: it compiles... but bombs in unit tests
5 * Created by Jens Alfke on 8/20/09.
6 * Copyright 2009 Jens Alfke. All rights reserved.
7 * BSD-Licensed: See the file "LICENSE.txt" for details.
10 #ifndef _MOOSEYARD_FILE_
11 #define _MOOSEYARD_FILE_
19 /** An open file on disk; a thin wrapper around a Unix file descriptor. */
25 const char* const message;
27 Error(int c, const char *m) :code(c), message(m) { }
30 static const int kEOF = 10001;
33 File (const char *filename, bool writeable =false, bool create =false) throw(Error);
34 File (const char *filename, int oflag, bool locked) throw(Error);
37 off_t length() const throw(Error);
38 void setLength (off_t) throw(Error);
40 off_t position() const throw(Error);
41 void setPosition (off_t) throw(Error);
42 off_t setPositionToEnd (off_t bytesBefore =0) throw(Error);
44 void read (void *dst, size_t) throw(Error);
45 size_t write (const void *src, size_t) throw(Error);
47 void readFrom (off_t where, void *dst, size_t) throw(Error);
48 void writeTo (off_t where, const void *src, size_t) throw(Error);
50 size_t writeMultiple (Blob blobs[], int count) throw(Error);
51 size_t writePadding (int alignment); // alignment should be a power of 2
54 const MemoryMap* map() const {return const_cast<File*>(this)->map();}
55 void mapRegion (off_t position, size_t length);
56 const void* mappedPosition (off_t position) const;
58 void flush() throw(Error); // Regular fsync call
59 void flushDisk() throw(Error); // Expensive F_FULLFSYNC call
62 void read (T& t) throw(Error) {read(&t,sizeof(t));}
64 size_t write (const T& t) throw(Error) {return write(&t,sizeof(t));}
66 void readFrom (off_t where, T &t) throw(Error) {readFrom(where,&t,sizeof(t));}
68 void writeTo (off_t where, const T &t) throw(Error) {writeTo(where,&t,sizeof(t));}
70 bool hasPath (const char *path) const throw(Error);
72 static void unlink (const char *filename) throw(Error);
73 static void rename (const char *srcFilename, const char *dstFilename) throw(Error);
78 Lock (File*, bool block =true) throw(Error);
80 bool isLocked() const {return _locked;}
81 operator bool() const {return _locked;}
91 static int _open (const char *filename, int posixMode) throw(Error);
92 static int _check (int result) throw(Error);
93 #ifdef OSX /* On linux, these are the same type signature to gcc */
94 static ssize_t _check (ssize_t result) throw(Error) {_check((int)result); return result;}
95 static off_t _check (off_t result) throw(Error) {_check((int)result); return result;}
97 static void _checkRead (ssize_t result, size_t expectedSize) throw(Error);
98 bool _lock (bool block);
103 mutable MemoryMap *_memoryMap;
106 friend class MemoryMap;
111 #endif /* _MOOSEYARD_FILE_ */