Cerata
A library to generate structural hardware designs
cerata::Component Class Reference

A Component graph. More...

#include <graph.h>

+ Inheritance diagram for cerata::Component:
+ Collaboration diagram for cerata::Component:

Public Member Functions

 Component (std::string name)
 Construct an empty Component.
 
GraphAdd (const std::shared_ptr< Object > &object) override
 Add an object to the component.
 
GraphAdd (const std::vector< std::shared_ptr< Object >> &objects) override
 Add a list of objects to the component.
 
GraphRemove (Object *object) override
 Remove an object from the component.
 
InstanceInstantiate (Component *comp, const std::string &name="")
 Add an Instance of another Component to this component. More...
 
InstanceInstantiate (const std::shared_ptr< Component > &comp, const std::string &name="")
 Add an Instance of another Component to this component. More...
 
std::vector< Instance * > children () const
 Returns all Instance graphs from this Component.
 
virtual std::vector< const Component * > GetAllInstanceComponents () const
 Returns all unique Components that are referred to by child Instances of this graph.
 
bool HasChild (const std::string &name) const
 Return true if child graph exists on instance.
 
bool HasChild (const Instance &inst) const
 Return true if instance is a child of component.
 
NodeMapinst_to_comp_map ()
 Return the component node to instance node mapping.
 
- Public Member Functions inherited from cerata::Graph
 Graph (std::string name, ID id)
 Construct a new graph.
 
ID id () const
 Return the graph type ID.
 
bool IsComponent () const
 Return true if this graph is a component, false otherwise.
 
bool IsInstance () const
 Return true if this graph is an instance, false otherwise.
 
template<typename T >
std::vector< T * > GetAll () const
 Get all objects of a specific type.
 
template<typename T >
T * Get (const std::string &name) const
 Get one object of a specific type.
 
std::optional< Node * > FindNode (const std::string &node_name) const
 Find a node with a specific name.
 
NodeGetNode (const std::string &node_name) const
 Get a Node of a specific type with a specific name.
 
Nodeoperator() (const std::string &node_name) const
 Obtain a node by name.
 
std::vector< Node * > GetNodesOfTypes (std::initializer_list< Node::NodeID > ids) const
 Obtain all nodes which ids are in a list of Node::IDs.
 
size_t CountNodes (Node::NodeID id) const
 Count nodes of a specific node type.
 
size_t CountArrays (Node::NodeID id) const
 Count nodes of a specific array type.
 
std::vector< Node * > GetNodes () const
 Get all nodes.
 
std::vector< Node * > GetNodesOfType (Node::NodeID id) const
 Get all nodes of a specific type.
 
std::vector< NodeArray * > GetArraysOfType (Node::NodeID id) const
 Get all arrays of a specific type.
 
std::vector< Node * > GetImplicitNodes () const
 Return all graph nodes that do not explicitly belong to the graph.
 
PortArrayprt_arr (const std::string &name) const
 Shorthand to Get<PortArray>(...)
 
SignalArraysig_arr (const std::string &name) const
 Shorthand to Get<SignalArray>(...)
 
Portprt (const std::string &name) const
 Shorthand to Get<Port>(...)
 
Signalsig (const std::string &name) const
 Shorthand to Get<Signal>(...)
 
Parameterpar (const std::string &name) const
 Shorthand to Get<Parameter>(...)
 
Parameterpar (const Parameter &param) const
 Get a parameter by supplying another parameter. Lookup is done according to the name of the supplied param.
 
Parameterpar (const std::shared_ptr< Parameter > &param) const
 Get a parameter by supplying another parameter. Lookup is done according to the name of the supplied param.
 
std::unordered_map< std::string, std::string > meta () const
 Return a copy of the metadata.
 
std::vector< Object * > objects () const
 Get all objects.
 
bool Has (const std::string &name)
 Return true if object with name already exists on graph.
 
GraphSetMeta (const std::string &key, std::string value)
 Set metadata.
 
std::string ToString () const
 Return a human-readable representation.
 
std::string ToStringAllOjects () const
 Return a comma separated list of object names.
 
- Public Member Functions inherited from cerata::Named
 Named (std::string name)
 Named constructor.
 
std::string name () const
 Return the name of the object.
 
void SetName (std::string name)
 Change the name of the object.
 
virtual ~Named ()=default
 Destructor.
 

Protected Member Functions

ComponentAddChild (std::unique_ptr< Instance > child)
 Add and take ownership of an Instance graph. More...
 

Protected Attributes

std::vector< std::unique_ptr< Instance > > children_
 Instances.
 
bool was_instantiated = false
 Whether this component was instantiated.
 
NodeMap inst_to_comp
 Mapping for instance nodes that have been connected.
 
- Protected Attributes inherited from cerata::Graph
ID id_
 Graph type id for convenience.
 
std::vector< std::shared_ptr< Object > > objects_
 Graph objects.
 
std::unordered_map< std::string, std::string > meta_
 KV storage for metadata of tools or specific backend implementations.
 

Additional Inherited Members

- Public Types inherited from cerata::Graph
enum  ID { COMPONENT, INSTANCE }
 Graph type ID for convenient run-time type checking. More...
 

Detailed Description

A Component graph.

A component graph may contain all node types.

Definition at line 158 of file graph.h.

Member Function Documentation

◆ AddChild()

Component & cerata::Component::AddChild ( std::unique_ptr< Instance child)
protected

Add and take ownership of an Instance graph.

Parameters
childThe child graph to add.
Returns
This component if successful.

Definition at line 240 of file graph.cc.

◆ Instantiate() [1/2]

Instance * cerata::Component::Instantiate ( Component comp,
const std::string &  name = "" 
)

Add an Instance of another Component to this component.

Parameters
compThe component to instantiate and add.
nameThe name of the new instance. If left blank, it will use the Component name + "_inst".
Returns
A pointer to the instantiated component.

Definition at line 295 of file graph.cc.

◆ Instantiate() [2/2]

Instance * cerata::Component::Instantiate ( const std::shared_ptr< Component > &  comp,
const std::string &  name = "" 
)

Add an Instance of another Component to this component.

Parameters
compThe component to instantiate and add.
nameThe name of the new instance. If left blank, it will use the Component name + "_inst".
Returns
A pointer to the instantiated component.

Definition at line 291 of file graph.cc.


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