5 #include <wreport/fwd.h>
59 void assign_i_checked(int32_t val);
60 void assign_d_checked(
double val);
61 void assign_b_checked(uint8_t* val,
unsigned size);
62 void assign_c_checked(
const char* val,
unsigned size);
116 bool operator==(
const Var& var)
const;
117 bool operator!=(
const Var& var)
const {
return !operator==(var); }
159 T
enq(T default_value)
const
161 if (!
isset())
return default_value;
175 void sets(
const std::string& val);
208 void set(
const std::string& val) {
setc(val.c_str()); }
257 void seta(std::unique_ptr<Var>&& attr);
278 std::string
format(
const char* ifundef=
"")
const;
281 void format(FILE* out,
const char* ifundef=
"")
const;
297 void print(std::ostream& out)
const;
355 template<>
inline int Var::enq()
const {
return enqi(); }
356 template<>
inline float Var::enq()
const {
return (
float)
enqd(); }
357 template<>
inline double Var::enq()
const {
return enqd(); }
358 template<>
inline const char*
Var::enq()
const {
return enqc(); }
359 template<>
inline std::string
Var::enq()
const {
return enqs(); }
static Var * lua_check(struct lua_State *L, int idx)
Check that the element at idx is a Var.
void set(const std::string &val)
Shortcuts (use with care, as the semanthics are slightly different depending on the type)
Definition: var.h:208
double enqd() const
Get the value as a double.
void set(int val)
Shortcuts (use with care, as the semanthics are slightly different depending on the type)
Definition: var.h:205
Var * m_attrs
Attribute list (ordered by Varcode)
Definition: var.h:50
const char * enqc() const
Get the value as a string.
void seta(Var &&attr)
Set an attribute of the variable.
const Var * enqa(Varcode code) const
Query variable attributes.
std::string enqs() const
Get the value as a std::string.
Varinfo m_info
Metadata about the variable.
Definition: var.h:28
void print(std::ostream &out) const
Print the variable to an output stream.
Var(Varinfo info)
Create a new Var, with undefined value.
void copy_value(const Var &var)
Copy the value from var. var is assumed to have the same varinfo as us.
void lua_push(struct lua_State *L)
Push the variable as an object in the lua stack.
static const Var * lua_const_check(struct lua_State *L, int idx)
Check that the element at idx is a Var.
void print_without_attrs(FILE *out, const char *end="\n") const
Print the variable to an output stream, without its attributes.
void move_value(Var &var)
Move the value from var. var is assumed to have the same varinfo as us. var is left unset.
unsigned diff(const Var &var) const
Compare two Var and return the number of differences.
const Var * next_attr() const
Get the next attribute in the attribute list.
std::string format(const char *ifundef="") const
Create a formatted string representation of the variable value.
void allocate()
Make sure that m_value is allocated. It does nothing if it already is.
void unset()
Unset the value.
void set(const Var &var)
Shortcuts (use with care, as the semanthics are slightly different depending on the type)
Definition: var.h:209
Var(Varinfo info, double val)
Create a new Var, with double value.
Information about a variable.
Definition: varinfo.h:137
void clear_attrs()
Remove all attributes.
void unseta(Varcode code)
Remove the attribute with the given code.
union wreport::Var::@0 m_value
Value of the variable.
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition: fwd.h:12
Var & operator=(Var &&var)
Move assignment.
Var(const Var &var)
Copy constructor.
Reports that a feature is still not implemented.
Definition: error.h:241
Var(Varinfo info, int val)
Create a new Var, with integer value.
T enq() const
Templated version of enq.
Definition: var.h:149
Var(Var &&var)
Move constructor.
void seta(const Var &attr)
Set an attribute of the variable.
void sets(const std::string &val)
Set the value from a string or opaque binary value.
void set(const char *val)
Shortcuts (use with care, as the semanthics are slightly different depending on the type)
Definition: var.h:207
void setc(const char *val)
Set the value from a string or opaque binary value.
void print_without_attrs(std::ostream &out) const
Print the variable to an output stream, without its attributes.
void set(double val)
Shortcuts (use with care, as the semanthics are slightly different depending on the type)
Definition: var.h:206
Var & operator=(const Var &var)
Assignment.
Varcode code
Variable code, as in WMO BUFR/CREX table B.
Definition: varinfo.h:139
bool m_isset
True if the variable is set, false otherwise.
Definition: var.h:31
A physical variable.
Definition: var.h:25
void setd(double val)
Set the value from a double value.
T enq(T default_value) const
Return the variable value, or the given default value if the variable is not set.
Definition: var.h:159
void setattrs(const Var &src)
Replace all attributes in this variable with all the attributes from src.
void seti(int val)
Set the value from an integer value.
void format(FILE *out, const char *ifundef="") const
Write the formatted value of this variable to an output stream.
Var(Varinfo info, const Var &var)
Create a new Var with the value from another one.
void setc_truncate(const char *val)
Set the value from a string value, truncating it if it is too long.
void seta(std::unique_ptr< Var > &&attr)
Set an attribute of the variable.
bool value_equals(const Var &var) const
Test if the values are the same, regardless of variable codes or attributes.
Var(Varinfo info, const char *val)
Create a new Var, with character value.
Varinfo info() const
Get informations about the variable.
Definition: var.h:129
void print(FILE *out) const
Print the variable to an output stream.
void setval(const Var &src)
Set the value from another variable, performing conversions if needed.
int enqi() const
Get the value as an integer.
void lua_push(struct lua_State *L) const
Push the variable as an object in the lua stack, with only read-only methods.
void setf(const char *val)
Set from a value formatted with the format() method.
Implement fast access to information about WMO variables.
Varcode code() const
Retrieve the Varcode for a variable.
Definition: var.h:126
bool isset() const
Definition: var.h:132
String functions.
Definition: benchmark.h:13
Var(Varinfo info, const std::string &val)
Create a new Var, with character value.