API  4.5.1
For C++ developers
OpenSim::Socket< T > Class Template Reference
+ Inheritance diagram for OpenSim::Socket< T >:

Public Member Functions

virtual ~Socket ()
 
Socket< T > * clone () const override
 Create a dynamically-allocated copy. More...
 
bool isConnected () const override
 Is the Socket connected to object(s) of type T? More...
 
const ObjectgetConnecteeAsObject (int index=-1) const override
 Return a const reference to the Object connected to this Socket. More...
 
const T & getConnectee (int index=-1) const
 Return a const reference to the object connected to this Socket. More...
 
bool canConnectTo (const Object &object) const override
 Returns true if the socket can connect to the object (i.e. More...
 
void connect (const Object &object) override
 Connect this Socket to the provided connectee object. More...
 
void findAndConnect (const ComponentPath &connectee) override
 Find a component using a partial path or component name of the correct type anywhere in the model (using Component::findComponent()) and connect to that component. More...
 
void finalizeConnection (const Component &root) override
 Connect this Socket given its connectee path property. More...
 
void disconnect () override
 Clear references to connectees. More...
 
std::string getConnecteeTypeName () const override
 Derived classes must satisfy this Interface. More...
 
 SimTK_DOWNCAST (Socket, AbstractSocket)
 
- 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...
 
void findAndConnect (const std::string &connectee)
 Same as findAndConnect(const ComponentPath&), but using a string argument. More...
 
void setConnecteePath (const std::string &path, int index=-1)
 Set the connectee path. More...
 
const std::string & getConnecteePath (int index=-1) const
 Get the connectee path. More...
 
void appendConnecteePath (const std::string &path)
 Append a connectee path to this socket. More...
 
void assignConnecteePath (const std::string &path)
 Assign the connectee path to this socket. More...
 
void clearConnecteePath ()
 Clear all connectee paths in the connectee path property. More...
 
bool isConnecteePathEmpty () const
 Check to see if the connectee path property is "empty". More...
 
const ComponentgetOwner () const
 Get owner component of this socket. More...
 

Public Types

typedef std::vector< SimTK::ReferencePtr< const T > > ConnecteeList
 

Static Public Member Functions

static Socket< T > * safeDownCast (AbstractSocket *base)
 For use in python/java/MATLAB bindings. More...
 

Protected Member Functions

 Socket (const std::string &name, const PropertyIndex &connecteePathIndex, const SimTK::Stage &connectAtStage, Component &owner)
 Create a Socket that can only connect to Object of type T with specified 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...
 

Protected Attributes

friend Component
 So that Component can construct a Socket. More...
 

Related Functions

(Note that these are not member functions.)

Creating Sockets to other objects for your Component

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

#define OpenSim_DECLARE_SOCKET(cname, T, comment)
 Create a socket for this component's dependence on another component. More...
 
#define OpenSim_DECLARE_LIST_SOCKET(cname, T, comment)
 Create a list socket for this component's dependence other components of the same type. More...
 

Member Typedef Documentation

◆ ConnecteeList

template<class T>
typedef std::vector<SimTK::ReferencePtr<const T> > OpenSim::Socket< T >::ConnecteeList

Constructor & Destructor Documentation

◆ ~Socket()

template<class T>
virtual OpenSim::Socket< T >::~Socket ( )
inlinevirtual

◆ Socket()

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

Create a Socket that can only connect to Object of type T with specified name and stage at which it should be connected.

Only Component can ever construct this class.

Parameters
namename of the socket used to describe its dependency.
connecteePathIndexIndex of the property in the containing Component that holds this Socket's connectee path(s).
connectAtStageStage at which Socket should be connected.
ownerThe component that contains this input.

Member Function Documentation

◆ canConnectTo()

template<class T>
bool OpenSim::Socket< T >::canConnectTo ( const Object ) const
inlineoverridevirtual

Returns true if the socket can connect to the object (i.e.

because the object is a matching type for the socket)

Implements OpenSim::AbstractSocket.

◆ clone()

template<class T>
Socket<T>* OpenSim::Socket< 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::AbstractSocket.

◆ connect()

template<class T>
void OpenSim::Socket< T >::connect ( const Object object)
inlineoverridevirtual

Connect this Socket to the provided connectee object.

Implements OpenSim::AbstractSocket.

References OpenSim::Socket< T >::getConnecteeTypeName(), and OpenSim::AbstractSocket::getName().

◆ disconnect()

template<class T>
void OpenSim::Socket< 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()

template<class C >
void OpenSim::Socket< C >::finalizeConnection ( const Component root)
overridevirtual

◆ findAndConnect()

template<class C >
void OpenSim::Socket< C >::findAndConnect ( const ComponentPath connectee)
overridevirtual

Find a component using a partial path or component name of the correct type anywhere in the model (using Component::findComponent()) and connect to that component.

Throws an exception If you provide only a component name and the model has multiple components with that name.

Reimplemented from OpenSim::AbstractSocket.

References OpenSim::ComponentPath::toString().

◆ getConnectee()

template<class C >
const C & OpenSim::Socket< C >::getConnectee ( int  index = -1) const

Return a const reference to the object connected to this Socket.

Referenced by OpenSim::Component::getConnectee().

◆ getConnecteeAsObject()

template<class T>
const Object& OpenSim::Socket< T >::getConnecteeAsObject ( int  index = -1) const
inlineoverridevirtual

Return a const reference to the Object connected to this Socket.

Reimplemented from OpenSim::AbstractSocket.

References OpenSim::AbstractSocket::isListSocket().

◆ getConnecteeTypeName()

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

Derived classes must satisfy this Interface.

get the type of object this socket connects to

Implements OpenSim::AbstractSocket.

Referenced by OpenSim::Socket< T >::connect().

◆ isConnected()

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

Is the Socket connected to object(s) of type T?

Implements OpenSim::AbstractSocket.

Referenced by OpenSim::Component::getConnectee().

◆ safeDownCast()

template<class T>
static Socket<T>* OpenSim::Socket< T >::safeDownCast ( AbstractSocket< T > *  base)
inlinestatic

For use in python/java/MATLAB bindings.

◆ SimTK_DOWNCAST()

template<class T>
OpenSim::Socket< T >::SimTK_DOWNCAST ( Socket< T >  ,
AbstractSocket< T >   
)

Friends And Related Function Documentation

◆ OpenSim_DECLARE_LIST_SOCKET

template<class T>
#define OpenSim_DECLARE_LIST_SOCKET (   cname,
  T,
  comment 
)
related

Create a list socket for this component's dependence other components of the same type.

You must specify the type of the components that can be connected to this socket. The comment should describe how the connected component (connectee) is used by this component.

Here's an example for using this macro:

#include <OpenSim/Simulation/Model/PhysicalOffsetFrame.h>
class MyComponent : public Component {
public:
OpenSim_DECLARE_LIST_SOCKET(frames, PhysicalOffsetFrame,
"To re-express quantities in different frames.");
...
};
Note
This macro requires that you have included the header that defines type T, as shown in the example above. We currently do not support declaring sockets if T is only forward-declared.
If you use this macro in your class, then you should NOT implement a custom copy constructor—try to use the default one. The socket will not get copied properly if you create a custom copy constructor.
See also
Component::constructSocket()

◆ OpenSim_DECLARE_SOCKET

template<class T>
#define OpenSim_DECLARE_SOCKET (   cname,
  T,
  comment 
)
related

Create a socket for this component's dependence on another component.

You must specify the type of the component that can be connected to this socket. The comment should describe how the connected component (connectee) is used by this component.

Here's an example for using this macro:

#include <OpenSim/Simulation/Model/PhysicalOffsetFrame.h>
class MyComponent : public Component {
public:
OpenSim_DECLARE_SOCKET(parent, PhysicalOffsetFrame,
"To locate this component.");
...
};
Note
This macro requires that you have included the header that defines type T, as shown in the example above. We currently do not support declaring sockets if T is only forward-declared.
If you use this macro in your class, then you should NOT implement a custom copy constructor—try to use the default one. The socket will not get copied properly if you create a custom copy constructor.
See also
Component::constructSocket()

Member Data Documentation

◆ Component

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

So that Component can construct a Socket.


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