gnash::as_value Class Reference

ActionScript value type. More...

#include <as_value.h>

Inheritance diagram for gnash::as_value:

gnash::indexed_as_value

List of all members.

Public Types

enum  type {
  UNDEFINED, UNDEFINED_EXCEPT, NULLTYPE, NULLTYPE_EXCEPT,
  BOOLEAN, BOOLEAN_EXCEPT, STRING, STRING_EXCEPT,
  NUMBER, NUMBER_EXCEPT, OBJECT, OBJECT_EXCEPT,
  AS_FUNCTION, AS_FUNCTION_EXCEPT, MOVIECLIP, MOVIECLIP_EXCEPT
}

Public Member Functions

 as_value ()
 Construct an UNDEFINED value.
 as_value (const as_value &v)
 Copy-construct a STRING value.
 as_value (const char *str)
 Construct a STRING value.
 as_value (const std::string &str)
 Construct a STRING value.
 as_value (bool val)
 Construct a BOOLEAN value.
 as_value (int val)
 Construct a NUMBER value.
 as_value (unsigned int val)
 Construct a NUMBER value.
 as_value (float val)
 Construct a NUMBER value.
 as_value (double val)
 Construct a NUMBER value.
 as_value (long val)
 Construct a NUMBER value.
 as_value (unsigned long val)
 Construct a NUMBER value.
 as_value (asNamespace &)
 Chad: Document this.
 as_value (as_object *obj)
 Construct a NULL, OBJECT, MOVIECLIP or AS_FUNCTION value.
 as_value (boost::intrusive_ptr< as_object > obj)
 Construct an NULL, MOVIECLIP, AS_FUNCTION or OBJECT value.
 as_value (as_function *func)
 Construct a NULL or AS_FUNCTION value.
 ~as_value ()
void drop_refs ()
 Drop any ref counts we have.
const char * typeOf () const
 Return the primitive type of this value, as a string.
primitive_types ptype () const
 Get the primitive type of this value.
bool conforms_to (string_table::key name)
bool is_function () const
 Return true if this value is callable (AS_FUNCTION).
bool is_as_function () const
 Return true if this value is a AS function.
bool is_string () const
 Return true if this value is strictly a string.
bool is_number () const
 Return true if this value is strictly a number.
bool is_object () const
 Return true if this value is an object (OBJECT, AS_FUNCTION or MOVIECLIP).
bool is_sprite () const
 Return true if this value is a MOVIECLIP.
std::string to_string () const
 Get a std::string representation for this value.
std::string to_debug_string () const
std::string to_string_versioned (int version) const
 Get a string representation for this value.
double to_number () const
 Get a number representation for this value.
boost::int32_t to_int () const
 Conversion to 32bit integer.
template<typename T>
to_number () const
bool to_bool () const
 Conversion to boolean.
bool to_bool_v7 () const
 Conversion to boolean for SWF7 and up.
bool to_bool_v6 () const
 Conversion to boolean for SWF6.
bool to_bool_v5 () const
 Conversion to boolean up to SWF5.
boost::intrusive_ptr< as_objectto_object () const
 Return value as an object, converting primitive values as needed.
sprite_instanceto_sprite (bool skipRebinding=false) const
 Return value as a sprite or NULL if this is not possible.
characterto_character (bool skipRebinding=false) const
 Return value as a character or NULL if this is not possible.
as_functionto_as_function () const
 Return value as an ActionScript function ptr or NULL if it is not an ActionScript function.
as_value to_primitive () const
 Return value as a primitive type.
as_value to_primitive (type hint) const
 Return value as a primitive type, with a preference.
void convert_to_number ()
 Force type to number.
void convert_to_string ()
 Force type to string.
void convert_to_boolean ()
 Force type to bool.
void convert_to_string_versioned (int version)
 Force type to string.
void set_string (const std::string &str)
void set_std_string (const std::string &str)
void set_string (const char *str)
void set_double (double val)
void set_bool (bool val)
void set_sprite (sprite_instance &sp)
void set_character (character &sp)
void set_int (int val)
void set_nan ()
void set_as_object (as_object *obj)
 Make this value a NULL, OBJECT, MOVIECLIP or AS_FUNCTION value.
void set_as_object (boost::intrusive_ptr< as_object > obj)
void set_as_function (as_function *func)
 Make this a NULL or AS_FUNCTION value.
void set_undefined ()
void set_null ()
 Set this value to the NULL value.
bool operator== (const as_value &v) const
 Equality operator, follows strict equality semantic.
bool operator!= (const as_value &v) const
 Inequality operator, follows strict inequality semantic.
void operator= (const as_value &v)
bool is_undefined () const
bool is_null () const
bool is_bool () const
bool is_exception () const
void flag_exception ()
void unflag_exception ()
bool strictly_equals (const as_value &v) const
 Return true if this value is strictly equal to the given one.
bool equals (const as_value &v) const
 Return true if this value is abstractly equal to the given one.
void string_concat (const std::string &str)
 Sets this value to this string plus the given string.
void setReachable () const
 Set any object value as reachable (for the GC).

Static Public Member Functions

static std::string doubleToString (double val, int radix=10)
 Convert numeric value to string value, following ECMA-262 specification.


Detailed Description

ActionScript value type.

Any ActionScript value is stored into an instance of this class. The instance keeps primitive types by value and composite types by reference (smart pointer).


Member Enumeration Documentation

enum gnash::as_value::type

Enumerator:
UNDEFINED  Undefined value.
UNDEFINED_EXCEPT 
NULLTYPE  NULL value.
NULLTYPE_EXCEPT 
BOOLEAN  Boolean value.
BOOLEAN_EXCEPT 
STRING  String value.
STRING_EXCEPT 
NUMBER  Number value.
NUMBER_EXCEPT 
OBJECT  Object reference.
OBJECT_EXCEPT 
AS_FUNCTION  ActionScript function reference.
AS_FUNCTION_EXCEPT 
MOVIECLIP  MovieClip reference.
MOVIECLIP_EXCEPT 


Constructor & Destructor Documentation

gnash::as_value::as_value (  ) 

Construct an UNDEFINED value.

gnash::as_value::as_value ( const as_value v  ) 

Copy-construct a STRING value.

gnash::as_value::as_value ( const char *  str  ) 

Construct a STRING value.

gnash::as_value::as_value ( const std::string &  str  ) 

Construct a STRING value.

gnash::as_value::as_value ( bool  val  ) 

Construct a BOOLEAN value.

gnash::as_value::as_value ( int  val  ) 

Construct a NUMBER value.

gnash::as_value::as_value ( unsigned int  val  ) 

Construct a NUMBER value.

gnash::as_value::as_value ( float  val  ) 

Construct a NUMBER value.

gnash::as_value::as_value ( double  val  ) 

Construct a NUMBER value.

gnash::as_value::as_value ( long  val  ) 

Construct a NUMBER value.

gnash::as_value::as_value ( unsigned long  val  ) 

Construct a NUMBER value.

gnash::as_value::as_value ( asNamespace  )  [inline]

Chad: Document this.

gnash::as_value::as_value ( as_object obj  ) 

Construct a NULL, OBJECT, MOVIECLIP or AS_FUNCTION value.

See as_object::to_movie and as_object::to_function

Internally adds a reference to the ref-counted as_object, if not-null

gnash::as_value::as_value ( boost::intrusive_ptr< as_object obj  ) 

Construct an NULL, MOVIECLIP, AS_FUNCTION or OBJECT value.

gnash::as_value::as_value ( as_function func  ) 

Construct a NULL or AS_FUNCTION value.

gnash::as_value::~as_value (  ) 


Member Function Documentation

std::string gnash::as_value::doubleToString ( double  val,
int  radix = 10 
) [static]

Convert numeric value to string value, following ECMA-262 specification.

TODO: move here some of the good comments found in the function definition.

void gnash::as_value::drop_refs (  )  [inline]

Drop any ref counts we have.

This happens prior to changing our value. Useful when changing types/values.

const char * gnash::as_value::typeOf (  )  const

Return the primitive type of this value, as a string.

primitive_types gnash::as_value::ptype (  )  const

Get the primitive type of this value.

bool gnash::as_value::conforms_to ( string_table::key  name  ) 

bool gnash::as_value::is_function (  )  const [inline]

Return true if this value is callable (AS_FUNCTION).

bool gnash::as_value::is_as_function (  )  const [inline]

Return true if this value is a AS function.

bool gnash::as_value::is_string (  )  const [inline]

Return true if this value is strictly a string.

Note that you usually DON'T need to call this function, as if you really want a string you can always call the to_string() or to_std_string() method to perform a conversion.

bool gnash::as_value::is_number (  )  const [inline]

Return true if this value is strictly a number.

Note that you usually DON'T need to call this function, as if you really want a number you can always call the to_number() method to perform a conversion.

bool gnash::as_value::is_object (  )  const [inline]

Return true if this value is an object (OBJECT, AS_FUNCTION or MOVIECLIP).

bool gnash::as_value::is_sprite (  )  const [inline]

Return true if this value is a MOVIECLIP.

std::string gnash::as_value::to_string (  )  const

Get a std::string representation for this value.

Parameters:
env The environment to use for running the toString() method for object values. If NULL, toString() won't be run.

std::string gnash::as_value::to_debug_string (  )  const

std::string gnash::as_value::to_string_versioned ( int  version  )  const

Get a string representation for this value.

This differs from to_string() in that returned representation will depend on version of the SWF source. @ shouldn't this be the default ?

Parameters:
env The environment to use for running the toString() method for object values. If NULL, toString() won't be run.

double gnash::as_value::to_number (  )  const

Get a number representation for this value.

Parameters:
env The environment to use for running the valueOf() method for object values. If NULL, valueOf() won't be run.

boost::int32_t gnash::as_value::to_int (  )  const

Conversion to 32bit integer.

Use this conversion whenever an int is needed. This is NOT the same as calling to_number<boost::int32_t>().

Parameters:
env The environment to use for running the valueOf() method for object values.

template<typename T>
T gnash::as_value::to_number (  )  const [inline]

Shorthand: casts the result of to_number() to the requested number type. Parameter identical to that of to_number().

TODO: deprecate this function, it gets confusing as when an integer is needed the caller should invoke to_int() rather then to_number(). Implementing specializations for *all* integer types might be tedious

bool gnash::as_value::to_bool (  )  const

Conversion to boolean.

Will call version-dependent functions based on current version.

See to_bool_v5(), to_bool_v6(), to_bool_v7()

bool gnash::as_value::to_bool_v7 (  )  const

Conversion to boolean for SWF7 and up.

See to_bool()

bool gnash::as_value::to_bool_v6 (  )  const

Conversion to boolean for SWF6.

See to_bool()

bool gnash::as_value::to_bool_v5 (  )  const

Conversion to boolean up to SWF5.

See to_bool()

boost::intrusive_ptr< as_object > gnash::as_value::to_object (  )  const

Return value as an object, converting primitive values as needed.

Make sure you don't break the intrusive_ptr chain as the returned object might be a newly allocated one in case of a conversion from a primitive string, number or boolean value.

string values will be converted to String objects, numeric values will be converted to Number objects, boolean values are currently NOT converted, but should (FIXME!)

If you want to avoid the conversion, check with is_object() before calling this function.

sprite_instance * gnash::as_value::to_sprite ( bool  skipRebinding = false  )  const

Return value as a sprite or NULL if this is not possible.

This is just a wrapper around to_character() performing an additional final cast.

character * gnash::as_value::to_character ( bool  skipRebinding = false  )  const

Return value as a character or NULL if this is not possible.

If the value is a MOVIECLIP value, the stored character target is evaluated using the root movie's environment. If the target points to something that doesn't cast to a character, NULL is returned.

Note that if the value is NOT a MOVIECLIP type, NULL is always returned.

Parameters:
skipRebinding If true a reference to a destroyed character is still returned as such, rather then attempted to be resolved as a soft-reference. Main use for this is during paths resolution, to avoid infinite loops. See bug #21647.

as_function * gnash::as_value::to_as_function (  )  const

Return value as an ActionScript function ptr or NULL if it is not an ActionScript function.

as_value gnash::as_value::to_primitive (  )  const

Return value as a primitive type.

Primitive types are: undefined, null, boolean, string, number. See ECMA-2.6.2 (sections 4.3.2 and 8.6.2.6).

Parameters:
env The environment to use for calling the valueOf method.
Exceptions:
ActionTypeError if an object can't be converted to a primitive

as_value gnash::as_value::to_primitive ( type  hint  )  const

Return value as a primitive type, with a preference.

Primitive types are: undefined, null, boolean, string, number. See ECMA-2.6.2 (sections 4.3.2 and 8.6.2.6).

Parameters:
env The environment to use for calling the valueOf method.
hint NUMBER or STRING, the preferred representation we're asking for.
Exceptions:
ActionTypeError if an object can't be converted to a primitive

void gnash::as_value::convert_to_number (  ) 

Force type to number.

Parameters:
env The environment to use for running the valueOf() method for object values. If NULL, valueOf() won't be run.

void gnash::as_value::convert_to_string (  ) 

Force type to string.

void gnash::as_value::convert_to_boolean (  ) 

Force type to bool.

void gnash::as_value::convert_to_string_versioned ( int  version  ) 

Force type to string.

uses swf-version-aware converter

Parameters:
env The environment to use for running the toString() method for object values. If NULL, toString() won't be run.
See also:
to_string_versionioned

void gnash::as_value::set_string ( const std::string &  str  ) 

void gnash::as_value::set_std_string ( const std::string &  str  )  [inline]

void gnash::as_value::set_string ( const char *  str  )  [inline]

void gnash::as_value::set_double ( double  val  ) 

void gnash::as_value::set_bool ( bool  val  ) 

void gnash::as_value::set_sprite ( sprite_instance sp  ) 

void gnash::as_value::set_character ( character sp  ) 

void gnash::as_value::set_int ( int  val  )  [inline]

void gnash::as_value::set_nan (  )  [inline]

void gnash::as_value::set_as_object ( as_object obj  ) 

Make this value a NULL, OBJECT, MOVIECLIP or AS_FUNCTION value.

See as_object::to_movie and as_object::to_function

Internally adds a reference to the ref-counted as_object, if not-null

void gnash::as_value::set_as_object ( boost::intrusive_ptr< as_object obj  ) 

void gnash::as_value::set_as_function ( as_function func  ) 

Make this a NULL or AS_FUNCTION value.

void gnash::as_value::set_undefined (  ) 

void gnash::as_value::set_null (  ) 

Set this value to the NULL value.

bool gnash::as_value::operator== ( const as_value v  )  const [inline]

Equality operator, follows strict equality semantic.

See strictly_equals

bool gnash::as_value::operator!= ( const as_value v  )  const [inline]

Inequality operator, follows strict inequality semantic.

See strictly_equals

void gnash::as_value::operator= ( const as_value v  ) 

bool gnash::as_value::is_undefined (  )  const [inline]

bool gnash::as_value::is_null (  )  const [inline]

bool gnash::as_value::is_bool (  )  const [inline]

bool gnash::as_value::is_exception (  )  const [inline]

void gnash::as_value::flag_exception (  )  [inline]

void gnash::as_value::unflag_exception (  )  [inline]

bool gnash::as_value::strictly_equals ( const as_value v  )  const

Return true if this value is strictly equal to the given one.

Strict equality is defined as the two values being of the same type and the same value.

bool gnash::as_value::equals ( const as_value v  )  const

Return true if this value is abstractly equal to the given one.

See ECMA-262 abstract equality comparison (sect 11.9.3)

NOTE: these invariants should hold

Parameters:
env The environment to use for running the toString() and valueOf() methods for object values.

Compare to same type

void gnash::as_value::string_concat ( const std::string &  str  ) 

Sets this value to this string plus the given string.

void gnash::as_value::setReachable (  )  const

Set any object value as reachable (for the GC).

Object values are values stored by pointer (objects and functions)


The documentation for this class was generated from the following files:
Generated on Thu Mar 6 18:25:10 2008 for Gnash by  doxygen 1.5.4