libwreport
3.29
|
A physical variable. More...
#include <var.h>
Public Member Functions | |
Var (Varinfo info) | |
Create a new Var, with undefined value. | |
Var (Varinfo info, int val) | |
Create a new Var, with integer value. | |
Var (Varinfo info, double val) | |
Create a new Var, with double value. | |
Var (Varinfo info, const char *val) | |
Create a new Var, with character value. | |
Var (Varinfo info, const std::string &val) | |
Create a new Var, with character value. | |
Var (Varinfo info, const Var &var) | |
Create a new Var with the value from another one. More... | |
Var (const Var &var) | |
Copy constructor. | |
Var (Var &&var) | |
Move constructor. More... | |
Var & | operator= (const Var &var) |
Assignment. | |
Var & | operator= (Var &&var) |
Move assignment. More... | |
bool | operator== (const Var &var) const |
bool | operator!= (const Var &var) const |
bool | value_equals (const Var &var) const |
Test if the values are the same, regardless of variable codes or attributes. | |
Varcode | code () const throw () |
Retrieve the Varcode for a variable. | |
Varinfo | info () const throw () |
Get informations about the variable. | |
bool | isset () const throw () |
int | enqi () const |
Get the value as an integer. | |
double | enqd () const |
Get the value as a double. | |
const char * | enqc () const |
Get the value as a string. | |
std::string | enqs () const |
Get the value as a std::string. | |
template<typename T > | |
T | enq () const |
Templated version of enq. | |
template<typename T > | |
T | enq (T default_value) const |
Return the variable value, or the given default value if the variable is not set. | |
void | seti (int val) |
Set the value from an integer value. | |
void | setd (double val) |
Set the value from a double value. | |
void | setc (const char *val) |
Set the value from a string or opaque binary value. | |
void | sets (const std::string &val) |
Set the value from a string or opaque binary value. | |
void | setf (const char *val) |
Set from a value formatted with the format() method. | |
void | setc_truncate (const char *val) |
Set the value from a string value, truncating it if it is too long. More... | |
void | setval (const Var &src) |
Set the value from another variable, performing conversions if needed. More... | |
void | setattrs (const Var &src) |
Replace all attributes in this variable with all the attributes from src. | |
void | unset () |
Unset the value. | |
void | clear_attrs () |
Remove all attributes. | |
const Var * | enqa (Varcode code) const |
Query variable attributes. More... | |
void | seta (const Var &attr) |
Set an attribute of the variable. More... | |
void | seta (Var &&attr) |
Set an attribute of the variable. More... | |
void | seta (std::unique_ptr< Var > &&attr) |
Set an attribute of the variable. More... | |
void | unseta (Varcode code) |
Remove the attribute with the given code. | |
const Var * | next_attr () const |
Get the next attribute in the attribute list. More... | |
std::string | format (const char *ifundef="") const |
Create a formatted string representation of the variable value. More... | |
void | format (FILE *out, const char *ifundef="") const |
Write the formatted value of this variable to an output stream. | |
void | print (FILE *out) const |
Print the variable to an output stream. More... | |
void | print (std::ostream &out) const |
Print the variable to an output stream. More... | |
void | print_without_attrs (FILE *out, const char *end="\n") const |
Print the variable to an output stream, without its attributes. More... | |
void | print_without_attrs (std::ostream &out) const |
Print the variable to an output stream, without its attributes. More... | |
unsigned | diff (const Var &var) const |
Compare two Var and return the number of differences. More... | |
void | lua_push (struct lua_State *L) |
Push the variable as an object in the lua stack. | |
void | lua_push (struct lua_State *L) const |
Push the variable as an object in the lua stack, with only read-only methods. | |
template<> | |
int | enq () const |
void | set (int val) |
Shortcuts (use with care, as the semanthics are slightly different depending on the type) | |
void | set (double val) |
Shortcuts (use with care, as the semanthics are slightly different depending on the type) | |
void | set (const char *val) |
Shortcuts (use with care, as the semanthics are slightly different depending on the type) | |
void | set (const std::string &val) |
Shortcuts (use with care, as the semanthics are slightly different depending on the type) | |
void | set (const Var &var) |
Shortcuts (use with care, as the semanthics are slightly different depending on the type) | |
Static Public Member Functions | |
static Var * | lua_check (struct lua_State *L, int idx) |
Check that the element at idx is a Var. More... | |
static const Var * | lua_const_check (struct lua_State *L, int idx) |
Check that the element at idx is a Var. More... | |
Protected Member Functions | |
void | allocate () |
Make sure that m_value is allocated. It does nothing if it already is. | |
void | copy_value (const Var &var) |
Copy the value from var. var is assumed to have the same varinfo as us. | |
void | move_value (Var &var) |
Move the value from var. var is assumed to have the same varinfo as us. var is left unset. | |
void | assign_i_checked (int32_t val) |
void | assign_d_checked (double val) |
void | assign_b_checked (uint8_t *val, unsigned size) |
void | assign_c_checked (const char *val, unsigned size) |
Protected Attributes | |
Varinfo | m_info |
Metadata about the variable. | |
bool | m_isset |
True if the variable is set, false otherwise. | |
union { | |
int32_t i | |
char * c | |
} | m_value |
Value of the variable. More... | |
Var * | m_attrs |
Attribute list (ordered by Varcode) | |
A physical variable.
A wreport::Var contains:
Create a new Var with the value from another one.
Conversions are applied if necessary, attributes are not copied.
info | The wreport::Varinfo describing the variable to create |
var | The variable with the value to use |
wreport::Var::Var | ( | Var && | var | ) |
Move constructor.
After movement, var will still a valid variable, but it will be unset and without attributes.
unsigned wreport::Var::diff | ( | const Var & | var | ) | const |
Query variable attributes.
code | The wreport::Varcode of the attribute requested. See vartable.h |
std::string wreport::Var::format | ( | const char * | ifundef = "" | ) | const |
Create a formatted string representation of the variable value.
ifundef | String to use if the variable is undefiend |
|
inline |
|
static |
|
static |
const Var* wreport::Var::next_attr | ( | ) | const |
Get the next attribute in the attribute list.
Example attribute iteration:
for (const Var* a = var.next_attr(); a != NULL; a = a->next_attr()) // Do something with a
Move assignment.
After movement, var will still a valid variable, but it will be unset and without attributes.
void wreport::Var::print | ( | FILE * | out | ) | const |
Print the variable to an output stream.
out | The output stream to use for printing |
void wreport::Var::print | ( | std::ostream & | out | ) | const |
Print the variable to an output stream.
out | The output stream to use for printing |
void wreport::Var::print_without_attrs | ( | FILE * | out, |
const char * | end = "\n" |
||
) | const |
Print the variable to an output stream, without its attributes.
out | The output stream to use for printing |
void wreport::Var::print_without_attrs | ( | std::ostream & | out | ) | const |
Print the variable to an output stream, without its attributes.
out | The output stream to use for printing |
void wreport::Var::seta | ( | const Var & | attr | ) |
Set an attribute of the variable.
An existing attribute with the same wreport::Varcode will be replaced.
attr | The attribute to add. It will be copied inside var, and memory management will still be in charge of the caller. |
void wreport::Var::seta | ( | std::unique_ptr< Var > && | attr | ) |
Set an attribute of the variable.
An existing attribute with the same wreport::Varcode will be replaced.
attr | The attribute to add. It will be used directly, and var will take care of its memory management. |
void wreport::Var::seta | ( | Var && | attr | ) |
Set an attribute of the variable.
An existing attribute with the same wreport::Varcode will be replaced.
attr | The attribute to add. Its value will be moved inside the destination attribute, and attr will be unset. |
void wreport::Var::setc_truncate | ( | const char * | val | ) |
Set the value from a string value, truncating it if it is too long.
If a value is truncated, the last character is set to '>' to mark the truncation.
void wreport::Var::setval | ( | const Var & | src | ) |
Set the value from another variable, performing conversions if needed.
The attributes of src will be ignored.
Referenced by set().
union { ... } wreport::Var::m_value |
Value of the variable.
For numeric values, it is the value encoded to an integer decimal string according to m_info.
For string values, it is the 0-terminated string.
For binary values, it is a raw buffer where the first m_info->bit_len bits are the binary value, and the rest is set to 0.