Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

DynamicObject Class Reference

A dynamicly creatable class. More...

#include <DynamicObject.h>

Inherited by Camera, Fog, ImageFilter, Light, Region, Scene, Shade, and Shape.

Inheritance diagram for DynamicObject:

Inheritance graph
[legend]
Collaboration diagram for DynamicObject:

Collaboration graph
[legend]
List of all members.

Public Methods

virtual ~DynamicObject ()
const string & className ()
 Returns the name of the class.

bool isKindOf (const string aClass)
 Returns true iff 'this' inherits from the class named 'aClass'.

bool isKindOf (Class &aClass)
 Returns true iff 'this' inherits from 'aClass'.

void read (ObjectFile &file)
 Reads the body of an object description. More...

void write (ostream &stream)
 Writes the object description to 'stream'. More...

void readParams (ObjectFile &file)
 Reads all parameter sections inside the body of the object description. More...

virtual void writeParams (ostream &stream)
 Writes all parameter sections inside the body of the object description. More...

virtual void parseSymbol (Token &t, ObjectFile &file)
 Reads a single parameter sections inside the body of the object description. More...


Static Public Methods

bool find (RefObject &object, const string &name)
 Finds the instance 'name' from the object pool. More...

RefObject & store (RefObject &object, const string &name)
 Stores the object in the object pool. More...

RefObject readRefObject (const string className, ObjectFile &file)
 Reads an object from ObjectFile. More...


Protected Methods

virtual void createSymbols ()
 Creates all parameter symbols that are used within the body of the object description.


Static Protected Attributes

Mutex mutex
 Mutex for 'objectPool'.

map< string, RefObject > objectPool
 The object pool. More...


Related Functions

(Note that these are not member functions.)

ObjectFileoperator>> (ObjectFile &file, DynamicObject *&obj)
 Reads a string from ObjectFile. More...

ObjectFileoperator>> (ObjectFile &file, RefObject &object)
 Reads a string from ObjectFile, refcount version. More...

ostream & operator<< (ostream &stream, DynamicObject &obj)
 Writes a string to an ostream.


Detailed Description

A dynamicly creatable class.

A DynamicObject can be dynamically created, i.e. created from a class name. DynamicObjects can be read from ObjectFile and be written to ostream. A DYNAMIC_OBJECT macro must be inserted in the class body and a IMPLEMENT_DYNAMIC(<className>, <superClass>) must be part of its implementation.

Note:
class MT-safe
Format:
    OBJECT ::= className [label] OBJECT_BODY
    OBJECT_BODY ::= '{ PARAM_LIST '}'
    className ::= name of a DynamicObject class
    label ::= '"' char* '"'
    PARAM_LIST ::= <empty> | PARAM ';' PARAM_LIST

    Example:
    Person "myself" {
      name "Kees";
      age 10;
    }
    


Member Function Documentation

bool DynamicObject::find RefObject &    object,
const string &    name
[static]
 

Finds the instance 'name' from the object pool.

Parameters:
object  a reference counted object in which to receive the instance.
name  the name of the instance to look for.
Postcondition:
object contains a reference to the object with name 'name' or a NULL reference.
Returns:
true iff the object was found.

void DynamicObject::parseSymbol Token   t,
ObjectFile   file
[virtual]
 

Reads a single parameter sections inside the body of the object description.

Each object has a set of parameter names associated with it, called symbols. Symbols are declared inside the createSymbols method. The method parseSymbol expects the Token t to be such a symbol and reads the corresponding parameters. Unknown symbols are passed to its super class.

Parameters:
t  Token that is the current parameter symbol.
file  ObjectFile from which to read.
Precondition:
The file is opened for reading and is positioned just after the parameter name.
Postcondition:
The parameter section is read including the terminating semicolon (';').

Reimplemented in Camera.

void DynamicObject::read ObjectFile   file
 

Reads the body of an object description.

Reads the object body from an ObjectFile. Which parameters are accepted depends on parseSymbol method.

Parameters:
file  ObjectFile from which to read.
Precondition:
file has been opened and is positioned at opening brace ('{').
Postcondition:
file is positioned on closing brace of the object ('}'). The object is initialized using the file description.

void DynamicObject::readParams ObjectFile   file
 

Reads all parameter sections inside the body of the object description.

Reads the object body from an ObjectFile excluding braces. Which parameters are accepted depends on parseSymbol method.

Parameters:
file  ObjectFile from which to read.
Precondition:
file has been opened and is positioned just after the opening brace ('{').
Postcondition:
file is positioned on closing brace of the object ('}'). The object is initialized using the file description.

RefObject DynamicObject::readRefObject const string    className,
ObjectFile   file
[static]
 

Reads an object from ObjectFile.

Todo:
Implement copy-on-write.

Reads an object from ObjectFile in the 'Object "name" {}' format or 'Object {}'. If the object 'name' is present in the object pool it is returned, otherwise a new instance is created.

Parameters:
className  The name of the class to read.
file  the file from which to read an object.
Precondition:
file is an open ObjectFile.
Returns:
the ref counted object read.

RefObject & DynamicObject::store RefObject &    object,
const string &    name
[static]
 

Stores the object in the object pool.

The object that is currently stored under name will be removed from the object pool. Since the object pool contains ref counted objects the replaced object may or may not be deleted.

Parameters:
object  Ref counted object which will be stored in the object pool.
name  name under which the object is stored.
Postcondition:
the object pool now contains a mapping from 'name' to 'object'.
Returns:
a reference to the stored object.

void DynamicObject::write ostream &    stream
 

Writes the object description to 'stream'.

The object description is written to an ostream. Which parameters are actually written depends on implementaion of writeParams.

Parameters:
stream  ostream to which to write.
Precondition:
stream is opened for writing.
Postcondition:
Object is written to stream including closing brace ('}). No newline is written.

void DynamicObject::writeParams ostream &    stream [virtual]
 

Writes all parameter sections inside the body of the object description.

This method writes all object parameters to ostream. Inhereting classes will always call super::writeParams().

Parameters:
stream  ostream to which to write.
Precondition:
stream is opened for writing.
Postcondition:
All object parameters are written.

Reimplemented in Camera.


Friends And Related Function Documentation

ObjectFile & operator>> ObjectFile   file,
RefObject &    obj
[related]
 

Reads a string from ObjectFile, refcount version.

Creates and reads a DynamicObject, the object is instanciated given the class name that is to be read from file. (Ref. counted version). Named objects are accepeted and are taken from the object pool if the exists

See also:
readRefObject.
Parameters:
file  ObjectFile from which to read.
obj  Reference Counted DynamicObject.
Precondition:
file is opened.
Postcondition:
obj == NULL when no string or inproper class name was encountered. obj != NULL when an instance is created, obj has been read from file and file is positioned at closing brace ('}').
Returns:
file.

ObjectFile & operator>> ObjectFile   file,
DynamicObject *&    obj
[related]
 

Reads a string from ObjectFile.

Creates and reads a DynamicObject, the object is instanciated given the class name that is to be read from file.

Parameters:
file  ObjectFile from which to read.
obj  Reference to DynamicObject pointer.
Precondition:
file is opened.
Postcondition:
obj == NULL when no string or inproper class name was encountered. obj != NULL when an instance is created, obj has been read from file and file is positioned at closing brace ('}').
Returns:
file.


Member Data Documentation

map< string, RefObject > DynamicObject::objectPool [static, protected]
 

The object pool.

DynamicObject instances can be stored by name in the object pool. This is simply a mapping from string to reference counted DynamicObject instances.


The documentation for this class was generated from the following files:
This documentation was generated using doxygen. If you have any comments or additions please mail me.