libwreport  2.9
Public Member Functions | Static Public Member Functions | Protected Attributes
wreport::Var Class Reference

Holds a wreport 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 (const Var &var)
 Copy constructor.
 
 Var (const Var &var, bool with_attrs)
 Copy constructor.
 
 Var (Varinfo info, const Var &var)
 Create a new Var with the value from another one. More...
 
Varoperator= (const Var &var)
 Assignment.
 
bool operator== (const Var &var) const
 Equality.
 
bool operator!= (const Var &var) const
 Equality.
 
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.
 
const char * value () const throw ()
 Retrieve the internal string representation of the value for a 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.
 
template<typename T >
enq () const
 Templated version of enq.
 
template<typename 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 value.
 
void set_binary (const unsigned char *val)
 Set the raw, binary value from a string value. More...
 
void setc_truncate (const char *val)
 Set the value from a string value, truncating val if it is too long. More...
 
void set_from_formatted (const char *val)
 Set from a value formatted with the format() method.
 
void unset ()
 Unset the value.
 
void clear_attrs ()
 Remove all attributes.
 
const Varenqa (Varcode code) const
 Query variable attributes. More...
 
const Varenqa_by_associated_field_significance (unsigned significance) const
 Query variable attribute according to significance given in CODE TABLE 031021.
 
void seta (const Var &attr)
 Set an attribute of the variable. More...
 
void seta (std::auto_ptr< Var > attr)
 Set an attribute of the variable. More...
 
void unseta (Varcode code)
 Remove the attribute with the given code.
 
const Varnext_attr () const
 Get the next attribute in the attribute list. More...
 
void copy_val (const Var &src)
 Set the value from another variable, performing conversions if needed. More...
 
void copy_val_only (const Var &src)
 Set the value from another variable, performing conversions if needed. More...
 
void copy_attrs (const Var &src)
 Copy all the attributes from another variable. More...
 
void copy_attrs_if_defined (const Var &src)
 Copy all the attributes from another variable, unless they are set to an undefined value. More...
 
std::string format (const char *ifundef="(undef)") const
 Create a formatted string representation of the variable value. More...
 
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
 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.
 
template<>
int enq () const
 
template<>
float enq () const
 
template<>
double enq () const
 
template<>
const char * enq () const
 
template<>
std::string 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 Varlua_check (struct lua_State *L, int idx)
 Check that the element at idx is a Var. More...
 

Protected Attributes

Varinfo m_info
 Metadata about the variable.
 
char * m_value
 Value of the variable.
 
Varm_attrs
 Attribute list (ordered by Varcode)
 

Detailed Description

Holds a wreport variable.

A wreport::Var contains:

Constructor & Destructor Documentation

wreport::Var::Var ( Varinfo  info,
const Var var 
)

Create a new Var with the value from another one.

Conversions are applied if necessary

Parameters
infoThe wreport::Varinfo describing the variable to create
varThe variable with the value to use

Member Function Documentation

void wreport::Var::copy_attrs ( const Var src)

Copy all the attributes from another variable.

Parameters
srcThe variable with the attributes to copy.
void wreport::Var::copy_attrs_if_defined ( const Var src)

Copy all the attributes from another variable, unless they are set to an undefined value.

Parameters
srcThe variable with the attributes to copy.
void wreport::Var::copy_val ( const Var src)

Set the value from another variable, performing conversions if needed.

The attributes of src will also be copied

Referenced by set().

void wreport::Var::copy_val_only ( const Var src)

Set the value from another variable, performing conversions if needed.

The attributes of src will NOT be copied

unsigned wreport::Var::diff ( const Var var) const

Compare two Var and return the number of differences.

Details of the differences found will be formatted using the notes system (

See Also
notes.h).
Parameters
varThe variable to compare with this one
Returns
The number of differences found and reported
const Var* wreport::Var::enqa ( Varcode  code) const

Query variable attributes.

Parameters
codeThe wreport::Varcode of the attribute requested. See vartable.h
Returns
attr A pointer to the attribute if it exists, else NULL. The pointer points to the internal representation and must not be deallocated by the caller.
std::string wreport::Var::format ( const char *  ifundef = "(undef)") const

Create a formatted string representation of the variable value.

Parameters
ifundefString to use if the variable is undefiend
bool wreport::Var::isset ( ) const
throw (
)
Returns
true if the variable is defined, else false

Referenced by enq().

static Var* wreport::Var::lua_check ( struct lua_State *  L,
int  idx 
)
static

Check that the element at idx is a Var.

Returns
the Var element, or NULL if the check failed
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

void wreport::Var::print ( FILE *  out) const

Print the variable to an output stream.

Parameters
outThe output stream to use for printing
void wreport::Var::print ( std::ostream &  out) const

Print the variable to an output stream.

Parameters
outThe output stream to use for printing
void wreport::Var::print_without_attrs ( FILE *  out) const

Print the variable to an output stream, without its attributes.

Parameters
outThe 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.

Parameters
outThe output stream to use for printing
void wreport::Var::set_binary ( const unsigned char *  val)

Set the raw, binary value from a string value.

This is similar to setc(), but it always copies as many bytes as the variable is long, including null bytes.

void wreport::Var::seta ( const Var attr)

Set an attribute of the variable.

An existing attribute with the same wreport::Varcode will be replaced.

Parameters
attrThe 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::auto_ptr< Var attr)

Set an attribute of the variable.

An existing attribute with the same wreport::Varcode will be replaced.

Parameters
attrThe attribute to add. It will be used directly, and var will take care of its memory management.
void wreport::Var::setc_truncate ( const char *  val)

Set the value from a string value, truncating val if it is too long.

If a value is truncated, the last character is set to '>' to mark the truncation.


The documentation for this class was generated from the following file: