libwreport  3.42
Data Structures | Macros | Enumerations | Functions
varinfo.h File Reference

Implement fast access to information about WMO variables. More...

#include <cstdint>
#include <iosfwd>
#include <string>
#include <wreport/fwd.h>

Go to the source code of this file.

Data Structures

struct  wreport::_Varinfo
 Information about a variable. More...
 

Macros

#define WR_VAR(f, x, y)
 Create a WMO variable code from its F, X and Y components. More...
 
#define WR_STRING_TO_VAR(str)
 Convert a XXYYY string to a WMO variable code. More...
 
#define WR_VAR_F(code)   (((code) >> 14) & 0x3)
 Get the F part of a WMO variable code.
 
#define WR_VAR_X(code)   ((code) >> 8 & 0x3f)
 Get the X part of a WMO variable code.
 
#define WR_VAR_Y(code)   ((code) & 0xff)
 Get the Y part of a WMO variable code.
 
#define WR_VAR_FXY(code)   WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code)
 Expands to WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code). More...
 

Enumerations

enum  wreport::Vartype : unsigned { Integer, Decimal, String, Binary }
 Variable type.
 

Functions

std::string wreport::varcode_format (Varcode code)
 Format a varcode into a string.
 
Varcode wreport::varcode_parse (const char *desc)
 Convert a FXXYYY string descriptor code into its short integer representation. More...
 
const char * wreport::vartype_format (Vartype type)
 Return a string description of a Vartype.
 
Vartype wreport::vartype_parse (const char *s)
 Return a Vartype from its string description.
 
std::ostream & wreport::operator<< (std::ostream &out, const Vartype &t)
 
Varinfo wreport::varinfo_create_bufr (Varcode code, const char *desc, const char *unit, unsigned bit_len, uint32_t bit_ref=0, int scale=0)
 Allocate a new Varinfo to store BUFR values. More...
 
void wreport::varinfo_delete (Varinfo &&info)
 Deallocate a Varinfo created with create_bufr(). More...
 

Detailed Description

Implement fast access to information about WMO variables.

The measured value of a physical quantity has little meaning without specifying what quantity it represents, what units are used to measure it, and how many digits are significant for the value.

This module provides access to all this metadata:

There are many B tables with slight differences used by different meteorological centre or equipment. This module allows to access different vartables using dba_vartable_create().

wreport::Vartable and wreport::Varinfo have special memory management: they are never deallocated. This is a precise design choice to speed up passing and copying wreport::Varinfo values, that are used very intensely as they accompany all the physical values processed by wreport. This behaviour should not be a cause of memory leaks, since a software would only need to access a limited amount of B tables during its lifetime.

To construct a wreport::Varcode value one needs to provide three numbers: F, X and Y.

The normal text representation of a wreport::Varcode for a WMO B table uses the format Bxxyyy.

Macro Definition Documentation

◆ WR_STRING_TO_VAR

#define WR_STRING_TO_VAR (   str)
Value:
static_cast<wreport::Varcode>( \
((((str)[0] - '0') * 10 + ((str)[1] - '0')) << 8) | \
(((str)[2] - '0') * 100 + ((str)[3] - '0') * 10 + ((str)[4] - '0')))

Convert a XXYYY string to a WMO variable code.

This is useful only in rare cases, such as when parsing tables; use descriptor_code() to parse proper entry names such as "B01003" or "D21301".

◆ WR_VAR

#define WR_VAR (   f,
  x,
 
)
Value:
(static_cast<wreport::Varcode>((static_cast<unsigned>(f) << 14) | \
(static_cast<unsigned>(x) << 8) | \
static_cast<unsigned>(y)))

Create a WMO variable code from its F, X and Y components.

◆ WR_VAR_FXY

#define WR_VAR_FXY (   code)    WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code)

Expands to WR_VAR_F(code), WR_VAR_X(code), WR_VAR_Y(code).

This is intended as a convenient shortcut to pass a broken down varcode to functions like printf, but not much more than that. Of course it evaluates its argument multiple times.

Function Documentation

◆ varcode_parse()

Varcode wreport::varcode_parse ( const char *  desc)

Convert a FXXYYY string descriptor code into its short integer representation.

Parameters
descThe 6-byte string descriptor as FXXYYY
Returns
The short integer code that can be queried with the WR_GET_* macros

◆ varinfo_create_bufr()

Varinfo wreport::varinfo_create_bufr ( Varcode  code,
const char *  desc,
const char *  unit,
unsigned  bit_len,
uint32_t  bit_ref = 0,
int  scale = 0 
)

Allocate a new Varinfo to store BUFR values.

Returns
The newly allocated Varinfo, to be deallocated with delete_varinfo()

◆ varinfo_delete()

void wreport::varinfo_delete ( Varinfo &&  info)

Deallocate a Varinfo created with create_bufr().

Sets info to nullptr;