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. | |
| variant () | |
| Default constructor initializes the variant to an empty value. | |
| variant & | assign (const variant &x) |
| Assigns a new value from another variant. | |
| template<typename T > | |
| variant & | assign (const T &x, bool) |
| Assigns a value of arbitrary type. | |
| const std::type_info & | get_type () const |
| Gets the type of the value stored in variant. | |
| template<typename T > | |
| bool | is_of_type () const |
| Query if this object is of a particular type. | |
| template<typename T > | |
| 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 | |
| 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. | |
| bool | empty () const |
| Returns true if the variant is empty (has not been assigned a value or has been reset). | |
| void | reset () |
| Frees any value assigned and resets the variant to empty state. | |
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:
Generated on 19 Jun 2013 for FireBreath by
1.6.1
