libdballe  7.19
aoffile.h
Go to the documentation of this file.
1 /*
2  * dballe/aoffile - AOF File I/O
3  *
4  * Copyright (C) 2005--2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBA_CORE_AOFFILE_H
23 #define DBA_CORE_AOFFILE_H
24 
32 #include <dballe/core/file.h>
33 #include <stdint.h>
34 
35 namespace dballe {
36 namespace core {
37 
39 {
40 protected:
49  bool read_record(std::string& res);
50 
58  void write_record(const std::string& res);
59 
69  void write_record(const uint32_t* words, size_t wordcount);
70 
74  void write_word(uint32_t word);
75 
76 public:
77  AofFile(const std::string& name, FILE* fd, bool close_on_exit=true);
78  virtual ~AofFile();
79 
80  virtual Encoding encoding() const override { return AOF; }
81  BinaryMessage read() override;
82  void write(const std::string& msg) override;
83 
88  void read_header();
89 
91  void write_dummy_header();
92 
96  void fix_header();
97 };
98 
99 }
100 }
101 #endif
Encoding
Supported encodings.
Definition: file.h:20
void write_record(const std::string &res)
Write a Fortran Unformatted Sequential Binary record to a file.
void write_dummy_header()
Write a dummy file header.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
FILE * fd
FILE structure used to read or write to the file.
Definition: core/file.h:20
Definition: aoffile.h:38
void write_word(uint32_t word)
Write a word to the file, byteswapping it for endianness if needed.
virtual Encoding encoding() const override
Get the file encoding.
Definition: aoffile.h:80
void read_header()
Read the file header, perform some consistency checks then discard the data.
void fix_header()
Rewrite the file header, scanning the file to compute a correct one.
Binary message.
Definition: file.h:131
void write(const std::string &msg) override
Append the binary message to the file.
bool read_record(std::string &res)
Read a Fortran Unformatted Sequential Binary record from a file.
bool close_on_exit
True if fd should be closed on destruction.
Definition: core/file.h:22
Base for dballe::File implementations.
Definition: core/file.h:14
BinaryMessage read() override
Read a message from the file.