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