BlitzMax Extended  0.8.11
Pushing Blitz to the Max.
Data Structures | Defines | Functions | Variables
blitz_object.h File Reference

The root type which all other objects extend. More...

#include "_common.h"
#include "blitz_class.h"
#include "blitz_gc.h"

Go to the source code of this file.

Data Structures

struct  BBObject
 Basic BlitzMax object data type. More...

Defines

#define BBNULL   (&bbNullObject)
 General purpose NULL object pointer.

Functions

BBObjectbbObjectNew (const BBClass *clas)
 Creates a new instance of a class.
void bbObjectFree (BBObject *obj)
 Frees an object from memory.
void bbObjectCtor (BBObject *obj)
 Initializes a generic object.
void bbObjectDtor (BBObject *obj)
 Deinitializes a generic object.
BBStringbbObjectToString (const BBObject *obj)
 Gives the memory location of an object in a string.
BBInt bbObjectCompare (const BBObject *obj, const BBObject *rhs)
 Compares the memory location of two objects.
BBObjectbbObjectSendMessage (const BBObject *obj, const BBObject *src)
 Does not perform any action.
BBObjectbbObjectClone (const BBObject *obj)
 Creates an exact clone of the given object.
void bbObjectReserved ()
 Throws a warning that the called virtual function is reserved for future use.

Variables

BBClass bbObjectClass
 The parent class to all other user-defined classes.
BBObject bbNullObject
 A compile time instance representing a NULL object.

Detailed Description

The root type which all other objects extend.

While classes contain information and functionality for all instances of a kind. An object is one of said instances and holds variables ("Field") that describe its current state. These member variables can be modified via the virtual functions from the respective BBClass.

Author:
Mark Sibly
Fabian Niemann

Define Documentation

#define BBNULL   (&bbNullObject)

General purpose NULL object pointer.

Can be used as a NULL pointer for all BBObject* and user-defined types.

Note:
Strings and arrays have their own special NULL pointers
See also:
bbNullObject, BBNULLOBJECT

Referenced by bbExceptionInitCause(), bbNullFunctionExceptionCreate(), bbNullMethodExceptionCreate(), bbNullObjectExceptionCreate(), bbOutOfDataExceptionCreate(), bbStringFromChar(), and bbStringFromUTF8String().


Function Documentation

BBObject* bbObjectClone ( const BBObject obj)

Creates an exact clone of the given object.

Cloning means that the returned object is a completely new instance with the exact same property ("Field") values as the given one.

This default implementatin reads the necessary information for creating a new class instance from the debug_scope property of the given object's class. Every "Field" declaration that is found, is then copied depending on its type:

All primitive data types are copied by value using memcpy. The complex ones (BBObject, BBString & BBArray) are copied by reference, which means the cloned object's members point to the same instance.

If the given object is either NULL, does not have a valid class or is a pointer to bbNullObject, BBNULL is returned.

Warning:
Parameters:
objAny class instance
Returns:
A new instance of the given object's class with the same values.
BBInt bbObjectCompare ( const BBObject obj,
const BBObject rhs 
)

Compares the memory location of two objects.

Parameters:
objThe object to compare with
rhsThe righthand side object to compare against the first one
Returns:
The difference of both objects memory locations. 0 means they are at the same location and therefore equal.
void bbObjectCtor ( BBObject obj)

Initializes a generic object.

This sets the object's "clas" member to bbObjectClass.

Parameters:
objA pointer to any object
void bbObjectDtor ( BBObject obj)

Deinitializes a generic object.

This sets the object's "clas" member to NULL.

Parameters:
objA pointer to any object
void bbObjectFree ( BBObject obj)

Frees an object from memory.

Calls the class' destructor on the given obj. In single-threaded mode this also deallocates the instance using the GC.

Note:
Passing BBNULL to this function does no harm.
Parameters:
objA pointer to the object to be freed
BBObject* bbObjectNew ( const BBClass clas)

Creates a new instance of a class.

This allocates a new object with the GC and initializes it with the given class' constructor function.

All new instances of user defined classes (BlitzMax "Type") are created with this function. The compiler calls it whenever he comes across the "New" keyword in BlitzMax code.

Parameters:
clasThe class of the object to create
Returns:
A pointer to the newly allocated and initialized object
void bbObjectReserved ( )

Throws a warning that the called virtual function is reserved for future use.

Note:
If you try to access either "_reserved1_" or "_reserved2_" of a BBClass this function is called.
BBObject* bbObjectSendMessage ( const BBObject obj,
const BBObject src 
)

Does not perform any action.

This is only a place holder for the named virtual function in each class.

Parameters:
objThe object
srcThe source
Returns:
BBNULL
BBString* bbObjectToString ( const BBObject obj)

Gives the memory location of an object in a string.

Parameters:
objThe object of which the memory location is returned
Returns:
A string containing the location of the object instance in memory.

Variable Documentation

A compile time instance representing a NULL object.

This is used not only for variables of type BBObject, but for every other object except BBString and BBArray.

All uninitialized user-defined objects point to this.

Warning:
Do not free this compile-time object instance.

The parent class to all other user-defined classes.

It contains default implementations for all named virtual functions that are used if a class (and its parents) do not defined their own.