ARTS 2.5.11 (git: 6827797f)
bofstream.cc
Go to the documentation of this file.
1
2// File description
4
13#include "bofstream.h"
14#include <fstream>
15#include <stdexcept>
16
17void bofstream::seek(long spos, Offset offs) {
18 if (!in) {
19 err = NotOpen;
20 return;
21 }
22
23 switch (offs) {
24 case Set:
25 this->seekp(spos, ios::beg);
26 break;
27 case Add:
28 this->seekp(spos, ios::cur);
29 break;
30 case End:
31 this->seekp(spos, ios::end);
32 break;
33 }
34}
35
36streampos bofstream::pos() {
37 if (!in) {
38 err = NotOpen;
39 return 0;
40 }
41 return streamoff(this->tellp());
42}
43
45 if (!this->good()) {
46 err |= NotOpen;
47 ARTS_USER_ERROR ("Cannot open binary file for writing");
48 return;
49 }
50
51 this->put(b);
52 if (this->bad()) {
53 err |= Fatal;
54 ARTS_USER_ERROR ("Writing to binary file failed");
55 }
56}
57
58/* Overloaded output operators */
59bofstream& operator<<(bofstream& bof, double n) {
60 bof.writeFloat(n, binio::Double);
61 return (bof);
62}
63
65 bof.writeFloat(n, binio::Double);
66 return (bof);
67}
68
69bofstream& operator<<(bofstream& bof, std::int64_t n) {
70 bof.writeInt(n, 4);
71 return (bof);
72}
73
75 bof.writeInt(n, 4);
76 return (bof);
77}
bofstream & operator<<(bofstream &bof, double n)
Definition: bofstream.cc:59
This file contains the class declaration of bofstream.
enum { Set, Add, End } Offset
Definition: binio.h:64
unsigned char Byte
Definition: binio.h:82
Error err
Definition: binio.h:88
void writeInt(Int val, unsigned int size)
Definition: binio.cc:277
void writeFloat(Float f, FType ft)
Definition: binio.cc:298
Binary output file stream class.
Definition: bofstream.h:25
streampos pos() override final
Definition: bofstream.cc:36
void putByte(bofstream::Byte b) override final
Definition: bofstream.cc:44
void seek(long spos, Offset offs) override final
Definition: bofstream.cc:17
#define ARTS_USER_ERROR(...)
Definition: debug.h:151
#define b