Workspace 6.21.5
Public Member Functions | List of all members
NodeScriptMapper Class Reference

Node mapper using QtScript to return a value for a node.

#include <Mesh/DataStructures/nodescriptmapper.h>

Inheritance diagram for NodeScriptMapper:
[legend]

Public Member Functions

 NodeScriptMapper ()
 
 NodeScriptMapper (const NodeScriptMapper &mapper)
 
 ~NodeScriptMapper () override
 
NodeScriptMapperclone () const override
 
Application::Memento::DatacreateMementoData (const MeshModelInterface &model) const override
 
const QString & getFunctionName () const
 
const QString & getScript () const
 
double getValue (const NodeHandle &node, Application::Memento::Data &mementoData) const override
 
NodeScriptMapperoperator= (const NodeScriptMapper &mapper)
 
void setFunctionName (const QString &functionName)
 
void setScript (const QString &script)
 
- Public Member Functions inherited from NodeMapper
bool canSerialize () const override
 
NodeMapperclone () const override=0
 
virtual Application::Memento::DatacreateMementoData (const MeshModelInterface &model) const =0
 
virtual double getValue (const NodeHandle &node, Application::Memento::Data &mementoData) const =0
 
bool load (const DataExecution::SerializedItem &item) override
 
void logText (const QString &msg) const
 
bool save (DataExecution::SerializedItem &item) const override
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 
- Public Member Functions inherited from Serialize
virtual ~Serialize ()=default
 
virtual bool canSerialize () const =0
 
virtual bool load (const SerializedItem &item)=0
 
virtual bool save (SerializedItem &item) const =0
 

Constructor & Destructor Documentation

◆ NodeScriptMapper() [1/2]

◆ NodeScriptMapper() [2/2]

NodeScriptMapper ( const NodeScriptMapper mapper)

◆ ~NodeScriptMapper()

~NodeScriptMapper ( )
override

Member Function Documentation

◆ clone()

NodeScriptMapper * clone ( ) const
overridevirtual
Returns
A clone of this object.
Note
Subclasses would normally return their own type rather than the Clonable type. The C++ language rules allow a more derived type to be returned from a virtual function and the compiler will still treat it as a valid override.

Implements NodeMapper.

◆ createMementoData()

Application::Memento::Data * createMementoData ( const MeshModelInterface model) const
overridevirtual
Parameters
modelThe model that will be used for mapping nodes to values.
Returns
A memento object which client code cannot do anything useful with except pass it around. The memento is ultimately only useful to the getValue() function. It holds internal data the mapper will use to perform the required mapping.

Implements NodeMapper.

◆ getFunctionName()

const QString & getFunctionName ( ) const
Returns
The name of the function that will be called to map each node to a value.

The default function name is an empty string, however the convention is to use mapToValue as the function name. The default is empty because it allows the script contents to be as trivial as possible. See setFunctionName() for more details on this issue.

See also
setFunctionName()

◆ getScript()

const QString & getScript ( ) const
Returns
The script being used by the mapper.
See also
setScript()

◆ getValue()

double getValue ( const NodeHandle node,
Application::Memento::Data mementoData 
) const
overridevirtual
Parameters
nodeThe node for which a mapped value is required.
mementoDataThe data from the memento created by a previous call to createMementoData(). It is used internally by this function to work out what value needs to be returned.
Returns
The value for the requested node. If mementoData is invalid, which can happen if the script for this mapper generates an exception, this function returns 0.

Implements NodeMapper.

◆ operator=()

NodeScriptMapper & operator= ( const NodeScriptMapper mapper)

◆ setFunctionName()

void setFunctionName ( const QString &  functionName)
Parameters
functionNameThe name of the function to call to map each node to a value.

The functionName should refer to a valid function defined in the script provided to the mapper. If it does not, an error will occur and the mapper will fail (and therefore return 0 for all values). The one exception to this is if functionName is empty. In this case, the contents of the script are assumed to be just the body of a function and the mapper should wrap it in its own function. This is not as clear, since the script still needs to have return statements but the script itself won't show what is being returned from. Still, some users may find this "feature" useful if their script contents are more or less trivial.

See also
getFunctionName()

◆ setScript()

void setScript ( const QString &  script)
Parameters
scriptThe script to use for the mapper.
See also
getScript()