ARTS 2.5.0 (git: 9ee3ac6c)
bifstream.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 "bifstream.h"
31#include <fstream>
32#include <stdexcept>
33
34void bifstream::seek(long spos, Offset offs) {
35 if (!in) {
36 err = NotOpen;
37 return;
38 }
39
40 switch (offs) {
41 case Set:
42 this->seekg(spos, ios::beg);
43 break;
44 case Add:
45 this->seekg(spos, ios::cur);
46 break;
47 case End:
48 this->seekg(spos, ios::end);
49 break;
50 }
51}
52
53streampos bifstream::pos() {
54 if (!in) {
55 err = NotOpen;
56 return 0;
57 }
58 return streampos(this->tellg());
59}
60
62 if (this->good()) {
63 int iread;
64 iread = this->get();
65 if (iread == EOF) err |= Eof;
66 return (Byte)iread;
67 } else {
68 err |= NotOpen;
69 throw runtime_error("Reading from binary file failed");
70 return 0;
71 }
72}
73
74/* Overloaded input operators */
75bifstream& operator>>(bifstream& bif, double& n) {
76 n = (double)bif.readFloat(binio::Double);
77 return (bif);
78}
79
80bifstream& operator>>(bifstream& bif, float& n) {
81 n = (float)bif.readFloat(binio::Double);
82 return (bif);
83}
84
86 n = (long)bif.readInt(4);
87 return (bif);
88}
89
91 n = (int)bif.readInt(4);
92 return (bif);
93}
bifstream & operator>>(bifstream &bif, double &n)
Definition: bifstream.cc:75
This file contains the class declaration of bifstream.
Binary output file stream class.
Definition: bifstream.h:42
void seek(long spos, Offset offs) override final
Definition: bifstream.cc:34
streampos pos() override final
Definition: bifstream.cc:53
bifstream::Byte getByte() override final
Definition: bifstream.cc:61
@ Double
Definition: binio.h:81
@ Eof
Definition: binio.h:77
@ 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
Int readInt(unsigned int size)
Definition: binio.cc:108
Float readFloat(FType ft)
Definition: binio.cc:132
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