The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | List of all members
PropertyAccessor Class Reference

#include <PropertyAccessor.hpp>

Inheritance diagram for PropertyAccessor:
Inheritance graph
[legend]

Public Member Functions

 PropertyAccessor (const PropertyAccessor &)=delete
 
PropertyAccessoroperator= (const PropertyAccessor &)=delete
 

Detailed Description

The PropertyAccessor template class hierarchy implements the heart of the technique that allows type-safe access to discoverable properties of Item subclasses based on property name. There are three inheritance levels in the property accessor class hierarchy. At level zero, the PropertyAccessor class serves as a generic base class for all classes in the hierarchy. It has a virtual destructor to enable dynamic casting for PropertyAccessor subclass instances. Otherwise, it does not offer any functionality at all. PropertyAccessor is not a template class, but all of its subclasses are.

At inheritance level one, the TypedPropertyAccessor template class defines the pure virtual interface for getting and setting a property of value type V, given as template parameter. The template is specialized for a value type representing a list of items, because this type requires a different set of setters to manage individual items in the list.

At inheritance level two, the TargetTypedPropertyAccessor template class actually implements the property access interface for a value type V and for a target type T (which must inherit Item), both given as template parameters. TargetTypedPropertyAccessor inherits TypedPropertyAccessor with an appropriate value type. The template is specialized for several value types to allow special processing, such as casting pointers between Item and one of its subclasses, or translating an enumeration value to an integer and vice versa.

This setup enables a usage pattern as follows. The PROPERTY macro's in the Item.hpp header expand to functions that load appropriate metadata for the discoverable properties defined in Item subclasses. These functions are invoked at program startup by the item registry. Each of these functions creates a TargetTypedPropertyAccessor instance with the value type of the property and the target type of the Item subclass in which the property is defined. The item registry subsequently stores this property accessor instance in a PropertyDef instance using its generic PropertyAccessor type. The generic property access functions defined in the Item class, e.g. getIntProperty(), retrieve the PropertyAccessor instance from the property definition, cast it to a TypedPropertyAccessor instance of the appropriate value type, and invoke the latter's access functions to actually access the property in the target item.


The documentation for this class was generated from the following file: