ARTS 2.5.0 (git: 9ee3ac6c)
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
19// File description
21
30#include "bofstream.h"
31#include <fstream>
32#include <stdexcept>
33
34void bofstream::seek(long spos, Offset offs) {
35 if (!in) {
36 err = NotOpen;
37 return;
38 }
39
40 switch (offs) {
41 case Set:
42 this->seekp(spos, ios::beg);
43 break;
44 case Add:
45 this->seekp(spos, ios::cur);
46 break;
47 case End:
48 this->seekp(spos, ios::end);
49 break;
50 }
51}
52
53streampos bofstream::pos() {
54 if (!in) {
55 err = NotOpen;
56 return 0;
57 }
58 return streamoff(this->tellp());
59}
60
62 if (!this->good()) {
63 err |= NotOpen;
64 ARTS_USER_ERROR ("Cannot open binary file for writing");
65 return;
66 }
67
68 this->put(b);
69 if (this->bad()) {
70 err |= Fatal;
71 ARTS_USER_ERROR ("Writing to binary file failed");
72 }
73}
74
75/* Overloaded output operators */
76bofstream& operator<<(bofstream& bof, double n) {
78 return (bof);
79}
80
83 return (bof);
84}
85
87 bof.writeInt(n, 4);
88 return (bof);
89}
90
92 bof.writeInt(n, 4);
93 return (bof);
94}
bofstream & operator<<(bofstream &bof, double n)
Definition: bofstream.cc:76
This file contains the class declaration of bofstream.
@ Double
Definition: binio.h:81
@ Fatal
Definition: binio.h:72
@ NotOpen
Definition: binio.h:74
Offset
Definition: binio.h:80
@ Add
Definition: binio.h:80
@ End
Definition: binio.h:80
@ Set
Definition: binio.h:80
unsigned char Byte
Definition: binio.h:99
Error err
Definition: binio.h:105
void writeInt(Int val, unsigned int size)
Definition: binio.cc:399
void writeFloat(Float f, FType ft)
Definition: binio.cc:420
Binary output file stream class.
Definition: bofstream.h:42
streampos pos() override final
Definition: bofstream.cc:53
void putByte(bofstream::Byte b) override final
Definition: bofstream.cc:61
void seek(long spos, Offset offs) override final
Definition: bofstream.cc:34
#define ARTS_USER_ERROR(...)
Definition: debug.h:150
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:109
#define b