HxmClass Class

class hexaly.modeler.HxmClass

Each instance of an HxmClass represents a class available and loaded in a module. Each HXM object has a type represented by an HxmClass whether it comes from a builtin or a user defined class. Therefore, it is possible to retrieve the class of any value that is not a boolean, integer, double or nil.

The functions below can be used to introspect the contents of all HXM classes and, in particular, to extract the various functions, properties and fields of the class, including static fields. It is also possible to build new instances of this class using the HxmClass.__call__() function.

Since an HxmClass is a value, each HxmClass also has a type represented by another HxmClass that describes the fundamental type of all other types.

Since:

13.0

Summary

Attributes

name

Returns the name of the class.

final

Returns true if the class is final.

super_class

Returns the super class of this class if it has one.

nb_members

Returns the number of members of the class.

nb_static_members

Returns the number of static members of the class.

Methods

get_name

Returns the full name of the class including the name of the module in which the class has been declared (e.

is_final

Returns true if the class has been declared as final.

is_subclass_of

Returns true if this class is a subclass of the class given as parameter.

is_instance

Returns true if the value passed in parameter is an instance of this class.

has_super_class

Returns true if this class extends another class.

get_super_class

Returns the class extended by this class.

get_nb_members

Returns the number of members present in this class.

get_member_name

Returns the name of the member with the given id.

find_member_id

Returns the id of the member with the given name or -1 if no such member exists in the class.

is_member

Returns true if a member with the given name is present in the class.

is_method

Returns true if a method with the given name or id is present in the class or inherited from a parent class.

is_field

Returns true if a field with the given name or id is present in the class or inherited from a parent class.

is_property

Returns true if a property with the given name or id is present in the class or inherited from a parent class.

get_member

Returns the member associated with the given name or id.

get_nb_static_members

Returns the number of static members declared in the class.

get_static_member_name

Returns the name of the static member with the given id.

find_static_member_id

Returns the id of the static member with the given name or -1 if no such member exists in the class.

is_static_member

Returns true if a static member with the given name is declared in the class.

get_static_member

Returns the value of the static member associated with the given name or id.

set_static_member

Sets the value of the static member with the given id.

Special methods

__call__

Returns a new instance of this class.

Instance methods

HxmClass.get_name()

Returns the full name of the class including the name of the module in which the class has been declared (e.g. module_name.ClassName).

Returns:

The name of the class.

Return type:

str

HxmClass.is_final()

Returns true if the class has been declared as final. A final class is a class that cannot be extended by inheritance.

Returns:

True if the class is final.

Return type:

bool

HxmClass.is_subclass_of(other)

Returns true if this class is a subclass of the class given as parameter. To be considered a subclass, this class must inherit directly or indirectly from the class given as parameter.

Parameters:

other (HxmClass) – Other class from which the inheritance will be tested.

Returns:

True if this class is a subclass of the class the given as parameter.

Return type:

bool

HxmClass.is_instance(value)

Returns true if the value passed in parameter is an instance of this class. An object is considered to be an instance of the class if the object’s type is equal to this class, or if the object’s type is a subclass of this class. If the value passed in parameter is not an object (such as a boolean, integer, double or nil), then false is always returned.

Parameters:

value (HxmValue) – Value for which the inheritance will be tested.

Returns:

True if the given value is an instance of this class.

Return type:

bool

HxmClass.has_super_class()

Returns true if this class extends another class. The extended class can be retrieved with the method HxmClass.get_super_class().

Returns:

True if this class extends another class.

Return type:

bool

HxmClass.get_super_class()

Returns the class extended by this class. An exception is thrown if this class does not have a super class.

Returns:

The class extended by this class.

Return type:

HxmClass

HxmClass.get_nb_members()

Returns the number of members present in this class. The members considered are those declared in this class or inherited from parent classes. A member is a field, property, method or constructor. The returned number can be used to browse members using the following methods, which take a memberId parameter ranging from 0 to HxmClass.nb_members.

Returns:

Number of members declared in the class or in the parent classes.

Return type:

int

HxmClass.get_member_name(member_id)

Returns the name of the member with the given id. An exception is thrown if memberId is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_members.

Parameters:

memberId (int) – Id of the member to get the name.

Returns:

Name of the member with the given id.

Return type:

string

HxmClass.find_member_id(member_name)

Returns the id of the member with the given name or -1 if no such member exists in the class. The considered members are those declared in this class or inherited from parent classes. The member name is case sensitive.

Parameters:

member_name (string) – Name of the member to get the id.

Returns:

The id of the member with the given name.

Return type:

int

HxmClass.is_member(member_name)

Returns true if a member with the given name is present in the class. The considered members are those declared in this class or inherited from parent classes. The member name is case sensitive. This method is equivalent to find_member_id(member_name) != -1.

Parameters:

member_name (string) – Name of the member to check.

Returns:

True if a member with the given name is present in the class.

Return type:

bool

HxmClass.is_method(member_name_or_id)

Returns true if a method with the given name or id is present in the class or inherited from a parent class. Returns false if no method with the given name is present or if the member is not a method. The member name is case sensitive. An exception is thrown if an id is provided and the id is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_members.

Parameters:

member_name_or_id (string or int) – Name or id of the method to check.

Returns:

True if a method with the given name or id is present in the class.

Return type:

bool

HxmClass.is_field(member_name_or_id)

Returns true if a field with the given name or id is present in the class or inherited from a parent class. Returns false if no field with the given name is present or if the member is not a field. The member name is case sensitive. An exception is thrown if an id is provided and the id is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_members.

Parameters:

member_name_or_id (string or int) – Name or id of the field to check.

Returns:

True if a field with the given name or id is present in the class.

Return type:

bool

HxmClass.is_property(member_name_or_id)

Returns true if a property with the given name or id is present in the class or inherited from a parent class. Returns false if no property with the given name is present or if the member is not a property. The member name is case sensitive. An exception is thrown if an id is provided and the id is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_members.

Parameters:

member_name_or_id (string or int) – Name or id of the property to check.

Returns:

True if a property with the given name or id is present in the class.

Return type:

bool

HxmClass.get_member(member_name_or_id)

Returns the member associated with the given name or id. An exception is thrown if a name is given and no member with this name exists in the class. An exception is thrown if an id is given and the id is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_members. An exception is thrown if the requested member is the constructor (to create a new instance of this class, use the method HxmClass.__call__()).

This method can return values of the following types:

Parameters:

member_name_or_id (string or int) – Name or id of the property to check.

Returns:

The member with the given name or id.

HxmClass.get_nb_static_members()

Returns the number of static members declared in the class. Only the static members declared specfically in this class actually count. There is no inheritance for static members and therefore parent classes are ignored. The returned number can be used to browse static members using the following methods, which take a staticMemberId parameter ranging from 0 to HxmClass.nb_static_members.

Returns:

Number of static members declared in the class.

Return type:

int

HxmClass.get_static_member_name(static_member_id)

Returns the name of the static member with the given id. An exception is thrown if staticMemberId is less than 0 or greater than the number of static members returned by the method HxmClass.nb_static_members.

Parameters:

static_member_id (int) – Id of the static member to get.

Returns:

Name of the member with the given id.

Return type:

string

HxmClass.find_static_member_id(static_member_name)

Returns the id of the static member with the given name or -1 if no such member exists in the class. Only the static members declared specfically in this class are actually considered for the search. The static member name is case sensitive.

Parameters:

static_member_name (string) – Name of the static member to get.

Returns:

Id of the member with the given name.

Return type:

int

HxmClass.is_static_member(static_member_name)

Returns true if a static member with the given name is declared in the class. The considered static members are only those specifically declared in the current class. There is no inheritance for static members, therefore parent classes are ignored in the search. The static member name is case sensitive.

Parameters:

static_member_name (string) – Name of the static member to check.

Returns:

True if a static member with the given name is declared in the class.

Return type:

bool

HxmClass.get_static_member(static_member_name_or_id)

Returns the value of the static member associated with the given name or id. An exception is thrown if a name is given and no member with this name exists in the class. An exception is thrown if an id is given and the id is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_static_members.

This method can return a value of the following types:

Parameters:

static_member_name_or_id (string or int) – Name of the static member to get.

Returns:

Value of the static member with the given name or id.

HxmClass.set_static_member(static_member_name_or_id, value)

Sets the value of the static member with the given id. An exception is thrown if a name is given and no static member with this name exists in the class. An exception is thrown if an id is given and the id is less than 0 or greater than the number of members returned by the attribute HxmClass.nb_static_members.

This method accepts a value of the following types:

Parameters:
  • static_member_name_or_id (string or int) – Name of the static member to check.

  • value – Value of the static member with the given name or id.

Instance attributes

HxmClass.name

Returns the name of the class. This is a shortcut for HxmClass.get_name().

HxmClass.final

Returns true if the class is final. This is a shortcut for HxmClass.is_final().

HxmClass.super_class

Returns the super class of this class if it has one. This is a shortcut for HxmClass.get_super_class().

HxmClass.nb_members

Returns the number of members of the class. This is a shortcut for HxmClass.get_nb_members().

HxmClass.nb_static_members

Returns the number of static members of the class. This is a shortcut for HxmClass.get_nb_static_members().

Special operators and methods

HxmClass.__call__(*args)

Returns a new instance of this class. The constructor is called with the arguments passed as parameters. If this class is not an exposed type (e.g. HxmMap) a value of type HxmValue is returned.

The arguments must be of the following types:

Parameters:

args – List of arguments passed to the constructor.

Returns:

A new instance of this class.

Return type:

HxmValue