Main Page Modules Namespaces C++ Classes Compound List File List Index
TNL: TNL::Object Class Reference

# TNL::Object Class Reference

`#include <tnlNetBase.h>`

Inheritance diagram for TNL::Object:

## Detailed Description

Base class for all NetObject, NetEvent, NetConnection and NetInterface instances.

## Ways of Referencing Object

Object supports both reference counting and safe pointers. Ref counted objects are accessed via the RefPtr template class. Once an object has been assigned using a RefPtr, it will be deleted when all the reference pointers to it are destructed. Object instances can also be safely referenced with the SafePtr template. The SafePtr template instances are automatically set NULL when the object they point to is deleted.

## The Basics

Any object which you want to work with the networking system should derive from this, and access functionality through the static interface.

This class is always used with the TNL_DECLARE_CLASS and TNL_IMPLEMENT_CLASS macros.

     // A very basic example object. It will do nothing!
     class TestObject : public NetObject {
          // Must provide a Parent typedef so the console system knows what we inherit from.
          typedef NetObject Parent;

          // This does a lot of menial declaration for you.
          TNL_DECLARE_CLASS(TestObject);
     }

     // And the accordant implementation...
     TNL_IMPLEMENT_CLASS(TestObject);

That's all you need to do to get a class registered with the TNL object system. At this point, you can instantiate it via TNL::Object::create, ghost it, and so forth.

See also:
  NetClassRepInstance for gory implementation details.

## Object Creation

These helper functions let you create an instance of a class by name or ID.

Note:
  Call these instead of NetClassRep::create

void | incRef ()
void | decRef ()
static Object * | create (const char *className)
| static function to create an instance of a named class
static Object * | create (const NetClassGroup groupId, const NetClassType typeId, const U32 classId)
| static function to create an instance of a class identified by a class group, class type and class id

## Public Member Functions

virtual NetClassRep * | getClassRep () const
| Returns the NetClassRep associated with this object.
| Object ()
virtual | ~Object ()
virtual void | destroySelf ()
| Object destroy self call (from RefPtr).
U32 | getClassId (NetClassGroup classGroup) const
| Get our class ID within the specified NetClassGroup.
const char * | getClassName () const
| Get our unmangled class name.

## Private Attributes

SafeObjectRef * | mFirstObjectRef
| The head of the linked list of safe object references.
U32 | mRefCount
| Reference counter for RefPtr objects.

## Friends

class | SafeObjectRef
class | RefObjectRef

## Constructor & Destructor Documentation

TNL::Object::Object | ( |  | ) |

virtual TNL::Object::~Object | ( |  | ) | `[virtual]`

## Member Function Documentation

virtual NetClassRep* TNL::Object::getClassRep | ( |  | ) | const`[virtual]`

Returns the NetClassRep associated with this object.

virtual void TNL::Object::destroySelf | ( |  | ) | `[inline, virtual]`

Object destroy self call (from RefPtr).

Note:
  Override if this class has specially allocated memory.

U32 TNL::Object::getClassId | ( | NetClassGroup | classGroup | ) | const`[inline]`

Get our class ID within the specified NetClassGroup.

const char * TNL::Object::getClassName | ( |  | ) | const`[inline]`

Get our unmangled class name.

static Object* TNL::Object::create | ( | const char * | className | ) | `[inline, static]`

static function to create an instance of a named class

static Object* TNL::Object::create | ( | const NetClassGroup | groupId,
|  | const NetClassType | typeId,
|  | const U32 | classId |
| ) |  |  | `[inline, static]`

static function to create an instance of a class identified by a class group, class type and class id

void TNL::Object::incRef | ( |  | ) | `[inline]`

void TNL::Object::decRef | ( |  | ) | `[inline]`

## Friends And Related Function Documentation

friend class SafeObjectRef`[friend]`

friend class RefObjectRef`[friend]`

## Field Documentation

SafeObjectRef* TNL::Object::mFirstObjectRef`[private]`

The head of the linked list of safe object references.

Reimplemented in TNL::NetObject.

U32 TNL::Object::mRefCount`[private]`

Reference counter for RefPtr objects.