/usr/include/dballe/file.h is in libdballe-dev 7.21-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | #ifndef DBALLE_FILE_H
#define DBALLE_FILE_H
#include <dballe/types.h>
#include <memory>
#include <string>
namespace dballe {
struct BinaryMessage;
/**
* File object for doing I/O on binary message streams.
*
* It provides a unified interface to read and write messages to files.
*/
struct File
{
/// Supported encodings
typedef enum {
BUFR = 0,
CREX = 1,
AOF = 2,
} Encoding;
virtual ~File();
/// Get the file pathname
virtual std::string pathname() const = 0;
/// Get the file encoding
virtual Encoding encoding() const = 0;
/**
* Read a message from the file.
*
* @return
* the BinaryMessage with the binary data that have been read, or nullptr
* when the end of file has been reached.
*/
virtual BinaryMessage read() = 0;
/**
* Read all the messages from the file, calling the function on each of
* them.
*
* If @a dest returns false, reading will stop.
*
* @return
* true if all file was read, false if reading was stopped because
* @a dest returned false.
*/
virtual bool foreach(std::function<bool(const BinaryMessage&)> dest) = 0;
/// Append the binary message to the file
virtual void write(const std::string& msg) = 0;
/**
* Open a file from the filesystem, autodetecting the encoding type.
*
* @param pathname
* The pathname of the file to access.
* @param mode
* The opening mode of the file, as used by fopen.
* @returns
* The new File object.
*/
static std::unique_ptr<File> create(const std::string& pathname, const char* mode);
/**
* Open a file from the filesystem.
*
* @param type
* The type of data contained in the file.
* @param pathname
* The pathname of the file to access.
* @param mode
* The opening mode of the file, as used by fopen.
* @returns
* The new File object.
*/
static std::unique_ptr<File> create(Encoding type, const std::string& pathname, const char* mode);
/**
* Create a File from an existing FILE* stream, autodetecting the encoding
* type.
*
* @param file
* The FILE* stream for the file to access.
* @param close_on_exit
* If true, fclose() will be called on the stream when the File object is
* destroyed.
* @param name
* Pathname or description of the stream, used when generating error
* messages
* @returns
* The new File object.
*/
static std::unique_ptr<File> create(FILE* file, bool close_on_exit, const std::string& name="(fp)");
/**
* Create a File from an existing FILE* stream.
*
* @param type
* The type of data contained in the file.
* @param file
* The FILE* stream for the file to access.
* @param close_on_exit
* If true, fclose() will be called on the stream when the File object is
* destroyed.
* @param name
* Pathname or description of the stream, used when generating error
* messages
* @returns
* The new File object.
*/
static std::unique_ptr<File> create(Encoding type, FILE* file, bool close_on_exit, const std::string& name="(fp)");
/// Return a string with the name of this encoding
static const char* encoding_name(Encoding enc);
/// Return the Encoding corresponding to the given name
static Encoding parse_encoding(const char* s);
/// Return the Encoding corresponding to the given name
static Encoding parse_encoding(const std::string& s);
};
/// Binary message
struct BinaryMessage
{
/// Format of the binary data
File::Encoding encoding;
/// Binary message data
std::string data;
/**
* Pathname of the file from where the BinaryMessage has been read. It can be
* empty when not applicable, such as when the message is created from
* scratch and not yet written
*/
std::string pathname;
/// Start offset of this message inside the file
off_t offset = (off_t)-1;
/// Index of the message from the beginning of the file
int index = MISSING_INT;
BinaryMessage(File::Encoding encoding)
: encoding(encoding) {}
/// Return true if the message is not empty
operator bool() const;
};
}
#endif
|