University of Sheffield   

    The Simons
    Component Library

Introduction   Class Hierarchy   Class Listing   Index of Classes   Index of Methods   Header Files  

Object Class Reference

#include <Object.h>

Inheritance diagram for Object:

Collection Entry Exception Null Stream Type Value Sequence Unordered DataError DeviceError MethodError ObjectError FileStream FormatStream BooleanBox CharacterBox DecimalBox IntegerBox NaturalBox List of all members.

Detailed Description

Object: the abstract superclass of all objects.

The Object class is the root of the component class hierarchy. Object and its descendants are created dynamically on the heap and are passed by reference. Memory management for all Objects is achieved by reference counting. For each type of Object, a corresponding smart reference ObjectID is defined. When a client program allocates a new Object* dynamically on the heap, this should be passed immediately into an ObjectID reference. This ensures that references to the Object will be counted and, when the reference count falls to zero, the Object will be deleted. Object defines the interface for identifying, comparing, hashing, cloning, reading and writing objects, and for accessing their type.


Public Member Functions

 Object ()
 Create a new Object.

virtual ~Object ()
 Release an Object.

Natural references () const
 Return the number of references to this Object.

Natural acquire ()
 Increment this Object's reference count.

Natural release ()
 Decrement this Object's reference count.

virtual ObjectID clone () const
 Clone this Object.

virtual TypeID type () const
 Return the Type of this Object.

Natural identity () const
 Return the unique identity of this Object.

virtual Natural hash () const
 Return a quasi-unique hash code for this Object.

virtual Order compare (ObjectID) const
 Compare this Object with another Object.

virtual Void readOn (ReaderID)
 Read this Object on a Reader stream.

virtual Void writeOn (WriterID) const
 Write this Object on a Writer stream.

virtual Boolean toBoolean () const
 Attempt to convert this Object to a Boolean.

virtual Character toCharacter () const
 Attempt to convert this Object to a Character.

virtual Natural toNatural () const
 Attempt to convert this Object to a Natural.

virtual Integer toInteger () const
 Attempt to convert this Object to an Integer.

virtual Decimal toDecimal () const
 Attempt to convert this Object to a Decimal.


Protected Member Functions

 Object (const Object &)
 Copy an Object.

Void nullPointer (StringID) const
 Signal that a pointer was not initialised.

Void typeFailure (StringID) const
 Signal that an Object is not of the expected type.

Void undefined (StringID) const
 Signal that a method is abstract, and not implemented at this level.


Constructor & Destructor Documentation

Object::Object const Object &  object  )  [protected]
 

Copy an Object.

A secret copy constructor is provided for every Object type, in order to implement the clone() method, which is the primary means of duplicating an Object. Copying typically takes a shallow copy, down to the next level of managed ObjectID references, which are shared with the copy.

Parameters:
object - the Object to copy.
Returns:
a shallow copy of the Object.

Object::Object  ) 
 

Create a new Object.

Returns:
a new Object.

Object::~Object  )  [virtual]
 

Release an Object.


Member Function Documentation

unsigned Object::acquire  ) 
 

Increment this Object's reference count.

ObjectID Object::clone  )  const [virtual]
 

Clone this Object.

Cloning is the primary means of duplicating an Object. Objects are typically passed by reference and may be shared by many other client Objects in programs. Where such sharing is not desired and would cause problems due to aliasing the same Object, a clone should be taken. Cloning typically takes a shallow copy and is implemented using the secret copy constructor. By default, clone() is abstract in Object. It should be redefined in every concrete subclass.

Reimplemented in Bag, CGIReader, DeviceBusy, Entry, Exception, List, Map, NoElements, NoResponse, NotFound, NullPointer, OutOfRange, ReadFailure, Relation, Set, String, TextInput, TextOutput, Type, TypeFailure, Undefined, BooleanBox, CharacterBox, NaturalBox, IntegerBox, DecimalBox, Vector, WebOutput, WriteFailure, XMLReader, and XMLWriter.

Order Object::compare ObjectID  object  )  const [virtual]
 

Compare this Object with another Object.

Comparison is a generalisation of separate less than, equal, greater than, and not-equal functions. On the totally-ordered types, compare() always yields an Order result in { LESS, EQUAL, MORE }. On the partially-ordered types, compare() may also yield a result in { SOME, NONE } which denote different kinds of incomparability. In Sequence, compare() describes lexicographical ordering. In Unordered, compare() describes set and bag inclusion. By default, objects are only EQUAL if they are identical, otherwise the result is NONE. Any subclass which compares itself according to the values of its fields must redefine this method.

Parameters:
object - the other Object.
Returns:
an Order in { NONE, LESS, EQUAL, MORE, SOME }

Reimplemented in Entry, Sequence, String, Type, Unordered, BooleanBox, CharacterBox, NaturalBox, IntegerBox, and DecimalBox.

Natural Object::hash  )  const [virtual]
 

Return a quasi-unique hash code for this Object.

Hash codes are computed from the values of an Object's fields, such that any two Objects that are EQUAL under compare() will always hash to the same code. The inverse is not necessarily true, that is, two non-EQUAL Objects may occasionally hash to the same code. By default, the hash code is the same as the Object's identity(), since the root Object has no fields. Any subclass which compares itself according to the values of its fields must redefine this method.

Returns:
a quasi-unique hash code.

Reimplemented in Entry, Sequence, String, Type, Unordered, BooleanBox, CharacterBox, NaturalBox, IntegerBox, and DecimalBox.

Natural Object::identity  )  const [inline]
 

Return the unique identity of this Object.

The identity is computed from the memory address of this Object, which is converted into a Natural number. The identity is guaranteed to be unique within a single execution of a program, but not across multiple executions, or multiple programs, on 32-bit memory architectures. On 64-bit memory architectures, the identity is computed as the XOR of the two halves of the memory address, so is not guaranteed to be absolutely unique in very large programs that use the full address space.

Returns:
a unique identity code.

Void Object::nullPointer StringID  label  )  const [protected]
 

Signal that a pointer was not initialised.

Provided for convenience, this method is inherited by all classes and may be used to raise a NullPointer exception, to signal that the program expected a variable to contain a valid Object, but was found to contain null.

Parameters:
label - the name of the expected type.

Void Object::readOn ReaderID  in  )  [virtual]
 

Read this Object on a Reader stream.

Reconstructs the field-values of this Object by reading the fields from the Reader stream using getField(). This method is used during the reconstruction of Objects from their serially-encoded textual representation. Any subclass which expects to be serialised on a Writer stream must reimplement this method to fetch each field.

Parameters:
in - a Reader stream.

Reimplemented in Collection, Entry, String, BooleanBox, CharacterBox, NaturalBox, IntegerBox, and DecimalBox.

Natural Object::references  )  const [inline]
 

Return the number of references to this Object.

This is a count of the number of variables which currently hold this Object.

Returns:
the references to this Object.

unsigned Object::release  ) 
 

Decrement this Object's reference count.

Boolean Object::toBoolean  )  const [virtual]
 

Attempt to convert this Object to a Boolean.

By default, raises a TypeFailure exception.

Returns:
a Boolean value, when successful.

Reimplemented in String, and BooleanBox.

Character Object::toCharacter  )  const [virtual]
 

Attempt to convert this Object to a Character.

By default, raises a TypeFailure exception.

Returns:
a Character value, when successful.

Reimplemented in String, and CharacterBox.

Decimal Object::toDecimal  )  const [virtual]
 

Attempt to convert this Object to a Decimal.

By default, raises a TypeFailure exception.

Returns:
a Decimal value, when successful.

Reimplemented in String, and DecimalBox.

Integer Object::toInteger  )  const [virtual]
 

Attempt to convert this Object to an Integer.

By default, raises a TypeFailure exception.

Returns:
an Integer value, when successful.

Reimplemented in String, and IntegerBox.

Natural Object::toNatural  )  const [virtual]
 

Attempt to convert this Object to a Natural.

By default, raises a TypeFailure exception.

Returns:
a Natural value, when successful.

Reimplemented in String, and NaturalBox.

TypeID Object::type  )  const [virtual]
 

Return the Type of this Object.

Returns a Type descriptor for this Object. A Type may be used during serialisation, or in the reporting of exceptions. The Type contains a String representation of this Object's type. The extraction of type name strings depends on run-time type identification (RTTI) using typeinfo objects, which is platform dependent (see your C++ manual). This implementation works with GNU C++ and may need to be changed for other C++ compilers. You have been warned!

Returns:
a Type descriptor for this type of Object.

Reimplemented in BooleanBox, CharacterBox, NaturalBox, IntegerBox, and DecimalBox.

Void Object::typeFailure StringID  label  )  const [protected]
 

Signal that an Object is not of the expected type.

Provided for convenience, this method is inherited by all classes and may be used to raise a TypeFailure exception to signal that a given object is not of the expected type after some type conversion.

Parameters:
label - the name of the expected type.

Void Object::undefined StringID  label  )  const [protected]
 

Signal that a method is abstract, and not implemented at this level.

Provided for convenience, this method is inherited by all classes and may be used to raise an Undefined exception to signal that a given method is abstract and not implemented in that class.

Parameters:
label - the name of the not implemented method.

Void Object::writeOn WriterID  out  )  const [virtual]
 

Write this Object on a Writer stream.

Encodes the field-values of this Object by writing the fields to the Writer stream using putField(). This method is used during the encoding of Objects into their serial textual representation. Any subclass which expects to be serialised on a Writer stream must reimplement this method to write each field.

Parameters:
out - a Writer stream.

Reimplemented in Collection, Entry, String, BooleanBox, CharacterBox, NaturalBox, IntegerBox, and DecimalBox.


The documentation for this class was generated from the following files:
Generated on Fri May 5 17:17:18 2006 for The Simons Component Library by doxygen1.3