libdballe  7.7
core/file.h
1 #ifndef DBA_CORE_FILE_H
2 #define DBA_CORE_FILE_H
3 
4 #include <dballe/file.h>
5 #include <dballe/core/defs.h>
6 #include <memory>
7 #include <string>
8 #include <cstdio>
9 
10 namespace dballe {
11 namespace core {
12 
14 class File : public dballe::File
15 {
16 protected:
18  std::string m_name;
20  FILE* fd;
24  int idx;
25 
26 public:
27  File(const std::string& name, FILE* fd, bool close_on_exit=true);
28  virtual ~File();
29 
30  std::string pathname() const override { return m_name; }
31  bool foreach(std::function<bool(const BinaryMessage&)> dest) override;
32 
38  static std::string resolve_test_data_file(const std::string& name);
39 
45  static std::unique_ptr<dballe::File> open_test_data_file(Encoding type, const std::string& name);
46 };
47 
49 {
50 public:
51  BufrFile(const std::string& name, FILE* fd, bool close_on_exit=true)
52  : File(name, fd, close_on_exit) {}
53 
54  Encoding encoding() const override { return BUFR; }
55  BinaryMessage read() override;
56  void write(const std::string& msg) override;
57 };
58 
60 {
61 public:
62  CrexFile(const std::string& name, FILE* fd, bool close_on_exit=true)
63  : File(name, fd, close_on_exit) {}
64 
65  Encoding encoding() const override { return CREX; }
66  BinaryMessage read() override;
67  void write(const std::string& msg) override;
68 };
69 
70 }
71 }
72 #endif
Encoding
Supported encodings.
Definition: file.h:20
virtual BinaryMessage read()=0
Read a message from the file.
static std::unique_ptr< dballe::File > open_test_data_file(Encoding type, const std::string &name)
Open a test data file.
std::string m_name
Name of the file.
Definition: core/file.h:18
Definition: core/file.h:59
Encoding encoding() const override
Get the file encoding.
Definition: core/file.h:65
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
virtual void write(const std::string &msg)=0
Append the binary message to the file.
FILE * fd
FILE structure used to read or write to the file.
Definition: core/file.h:20
std::string pathname() const override
Get the file pathname.
Definition: core/file.h:30
int idx
Index of the last message read from the file or written to the file.
Definition: core/file.h:24
static std::string resolve_test_data_file(const std::string &name)
Resolve the location of a test data file.
Binary message.
Definition: file.h:131
Definition: core/file.h:48
Common definitions.
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
Encoding encoding() const override
Get the file encoding.
Definition: core/file.h:54
File object for doing I/O on binary message streams.
Definition: file.h:17