The SKIRT project
advanced radiative transfer for astrophysics
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
SimulationItem Class Reference

#include <SimulationItem.hpp>

Inheritance diagram for SimulationItem:
Inheritance graph
[legend]

Public Member Functions

template<class T >
T * find (bool setup=true) const
 
template<class T >
T * interface (int levels=-999999, bool setup=true) const
 
virtual string itemName () const
 
void setup ()
 
string typeAndName () const
 
- Public Member Functions inherited from Item
 Item (const Item &)=delete
 
virtual ~Item ()
 
void addChild (Item *child)
 
const vector< Item * > & children () const
 
virtual void clearItemListProperty (const PropertyDef *property)
 
void destroyChild (Item *child)
 
virtual bool getBoolProperty (const PropertyDef *property) const
 
virtual vector< double > getDoubleListProperty (const PropertyDef *property) const
 
virtual double getDoubleProperty (const PropertyDef *property) const
 
virtual string getEnumProperty (const PropertyDef *property) const
 
virtual int getIntProperty (const PropertyDef *property) const
 
virtual vector< Item * > getItemListProperty (const PropertyDef *property) const
 
virtual ItemgetItemProperty (const PropertyDef *property) const
 
virtual string getStringProperty (const PropertyDef *property) const
 
int getUtilityProperty (string name) const
 
virtual void insertIntoItemListProperty (const PropertyDef *property, int index, Item *item)
 
Itemoperator= (const Item &)=delete
 
Itemparent () const
 
virtual void removeFromItemListProperty (const PropertyDef *property, int index)
 
virtual void setBoolProperty (const PropertyDef *property, bool value)
 
virtual void setDoubleListProperty (const PropertyDef *property, vector< double > value)
 
virtual void setDoubleProperty (const PropertyDef *property, double value)
 
virtual void setEnumProperty (const PropertyDef *property, string value)
 
virtual void setIntProperty (const PropertyDef *property, int value)
 
virtual void setItemProperty (const PropertyDef *property, Item *item)
 
virtual void setStringProperty (const PropertyDef *property, string value)
 
void setUtilityProperty (string name, int value)
 
virtual string type () const
 

Protected Member Functions

 SimulationItem ()
 
virtual bool offersInterface (const std::type_info &interfaceTypeInfo) const
 
virtual void setupSelfAfter ()
 
virtual void setupSelfBefore ()
 
- Protected Member Functions inherited from Item
 Item ()
 

Private Types

using BaseType = Item
 
using ItemType = SimulationItem
 

Private Member Functions

Itemfind (bool setup, SimulationItem *castToRequestedType(Item *)) const
 
SimulationIteminterface (int levels, bool setup, bool offersRequestedInterface(SimulationItem *)) const
 

Private Attributes

bool _setupStarted
 

Friends

class ItemRegistry
 

Detailed Description

This is the base class for all classes in the simulation hierarchy. It inherits from Item so that we can use its facilities for object hierarchies and for class introspection. Simulation items form a compile-time class hierarchy through inheritance (with the SimulationItem class at the top), and a run-time object hierarchy using the Item parent/children mechanism (usually with an instance of a MonteCarloSimulation subclass at the top).

Constructor & Destructor Documentation

◆ SimulationItem()

SimulationItem::SimulationItem ( )
inlineprotected

Default constructor for abstract Item subclass SimulationItem : "a simulation item" .

Member Function Documentation

◆ find() [1/2]

Item * SimulationItem::find ( bool  setup,
SimulationItem castToRequestedTypeItem * 
) const
private

This is the private implementation used by the find() template function. The first argument has the same semantics as the setup argument of the template function. The second argument accepts a function that dynamically casts a given Item instance to the requested simulation item type (or returns a null pointer if the Item instance is not of that type).

◆ find() [2/2]

template<class T >
T * SimulationItem::find ( bool  setup = true) const
inline

This template function looks for a simulation item of the type specified as template argument in the hierarchy containing the receiving object and, if found, returns a pointer to that item. The class specified as template parameter must inherit from SimulationItem. The function searches for an appropriate item among all ancestors of the receiving item (including the receiving item itself) and their immediate children. In other words, it recursively runs upwards along the ancestors and goes just one level down for each ancestor. The function returns the first appropriate item found; if multiple items of the same type exist in the hierarchy, it is undefined which one of these will be returned.

If the setup flag is true (the default value), the function invokes the setup() function on the item before it is returned; if no appropriate item is found, a FatalError is thrown. If the setup flag is false, the function does not perform setup on the item, and if no appropriate item is found, the function returns a null pointer.

◆ interface() [1/2]

SimulationItem * SimulationItem::interface ( int  levels,
bool  setup,
bool   offersRequestedInterfaceSimulationItem * 
) const
private

This is the private implementation used by the interface() template function. The first two arguments have the same semantics as the corresponding arguments of the template function. The last argument accepts a function that returns true if the given simulation item implements the requested interface, and false otherwise.

◆ interface() [2/2]

template<class T >
T * SimulationItem::interface ( int  levels = -999999,
bool  setup = true 
) const
inline

This template function looks for a simulation item that offers the interface specified as template argument in the hierarchy containing the receiving object and, if found, returns a pointer to that item (or rather, a pointer to the item after it has been dynamically cast to the requested interface type). The function returns the first appropriate item found. The portion of the hierarchy searched by the function for an appropriate item is defined by the value of the levels argument as follows.

For levels=0, only the receiving object is considered. For levels=-N (with N a positive integer), the receiving object plus N of its ancestors are considered in the order from nearest to more distant ancestor. For levels=N (with N a positive integer), the receiving object plus N levels of children are considered. Children at the same level are searched in an undefined order, except that children part of the same item list property are guaranteed to be searched in configuration order. Multiple levels are searched depth-first, i.e. the children of an item are searched before the next item on the same level is considered. The default value of levels is -999999, which has the effect of searching the receiving object plus all of its ancestors.

For a simulation item to be considered as offering the requested interface, two conditions must be fullfilled. First, obviously, the item's class must inherit from and implement the interface. Second, the offersInterface() function, when invoked on the item under consideration for the requested interface type, must return true. The default implementation of the offersInterface() function provided in this base class always returns true. Overriding it in a subclass allows the subclass to decide at run time whether the conditions for offering a certain interface are fullfilled.

If the setup flag is true (the default value), the function invokes the setup() function on the item before it is returned; if no appropriate item is found, a FatalError is thrown. If the setup flag is false, the function does not perform setup on the item, and if no appropriate item is found, the function returns a null pointer.

◆ itemName()

virtual string SimulationItem::itemName ( ) const
virtual

This function returns a human-readable name for the simulation item, or the empty string if it does not have one. The item name can be used to differentiate the item from other items of a similar type. The implementation in this base class returns the empty string. Subclasses can override the implementation to return something meaningful.

Reimplemented in Instrument, and Probe.

◆ offersInterface()

virtual bool SimulationItem::offersInterface ( const std::type_info &  interfaceTypeInfo) const
protectedvirtual

This function is for use only by the interface() function. After detecting that the receiving item implements the specified interface (i.e. its type inherits the interface), the interface() function invokes the offersInterface() function to ensure that the object can actually offer the interface.

Thus, this function must return true if the receiving item actually offers (not just implements) the specified interface in the current run-time environment, and false if not. The default implementation of the function provided in this base class always returns true. Overriding it in a subclass allows the subclass to decide at run time whether the conditions for offering a certain interface are fullfilled.

Reimplemented in AdaptiveMeshSpatialGrid, and VoronoiMeshSpatialGrid.

◆ setup()

void SimulationItem::setup ( )

This function performs setup for this simulation item and for all its descendents. Specifically it invokes setupSelfBefore() on itself, then setup() on all its children, and finally setupSelfAfter() on itself. As a rule, the constructor of a SimulationItem subclass sets any attributes to null values rather than to meaningful defaults (to avoid the extra construction time). Thus all attributes in the simulation hierarchy must have been explicitly set by the caller before invoking setup(). If setup() has already been invoked for the same item, this function does nothing. Do not override this function in subclasses; implement setupSelfBefore() and/or setupSelfAfter() instead.

◆ setupSelfAfter()

virtual void SimulationItem::setupSelfAfter ( )
protectedvirtual

This function should be overridden in a subclass to perform any setup that must happen after the children of the class instance have been setup. This implementation here in the SimulationItem class does nothing. Any implementation overriding this function should start by calling the same function in its immediate base class.

Reimplemented in AxPowerLawRedistributeGeometryDecorator, Band, BandWavelengthGrid, CartesianSpatialGrid, ClipGeometryDecorator, ClumpyGeometryDecorator, CompositeWavelengthGrid, Configuration, Cylinder2DSpatialGrid, DiscreteWavelengthDistribution, DisjointWavelengthGrid, DustMix, DustMixFragment, FilePolarizedPointSource, FragmentDustMixDecorator, GeometricMedium, ImportedGeometry, ImportedMedium, ImportedSource, Instrument, InstrumentSystem, LyaSEDDecorator, LyaSEDFamilyDecorator, MediumSystem, MonteCarloSimulation, NormalizedSource, RedistributeGeometryDecorator, SourceSystem, Sphere1DSpatialGrid, Sphere2DSpatialGrid, and TreeSpatialGrid.

◆ setupSelfBefore()

virtual void SimulationItem::setupSelfBefore ( )
protectedvirtual

This function should be overridden in a subclass to verify validity and completeness of the attribute values set for the class instance, and to perform any setup that must happen before the children of the class instance have been setup. This implementation here in the SimulationItem class does nothing. Any implementation overriding this function should start by calling the same function in its immediate base class.

Reimplemented in AdaptiveMeshSpatialGrid, AllSkyInstrument, AllSkyProjectionForm, AngularDistribution, AnnulusGeometry, AxAngularDistribution, BlackBodySED, BoxClipGeometryDecorator, BoxSpatialGrid, BpassSEDFamily, BroadBand, BrokenExpDiskGeometry, BruzualCharlotSEDFamily, CastelliKuruczSEDFamily, CombineGeometryDecorator, ConfigurableDustMix, Configuration, ConicalAngularDistribution, ConicalShellGeometry, ConvergenceCutsProbe, CubicSplineSmoothingKernel, CylinderSpatialGrid, DefaultWavelengthDistribution, DensityTreePolicy, DistantInstrument, DonutGeometry, DraineLiDustMix, DustMixFragment, EinastoGeometry, ElectronMix, ExpDiskGeometry, FamilySED, FileBorderWavelengthGrid, FileGrainSizeDistribution, FileIndexedSEDFamily, FileLog, FilePaths, FilePolarizedPointSource, FileSSPSEDFamily, FileWavelengthGrid, FrameInstrument, FSPSSEDFamily, FullInstrument, GammaGeometry, GaussianGeometry, GeometricSource, Geometry, HEALPixSkyInstrument, HyperboloidGeometry, HyperboloidShellGeometry, Instrument, LinBorderWavelengthGrid, LinearDustDestructionRecipe, LineSED, LinWavelengthGrid, ListBorderWavelengthGrid, ListGrainSizeDistribution, ListWavelengthGrid, Log, LogBorderWavelengthGrid, LogWavelengthDistribution, LogWavelengthGrid, LyaDoublePeakedSED, LyaGaussianSED, LyaNeutralHydrogenGasMix, MappingsSEDFamily, MarastonSEDFamily, MaterialMix, MeshGeometry, MeshMedium, MeshSource, MRNDustMix, MultiGaussianExpansionGeometry, NestedDensityTreePolicy, NestedLogWavelengthGrid, NetzerAngularDistribution, NonLTELineGasMix, NormalizedSource, OligoWavelengthGrid, ParaboloidGeometry, ParaboloidShellGeometry, PerspectiveInstrument, PlummerGeometry, PseudoSersicGeometry, Random, RangeGrainSizeDistribution, RangeWavelengthDistribution, ReadFits3DGeometry, ReadFitsGeometry, ResolutionBorderWavelengthGrid, ResolutionWavelengthGrid, ResourceSED, RingGeometry, RotateGeometryDecorator, RotateVectorFieldDecorator, ScaledGaussianSmoothingKernel, SecondarySourceSystem, SED, SEDInstrument, SersicGeometry, ShellGeometry, SineSquarePolarizationProfile, SmoothingKernel, Source, SpatialGrid, SpecialtySource, SphericalClipGeometryDecorator, SpinFlipHydrogenGasMix, SpiralStructureGeometryDecorator, Starburst99SEDFamily, TabulatedBand, TabulatedMesh, TabulatedSED, TabulatedWavelengthDistribution, ThemisDustMix, ToddlersSEDFamily, TorusGeometry, TreePolicy, TrustBenchmarkDustMix, TTauriDiskGeometry, UnidirectionalVectorField, UniformBoxGeometry, VoronoiMeshSpatialGrid, WavelengthDistribution, WeingartnerDraineDustMix, XRayAtomicGasMix, and ZubkoDustMix.

◆ typeAndName()

string SimulationItem::typeAndName ( ) const

This function returns the concatenation the type of the simulation item and its human-readable name if it has one. The resulting string can be used, for example, in log messages to identify the item and differentiate it from other items of a similar type.


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