Collection for buses. More...
Public Types | |
typedef std::map< std::string, std::vector< unsigned > > | map |
Public Member Functions | |
bus_collection () | |
Standard constructor. More... | |
~bus_collection () | |
Deconstructor. More... | |
void | add (const std::string &name, const std::vector< unsigned > &line_indices, const boost::optional< unsigned > &initial_value=boost::optional< unsigned >()) |
Adds a new bus to the collection. More... | |
const std::vector< unsigned > & | get (const std::string &name) const |
Gets the corresponding lines of a bus by the name. More... | |
const map & | buses () const |
Returns all buses of the collection. More... | |
std::string | find_bus (unsigned line_index) const |
This method finds the bus for a line. More... | |
bool | has_bus (unsigned line_index) const |
This method determines whether there exists a bus for a given line. More... | |
unsigned | signal_index (unsigned line_index) const |
Returns the signal index relative to the bus. More... | |
void | set_initial_value (const std::string &name, unsigned initial_value) |
Sets the initial value of a bus. More... | |
boost::optional< unsigned > | initial_value (const std::string &name) const |
Retrieves the initial value of a bus. More... | |
Collection for buses.
This class represents a collection of buses. Using respective methods it is possible to add new buses or find buses by name or line index.
Buses are usually accessed via the methods circuit::inputbuses() and circuit::outputbuses()
typedef std::map<std::string, std::vector<unsigned> > map |
bus_collection | ( | ) |
Standard constructor.
~bus_collection | ( | ) |
Deconstructor.
void add | ( | const std::string & | name, |
const std::vector< unsigned > & | line_indices, | ||
const boost::optional< unsigned > & | initial_value = boost::optional< unsigned >() |
||
) |
Adds a new bus to the collection.
name | Name of the bus |
line_indices | Corresponding lines of the bus |
initial_value | This value can optional be set to assign an initial value to this bus. |
const map& buses | ( | ) | const |
Returns all buses of the collection.
This method returns all the buses of the collection.
std::string find_bus | ( | unsigned | line_index | ) | const |
This method finds the bus for a line.
If the line belongs to a bus, the name of the bus is returned, otherwise an empty string is returned.
If the name is not important, but just the check whether the line is contained in some bus, use this method rather than bus_collection::find_bus
line_index | Index of the line |
const std::vector<unsigned>& get | ( | const std::string & | name | ) | const |
Gets the corresponding lines of a bus by the name.
If there is no such bus with the name name
in the collection, an assertion is thrown. This method is meant to be used in conjunction with find_bus.
name | Name of the bus |
bool has_bus | ( | unsigned | line_index | ) | const |
This method determines whether there exists a bus for a given line.
If the line at line_index
is contained in a bus, this method returns true, otherwise false.
If the name is not important, but just the check whether the line is contained in some bus, use this method rather than bus_collection::find_bus
line_index | Index of the line |
line_index
is contained in a bus boost::optional<unsigned> initial_value | ( | const std::string & | name | ) | const |
Retrieves the initial value of a bus.
Given a name of the bus, this method tries to retrieve an initial value. If no bus with this name exists, or if a bus exist but does not have an initial value, an empty optional is returned. Thus, this method should be used as demonstrated in the following example:
If there exists a default value for the initial value, the following shorter snippet can be used:
name | Name of the bus |
void set_initial_value | ( | const std::string & | name, |
unsigned | initial_value | ||
) |
Sets the initial value of a bus.
This method is used primarily for state signals, which can be assigned an initial value. This method is called with the name of the bus. If no such bus exists, this method call has no effect.
name | Name of the bus |
initial_value | Initial value |
unsigned signal_index | ( | unsigned | line_index | ) | const |
Returns the signal index relative to the bus.
If e.g. a bus A is defined by the line indices 3,4,6 then the signal index of 4 is 1, since it is the 2nd signal in the bus (considering counting from 0).
This method requires, that line_index
belongs to a bus, otherwise an assertion is thrown.
line_index | Index of the line |