BlitzMax Extended  0.8.17
Pushing Blitz to the Max.
Data Fields
BBClass Struct Reference

Contains critical information and functionality for object instances. More...

#include <blitz_class.h>

Data Fields

BBClasssuper
 The class' parent class.
void(* free )(BBObject *obj)
 The function used to free an instance from memory.
BBDebugScopedebug_scope
 The debug scope containing additional information about the class.
BBSize instance_size
 The amount of memory an instance of the class takes.
void(* ctor )(BBObject *obj)
 The class constructor.
void(* dtor )(BBObject *obj)
 The class destructor.
BBString *(* ToString )(BBObject *obj)
 Gives a string representation of the class instance.
BBInt(* Compare )(BBObject *obj, BBObject *rhs)
 Compares two instances of a class.
BBObject *(* SendMessage )(BBObject *msg, BBObject *src)
 Sends a message to an object.
BBObject *(* Clone )(BBObject *obj)
 Creates an exact copy of the object.
void * vfns [BBCLASS_NUM_VFNS]
 The virtual function table.

Detailed Description

Contains critical information and functionality for object instances.

A class is a structure which contains all necessary information to allocate and initialize an new instance of it with the GC.

It also contains all functions that the user can call to work with the class' instances that hold the data of an object.

Every class has a basic set of named function pointers: free, ctor, dtor, ToString, Compare, SendMessage and Clone. These provide some often used funtionality and should be defined in every class available to users.

In contrast to the named function pointers, the class specific functionality is contained in the virtual function table (vfns). Extending classes copy these functions from their parent class and overwrite them if necessary.


Field Documentation

BBObject*(* BBClass::Clone)(BBObject *obj)

Creates an exact copy of the object.

This should take the given object and create a new instance of the same class with the values set to be equal to the ones in the given object.

If cloning is not desirable (static class) or impossible in a certain situation, a pointer to bbNullObject should be returned.

Note:
The actual impementation depends on the specific class, these are just suggestions on how the function should behave.
Take caution when cloning instances containing pointers to other complex data types. Remember to increase references.
Parameters:
objThe class instance to be cloned
Returns:
A new instance of the class with the same properties as the given object. If that is not possible, BBNULL should be returned.
BBInt(* BBClass::Compare)(BBObject *obj, BBObject *rhs)

Compares two instances of a class.

Parameters:
objThe object to compare against
rhsThe right-hand side object which is compared to the first one
Return values:
0If both objects are equal.
>0If the object is greater than the one on the right-hand side
<0If the object is lesser than the one on the right-hand side

Referenced by bbArrayEndsWith(), bbArrayFindObject(), and bbArrayStartsWith().

void(* BBClass::ctor)(BBObject *obj)

The class constructor.

This initializes the instance's data.

Parameters:
objThe class instance to be initialized

Referenced by bbObjectNew().

BBDebugScope* BBClass::debug_scope

The debug scope containing additional information about the class.

An often used property of this structure is the name of the class. Also the reflection functionality depends on the information in this property to be complete and correct.

See also:
BBDebugScope

Referenced by bbObjectClone().

void(* BBClass::dtor)(BBObject *obj)

The class destructor.

This deinitializes any data if necessary.

Note:
Due to BlitzMax' managed memory nature, you can not be sure when a destructor is called.
Parameters:
objThe class instance to be deinitialized

Referenced by bbObjectFree(), and bbObjectNew().

void(* BBClass::free)(BBObject *obj)

The function used to free an instance from memory.

Parameters:
objThe instance to be freed
BBSize BBClass::instance_size

The amount of memory an instance of the class takes.

This information is used to allocate a new instance with the GC. Usually this is automatically set by BlitzMax' compiler.

Note:
bbStringClass and bbArrayClass are exceptions as they have an instance_size of 0. That is because their size depends on how big the variable data they encapsulate really is.
This value must not be negative at any time.

Referenced by bbClassRegister(), bbObjectFree(), and bbObjectNew().

BBObject*(* BBClass::SendMessage)(BBObject *msg, BBObject *src)

Sends a message to an object.

Parameters:
msgThe action or notice that should be processed
srcThe object that send the message and is associated with it
Returns:
The response to the send message. If there is none, BBNULL should be returned instead.
BBClass* BBClass::super

The class' parent class.

Note:
At the end of the cascade this will always point to bbObjectClass for user-defined classes.
BBString*(* BBClass::ToString)(BBObject *obj)

Gives a string representation of the class instance.

The actual format of the returned string is not specified. By default the bbObjectToString function – which only returns a string containing the memory address of the instance – is called.

But especially for debugging purposes it can be usefull to actually return information which have a higher descriptive value.

Parameters:
objThe instance to get a description of
Returns:
A string representing/describing the instance
void* BBClass::vfns[BBCLASS_NUM_VFNS]

The virtual function table.

This contains all additional (user-defined) functions.