00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00022
00031 #include <fstream>
00032 #include <stdexcept>
00033 #include "bofstream.h"
00034
00035 void bofstream::seek(long spos, Offset offs)
00036 {
00037 if(!in) { err = NotOpen; return; }
00038
00039 switch(offs) {
00040 case Set: this->seekp(spos, ios::beg); break;
00041 case Add: this->seekp(spos, ios::cur); break;
00042 case End: this->seekp(spos, ios::end); break;
00043 }
00044 }
00045
00046 long bofstream::pos()
00047 {
00048 if(!in) { err = NotOpen; return 0; }
00049 return streamoff (this->tellp ());
00050 }
00051
00052 void bofstream::putByte (bofstream::Byte b)
00053 {
00054 if(!this->good ()) {
00055 err |= NotOpen;
00056 throw runtime_error ("Cannot open binary file for writing");
00057 return;
00058 }
00059
00060 this->put (b);
00061 if (this->bad ())
00062 {
00063 err |= Fatal;
00064 throw runtime_error ("Writing to binary file failed");
00065 }
00066 }
00067
00068
00069
00070 bofstream& operator<< (bofstream& bof, double n)
00071 { bof.writeFloat (n, binio::Double); return (bof); }
00072
00073 bofstream& operator<< (bofstream& bof, float n)
00074 { bof.writeFloat (n, binio::Double); return (bof); }
00075
00076 bofstream& operator<< (bofstream& bof, long n)
00077 { bof.writeInt (n, 4); return (bof); }
00078
00079 bofstream& operator<< (bofstream& bof, int n)
00080 { bof.writeInt (n, 4); return (bof); }
00081