Drake
DiagramBuilder< T > Class Template Reference

DiagramBuilder is a factory class for Diagram. More...

#include <drake/systems/framework/diagram.h>

Public Member Functions

 DiagramBuilder ()
 
virtual ~DiagramBuilder ()
 
template<class S >
S * AddSystem (std::unique_ptr< S > system)
 Takes ownership of system and adds it to the builder. More...
 
template<class S , typename... Args>
S * AddSystem (Args &&...args)
 Constructs a new system with the given args, and adds it to the builder, which retains ownership. More...
 
template<template< typename Scalar > class S, typename... Args>
S< T > * AddSystem (Args &&...args)
 Constructs a new system with the given args, and adds it to the builder, which retains ownership. More...
 
bool empty () const
 Returns whether any Systems have been added yet. More...
 
std::vector< systems::System< T > * > GetMutableSystems ()
 Returns the list of contained Systems. More...
 
void Connect (const OutputPort< T > &src, const InputPortDescriptor< T > &dest)
 Declares that input port dest is connected to output port src. More...
 
void Connect (const System< T > &src, const System< T > &dest)
 Declares that sole input port on the dest system is connected to sole output port on the src system. More...
 
void Cascade (const System< T > &src, const System< T > &dest)
 Cascades src and dest. More...
 
int ExportInput (const InputPortDescriptor< T > &input)
 Declares that the given input port of a constituent system is an input to the entire Diagram. More...
 
int ExportOutput (const OutputPort< T > &output)
 Declares that the given output port of a constituent system is an output of the entire diagram. More...
 
std::unique_ptr< Diagram< T > > Build ()
 Builds the Diagram that has been described by the calls to Connect, ExportInput, and ExportOutput. More...
 
void BuildInto (Diagram< T > *target)
 Configures target to have the topology that has been described by the calls to Connect, ExportInput, and ExportOutput. More...
 
Does not allow copy, move, or assignment
 DiagramBuilder (const DiagramBuilder &)=delete
 
DiagramBuilderoperator= (const DiagramBuilder &)=delete
 
 DiagramBuilder (DiagramBuilder &&)=delete
 
DiagramBuilderoperator= (DiagramBuilder &&)=delete
 

Detailed Description

template<typename T>
class drake::systems::DiagramBuilder< T >

DiagramBuilder is a factory class for Diagram.

It is single use: after calling Build or BuildInto, DiagramBuilder gives up ownership of the constituent systems, and should therefore be discarded.

A system must be added to the DiagramBuilder with AddSystem before it can be wired up in any way. Every system must have a unique, non-empty name.

Constructor & Destructor Documentation

DiagramBuilder ( const DiagramBuilder< T > &  )
delete
DiagramBuilder ( DiagramBuilder< T > &&  )
delete
DiagramBuilder ( )
inline
virtual ~DiagramBuilder ( )
inlinevirtual

Member Function Documentation

S* AddSystem ( std::unique_ptr< S >  system)
inline

Takes ownership of system and adds it to the builder.

Returns a bare pointer to the System, which will remain valid for the lifetime of the Diagram built by this builder.

If the system's name is unset, sets it to System::GetMemoryObjectName() as a default in order to have unique names within the diagram.

DiagramBuilder<T> builder;
auto foo = builder.AddSystem(std::make_unique<Foo<T>>());
Template Parameters
SThe type of system to add.

Here is the caller graph for this function:

S* AddSystem ( Args &&...  args)
inline

Constructs a new system with the given args, and adds it to the builder, which retains ownership.

Returns a bare pointer to the System, which will remain valid for the lifetime of the Diagram built by this builder.

DiagramBuilder<double> builder;
auto foo = builder.AddSystem<Foo<double>>("name", 3.14);

Note that for dependent names you must use the template keyword:

DiagramBuilder<T> builder;
auto foo = builder.template AddSystem<Foo<T>>("name", 3.14);

You may prefer the unique_ptr variant instead.

Template Parameters
SThe type of System to construct. Must subclass System<T>.
S<T>* AddSystem ( Args &&...  args)
inline

Constructs a new system with the given args, and adds it to the builder, which retains ownership.

Returns a bare pointer to the System, which will remain valid for the lifetime of the Diagram built by this builder.

DiagramBuilder<double> builder;
// Foo must be a template.
auto foo = builder.AddSystem<Foo>("name", 3.14);

Note that for dependent names you must use the template keyword:

DiagramBuilder<T> builder;
auto foo = builder.template AddSystem<Foo>("name", 3.14);

You may prefer the unique_ptr variant instead.

Template Parameters
SA template for the type of System to construct. The template will be specialized on the scalar type T of this builder.
std::unique_ptr<Diagram<T> > Build ( void  )
inline

Builds the Diagram that has been described by the calls to Connect, ExportInput, and ExportOutput.

Throws std::logic_error if the graph is not buildable.

Here is the caller graph for this function:

void BuildInto ( Diagram< T > *  target)
inline

Configures target to have the topology that has been described by the calls to Connect, ExportInput, and ExportOutput.

Throws std::logic_error if the graph is not buildable.

Only Diagram subclasses should call this method. The target must not already be initialized.

Here is the caller graph for this function:

void Cascade ( const System< T > &  src,
const System< T > &  dest 
)
inline

Cascades src and dest.

The sole input port on the dest system is connected to sole output port on the src system. Throws an exception if the sole-port precondition is not met (i.e., if dest has no input ports, or dest has more than one input port, or src has no output ports, or src has more than one output port).

Here is the caller graph for this function:

void Connect ( const OutputPort< T > &  src,
const InputPortDescriptor< T > &  dest 
)
inline

Declares that input port dest is connected to output port src.

Here is the caller graph for this function:

void Connect ( const System< T > &  src,
const System< T > &  dest 
)
inline

Declares that sole input port on the dest system is connected to sole output port on the src system.

Throws an exception if the sole-port precondition is not met (i.e., if dest has no input ports, or dest has more than one input port, or src has no output ports, or src has more than one output port).

bool empty ( ) const
inline

Returns whether any Systems have been added yet.

int ExportInput ( const InputPortDescriptor< T > &  input)
inline

Declares that the given input port of a constituent system is an input to the entire Diagram.

Returns
The index of the exported input port of the entire diagram.

Here is the caller graph for this function:

int ExportOutput ( const OutputPort< T > &  output)
inline

Declares that the given output port of a constituent system is an output of the entire diagram.

Returns
The index of the exported output port of the entire diagram.

Here is the caller graph for this function:

std::vector<systems::System<T>*> GetMutableSystems ( )
inline

Returns the list of contained Systems.

Here is the caller graph for this function:

DiagramBuilder& operator= ( DiagramBuilder< T > &&  )
delete
DiagramBuilder& operator= ( const DiagramBuilder< T > &  )
delete

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