Pepper_56_C++_interfaces
Pepper_56_C++_interfaces
 All Classes Namespaces Files Functions Typedefs Enumerations Macros Groups
pp::Var Class Reference

A generic type used for passing data types between the module and the page. More...

#include <var.h>

Inheritance diagram for pp::Var:
pp::VarArray pp::VarArrayBuffer pp::VarDictionary pp::VarPrivate

Classes

struct  DontManage
 
struct  Null
 Special value passed to constructor to make NULL. More...
 
class  OutException
 

Public Member Functions

 Var ()
 
 Var (Null)
 A constructor used to create a Var of type Null.
 
 Var (bool b)
 
 Var (int32_t i)
 
 Var (double d)
 
 Var (const char *utf8_str)
 A constructor used to create a UTF-8 character Var.
 
 Var (const std::string &utf8_str)
 A constructor used to create a UTF-8 character Var.
 
 Var (const pp::Resource &resource)
 A constructor used to create a resource Var.
 
 Var (PassRef, const PP_Var &var)
 
 Var (const PP_Var &var)
 A constructor that increments the reference count.
 
 Var (DontManage, const PP_Var &var)
 
 Var (const Var &other)
 A constructor for copying a Var.
 
virtual ~Var ()
 Destructor.
 
virtual Varoperator= (const Var &other)
 
bool operator== (const Var &other) const
 
bool is_undefined () const
 
bool is_null () const
 
bool is_bool () const
 
bool is_string () const
 
bool is_object () const
 
bool is_array () const
 
bool is_dictionary () const
 
bool is_resource () const
 
bool is_int () const
 
bool is_double () const
 
bool is_number () const
 
bool is_array_buffer () const
 This function determines if this Var is an ArrayBuffer.
 
bool AsBool () const
 
int32_t AsInt () const
 
double AsDouble () const
 
std::string AsString () const
 
pp::Resource AsResource () const
 
const PP_Var & pp_var () const
 
PP_Var Detach ()
 
std::string DebugString () const
 

Protected Attributes

PP_Var var_
 
bool is_managed_
 

Detailed Description

A generic type used for passing data types between the module and the page.

Constructor & Destructor Documentation

pp::Var::Var ( )

Default constructor. Creates a Var of type Undefined.

pp::Var::Var ( bool  b)

A constructor used to create a Var of type Bool.

Parameters
[in]bA boolean value.
pp::Var::Var ( int32_t  i)

A constructor used to create a 32 bit integer Var.

Parameters
[in]iA 32 bit integer value.
pp::Var::Var ( double  d)

A constructor used to create a double value Var.

Parameters
[in]dA double value.
pp::Var::Var ( PassRef  ,
const PP_Var &  var 
)
inline

A constructor used when you have received a Var as a return value that has had its reference count incremented for you.

You will not normally need to use this constructor because the reference count will not normally be incremented for you.

pp::Var::Var ( DontManage  ,
const PP_Var &  var 
)
inline

This constructor is used when we've given a PP_Var as an input argument from somewhere and that reference is managing the reference count for us. The object will not have its reference count increased or decreased by this class instance.

Parameters
[in]varA Var.

Member Function Documentation

bool pp::Var::AsBool ( ) const

AsBool() converts this Var to a bool. Assumes the internal representation is_bool(). If it's not, it will assert in debug mode, and return false.

Returns
A bool version of this Var.
double pp::Var::AsDouble ( ) const

AsDouble() converts this Var to a double. This function is necessary because JavaScript doesn't have a concept of ints and doubles, only numbers. The distinction between the two is an optimization inside the compiler. Since converting from a double to an int may be lossy, if you care about the distinction, either always work in doubles, or check !is_double() before calling AsInt().

These functions will assert in debug mode and return 0 if the internal representation is not is_number().

Returns
An double version of this Var.
int32_t pp::Var::AsInt ( ) const

AsInt() converts this Var to an int32_t. This function is required because JavaScript doesn't have a concept of ints and doubles, only numbers. The distinction between the two is an optimization inside the compiler. Since converting from a double to an int may be lossy, if you care about the distinction, either always work in doubles, or check !is_double() before calling AsInt().

These functions will assert in debug mode and return 0 if the internal representation is not is_number().

Returns
An int32_t version of this Var.
pp::Resource pp::Var::AsResource ( ) const

Gets the resource contained in the var. If this object is not a resource, it will assert in debug mode, and return a null resource.

Returns
The pp::Resource that is contained in the var.
std::string pp::Var::AsString ( ) const

AsString() converts this Var to a string. If this object is not a string, it will assert in debug mode, and return an empty string.

Returns
A string version of this Var.
std::string pp::Var::DebugString ( ) const

DebugString() returns a short description "Var<X>" that can be used for logging, where "X" is the underlying scalar or "UNDEFINED" or "OBJ" as it does not call into the browser to get the object description.

Returns
A string displaying the value of this Var. This function is used for debugging.
PP_Var pp::Var::Detach ( )
inline

Detach() detaches from the internal PP_Var of this object, keeping the reference count the same. This is used when returning a PP_Var from an API function where the caller expects the return value to have the reference count incremented for it.

Returns
A detached version of this object without affecting the reference count.
bool pp::Var::is_array ( ) const
inline

This function determines if this Var is an array.

Returns
true if this Var is an array, otherwise false.
bool pp::Var::is_bool ( ) const
inline

This function determines if this Var is a bool value.

Returns
true if this Var is a bool, otherwise false.
bool pp::Var::is_dictionary ( ) const
inline

This function determines if this Var is a dictionary.

Returns
true if this Var is a dictionary, otherwise false.
bool pp::Var::is_double ( ) const
inline

This function determines if this Var is a double value. The is_double function returns the internal representation. The JavaScript runtime may convert between the two as needed, so the distinction may not be relevant in all cases (int is really an optimization inside the runtime). So most of the time, you will want to check is_number().

Returns
true if this Var is a double, otherwise false.
bool pp::Var::is_int ( ) const
inline

This function determines if this Var is an integer value. The is_int function returns the internal representation. The JavaScript runtime may convert between the two as needed, so the distinction may not be relevant in all cases (int is really an optimization inside the runtime). So most of the time, you will want to check is_number().

Returns
true if this Var is an integer, otherwise false.
bool pp::Var::is_null ( ) const
inline

This function determines if this Var is a null value.

Returns
true if this Var is null, otherwise false.
bool pp::Var::is_number ( ) const
inline

This function determines if this Var is a number.

Returns
true if this Var is an int32_t or double number, otherwise false.
bool pp::Var::is_object ( ) const
inline

This function determines if this Var is an object.

Returns
true if this Var is an object, otherwise false.
bool pp::Var::is_resource ( ) const
inline

This function determines if this Var is a resource.

Returns
true if this Var is a resource, otherwise false.
bool pp::Var::is_string ( ) const
inline

This function determines if this Var is a string value.

Returns
true if this Var is a string, otherwise false.
bool pp::Var::is_undefined ( ) const
inline

This function determines if this Var is an undefined value.

Returns
true if this Var is undefined, otherwise false.
virtual Var& pp::Var::operator= ( const Var other)
virtual

This function assigns one Var to another Var.

Parameters
[in]otherThe Var to be assigned.
Returns
A resulting Var.

Reimplemented in pp::VarArrayBuffer, pp::VarDictionary, and pp::VarArray.

bool pp::Var::operator== ( const Var other) const

This function compares object identity (rather than value identity) for objects, dictionaries, and arrays

Parameters
[in]otherThe Var to be compared to this Var.
Returns
true if the other Var is the same as this Var, otherwise false.
const PP_Var& pp::Var::pp_var ( ) const
inline

This function returns the internal PP_Var managed by this Var object.

Returns
A const reference to a PP_Var.

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