FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
Public Member Functions | List of all members
FB::variant Class Reference

Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out the type you put in or for coercing that type into another type (if possible). More...

#include "variant.h"

Public Member Functions

template<typename T >
 variant (const T &x)
 Templated constructor to allow any arbitrary type. More...
 
 variant ()
 Default constructor initializes the variant to an empty value. More...
 
variantassign (const variant &x)
 Assigns a new value from another variant. More...
 
template<typename T >
variantassign (const T &x, bool)
 Assigns a value of arbitrary type. More...
 
const std::type_info & get_type () const
 Gets the type of the value stored in variant. More...
 
template<typename T >
bool is_of_type () const
 Query if this object is of a particular type. More...
 
template<typename T >
cast () const
 returns the value cast as the given type; throws bad_variant_type if that type is not the type of the value stored in variant More...
 
template<typename T >
const T convert_cast () const
 Converts the stored value to the requested type if possible and returns the resulting value. If the conversion is not possible, throws bad_variant_cast. More...
 
bool empty () const
 Returns true if the variant is empty (has not been assigned a value or has been reset) More...
 
void reset ()
 Frees any value assigned and resets the variant to empty state. More...
 

Detailed Description

Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out the type you put in or for coercing that type into another type (if possible).

variant is the most versatile and fundamental class in FireBreath. Any type can be assigned to a variant, and you can get that type back out using cast(), like so:

variant a = 5;
int i_a = a.cast<int>();

Basic type conversion can be handled using convert_cast(), like so:

variant str = "5";
int i_a = a.convert_cast<int>();

JSAPIAuto relies heavily on the ability of variant to convert_cast effectively for all type conversion. If the type conversion fails, a FB::bad_variant_cast exception will be thrown.

Note
If you assign a char* to variant it will be automatically converted to a std::string before the assignment.
If you assign a wchar_t* to variant it will be automatically converted to a std::wstring before the assignment

Definition at line 198 of file variant.h.


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