/usr/share/doc/libwreport-doc/apidocs/examples.html is in libwreport-doc 3.6-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 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>libwreport: Code examples</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">libwreport
 <span id="projectnumber">3.6</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Code examples </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="examples_reading"></a>
Reading and decoding bulletins</h1>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * input - BUFR and CREX input examples</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Copyright (C) 2011 ARPA-SIM <urpsim@smr.arpa.emr.it></span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation; either version 2 of the License.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> * GNU General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div><div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Author: Enrico Zini <enrico@enricozini.com></span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <wreport/bulletin.h></span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="options_8h.html">options.h</a>"</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacewreport.html">wreport</a>;</div><div class="line"></div><div class="line"><span class="comment">// Read all BUFR messages from a file</span></div><div class="line"><span class="keywordtype">void</span> read_bufr_raw(<span class="keyword">const</span> Options& opts, <span class="keyword">const</span> <span class="keywordtype">char</span>* fname, RawHandler& handler)</div><div class="line">{</div><div class="line"> <span class="comment">// Open the input file</span></div><div class="line"> FILE* in = fopen(fname, <span class="stringliteral">"rb"</span>);</div><div class="line"> <span class="keywordflow">if</span> (in == NULL)</div><div class="line"> <a class="code" href="structwreport_1_1error__system.html#ae91b8d57c825a893e74599a1e2664844">error_system::throwf</a>(<span class="stringliteral">"opening file %s"</span>, fname);</div><div class="line"></div><div class="line"> <span class="comment">// Use a generic try/catch block to ensure we always close the input file,</span></div><div class="line"> <span class="comment">// even in case of errors</span></div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> <span class="comment">// String used to hold raw data read from the input file</span></div><div class="line"> <span class="keywordtype">string</span> raw_data;</div><div class="line"></div><div class="line"> <span class="comment">// (optional) offset of the start of the BUFR message read, which we</span></div><div class="line"> <span class="comment">// pass to the decoder to have nicer error messages</span></div><div class="line"> off_t offset;</div><div class="line"></div><div class="line"> <span class="comment">// Read all BUFR data in the input file, one message at a time. Extra</span></div><div class="line"> <span class="comment">// data before and after each BUFR message is skipped.</span></div><div class="line"> <span class="comment">// fname and offset are optional and we pass them just to have nicer</span></div><div class="line"> <span class="comment">// error messages.</span></div><div class="line"> <span class="keywordflow">while</span> (<a class="code" href="structwreport_1_1BufrBulletin.html#a25cad04956c36ed98ae0958643b81049">BufrBulletin::read</a>(in, raw_data, fname, &offset))</div><div class="line"> handler.handle_raw_bufr(raw_data, fname, offset);</div><div class="line"></div><div class="line"> <span class="comment">// Cleanup</span></div><div class="line"> fclose(in);</div><div class="line"> } <span class="keywordflow">catch</span> (...) {</div><div class="line"> fclose(in);</div><div class="line"> <span class="keywordflow">throw</span>;</div><div class="line"> }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Read all CREX messages from a file</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Note that the code is basically the same as with reading BUFRs, with only</span></div><div class="line"><span class="comment"> * two changes:</span></div><div class="line"><span class="comment"> * - it uses a CrexBulletin instead of a BufrBulletin</span></div><div class="line"><span class="comment"> * - it uses CrexBulletin::read instead of BufrBulletin::read</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keywordtype">void</span> read_crex_raw(<span class="keyword">const</span> Options& opts, <span class="keyword">const</span> <span class="keywordtype">char</span>* fname, RawHandler& handler)</div><div class="line">{</div><div class="line"> <span class="comment">// Open the input file</span></div><div class="line"> FILE* in = fopen(fname, <span class="stringliteral">"rt"</span>);</div><div class="line"> <span class="keywordflow">if</span> (in == NULL)</div><div class="line"> <a class="code" href="structwreport_1_1error__system.html#ae91b8d57c825a893e74599a1e2664844">error_system::throwf</a>(<span class="stringliteral">"opening file %s"</span>, fname);</div><div class="line"></div><div class="line"> <span class="comment">// Use a generic try/catch block to ensure we always close the input file,</span></div><div class="line"> <span class="comment">// even in case of errors</span></div><div class="line"> <span class="keywordflow">try</span> {</div><div class="line"> <span class="comment">// Create a CREX bulletin</span></div><div class="line"> unique_ptr<Bulletin> bulletin(<a class="code" href="structwreport_1_1CrexBulletin.html#a7aac002f41f977a8b6a3763c0c1d59c1">CrexBulletin::create</a>());</div><div class="line"></div><div class="line"> <span class="comment">// String used to hold raw data read from the input file</span></div><div class="line"> <span class="keywordtype">string</span> raw_data;</div><div class="line"></div><div class="line"> <span class="comment">// (optional) offset of the start of the CREX message read, which we</span></div><div class="line"> <span class="comment">// pass to the decoder to have nicer error messages</span></div><div class="line"> off_t offset;</div><div class="line"></div><div class="line"> <span class="comment">// Read all CREX data in the input file, one message at a time. Extra</span></div><div class="line"> <span class="comment">// data before and after each CREX message is skipped.</span></div><div class="line"> <span class="comment">// fname and offset are optional and we pass them just to have nicer</span></div><div class="line"> <span class="comment">// error messages.</span></div><div class="line"> <span class="keywordflow">while</span> (<a class="code" href="structwreport_1_1CrexBulletin.html#a2961fd300e3a89589864e84c5f2b5b92">CrexBulletin::read</a>(in, raw_data, fname, &offset))</div><div class="line"> handler.handle_raw_crex(raw_data, fname, offset);</div><div class="line"></div><div class="line"> <span class="comment">// Cleanup</span></div><div class="line"> fclose(in);</div><div class="line"> } <span class="keywordflow">catch</span> (...) {</div><div class="line"> fclose(in);</div><div class="line"> <span class="keywordflow">throw</span>;</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="examples_writing"></a>
Creating bulletins</h1>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * makebuoy - Example on how to create a buoy BUFR message</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Copyright (C) 2011 ARPA-SIM <urpsim@smr.arpa.emr.it></span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation; either version 2 of the License.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> * GNU General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div><div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Author: Enrico Zini <enrico@enricozini.com></span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <wreport/bulletin.h></span></div><div class="line"><span class="preprocessor">#include <cstring></span></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> do_makebuoy()</div><div class="line">{</div><div class="line"> <span class="comment">// Create a blank BUFR bulletin</span></div><div class="line"> unique_ptr<BufrBulletin> bulletin(BufrBulletin::create());</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// * Fill up metadata</span></div><div class="line"></div><div class="line"> <span class="comment">// BUFR edition number</span></div><div class="line"> bulletin->edition_number = 4;</div><div class="line"></div><div class="line"> <span class="comment">// Master table number is 0 by default</span></div><div class="line"> <span class="comment">// bulletin->master_table_number = 0;</span></div><div class="line"></div><div class="line"> <span class="comment">// Data category information</span></div><div class="line"> bulletin->data_category = 1;</div><div class="line"> bulletin->data_subcategory = 21;</div><div class="line"> bulletin->data_subcategory_local = 255;</div><div class="line"></div><div class="line"> <span class="comment">// Reference time</span></div><div class="line"> bulletin->rep_year = 2011;</div><div class="line"> bulletin->rep_month = 10;</div><div class="line"> bulletin->rep_day = 3;</div><div class="line"> bulletin->rep_hour = 17;</div><div class="line"> bulletin->rep_minute = 0;</div><div class="line"> bulletin->rep_second = 0;</div><div class="line"></div><div class="line"> <span class="comment">// Originating centre information</span></div><div class="line"> bulletin->originating_centre = 98; <span class="comment">// ECMWF</span></div><div class="line"> bulletin->originating_subcentre = 0;</div><div class="line"></div><div class="line"> <span class="comment">// B table version used by the message</span></div><div class="line"> bulletin->master_table_version_number = 14;</div><div class="line"> bulletin->master_table_version_number_local = 0;</div><div class="line"></div><div class="line"> <span class="comment">// Compression is still not supported when encoding BUFR</span></div><div class="line"> bulletin->compression = <span class="keyword">false</span>;</div><div class="line"></div><div class="line"> <span class="comment">// Update sequence number is 0 by default</span></div><div class="line"> <span class="comment">// bulletin->update_sequence_number = 0;</span></div><div class="line"></div><div class="line"> <span class="comment">// Optional section</span></div><div class="line"> bulletin->optional_section = <span class="stringliteral">"test"</span>;</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// * Fill up data descriptor section</span></div><div class="line"></div><div class="line"> <span class="comment">// There is only one descriptor in this case, but one can push_back as many</span></div><div class="line"> <span class="comment">// as one likes</span></div><div class="line"> bulletin->datadesc.push_back(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(3, 8, 3)); <span class="comment">// D08003</span></div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// * Fill up the data section</span></div><div class="line"></div><div class="line"> <span class="comment">// Load encoding tables</span></div><div class="line"> bulletin->load_tables();</div><div class="line"></div><div class="line"> <span class="comment">// Create the first (and only) subset</span></div><div class="line"> Subset& s = bulletin->obtain_subset(0);</div><div class="line"></div><div class="line"> <span class="comment">// Add variables to the subset, as dictated by the data descriptor section</span></div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 1, 5), 65602);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 1, 12), 12.0);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 1, 13), 0.2);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 2, 1), 0);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 4, 1), 2011);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 4, 2), 10);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 4, 3), 3);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 4, 4), 17);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 4, 5), 0);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 5, 2), 59.03);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 6, 2), -2.99);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 10, 4), 99520.0);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 10, 51), 99520.0);</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 10, 61), 310);</div><div class="line"> s.store_variable_i(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 10, 63), 7);</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 11, 11));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 11, 12));</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 12, 4), 278.5);</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 12, 6));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 13, 3));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 1));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 3));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 4));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 5));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 10));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 8, 2));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 11));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 13));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 12));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 12));</div><div class="line"> s.store_variable_undef(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 20, 12));</div><div class="line"> s.store_variable_d(<a class="code" href="varinfo_8h.html#a2c4904311fb1c39d5279e5076e81d6df">WR_VAR</a>(0, 22, 42), 280.8);</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// Encode the BUFR</span></div><div class="line"> <span class="keywordtype">string</span> encoded = bulletin->encode();</div><div class="line"></div><div class="line"> <span class="comment">// Output the BUFR</span></div><div class="line"> <span class="keywordflow">if</span> (fwrite(encoded.data(), encoded.size(), 1, stdout) != 1)</div><div class="line"> perror(<span class="stringliteral">"cannot write BUFR to standard output"</span>);</div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="examples_printing"></a>
Printing bulletin contents</h1>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * output - output bulletin contents</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Copyright (C) 2011 ARPA-SIM <urpsim@smr.arpa.emr.it></span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation; either version 2 of the License.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> * GNU General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div><div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Author: Enrico Zini <enrico@enricozini.com></span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <wreport/bulletin.h></span></div><div class="line"><span class="preprocessor">#include <wreport/bulletin/dds-scanfeatures.h></span></div><div class="line"><span class="preprocessor">#include "<a class="code" href="options_8h.html">options.h</a>"</span></div><div class="line"><span class="preprocessor">#include <cstring></span></div><div class="line"></div><div class="line"><span class="keyword">struct </span>PrintContents : <span class="keyword">public</span> BulletinFullHandler</div><div class="line">{</div><div class="line"> FILE* out;</div><div class="line"> PrintContents(FILE* out=stderr) : out(out) {}</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> handle(<a class="code" href="structwreport_1_1Bulletin.html">wreport::Bulletin</a>& b)<span class="keyword"> override</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> b.<a class="code" href="structwreport_1_1Bulletin.html#a45d7cfad201f1d56b60a0147a7f388aa">print</a>(out);</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">struct </span>PrintStructure : <span class="keyword">public</span> BulletinFullHandler</div><div class="line">{</div><div class="line"> FILE* out;</div><div class="line"> PrintStructure(FILE* out=stderr) : out(out) {}</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> handle(<a class="code" href="structwreport_1_1Bulletin.html">wreport::Bulletin</a>& b)<span class="keyword"> override</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> b.<a class="code" href="structwreport_1_1Bulletin.html#a30b72bf1cb4a00feb8c5c1c2f259725e">print_structured</a>(out);</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">struct </span>PrintDDS : <span class="keyword">public</span> BulletinHeadHandler</div><div class="line">{</div><div class="line"> FILE* out;</div><div class="line"> PrintDDS(FILE* out=stderr) : out(out) {}</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> handle(<a class="code" href="structwreport_1_1Bulletin.html">wreport::Bulletin</a>& b)<span class="keyword"> override</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> b.<a class="code" href="structwreport_1_1Bulletin.html#a6f1d1a8e450fb6d9cafb9b35453840e7">print_datadesc</a>(out);</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">struct </span>PrintTables : <span class="keyword">public</span> BulletinHeadHandler</div><div class="line">{</div><div class="line"> FILE* out;</div><div class="line"> <span class="keywordtype">bool</span> header_printed;</div><div class="line"> PrintTables(FILE* out=stderr) : out(out), header_printed(false) {}</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> handle(<a class="code" href="structwreport_1_1Bulletin.html">wreport::Bulletin</a>& b)<span class="keyword"> override</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> <span class="keywordflow">if</span> (<span class="keyword">const</span> BufrBulletin* m = dynamic_cast<const BufrBulletin*>(&b))</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (!header_printed)</div><div class="line"> {</div><div class="line"> fprintf(out, <span class="stringliteral">"%-*s\tOffset\tCentre\tSubc.\tMaster\tLocal\n"</span>, (<span class="keywordtype">int</span>)b.<a class="code" href="structwreport_1_1Bulletin.html#aa6e883c75c08e7d58c8ab9dbe62cbb53">fname</a>.size(), <span class="stringliteral">"Filename"</span>);</div><div class="line"> header_printed = <span class="keyword">true</span>;</div><div class="line"> }</div><div class="line"> fprintf(out, <span class="stringliteral">"%s\t%zd\t%d\t%d\t%d\t%d\n"</span>,</div><div class="line"> b.<a class="code" href="structwreport_1_1Bulletin.html#aa6e883c75c08e7d58c8ab9dbe62cbb53">fname</a>.c_str(), b.<a class="code" href="structwreport_1_1Bulletin.html#a9700a2d4f14e6741c4df9e8b07cd8ece">offset</a>,</div><div class="line"> m->originating_centre, m->originating_subcentre,</div><div class="line"> m->master_table_version_number, m->master_table_version_number_local);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keyword">const</span> CrexBulletin* m = dynamic_cast<const CrexBulletin*>(&b))</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (!header_printed)</div><div class="line"> {</div><div class="line"> fprintf(out, <span class="stringliteral">"Filename\tOffset\tMaster\tEdition\tTable\n"</span>);</div><div class="line"> header_printed = <span class="keyword">true</span>;</div><div class="line"> }</div><div class="line"> fprintf(out, <span class="stringliteral">"%s\t%zd\t%d\t%d\t%d\n"</span>,</div><div class="line"> b.<a class="code" href="structwreport_1_1Bulletin.html#aa6e883c75c08e7d58c8ab9dbe62cbb53">fname</a>.c_str(), b.<a class="code" href="structwreport_1_1Bulletin.html#a9700a2d4f14e6741c4df9e8b07cd8ece">offset</a>,</div><div class="line"> m->master_table_number, m->edition_number, m->master_table_version_number);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> {</div><div class="line"> fprintf(out, <span class="stringliteral">"%s\t%zd\tunknown message type\n"</span>,</div><div class="line"> b.<a class="code" href="structwreport_1_1Bulletin.html#aa6e883c75c08e7d58c8ab9dbe62cbb53">fname</a>.c_str(), b.<a class="code" href="structwreport_1_1Bulletin.html#a9700a2d4f14e6741c4df9e8b07cd8ece">offset</a>);</div><div class="line"> }</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">struct </span>PrintFeatures : <span class="keyword">public</span> BulletinHeadHandler</div><div class="line">{</div><div class="line"> FILE* out;</div><div class="line"> PrintFeatures(FILE* out=stderr) : out(out) {}</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> handle(<a class="code" href="structwreport_1_1Bulletin.html">wreport::Bulletin</a>& b)<span class="keyword"> override</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> bulletin::ScanFeatures scan(b.<a class="code" href="structwreport_1_1Bulletin.html#a9f555079913237cd2c80a924a177db28">tables</a>, b.<a class="code" href="structwreport_1_1Bulletin.html#a91f2fe233798c17e2252fdc45c078f20">datadesc</a>);</div><div class="line"> scan.run();</div><div class="line"> fprintf(out, <span class="stringliteral">"%s:%zd:"</span>, b.<a class="code" href="structwreport_1_1Bulletin.html#aa6e883c75c08e7d58c8ab9dbe62cbb53">fname</a>.c_str(), b.<a class="code" href="structwreport_1_1Bulletin.html#a9700a2d4f14e6741c4df9e8b07cd8ece">offset</a>);</div><div class="line"> <span class="keywordtype">bool</span> first = <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keyword">auto</span>& f: scan.features)</div><div class="line"> <span class="keywordflow">if</span> (first)</div><div class="line"> {</div><div class="line"> fprintf(out, <span class="stringliteral">"%s"</span>, f.c_str());</div><div class="line"> first = <span class="keyword">false</span>;</div><div class="line"> } <span class="keywordflow">else</span></div><div class="line"> fprintf(out, <span class="stringliteral">",%s"</span>, f.c_str());</div><div class="line"> fprintf(out, <span class="stringliteral">"\n"</span>);</div><div class="line"> }</div><div class="line">};</div></div><!-- fragment --><h1><a class="anchor" id="examples_config"></a>
Printing library configuration</h1>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * info - print library configuration</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Copyright (C) 2011 ARPA-SIM <urpsim@smr.arpa.emr.it></span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation; either version 2 of the License.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> * GNU General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div><div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Author: Enrico Zini <enrico@enricozini.com></span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <cstdlib></span></div><div class="line"></div><div class="line"><span class="comment">// Print information about the library</span></div><div class="line"><span class="keywordtype">void</span> do_info()</div><div class="line">{</div><div class="line"> printf(<span class="stringliteral">"Tables search paths (tried in order):\n"</span>);</div><div class="line"> printf(<span class="stringliteral">"Extra tables directory: %s (env var WREPORT_EXTRA_TABLES)\n"</span>, getenv(<span class="stringliteral">"WREPORT_EXTRA_TABLES"</span>));</div><div class="line"> printf(<span class="stringliteral">"System tables directory: %s (env var WREPORT_TABLES)\n"</span>, getenv(<span class="stringliteral">"WREPORT_TABLES"</span>));</div><div class="line"> printf(<span class="stringliteral">"Compiled-in default tables directory: %s\n"</span>, TABLE_DIR);</div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="examples_iterate"></a>
Iterating bulletin contents</h1>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * iterate - iterate bulletin contents</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Copyright (C) 2011 ARPA-SIM <urpsim@smr.arpa.emr.it></span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div><div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment"> * the Free Software Foundation; either version 2 of the License.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div><div class="line"><span class="comment"> * GNU General Public License for more details.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div><div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Author: Enrico Zini <enrico@enricozini.com></span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="keyword">struct </span>PrintVars : <span class="keyword">public</span> BulletinFullHandler</div><div class="line">{</div><div class="line"> FILE* out;</div><div class="line"> <span class="keyword">const</span> std::vector<wreport::Varcode>& codes;</div><div class="line"></div><div class="line"> PrintVars(<span class="keyword">const</span> std::vector<wreport::Varcode>& codes, FILE* out=stdout)</div><div class="line"> : out(out), codes(codes) {}</div><div class="line"></div><div class="line"> <span class="keyword">const</span> Var* find_varcode(<span class="keyword">const</span> <a class="code" href="structwreport_1_1Subset.html">wreport::Subset</a>& subset, <a class="code" href="namespacewreport.html#af9fa16e12fde1ccfb4ce11b3988f5b05">Varcode</a> code)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < subset.size(); ++i)</div><div class="line"> <span class="keywordflow">if</span> (subset[i].code() == code)</div><div class="line"> <span class="keywordflow">return</span> &subset[i];</div><div class="line"> <span class="keywordflow">return</span> NULL;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordtype">void</span> handle(<a class="code" href="structwreport_1_1Bulletin.html">wreport::Bulletin</a>& b)<span class="keyword"> override</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> sset = 0; sset < b.<a class="code" href="structwreport_1_1Bulletin.html#a544f248fc72a7c75e48ed6835bb22e62">subsets</a>.size(); ++sset)</div><div class="line"> {</div><div class="line"> fprintf(out, <span class="stringliteral">"%s:%zd:"</span>, b.<a class="code" href="structwreport_1_1Bulletin.html#aa6e883c75c08e7d58c8ab9dbe62cbb53">fname</a>.c_str(), sset + 1);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < codes.size(); ++i)</div><div class="line"> {</div><div class="line"> <span class="keyword">const</span> Var* var = find_varcode(b.<a class="code" href="structwreport_1_1Bulletin.html#a544f248fc72a7c75e48ed6835bb22e62">subsets</a>[sset], codes[i]);</div><div class="line"> <span class="keywordflow">if</span> (var)</div><div class="line"> {</div><div class="line"> <span class="keywordtype">string</span> formatted = var->format();</div><div class="line"> fprintf(out, <span class="stringliteral">"\t%s"</span>, formatted.c_str());</div><div class="line"> }</div><div class="line"> }</div><div class="line"> putc(<span class="charliteral">'\n'</span>, out);</div><div class="line"> }</div><div class="line"> }</div><div class="line">};</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Aug 18 2016 13:32:18 for libwreport by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
</html>
|