Classes and native objects

Classes and native objects. More...

Classes

struct  flusspferd::class_info
 Information about classes exposed to javascript. More...
class  flusspferd::native_object_base
 Native object base. More...

Defines

#define FLUSSPFERD_CLASS_DESCRIPTION(cpp_name, named_parameters)   ...
 Generate a loadable class named cpp_name.

Functions

template<typename T >
object flusspferd::load_class (object container=global())
 Expose a class to Javascript.
template<typename T >
boost::enable_if< typename
boost::is_base_of
< native_function_base, T >
::type, T & >::type 
flusspferd::get_native (object const &o)
 Gets o as native function of class T.
template<typename T >
boost::enable_if< typename
boost::is_base_of
< native_function_base, T >
::type, bool >::type 
flusspferd::is_native (object const &o)
 Checks if o is a native function of class T.

Detailed Description

Classes and native objects.


Define Documentation

#define FLUSSPFERD_CLASS_DESCRIPTION ( cpp_name,
named_parameters   )     ...

Generate a loadable class named cpp_name.

Also generates a template class cpp_name_base<T>. This class contains a typedef base_type to itself, and it is the direct base class of cpp_name. This implies that inside cpp_name, the identifier base_type can be used to reference the direct base class, especially in constructors.

The class base_type has forwarding constructors to its base class (by default flusspferd::native_object_base), taking each parameter as a constant reference to its type. These forwarding constructors can be used to initialize the real (indirect) base class.

Most importantly, base_type contains a class class_info, with all elements set according to the named parameters.

Usage template:
FLUSSPFERD_CLASS_DESCRIPTION(
    cpp_name,
    (parameter_name_1, parameter_value_1)
    (parameter_name_2, parameter_value_2)
    ...
)
{
    CONTENTS
};
Parameters:
cpp_name The name of the generated class.
named_parameters A sequence of named parameters in the form (parameter1_name, parameter2_value) (parameter2_name, parameter2_value) ...
Named parameters:
base (optional)
{Class} The (indirect) base class. Must be derived from flusspferd::native_object_base and contain a valid class_info. The class' prototype will be used as the prototype of the generated prototype (i.e., instanceof works).
Default: flusspferd::native_object_base.
constructor_name (required)
{String} The name of the constructor inside the container passed to flusspferd::load_class.
constructor_arity (optional)
{Integer} The Javascript constructor's arity.
Default: 0.
constructible (optional)
{Boolean} Whether the class is constructible from Javascript.
Default: true.
full_name (required)
{String} The full, identifying name of the class, must be system-unique.
methods (optional)
[3-tuple Sequence] Sequence of automatically generated Javascript methods. Of the form (method_name, type, parameter)..., where method_name is a string.
Default: (~, none, ~)
constructor_methods (optional)
[3-tuple Sequence] Sequence of automatically generated Javascript methods on the constructor. Of the form (method_name, type, parameter)..., where method_name is a string.
Default: (~, none, ~)
properties (optional)
[3-tuple Sequence] Sequence of automatically generated Javascript properties. Of the form (property_name, type, parameter)..., where property_name is a string.
Default: (~, none, ~)
constructor_properties (optional)
[3-tuple Sequence] Sequence of automatically generated Javascript properties on the constructor. Of the form (property_name, type, parameter)..., where property_name is a string.
Default: (~, none, ~)
custom_enumerate (optional)
{Boolean} Whether the class overrides the standard enumerate hooks. (Enables class_info::custom_enumerate.)
Default: true.
augment_constructor (optional)
{0,1} If set to 1, cpp_name::augment_constructor(ctor) will be called with the constructor object as parameter when the Javascript constructor is being generated by flusspferd::load_class (or more specifically, base_type::class_info::augment_constructor).
Default: 0
augment_prototype (optional)
{0,1} If set to 1, cpp_name::augment_prototype(ctor) will be called with the prototype object as parameter when the Javascript constructor is being generated by flusspferd::load_class (or more specifically, base_type::class_info::create_prototype).
Default: 0
Method types:
The parameters methods and constructor_methods take sequences with elements of the form (method_name, type, parameter), where type is one of the identifiers mentioned below.

(?, none, ?)
Generates no method. Used as a dummy of the form (~, none, ~) because empty sequences are not valid.
(name, bind, method)
Binds the method with name name to non-static method cpp_name::method.
(name, bind_static, method)
Binds the method with name name to the static method cpp_name::method.
(name, alias, alias_name)
Copies the method alias_name into a property with name name. The method alias_name must be already defined above this method.
(name, function, (signature, expression))
Add a function expression (a functor or a Boost.Phoenix expression, for example) with a given function signature. The class object will not be passed.
Note:
Use (literally) Class instead of the class name in the expression.
(name, method, (signature, expression))
Add a function expression (a functor or a Boost.Phoenix expression, for example) with a given function signature. The class object will be passed.
Note:
Use (literally) Class instead of the class name in the expression!
Property types:
The parameters properties and constructor_properties take sequences with elements of the form (property_name, type, parameter), where type is one of the identifiers mentioned below.

(?, none, ?)
Generates no property. Used as a dummy of the form (~, none, ~) because empty sequences are not valid.
(name, getter_setter, (getter, setter))
Generates a property that is accessed through the accessors (non-static methods) cpp_name::getter and cpp_name::setter.
(name, getter, getter)
Generates a constant property that is accessed through the non-static method cpp_name::getter.
(name, variable, initial_value)
Generates a standard property with the initial value initial_value.
(name, constant, value)
Generates a constant property with the value value.
(name, getter_expression, (signature, expression))
Generates a constant property that is accessed through a getter expression (a functor or a Boost.Phoenix expression, for example) with a given function signature. The class object will be passed.
Note:
Use (literally) Class instead of the class name in the expression!
(name, getter_setter_expression, (getter_signature, getter_expression, setter_signature, setter_expression))
Generates a property that is accessed through each a getter and setter expression (a functor or a Boost.Phoenix expression, for example) with a given function signature. The class object will be passed.
Note:
Use (literally) Class instead of the class name in the expression!
Example:
FLUSSPFERD_CLASS_DESCRIPTION(
    my_class,
    (full_name, "MyModule.MyClass")
    (constructor_name, "MyClass")
    (methods,
        ("myMethod", bind, my_method)
        ("anotherName", alias, "myMethod"))
    (constructor_methods,
        ("constructorMethod", bind_static, constructor_method))
    (constructor_properties,
        ("VERSION", constant, "1.0")))
{
    double my_method(double parameter) {
        return parameter * 2;
    }
    static double constructor_method(double parameter1, int parameter2) {
        return parameter1 + parameter1;
    }
};

void some_function() {
    flusspferd::load_class<my_class>();
}
See also:
flusspferd::load_class, flusspferd::class_info

Function Documentation

template<typename T >
boost::enable_if< typename boost::is_base_of< native_object_base, T >::type, T & >::type flusspferd::get_native ( object const &  o  )  [inline]

Gets o as native function of class T.

Gets o as native object of class T.

If o is not a function, not native or not of class T then an exception will be thrown.

Parameters:
o object to check
See also:
is_native

If o is not an object, not native or not of class T then an exception will be thrown.

Parameters:
o object to check
See also:
is_native
template<typename T >
boost::enable_if< typename boost::is_base_of< native_object_base, T >::type, bool >::type flusspferd::is_native ( object const &  o  )  [inline]

Checks if o is a native function of class T.

Checks if o is a native object of class T.

flusspferd::object o = v.get_object();
if (flusspferd::is_native<my_fun>(o) {
  my_fun &b = flusspferd::get_native<my_fun>(o);
}
Parameters:
o object to check
See also:
get_native
flusspferd::object o = v.get_object();
if (flusspferd::is_native<flusspferd::binary>(o) {
  flusspferd::binary &b = flusspferd::get_native<flusspferd::binary>(o);
}
Parameters:
o object to check
See also:
get_native
template<typename T >
object flusspferd::load_class ( object  container = global()  )  [inline]

Expose a class to Javascript.

If the class is not constructible, trying to create an instance of the class will throw an error. A dummy "constructor" will be created though.

The class name is pulled from the class's class_info struct, as well as other information.

Parameters:
container Object in which to define the constructor.
See also:
flusspferd::class_info

Contact us at team -AT- flusspferd -DOT- org or as described on our homepage.

Generated on Fri Sep 3 19:05:01 2010 for Flusspferd by doxygen 1.6.1