FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
fhsim_base::SignalBlock Class Reference

#include <SignalBlock.h>

+ Inheritance diagram for fhsim_base::SignalBlock:
+ Collaboration diagram for fhsim_base::SignalBlock:

Public Types

enum class  PortWidthRule { DefaultOne , Required }
 Whether the parameter PortWidth must be in the input file. More...
 

Public Member Functions

 SignalBlock (const std::string &name, ISimObjectCreator *creator, PortWidthRule rule=PortWidthRule::DefaultOne)
 

Static Public Member Functions

static int ReadCount (ISimObjectCreator *creator, const std::string &name, int defaultValue)
 
static int ReadCount (ISimObjectCreator *creator, const std::string &name)
 As above for a count that must be in the file.
 

Protected Member Functions

int PortWidth () const
 The number of elements in the signals of the block (the parameter PortWidth).
 
std::vector< double > ReadScalarOrVector (ISimObjectCreator *creator, const std::string &name, double defaultValue) const
 
std::vector< double > ReadScalarOrVector (ISimObjectCreator *creator, const std::string &name) const
 

Protected Attributes

std::vector< double > m_out
 The output buffer, PortWidth() elements. A block may resize it, for example to the width of an output port that differs from PortWidth.
 

Detailed Description

Base class of the signal blocks: SimObjects with one width for their signals (the parameter PortWidth) and an output buffer of that width.

It reads PortWidth in one place, owns the output buffer, and has the helpers that read a parameter with one value per signal element. Blocks keep no raw new[] buffers: they use std::vector.

Member Enumeration Documentation

◆ PortWidthRule

Enumerator
DefaultOne 

Not in the file: the width is 1.

Required 

Not in the file: an error is reported.

Constructor & Destructor Documentation

◆ SignalBlock()

fhsim_base::SignalBlock::SignalBlock ( const std::string &  name,
ISimObjectCreator *  creator,
PortWidthRule  rule = PortWidthRule::DefaultOne 
)

Reads PortWidth and sizes the output buffer m_out. A width below 1 is an error reported for PortWidth; the block then continues with width 1.

Parameters
[in]nameThe name of the SimObject.
[in]creatorThe creator, used for reading parameters and for reporting errors.
[in]ruleWhether PortWidth has a default value.

Member Function Documentation

◆ ReadCount()

static int fhsim_base::SignalBlock::ReadCount ( ISimObjectCreator *  creator,
const std::string &  name,
int  defaultValue 
)
static

Reads a whole number that counts something (NumInput, NumOutput, InPortWidth<k>, OutPortWidth<k>). A count below 1 is an error reported for the parameter; the block then continues with 1. Public, so that the blocks that are not signal blocks (CMux, CDemux, CExit) read their counts in the same way.

Parameters
[in]creatorThe creator, used for reading the parameter.
[in]nameThe name of the parameter.
[in]defaultValueThe value when the parameter is not in the file.

◆ ReadScalarOrVector() [1/2]

std::vector< double > fhsim_base::SignalBlock::ReadScalarOrVector ( ISimObjectCreator *  creator,
const std::string &  name 
) const
protected

As above for a parameter that must be in the file: not in the file is an error reported for the parameter.

Parameters
[in]creatorThe creator, used for reading the parameter and for reporting errors.
[in]nameThe name of the parameter.
Returns
PortWidth() values.

◆ ReadScalarOrVector() [2/2]

std::vector< double > fhsim_base::SignalBlock::ReadScalarOrVector ( ISimObjectCreator *  creator,
const std::string &  name,
double  defaultValue 
) const
protected

Reads a parameter that has one value per signal element, with the following rules:

  • Not in the file: defaultValue is used for all elements.
  • One value: it is used for all elements.
  • PortWidth() values: one value for each element.
  • Otherwise an error is reported for the parameter.
    Parameters
    [in]creatorThe creator, used for reading the parameter and for reporting errors.
    [in]nameThe name of the parameter.
    [in]defaultValueThe value for all elements when the parameter is not in the file.
    Returns
    PortWidth() values.

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