API  4.1
For C++ developers
OpenSim::Input< T > Class Template Reference

An Input<Y> must be connected by an Output<Y> More...

+ Inheritance diagram for OpenSim::Input< T >:

Public Member Functions

Input< T > * clone () const override
 Create a dynamically-allocated copy. More...
 
void connect (const AbstractOutput &output, const std::string &alias="") override
 Connect this Input to the provided (Abstract)Output. More...
 
void connect (const AbstractChannel &channel, const std::string &alias="") override
 Connect this Input to a single output channel. More...
 
void finalizeConnection (const Component &root) override
 Connect this Input given a root Component to search for the Output according to the connectee path of this Input. More...
 
void disconnect () override
 Clear references to connectees. More...
 
bool isConnected () const override
 Derived classes must satisfy this Interface. More...
 
const T & getValue (const SimTK::State &state) const
 Get the value of this Input when it is connected. More...
 
const T & getValue (const SimTK::State &state, unsigned index) const
 Get the value of this Input when it is connected. More...
 
const ChannelgetChannel () const
 Get the Channel associated with this Input. More...
 
const ChannelgetChannel (unsigned index) const
 Get the Channel associated with this Input. More...
 
const std::string & getAlias () const override
 Get the alias for a Channel. More...
 
const std::string & getAlias (unsigned index) const override
 Get the alias for the Channel indicated by the provided index. More...
 
void setAlias (const std::string &alias) override
 Set the alias for a Channel. More...
 
void setAlias (unsigned index, const std::string &alias) override
 Set the alias for the Channel indicated by the provided index. More...
 
std::string getLabel () const override
 Get the label for this Channel. More...
 
std::string getLabel (unsigned index) const override
 Get the label for the Channel indicated by the provided index. More...
 
SimTK::Vector_< T > getVector (const SimTK::State &state) const
 Access the values of all the channels connected to this Input as a SimTK::Vector_<T>. More...
 
const ChannelListgetChannels () const
 Get const access to the channels connected to this input. More...
 
std::string getConnecteeTypeName () const override
 Return the typename of the Output value, T, that satisfies this Input<T>. More...
 
 SimTK_DOWNCAST (Input, AbstractInput)
 
- Public Member Functions inherited from OpenSim::AbstractInput
virtual ~AbstractInput ()
 
void connect (const Object &object) override
 Connect this Socket to the provided connectee object. More...
 
- Public Member Functions inherited from OpenSim::AbstractSocket
virtual ~AbstractSocket ()
 
const std::string & getName () const
 
SimTK::Stage getConnectAtStage () const
 Get the system Stage when the connection should be made. More...
 
bool isListSocket () const
 Can this Socket have more than one connectee? More...
 
unsigned getNumConnectees () const
 The number of slots to fill in order to satisfy this socket. More...
 
virtual const ObjectgetConnecteeAsObject () const
 Generic access to the connectee. More...
 
virtual void findAndConnect (const ComponentPath &connectee)
 Find the connectee using a search with a partial path. More...
 
void findAndConnect (const std::string &connectee)
 Same as findAndConnect(const ComponentPath&), but using a string argument. More...
 
void setConnecteePath (const std::string &name)
 Set connectee path. More...
 
void setConnecteePath (const std::string &name, unsigned ix)
 Set connectee path of a connectee among a list of connectees. More...
 
const std::string & getConnecteePath () const
 Get connectee path. More...
 
const std::string & getConnecteePath (unsigned ix) const
 Get connectee path of a connectee among a list of connectees. More...
 
void appendConnecteePath (const std::string &name)
 
void clearConnecteePath ()
 Clear all connectee paths in the connectee path property. More...
 
const ComponentgetOwner () const
 Get owner component of this socket. More...
 

Public Types

typedef Output< T >::Channel Channel
 
typedef std::vector< SimTK::ReferencePtr< const Channel > > ChannelList
 
typedef std::vector< std::string > AliasList
 

Static Public Member Functions

static Input< T > * safeDownCast (AbstractInput *base)
 For use in python/java/MATLAB bindings. More...
 
- Static Public Member Functions inherited from OpenSim::AbstractInput
static bool parseConnecteePath (const std::string &connecteePath, std::string &componentPath, std::string &outputName, std::string &channelName, std::string &alias)
 Break up a connectee path into its output path, channel name (empty for single-value outputs), and alias. More...
 
static std::string composeConnecteePath (const std::string &componentPath, const std::string &outputName, const std::string &channelName, const std::string &alias)
 Compose the connectee path from its constituents. More...
 

Protected Member Functions

 Input (const std::string &name, const PropertyIndex &connecteePathIndex, const SimTK::Stage &connectAtStage, Component &owner)
 Create an Input<T> (Socket) that can only connect to an Output<T> name and stage at which it should be connected. More...
 
- Protected Member Functions inherited from OpenSim::AbstractInput
 AbstractInput (const std::string &name, const PropertyIndex &connecteePathIndex, const SimTK::Stage &connectAtStage, Component &owner)
 Create an AbstractInput (Socket) that connects only to an AbstractOutput specified by name and stage at which it should be connected. More...
 
- Protected Member Functions inherited from OpenSim::AbstractSocket
 AbstractSocket (const std::string &name, const PropertyIndex &connecteePathIndex, const SimTK::Stage &connectAtStage, Component &owner)
 Create a Socket with specified name and stage at which it should be connected. More...
 
void setOwner (Component &o)
 Set an internal pointer to the Component that contains this Socket. More...
 
bool hasOwner () const
 This will be false immediately after copy construction or assignment. More...
 
void checkConnecteePathProperty ()
 Check if entries of the connectee path property's value is valid (if it contains spaces, etc.); if so, print out a warning. More...
 
const Property< std::string > & getConnecteePathProp () const
 Const access to the connectee path property from the Component in which this Socket resides. More...
 
Property< std::string > & updConnecteePathProp ()
 Writable access to the connectee path property from the Component in which this Socket resides. More...
 

Protected Attributes

friend Component
 So that Component can construct an Input. More...
 

Related Functions

(Note that these are not member functions.)

Creating Inputs for your Component

Use these macros at the top of your component class declaration, near where you declare Property properties.

#define OpenSim_DECLARE_INPUT(iname, T, istage, comment)
 Create a socket for this component's dependence on an output signal from another component. More...
 
#define OpenSim_DECLARE_LIST_INPUT(iname, T, istage, comment)
 Create a list input, which can connect to more than one Channel. More...
 

Detailed Description

template<class T>
class OpenSim::Input< T >

An Input<Y> must be connected by an Output<Y>

Member Typedef Documentation

◆ AliasList

template<class T>
typedef std::vector<std::string> OpenSim::Input< T >::AliasList

◆ Channel

template<class T>
typedef Output<T>::Channel OpenSim::Input< T >::Channel

◆ ChannelList

template<class T>
typedef std::vector<SimTK::ReferencePtr<const Channel> > OpenSim::Input< T >::ChannelList

Constructor & Destructor Documentation

◆ Input()

template<class T>
OpenSim::Input< T >::Input ( const std::string &  name,
const PropertyIndex &  connecteePathIndex,
const SimTK::Stage &  connectAtStage,
Component owner 
)
inlineprotected

Create an Input<T> (Socket) that can only connect to an Output<T> name and stage at which it should be connected.

Only Component should ever construct an Input.

Parameters
namename of the Output dependency.
connecteePathIndexIndex of the property in the containing Component that holds this Input's connectee path(s).
connectAtStageStage at which Input should be connected.
ownerThe component that contains this input.

Member Function Documentation

◆ clone()

template<class T>
Input<T>* OpenSim::Input< T >::clone ( ) const
inlineoverridevirtual

Create a dynamically-allocated copy.

You must manage the memory for the returned pointer. This function exists to facilitate the use of SimTK::ClonePtr<AbstractSocket>.

Implements OpenSim::AbstractInput.

◆ connect() [1/2]

template<class T >
void OpenSim::Input< T >::connect ( const AbstractOutput output,
const std::string &  alias = "" 
)
overridevirtual

◆ connect() [2/2]

template<class T >
void OpenSim::Input< T >::connect ( const AbstractChannel channel,
const std::string &  alias = "" 
)
overridevirtual

Connect this Input to a single output channel.

This method can be used with both single-valued and list Inputs. You can optionally provide an alias that will be used by the Component owning this Input to refer to the Channel.

Implements OpenSim::AbstractInput.

◆ disconnect()

template<class T>
void OpenSim::Input< T >::disconnect ( )
inlineoverridevirtual

Clear references to connectees.

The connectee path property is not affected. Calling finalizeConnection() will use the connectee path property to satisfy the socket.

Implements OpenSim::AbstractSocket.

◆ finalizeConnection()

◆ getAlias() [1/2]

template<class T>
const std::string& OpenSim::Input< T >::getAlias ( ) const
inlineoverridevirtual

Get the alias for a Channel.

An alias is a description for a Channel that is specific to how the Input will use the Channel. For example, the Component that owns this Input might expect the aliases to be the names of markers in the model. This method can be used only for non-list Inputs; for list Inputs, use the overload that takes an index. You must finalize connections (Component::finalizeConnections()) first.

Implements OpenSim::AbstractInput.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getAlias() [2/2]

template<class T>
const std::string& OpenSim::Input< T >::getAlias ( unsigned  index) const
inlineoverridevirtual

Get the alias for the Channel indicated by the provided index.

An alias is a description for a Channel that is specific to how the Input will use the Channel. For example, the Component that owns this Input might expect the aliases to be the names of markers in the model. You must finalize connections (Component::finalizeConnections()) first.

Implements OpenSim::AbstractInput.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getChannel() [1/2]

template<class T>
const Channel& OpenSim::Input< T >::getChannel ( ) const
inline

Get the Channel associated with this Input.

This method can only be used for non-list Input(s). For list Input(s), use the other overload.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getChannel() [2/2]

template<class T>
const Channel& OpenSim::Input< T >::getChannel ( unsigned  index) const
inline

Get the Channel associated with this Input.

Specify the index of the channel desired.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getChannels()

template<class T>
const ChannelList& OpenSim::Input< T >::getChannels ( ) const
inline

Get const access to the channels connected to this input.

You can use this to iterate through the channels.

for (const auto& chan : getChannels()) {
std::cout << chan.getValue(state) << std::endl;
}

◆ getConnecteeTypeName()

template<class T>
std::string OpenSim::Input< T >::getConnecteeTypeName ( ) const
inlineoverridevirtual

Return the typename of the Output value, T, that satisfies this Input<T>.

No reason to return Output<T> since it is a given that only an Output can satisfy an Input.

Implements OpenSim::AbstractSocket.

◆ getLabel() [1/2]

template<class T>
std::string OpenSim::Input< T >::getLabel ( ) const
inlineoverridevirtual

Get the label for this Channel.

If an alias has been set, the label is the alias; otherwise, the label is the full path of the Output that has been connected to this Input. This method can be used only for non-list Inputs; for list Inputs, use the single-argument overload. You must finalize connections (Component::finalizeConnections()) first.

Implements OpenSim::AbstractInput.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getLabel() [2/2]

template<class T>
std::string OpenSim::Input< T >::getLabel ( unsigned  index) const
inlineoverridevirtual

Get the label for the Channel indicated by the provided index.

If an alias has been set, the label is the alias; otherwise, the label is the full path of the Channel that has been connected to this Input. You must finalize connections (Component::finalizeConnections()) first.

Implements OpenSim::AbstractInput.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getValue() [1/2]

template<class T>
const T& OpenSim::Input< T >::getValue ( const SimTK::State &  state) const
inline

Get the value of this Input when it is connected.

Redirects to connected Output<T>'s getValue() with minimal overhead. This method can be used only for non-list Input(s). For list Input(s), use the other overload.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getValue() [2/2]

template<class T>
const T& OpenSim::Input< T >::getValue ( const SimTK::State &  state,
unsigned  index 
) const
inline

Get the value of this Input when it is connected.

Redirects to connected Output<T>'s getValue() with minimal overhead. Specify the index of the Channel whose value is desired.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ getVector()

template<class T>
SimTK::Vector_<T> OpenSim::Input< T >::getVector ( const SimTK::State &  state) const
inline

Access the values of all the channels connected to this Input as a SimTK::Vector_<T>.

The elements are in the same order as the channels.

◆ isConnected()

template<class T>
bool OpenSim::Input< T >::isConnected ( ) const
inlineoverridevirtual

Derived classes must satisfy this Interface.

Is the Socket connected to its connectee(s)? For a list socket, this is only true if this socket is connected to all its connectees.

Implements OpenSim::AbstractSocket.

◆ safeDownCast()

template<class T>
static Input<T>* OpenSim::Input< T >::safeDownCast ( AbstractInput< T > *  base)
inlinestatic

For use in python/java/MATLAB bindings.

◆ setAlias() [1/2]

template<class T>
void OpenSim::Input< T >::setAlias ( const std::string &  alias)
inlineoverridevirtual

Set the alias for a Channel.

If this is a list Input, the aliases of all Channels will be set to the provided string. If you wish to set the alias of only one Channel, use the two-argument overload. You must finalize connections (Component::finalizeConnections()) first.

Implements OpenSim::AbstractInput.

◆ setAlias() [2/2]

template<class T>
void OpenSim::Input< T >::setAlias ( unsigned  index,
const std::string &  alias 
)
inlineoverridevirtual

Set the alias for the Channel indicated by the provided index.

You must finalize connections (Component::finalizeConnections()) first.

Implements OpenSim::AbstractInput.

References OpenSim::Exception::OPENSIM_THROW_IF.

◆ SimTK_DOWNCAST()

template<class T>
OpenSim::Input< T >::SimTK_DOWNCAST ( Input< T >  ,
AbstractInput< T >   
)

Friends And Related Function Documentation

◆ OpenSim_DECLARE_INPUT

template<class T>
#define OpenSim_DECLARE_INPUT (   iname,
  T,
  istage,
  comment 
)
related

Create a socket for this component's dependence on an output signal from another component.

It is a placeholder for an Output that can be connected to it. An output must have the same type T as an input to be connected to it. You must also specify the stage at which you require this input quantity. The comment should describe how the input quantity is used.

An Input declared with this macro can connect to only one Output.

Here's an example for using this macro:

class MyComponent : public Component {
public:
OpenSim_DECLARE_INPUT(emg, double, SimTK::Stage::Velocity, "For validation.");
...
};
Note
If you use this macro in your class, then you should NOT implement a custom copy constructor—try to use the default one. The Input will not get copied properly if you create a custom copy constructor. We may add support for custom copy constructors with Inputs in the future.
See also
Component::constructInput()

◆ OpenSim_DECLARE_LIST_INPUT

template<class T>
#define OpenSim_DECLARE_LIST_INPUT (   iname,
  T,
  istage,
  comment 
)
related

Create a list input, which can connect to more than one Channel.

This makes sense for components like reporters that can handle a flexible number of input values.

Note
If you use this macro in your class, then you should NOT implement a custom copy constructor—try to use the default one. The Input will not get copied properly if you create a custom copy constructor. We may add support for custom copy constructors with Inputs in the future.
See also
Component::constructInput()

Member Data Documentation

◆ Component

template<class T>
friend OpenSim::Input< T >::Component
protected

So that Component can construct an Input.


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