Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SoType Class Reference

The SoType class is the basis for the run-time type system in Coin. More...

#include <Inventor/SoType.h>

List of all members.

Public Types

typedef void *(* instantiationMethod )(void)

Public Methods

SbName getName (void) const
const SoType getParent (void) const
SbBool isDerivedFrom (const SoType type) const
SbBool canCreateInstance (void) const
void * createInstance (void) const
uint16_t getData (void) const
int16_t getKey (void) const
SbBool operator== (const SoType type) const
SbBool operator!= (const SoType type) const
SbBool operator< (const SoType type) const
SbBool operator<= (const SoType type) const
SbBool operator>= (const SoType type) const
SbBool operator> (const SoType type) const
SbBool isBad (void) const
void makeInternal (void)
SbBool isInternal (void) const

Static Public Methods

SoType fromName (const SbName name)
int getAllDerivedFrom (const SoType type, SoTypeList &list)
const SoType createType (const SoType parent, const SbName name, const instantiationMethod method=(instantiationMethod) NULL, const uint16_t data=0)
const SoType overrideType (const SoType originalType, const instantiationMethod method=(instantiationMethod) NULL)
void init (void)
SoType fromKey (uint16_t key)
SoType badType (void)
int getNumTypes (void)


Detailed Description

The SoType class is the basis for the run-time type system in Coin.

Many of the classes in the Coin library must have their type information registered before any instances are created (including, but not limited to: engines, nodes, fields, actions, nodekits and manipulators). The use of SoType to store this information provides lots of various functionality for working with class hierarchies, comparing class types, instantiating objects from classnames, etc etc.

It is for instance possible to do things like this:

  void cleanLens(SoNode * anode)
  {
    assert(anode->getTypeId().isDerivedFrom(SoCamera::getClassTypeId()));

    if (anode->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
      // do something..
    }
    else if (anode->getTypeId() == SoOrthographicCamera::getClassTypeId()) {
      // do something..
    }
    else {
      SoDebugError::postWarning("cleanLens", "Unknown camera type %s!\n",
                                anode->getTypeId().getName());
    }
  }

A notable feature of the SoType class is that it is only 16 bits long and therefore should be passed around by value for efficiency reasons.

One important note about the use of SoType to register class information: super classes must be registered before any of their derived classes are.


Member Typedef Documentation

SoType::instantiationMethod
 

This is a convenience typedef for the function signature of a typed class' instantiation method. It is an extension on the original Inventor API. Mostly only useful for internal purposes.

An instantation method will take no arguments and returns a void-pointer to a newly allocated and initialized object of the class type.


Member Function Documentation

SoType SoType::fromName const SbName name [static]
 

This static method returns the SoType object associated with name name. If no known type matches the given name, SoType::badType() is returned.

SbName SoType::getName void const
 

This method returns the name of the SoBase-derived class type the SoType object is configured for.

const SoType SoType::getParent void const
 

This method returns the SoType type for the parent class of the SoBase-derived class the SoType object is configured for.

SbBool SoType::isDerivedFrom const SoType parent const
 

This method returns TRUE if the given type is derived from (or is) the parent type, and FALSE otherwise.

int SoType::getAllDerivedFrom const SoType type,
SoTypeList & list
[static]
 

This method appends all the class types derived from type to list, and returns the number of types added to the list. Internal types are not included in the list, nor are they counted.

type itself is also added to the list, as a type is seen as a derivation of its own type.

NB: do not write code which depends in any way on the order of the elements returned in list.

SbBool SoType::canCreateInstance void const
 

This method returns FALSE for abstract base classes, and TRUE for class types that can be instanciated.

void * SoType::createInstance void const
 

This method instantiates an object of the current type.

For types that can not be instanciated, NULL is returned.

uint16_t SoType::getData void const
 

This method returns a type specific data variable.

int16_t SoType::getKey void const [inline]
 

This method returns the type's index in the internal typelist.

SbBool SoType::operator== const SoType type const [inline]
 

Check type equality.

SbBool SoType::operator!= const SoType type const [inline]
 

Check type inequality.

SbBool SoType::operator< const SoType type const [inline]
 

Comparison operator for sorting type data according to some internal criterion.

SbBool SoType::operator<= const SoType type const [inline]
 

Comparison operator for sorting type data according to some internal criterion.

SbBool SoType::operator>= const SoType type const [inline]
 

Comparison operator for sorting type data according to some internal criterion.

SbBool SoType::operator> const SoType type const [inline]
 

Comparison operator for sorting type data according to some internal criterion.

const SoType SoType::createType const SoType parent,
const SbName name,
const instantiationMethod method = (instantiationMethod) NULL,
const uint16_t data = 0
[static]
 

This method creates and registers a new class type.

Abstract types should use NULL for the method argument.

If NULL is passed as the second argument, the type will be considered uninstantiable -- it does not revert the configuration to the default setting as one might think.

const SoType SoType::overrideType const SoType originalType,
const instantiationMethod method = (instantiationMethod) NULL
[static]
 

This method makes a new class override an existing class.

The new type should be a C++ subclass of the original class type, but this won't be checked though.

If NULL is passed as the second argument, the type will be considered uninstantiatable - it does not revert the configuration to the default setting as one might thing.

void SoType::init void [static]
 

This static method initializes the type system.

SoType SoType::fromKey uint16_t key [static]
 

Find and return a type from the given key ID.

SoType SoType::badType void [static]
 

This method returns an illegal type, useful for returning errors.

See also:
SbBool SoType::isBad() const

SbBool SoType::isBad void const [inline]
 

This method returns TRUE if the SoType object represents an illegal class type.

void SoType::makeInternal void
 

This method turns the specific type into an internal type.

SbBool SoType::isInternal void const
 

This function returns TRUE if the type is an internal type.

int SoType::getNumTypes void [static]
 

This function returns the number of types registered in the run-time type system.


The documentation for this class was generated from the following files:
Generated at Tue Mar 5 03:31:32 2002 for Coin by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001