Hopsan
MultiPort Class Referenceabstract
Inheritance diagram for MultiPort:
Port PowerMultiPort ReadMultiPort

Public Member Functions

 MultiPort (const HString &rNodeType, const HString &rPortName, Component *pParentComponent, Port *pParentPort=0)
 
virtual PortTypesEnumT getPortType () const =0
 Get the port type.
 
bool isMultiPort () const
 Convenience function to check if port is multiport.
 
double readNodeSafe (const size_t idx, const size_t subPortIdx) const
 Reads a value from the connected node.
 
void writeNodeSafe (const size_t idx, const double value, const size_t subPortIdx)
 Writes a value to the connected node.
 
double readNode (const size_t idx, const size_t subPortIdx) const
 Reads a value from the connected node.
 
void writeNode (const size_t idx, const double value, const size_t subPortIdx)
 Writes a value to the connected node.
 
const NodegetNodePtr (const size_t subPortIdx=0) const
 Returns the node pointer from one of the subports in the port (const version)
 
double * getNodeDataPtr (const size_t idx, const size_t subPortIdx) const
 
std::vector< double > * getDataVectorPtr (const size_t subPortIdx=0)
 
const std::vector< NodeDataDescription > * getNodeDataDescriptions (const size_t subPortIdx=0) const
 Get all node data descriptions from a connected sub port node.
 
const NodeDataDescriptiongetNodeDataDescription (const size_t dataid, const size_t subPortIdx=0) const
 Get a specific node data description from a connected sub port node.
 
int getNodeDataIdFromName (const HString &rName, const size_t subPortIdx=0)
 Ask the node for the dataId for a particular data name such as (Pressure)
 
bool haveLogData (const size_t subPortIdx=0)
 Check if log data exist in the ports node.
 
std::vector< double > * getLogTimeVectorPtr (const size_t subPortIdx=0)
 
std::vector< std::vector< double > > * getLogDataVectorPtr (const size_t subPortIdx=0)
 
const std::vector< std::vector< double > > * getLogDataVectorPtr (size_t subPortIdx=0) const
 
virtual void setEnableLogging (const bool enableLog)
 
double getStartValue (const size_t idx, const size_t subPortIdx=0)
 Get the an actual start value of the port.
 
void loadStartValues ()
 Load start values by copying the start values from the port to the node.
 
void loadStartValuesFromSimulation ()
 Load start values to the start value container from the node (last values from simulation)
 
virtual bool isConnectedTo (Port *pOtherPort)
 Check if this port is connected to other port.
 
bool isConnected () const
 Check if the port is currently connected.
 
size_t getNumPorts ()
 
std::vector< Port * > getConnectedPorts (const int subPortIdx=-1) const
 Get all the connected ports.
 
std::vector< double > & getNodeDataVector (const size_t subPortIdx)
 Returns a reference to the Node data in the port.
 
const std::vector< double > & getNodeDataVector (const size_t subPortIdx) const
 Returns a reference to the Node data in the port.
 
- Public Member Functions inherited from Port
 Port (const HString &rNodeType, const HString &rPortName, Component *pParentComponent, Port *pParentPort=0)
 Port base class constructor.
 
virtual ~Port ()
 Destructor.
 
double readNode (const size_t idx) const
 Reads a value from the connected node.
 
void writeNode (const size_t idx, const double value)
 Writes a value to the connected node.
 
virtual size_t getNumDataVariables () const
 Returns the number of data variables in the node.
 
virtual void setSignalNodeQuantityOrUnit (const HString &rQuantityOrUnit)
 A help function that makes it possible to overwrite the unit or quantity of scalar signal node variables.
 
virtual void setSignalNodeQuantityModifyable (bool tf)
 
virtual HString getSignalNodeQuantity () const
 
virtual bool getSignalNodeQuantityModifyable () const
 
const HStringgetVariableAlias (const size_t id) const
 Get the alias name for a specific node variable id.
 
int getVariableIdByAlias (const HString &rAlias) const
 Get the variable id for a specific alias name.
 
bool isLoggingEnabled () const
 
bool isConnectionRequired ()
 Check if the port MUST be connected.
 
size_t getNumConnectedPorts (const int subPortIdx=-1)
 Returns the number of ports connected to this port.
 
bool isInterfacePort () const
 
const HStringgetNodeType () const
 Returns the type of node that can be connected to this port.
 
virtual PortTypesEnumT getExternalPortType ()
 Get the External port type (virtual, should be overloaded in systemports only)
 
virtual PortTypesEnumT getInternalPortType ()
 Get the Internal port type (virtual, should be overloaded in systemports only)
 
virtual SortHintEnumT getSortHint () const
 
virtual void setSortHint (SortHintEnumT hint)
 
virtual SortHintEnumT getInternalSortHint ()
 
PortgetParentPort () const
 
ComponentgetComponent () const
 Returns the parent component.
 
const HStringgetName () const
 Get the port name.
 
const HStringgetComponentName () const
 Get the name of the component that the port is attached to.
 
const HStringgetDescription () const
 Get port description.
 
void setDescription (const HString &rDescription)
 Set port description.
 
std::vector< double > & getNodeDataVector ()
 Returns a reference to the Node data in the port.
 
const std::vector< double > & getNodeDataVector () const
 Returns a reference to the Node data in the port.
 

Protected Member Functions

void setNode (Node *pNode)
 Set the node that the port is connected to.
 
NodegetNodePtr (const size_t subPortIdx=0)
 Returns the node pointer from one of the subports in the port.
 
void removeSubPort (Port *ptr)
 Removes a specific subport.
 
PortaddSubPort (const hopsan::PortTypesEnumT type)
 Adds a subport of a particular type to a multiport.
 
- Protected Member Functions inherited from Port
virtual void setDefaultStartValue (const size_t idx, const double value, const size_t subPortIdx=0)
 Set the an actual start value of the port.
 
virtual void disableStartValue (const size_t idx)
 Disables start value for specified data type.
 
virtual NodegetStartNodePtr ()
 Get a pointer to the start node.
 
virtual PortaddSubPort ()
 Adds a subport to a multiport.
 
void registerStartValueParameters ()
 This function registers the startvalue parameters from the start node.
 
void unRegisterStartValueParameters ()
 Unregisters all startvalue parameters from the start node.
 
void addConnectedPort (Port *pPort, const size_t subPortIdx=0)
 Adds a pointer to an other connected port to a port.
 
void eraseConnectedPort (Port *pPort, const size_t subPortIdx=0)
 Removes a pointer to an other connected port from a port.
 
void createStartNode (const HString &rNodeType)
 Creates a start node in the port.
 
void eraseStartNode ()
 Removes the start node in the port and unregisters all start value parameters.
 
void setVariableAlias (const HString &rAlias, const size_t id)
 

Protected Attributes

std::vector< Port * > mSubPortsVector
 
- Protected Attributes inherited from Port
HString mNodeType
 
SortHintEnumT mSortHint
 
ComponentmpComponent
 
PortmpParentPort
 
bool mEnableLogging
 
std::vector< Port * > mConnectedPorts
 

Friends

class Component
 
class ComponentSystem
 
class ConnectionAssistant
 

Additional Inherited Members

- Public Types inherited from Port
enum  RequireConnectionEnumT { Required , NotRequired }
 This enum specifies the RequiredConnection enums.
 

Member Function Documentation

◆ getConnectedPorts()

std::vector< Port * > getConnectedPorts ( const int subPortIdx = -1) const
virtual

Get all the connected ports.

Parameters
[in]subPortIdxThe sub port to get connected ports from, Use -1 to indicate that all subports should be considered
Returns
A vector with port pointers to connected ports

Reimplemented from Port.

◆ getDataVectorPtr()

std::vector< double > * getDataVectorPtr ( const size_t subPortIdx = 0)
virtual
Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented from Port.

◆ getLogDataVectorPtr() [1/2]

std::vector< std::vector< double > > * getLogDataVectorPtr ( const size_t subPortIdx = 0)
virtual
Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented from Port.

◆ getLogDataVectorPtr() [2/2]

const std::vector< std::vector< double > > * getLogDataVectorPtr ( size_t subPortIdx = 0) const
virtual

Reimplemented from Port.

◆ getLogTimeVectorPtr()

std::vector< double > * getLogTimeVectorPtr ( const size_t subPortIdx = 0)
virtual
Parameters
[in]subPortIdxIgnored on non multi ports

Reimplemented from Port.

◆ getNodeDataDescription()

const NodeDataDescription * getNodeDataDescription ( const size_t dataid,
const size_t subPortIdx = 0 ) const
virtual

Get a specific node data description from a connected sub port node.

Parameters
[in]dataidThe node data id (Such as NodeHydraulic::Pressure)
[in]subPortIdxThe subport idx to fetch from (range is NOT checked)
Returns
A const pointer to the node data description, or 0 if no node exist

Reimplemented from Port.

◆ getNodeDataDescriptions()

const std::vector< NodeDataDescription > * getNodeDataDescriptions ( const size_t subPortIdx = 0) const
virtual

Get all node data descriptions from a connected sub port node.

Parameters
[in]subPortIdxThe subport idx to fetch from (range is checked)
Returns
A const pointer to the internal node vector with node data descriptions or 0 if subPortIdx is out of range or if no node exist in port

Reimplemented from Port.

◆ getNodeDataIdFromName()

int getNodeDataIdFromName ( const HString & rName,
const size_t subPortIdx = 0 )
virtual

Ask the node for the dataId for a particular data name such as (Pressure)

This is a wrapper function for the actual Node function,

Parameters
[in]rNameThe name of the variable (Such as Pressure)
[in]subPortIdxThe subPort to ask, (range is NOT checked)
Returns
The node data id (positive integer) if the variable name is found else returns -1 to indicate failure

Reimplemented from Port.

◆ getNodeDataPtr()

double * getNodeDataPtr ( const size_t idx,
const size_t subPortIdx ) const
virtual

Reimplemented from Port.

◆ getNodeDataVector() [1/2]

std::vector< double > & getNodeDataVector ( const size_t subPortIdx)
inlinevirtual

Returns a reference to the Node data in the port.

Parameters
[in]subPortIdxThe index of a multiport subport to access
Returns
A reference to the node data vector

Reimplemented from Port.

◆ getNodeDataVector() [2/2]

const std::vector< double > & getNodeDataVector ( const size_t subPortIdx) const
inlinevirtual

Returns a reference to the Node data in the port.

Parameters
[in]subPortIdxThe index of a multiport subport to access
Returns
A reference to the node data vector

Reimplemented from Port.

◆ getNodePtr() [1/2]

Node * getNodePtr ( const size_t subPortIdx = 0)
protectedvirtual

Returns the node pointer from one of the subports in the port.

Parameters
[in]subPortIdxThe sub port to retrieve from, (range check is performed)
Returns
The node pointer in the sub port, or 0 if index out of range

Reimplemented from Port.

◆ getNodePtr() [2/2]

const Node * getNodePtr ( const size_t subPortIdx = 0) const
virtual

Returns the node pointer from one of the subports in the port (const version)

Parameters
[in]subPortIdxThe sub port to retrieve from, (range check is NOT performed!)
Returns
The node pointer in the sub port

Reimplemented from Port.

◆ getNumPorts()

size_t getNumPorts ( )
virtual

Reimplemented from Port.

◆ getPortType()

virtual PortTypesEnumT getPortType ( ) const
pure virtual

Get the port type.

Reimplemented from Port.

Implemented in PowerMultiPort, and ReadMultiPort.

◆ getStartValue()

double getStartValue ( const size_t idx,
const size_t subPortIdx = 0 )
virtual

Get the an actual start value of the port.

Parameters
[in]idxis the index of the start value e.g. NodeHydraulic::Pressure
[in]subPortIdxThe sub port to get start value from
Returns
the start value

Reimplemented from Port.

◆ haveLogData()

bool haveLogData ( const size_t subPortIdx = 0)
virtual

Check if log data exist in the ports node.

Parameters
[in]subPortIdxIgnored on non multi ports
Returns
True or False

Reimplemented from Port.

◆ isConnected()

bool isConnected ( ) const
virtual

Check if the port is currently connected.

Reimplemented from Port.

◆ isConnectedTo()

bool isConnectedTo ( Port * pOtherPort)
virtual

Check if this port is connected to other port.

Reimplemented from Port.

◆ isMultiPort()

bool isMultiPort ( ) const
virtual

Convenience function to check if port is multiport.

Reimplemented from Port.

◆ loadStartValues()

void loadStartValues ( )
virtual

Load start values by copying the start values from the port to the node.

Reimplemented from Port.

◆ loadStartValuesFromSimulation()

void loadStartValuesFromSimulation ( )
virtual

Load start values to the start value container from the node (last values from simulation)

Reimplemented from Port.

◆ removeSubPort()

void removeSubPort ( Port * ptr)
protectedvirtual

Removes a specific subport.

Reimplemented from Port.

◆ setEnableLogging()

void setEnableLogging ( const bool enableLog)
virtual

Reimplemented from Port.

◆ setNode()

void setNode ( Node * pNode)
protectedvirtual

Set the node that the port is connected to.

Parameters
[in]pNodeA pointer to the Node

Reimplemented from Port.