/usr/include/wreport/bulletin.h is in libwreport-dev 2.1-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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | /*
* wreport/bulletin - Decoded weather bulletin
*
* Copyright (C) 2005--2011 ARPA-SIM <urpsim@smr.arpa.emr.it>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Enrico Zini <enrico@enricozini.com>
*/
#ifndef WREPORT_BULLETIN_H
#define WREPORT_BULLETIN_H
/** @file
* @ingroup bufrex
* Intermediate representation of parsed values, ordered according to a BUFR or
* CREX message template.
*/
#include <wreport/var.h>
#include <wreport/subset.h>
#include <vector>
#include <memory>
/**
* Main namespace
*/
namespace wreport {
namespace bulletin {
struct Visitor;
struct BufrInput;
}
struct DTable;
/**
* Storage for the decoded data of a BUFR or CREX message.
*/
struct Bulletin
{
/**
* Input file name (optional).
*
* If available, it will be used to generate better error messages.
*
* If not available, it is NULL.
*/
const char* fname;
/**
* File offset of the start of the message.
*
* If available, it will be used to generate better error messages.
*
* If not available, it is 0.
*/
size_t offset;
/** Message category */
int type;
/** International message subcategory */
int subtype;
/** Local message subcategory */
int localsubtype;
/** Edition number */
int edition;
/** Master table number */
int master_table_number;
/** Representative datetime for this data
* @{ */
int rep_year; /**< Year */
int rep_month; /**< Month */
int rep_day; /**< Day */
int rep_hour; /**< Hour */
int rep_minute; /**< Minute */
int rep_second; /**< Second */
/** @} */
/** vartable used to lookup B table codes */
const Vartable* btable;
/** dtable used to lookup D table codes */
const DTable* dtable;
/** Parsed data descriptor section */
std::vector<Varcode> datadesc;
/** Decoded variables */
std::vector<Subset> subsets;
Bulletin();
virtual ~Bulletin();
/// Reset the bulletin
virtual void clear();
/** Type of source/target encoding */
virtual const char* encoding_name() const throw () = 0;
/**
* Get a Subset from the message.
*
* The subset will be created if it does not exist, and it will be
* memory managed by the Bulletin.
*
* @param subsection
* The subsection index (starting from 0)
*/
Subset& obtain_subset(unsigned subsection);
/**
* Get a Subset from the message.
*
* An exception will be thrown if the subset does not exist
*
* @param subsection
* The subsection index (starting from 0)
*/
const Subset& subset(unsigned subsection) const;
/// Load a new set of tables to use for encoding this message
virtual void load_tables() = 0;
/**
* Parse only the header of an encoded message
*
* @param buf
* The buffer to decode
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
*/
virtual void decode_header(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
/**
* Parse an encoded message
*
* @param buf
* The buffer to decode
* @param fname
* The file name to use for error messages
* @param offset
* The offset inside the file of the start of the bulletin, used for
* error messages
*/
virtual void decode(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
/**
* Encode the message
*/
virtual void encode(std::string& buf) const = 0;
/**
* Walk the structure of the data descriptor section sending events to an
* opcode::Explorer
*/
void visit_datadesc(opcode::Visitor& e) const;
/**
* Run the Data Descriptor Section interpreter, sending commands to \a
* executor
*/
void visit(bulletin::Visitor& out) const;
/**
* Dump the contents of this bulletin
*/
void print(FILE* out) const;
/**
* Dump the contents of this bulletin, in a more structured way
*/
void print_structured(FILE* out) const;
/// Print format-specific details
virtual void print_details(FILE* out) const;
/**
* Pretty-print the data descriptor section
*
* @param out
* Output stream to use
* @param indent
* Indent all output by this amount of spaces
*/
void print_datadesc(FILE* out, unsigned indent=0) const;
/**
* Compute the differences between two bulletins
*
* Details of the differences found will be formatted using the notes
* system (@see notes.h).
*
* @param msg
* The bulletin to compare with this one
* @returns
* The number of differences found
*/
virtual unsigned diff(const Bulletin& msg) const;
/// Diff format-specific details
virtual unsigned diff_details(const Bulletin& msg) const;
};
/**
* Options used to configure BUFR decoding.
*/
struct BufrCodecOptions
{
/**
* By default (false) undefined attributes are not added to variables, and
* there is no difference between an undefined or a missing attribute.
*
* If this is set to true, undefined attributes are added to variables, so
* that it is possible to tell between a variable with no attributes and a
* variable for which the bulletin provides attributes but they have an
* missing value.
*/
bool decode_adds_undef_attrs;
/**
* Create a BufrCodecOptions
*
* Options may be added at any time to future versions of the structure. To
* reduce the likelyhook of breaking ABI, construction on stack is discouraged
* in favour of an allocator function.
*/
static std::auto_ptr<BufrCodecOptions> create();
protected:
BufrCodecOptions();
};
/**
* BUFR bulletin implementation
*/
struct BufrBulletin : public Bulletin
{
/** BUFR-specific encoding options */
/** Common Code table C-1 identifying the originating centre */
int centre;
/** Centre-specific subcentre code */
int subcentre;
/** Version number of master tables used */
int master_table;
/** Version number of local tables used to augment the master table */
int local_table;
/** 1 if the BUFR message uses compression, else 0 */
int compression;
/** Update sequence number from octet 7 in section 1*/
int update_sequence_number;
/** 0 if the BUFR message does not contain an optional section, else
* its length in bytes */
int optional_section_length;
/** Raw contents of the optional section */
char* optional_section;
/**
* Raw details about the message that has been decoded.
*
* It is only filled in by a decoding operation: in all other cases it is
* NULL.
*/
bulletin::BufrInput* raw_details;
/**
* Options used to customise encoding or decoding.
*
* It is NULL by default, in which case default options are used.
*
* To configure it, set it to point to a BufrCodecOptions structure with
* the parameters you need. The caller is responsible for the memory
* management of the BufrCodecOptions structure.
*/
const BufrCodecOptions* codec_options;
virtual ~BufrBulletin();
void clear();
virtual const char* encoding_name() const throw () { return "BUFR"; }
virtual void load_tables();
virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
virtual void encode(std::string& buf) const;
virtual void print_details(FILE* out) const;
virtual unsigned diff_details(const Bulletin& msg) const;
/**
* Create or reset the raw_details structure for this bulletin.
*
* This is only invoked during decoding.
*/
bulletin::BufrInput& reset_raw_details(const std::string& buf);
/**
* Read an encoded BUFR message from a stream
*
* @param in
* The stream to read from
* @param buf
* The buffer where the data will be written
* @param fname
* File name to use in error messages
* @retval offset
* The offset in the file of the beginning of the BUFR data
* @returns
* true if a message was found, false on EOF
*/
static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
/**
* Write an encoded BUFR message to a stream
*
* @param buf
* The buffer with the data to write
* @param out
* The stream to write to
* @param fname
* File name to use in error messages
*/
static void write(const std::string& buf, FILE* out, const char* fname = 0);
/**
* To prevent breaking ABI if new members are added to bulletins, direct
* construction is discouraged in favour of an allocator function
*/
static std::auto_ptr<BufrBulletin> create();
protected:
BufrBulletin();
};
/**
* CREX bulletin implementation
*/
struct CrexBulletin : public Bulletin
{
/** CREX-specific encoding options */
/** Table version number */
int table;
/** True if the CREX message uses the check digit feature */
bool has_check_digit;
void clear();
virtual const char* encoding_name() const throw () { return "CREX"; }
virtual void load_tables();
virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
virtual void encode(std::string& buf) const;
virtual void print_details(FILE* out) const;
virtual unsigned diff_details(const Bulletin& msg) const;
/**
* Read an encoded BUFR message from a stream
*
* @param in
* The stream to read from
* @param buf
* The buffer where the data will be written
* @param fname
* File name to use in error messages
* @retval offset
* The offset in the file of the beginning of the BUFR data
* @returns
* true if a message was found, false on EOF
*/
static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
/**
* Write an encoded BUFR message to a stream
*
* @param buf
* The buffer with the data to write
* @param out
* The stream to write to
* @param fname
* File name to use in error messages
*/
static void write(const std::string& buf, FILE* out, const char* fname = 0);
/**
* To prevent breaking ABI if new members are added to bulletins, direct
* construction is discouraged in favour of an allocator function
*/
static std::auto_ptr<CrexBulletin> create();
protected:
CrexBulletin();
};
/**
* The bulletin namespace contains bulletin implementation details, internals
* and utility functions.
*/
namespace bulletin {
}
}
/* vim:set ts=4 sw=4: */
#endif
|