Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32base.h
Link against: euser.lib

Class CObject

CObject

Support

Supported from 5.0

Description

Implements reference counting to track concurrent references to itself.

An object of this type arranges automatic destruction of itself when the final reference is removed.

A reference counting object is any object which has CObject as its base class. Constructing a CObject derived type or calling its Open() member function adds a reference to that object by adding one to the reference count; calling its Close() member function removes a reference by subtracting one from the reference count; when the last user of the object calls Close(), the reference count becomes zero and the object is automatically destroyed.

Derivation

CBaseBase class for all classes to be instantiated on the heap
CObjectImplements reference counting to track concurrent references to itself

Defined in CObject:
AccessCount(), CObject(), Close(), Dec(), FullName(), Inc(), Name(), Open(), Owner(), SetName(), SetNameL(), SetOwner(), UniqueID(), ~CObject()

Inherited from CBase:
operator new()


Construction and destruction


CObject()

CObject();

Description

Constructs the object and initializes the reference count to one.

Once constructed, a reference counting object cannot be deleted until its reference count is reduced to zero.

See also:


~CObject()

~CObject();

Description

Destructor.

It removes this reference counting object from its object container, a CObjectCon type.

The reference count must always be zero when the destructor is called, otherwise it raises an E32USER-CBase 33 panic.

See also:

[Top]


Opening and closing


Open()

virtual TInt Open();

Description

Opens this reference counting object.

The default behaviour increments the reference count by one and returns KErrNone. Where a derived class implements its own version of this function, it must either use the protected member function Inc() to increment the reference count or make a base call to this function.

Return value

TInt

KErrNone.


Close()

virtual void Close();

Description

Closes this reference counting object.

The default behaviour decrements the reference count by one. If this becomes zero, then the function deletes this reference counting object.

Where a derived class implements its own version of this function, it can use the protected member function Dec() to decrement the reference count or make a base call to this function.

The reference count must not be negative when this function is called, otherwise it raises an E32USER-CBase 34 panic.

[Top]


Naming an object


Name()

virtual TName Name() const;

Description

Gets the name of this reference counting object.

The default behaviour provided by this function depends on whether a name has been explicitly set into the object:

Return value

TName

A modifiable buffer descriptor with a defined maximum length containing the name of this reference counting object.


FullName()

virtual TFullName FullName() const;

Description

Gets the full name of this reference counting object.

By default, the full name is a concatenation of this reference counting object's name with the full name of its owning reference counting object.

Return value

TFullName

A modifiable buffer descriptor with a defined maximum length containing the full name of this reference counting object.


SetName()

TInt SetName(const TDesC* aName);

Description

Sets or clears this reference counting object's name.

To set the name, the specified descriptor must contain the name to be set. Once the name has been successfully set, then the specified source descriptor can be discarded.

To clear an existing name, specify a NULL argument.

Parameters

const TDesC* aName

A pointer to the descriptor containing the name to be set, or NULL if an existing name is to be cleared. The length of this descriptor must not be greater than KMaxName, otherwise the function raises a USER 11 panic if the descriptor is a 16 bit variant or a USER 23 panic if the descriptor is an 8 bit variant.

Return value

TInt

KErrNone, if the function is successful; KerrNoMemory, if there is insufficient memory available.


SetNameL()

void SetNameL(const TDesC* aName);

Description

Sets or clears this reference counting object's name.

To set the name, the specified descriptor must contain the name to be set. Once the name has been successfully set, then the specified source descriptor can be discarded.

To clear an existing name, specify a NULL argument.

The function leaves if there is insufficient memory.

Parameters

const TDesC* aName

A pointer to the descriptor containing the name to be set, or NULL if an existing name is to be cleared. The length of this descriptor must not be greater than KMaxName, otherwise the function raises a USER 11 panic if the descriptor is a 16 bit variant or a USER 23 panic if the descriptor is an 8 bit variant.

[Top]


Ownership


Owner()

CObject* Owner() const;

Description

Gets a pointer to the reference counting object which owns this reference counting object.

Return value

CObject*

A pointer to the owning reference counting object. This is NULL, if there is no owner.


SetOwner()

void SetOwner(CObject* anOwner);

Description

Sets the owner of this reference counting object.

If this reference counting object already has an owner, then all knowledge of this owner is lost.

Parameters

CObject* anOwner

A pointer to the reference counting object which is to be the new owner of this reference counting object.

[Top]


Diagnostic information


AccessCount()

TInt AccessCount() const;

Description

Gets the number of open references to this reference counting object.

Parameters

TInt

The number of open references.

[Top]


Changing the reference count


Inc()

protected: void Inc();

Description

Adds one to the reference count.

This function is called by the default implementation of the Open() member function of this class.

See also:


Dec()

protected: void Dec();

Description

Subtracts one from the reference count.

This function is called by the default implementation of the Close() member function of this class.

See also:

[Top]


Unique ID


UniqueID()

protected: TInt UniqueID() const;

Description

Gets this reference counting object's unique ID.

The unique ID is an integer which is a property of the object container. It forms part of the identity of all reference counting objects and is the same value for all reference counting objects held within the same object container.

See also: