ARTS  2.4.0(git:4fb77825)
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 
34 void 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 
53 streampos 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 */
75 bifstream& operator>>(bifstream& bif, double& n) {
76  n = (double)bif.readFloat(binio::Double);
77  return (bif);
78 }
79 
80 bifstream& operator>>(bifstream& bif, float& n) {
81  n = (float)bif.readFloat(binio::Double);
82  return (bif);
83 }
84 
85 bifstream& operator>>(bifstream& bif, long& n) {
86  n = (long)bif.readInt(4);
87  return (bif);
88 }
89 
90 bifstream& operator>>(bifstream& bif, int& n) {
91  n = (int)bif.readInt(4);
92  return (bif);
93 }
binio::Set
@ Set
Definition: binio.h:80
binio::err
Error err
Definition: binio.h:105
binio::Add
@ Add
Definition: binio.h:80
operator>>
bifstream & operator>>(bifstream &bif, double &n)
Definition: bifstream.cc:75
bifstream::seek
void seek(long spos, Offset offs) override final
Definition: bifstream.cc:34
bifstream
Binary output file stream class.
Definition: bifstream.h:42
binio::End
@ End
Definition: binio.h:80
bifstream.h
This file contains the class declaration of bifstream.
Zeeman::end
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:108
binio::Offset
Offset
Definition: binio.h:80
bifstream::pos
streampos pos() override final
Definition: bifstream.cc:53
binio::NotOpen
@ NotOpen
Definition: binio.h:74
binistream::readInt
Int readInt(unsigned int size)
Definition: binio.cc:108
binistream::readFloat
Float readFloat(FType ft)
Definition: binio.cc:132
binio::Byte
unsigned char Byte
Definition: binio.h:99
binio::Eof
@ Eof
Definition: binio.h:77
bifstream::getByte
bifstream::Byte getByte() override final
Definition: bifstream.cc:61
binio::Double
@ Double
Definition: binio.h:81