Hopsan
ComponentPowerAuthorFunctions

Functions

template<typename T >
T * getSafeConstantDataPtr (ComponentSystem *pSystem, Component *pComp, const HString &rConstantName)
 Help function to safely get the internal parameter data pointer from a subcomponent, the type needs to be known If parameter or component NULL, then error message instead of crash. More...
 
virtual bool preInitialize ()
 This function can be used to automate things prior to component initialization, only use this if you know what you are doing. More...
 
Component HOPSANCORE_DLLAPI * createSafeComponent (ComponentSystem *pSystem, const HString &rType)
 Help function to create components and abort safely if that fails. More...
 
bool HOPSANCORE_DLLAPI smartConnect (ComponentSystem *pSystem, Port *pPort1, Port *pPort2)
 Help function that only call connect if the ports are not already connected to each other. More...
 
bool HOPSANCORE_DLLAPI smartDisconnect (ComponentSystem *pSystem, Port *pPort1, Port *pPort2)
 Help function that only call disconnect if the ports are connected to each other. More...
 

Variables

bool mWarnIfUnusedSystemParameters
 This bool can be toggled off in programmed subsystems to avoid annoying warnings.
 

Detailed Description

Function Documentation

◆ createSafeComponent()

Component * createSafeComponent ( ComponentSystem pSystem,
const HString rType 
)

Help function to create components and abort safely if that fails.

Parameters
[in]pSystemA pointer to the system in which to create the component
[in]rTypeA string with the unique type name of the component to create
Returns
Pointer to created component or dummy

◆ getSafeConstantDataPtr()

T* hopsan::getSafeConstantDataPtr ( ComponentSystem pSystem,
Component pComp,
const HString rConstantName 
)

Help function to safely get the internal parameter data pointer from a subcomponent, the type needs to be known If parameter or component NULL, then error message instead of crash.

Note
circumvents the ordinary parameter system, use only if you know what you are doing
It will only work for Constants not input/output variables (then you will get pointer to start value instead)
Returns
A pointer to the parameter or a dummy parameter (to avoid crash on further use)

◆ preInitialize()

bool preInitialize ( )
virtual

This function can be used to automate things prior to component initialization, only use this if you know what you are doing.

One example of what you can do, is reconnecting internal connections in programmed subsystems

Returns
True or False to signal success or failure

Reimplemented in ComponentSystem.

◆ smartConnect()

bool smartConnect ( ComponentSystem pSystem,
Port pPort1,
Port pPort2 
)

Help function that only call connect if the ports are not already connected to each other.

Parameters
[in]pSystemThe system to handle the connection
[in]pPort1The first port to connect
[in]pPort2The other port to connect
Returns
true if connection was OK, else false

◆ smartDisconnect()

bool smartDisconnect ( ComponentSystem pSystem,
Port pPort1,
Port pPort2 
)

Help function that only call disconnect if the ports are connected to each other.

Parameters
[in]pSystemThe system to handle the disconnection
[in]pPort1The first port to disconnect
[in]pPort2The other port to disconnect
Returns
true if disconnection was OK, else false