ARTS  2.2.66
bofstream.cc
Go to the documentation of this file.
1 /* Copyright (C) 2003-2012 Oliver Lemke <olemke@core-dump.info>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
18 
20 // File description
22 
31 #include <fstream>
32 #include <stdexcept>
33 #include "bofstream.h"
34 
35 void bofstream::seek(long spos, Offset offs)
36 {
37  if(!in) { err = NotOpen; return; }
38 
39  switch(offs) {
40  case Set: this->seekp(spos, ios::beg); break;
41  case Add: this->seekp(spos, ios::cur); break;
42  case End: this->seekp(spos, ios::end); break;
43  }
44 }
45 
46 streampos bofstream::pos()
47 {
48  if(!in) { err = NotOpen; return 0; }
49  return streamoff (this->tellp ());
50 }
51 
53 {
54  if(!this->good ()) {
55  err |= NotOpen;
56  throw runtime_error ("Cannot open binary file for writing");
57  return;
58  }
59 
60  this->put (b);
61  if (this->bad ())
62  {
63  err |= Fatal;
64  throw runtime_error ("Writing to binary file failed");
65  }
66 }
67 
68 
69 /* Overloaded output operators */
71 { bof.writeFloat (n, binio::Double); return (bof); }
72 
74 { bof.writeFloat (n, binio::Double); return (bof); }
75 
77 { bof.writeInt (n, 4); return (bof); }
78 
80 { bof.writeInt (n, 4); return (bof); }
81 
unsigned char Byte
Definition: binio.h:103
void seek(long spos, Offset offs)
Definition: bofstream.cc:35
Error err
Definition: binio.h:109
streampos pos()
Definition: bofstream.cc:46
This file contains the class declaration of bofstream.
bofstream & operator<<(bofstream &bof, double n)
Definition: bofstream.cc:70
Offset
Definition: binio.h:84
void writeFloat(Float f, FType ft)
Definition: binio.cc:437
void writeInt(Int val, unsigned int size)
Definition: binio.cc:416
Binary output file stream class.
Definition: bofstream.h:44
void putByte(bofstream::Byte b)
Definition: bofstream.cc:52