List of all members | Public Types | Public Member Functions | Public Attributes
circuit Class Reference

Main circuit class. More...

Public Types

typedef
boost::transform_iterator
< filter_circuit,
boost::indirect_iterator
< std::vector
< boost::shared_ptr< gate >
>::iterator > > 
iterator
 Mutable iterator for accessing the gates in a circuit.
 
typedef
boost::transform_iterator
< const_filter_circuit,
boost::indirect_iterator
< std::vector
< boost::shared_ptr< gate >
>::const_iterator > > 
const_iterator
 Constant iterator for accessing the gates in a circuit.
 
typedef
boost::transform_iterator
< filter_circuit,
boost::indirect_iterator
< std::vector
< boost::shared_ptr< gate >
>::reverse_iterator > > 
reverse_iterator
 Mutable reverse iterator for accessing the gates in a circuit.
 
typedef
boost::transform_iterator
< const_filter_circuit,
boost::indirect_iterator
< std::vector
< boost::shared_ptr< gate >
>::const_reverse_iterator > > 
const_reverse_iterator
 Constant reverse iterator for accessing the gates in a circuit.
 

Public Member Functions

 circuit ()
 Default constructor. More...
 
 circuit (const standard_circuit &std_circ)
 Cast Constructor for a standard_circuit. More...
 
 circuit (standard_circuit &std_circ)
 Cast Constructor for a standard_circuit. More...
 
 circuit (const subcircuit &sub_circ)
 Cast Constructor for a subcircuit. More...
 
 circuit (subcircuit &sub_circ)
 Cast Constructor for a subcircuit. More...
 
 circuit (const circuit &other)
 Copy Constructor. More...
 
unsigned num_gates () const
 Returns the number of gates. More...
 
void set_lines (unsigned lines)
 Sets the number of line. More...
 
unsigned lines () const
 Returns the number of lines. More...
 
const_iterator begin () const
 Constant begin iterator pointing to gates. More...
 
const_iterator end () const
 Constant end iterator pointing to gates. More...
 
iterator begin ()
 Mutable begin iterator pointing to gates. More...
 
iterator end ()
 Mutable end iterator pointing to gates. More...
 
const_reverse_iterator rbegin () const
 Constant begin reverse iterator pointing to gates. More...
 
const_reverse_iterator rend () const
 Constant end reverse iterator pointing to gates. More...
 
reverse_iterator rbegin ()
 Mutable begin reverse iterator pointing to gates. More...
 
reverse_iterator rend ()
 Mutable end reverse iterator pointing to gates. More...
 
const gateoperator[] (unsigned index) const
 Random access operator for access to gates by index. More...
 
gateoperator[] (unsigned index)
 Random access operator for access to gates by index. More...
 
gateappend_gate ()
 Inserts a gate at the end of the circuit. More...
 
gateprepend_gate ()
 Inserts a gate at the beginning of the circuit. More...
 
gateinsert_gate (unsigned pos)
 Inserts a gate into the circuit. More...
 
void remove_gate_at (unsigned pos)
 Removes a gate at a given index. More...
 
void set_inputs (const std::vector< std::string > &inputs)
 Sets the input names of the lines in a circuit. More...
 
const std::vector< std::string > & inputs () const
 Returns the input names of the lines in a circuit. More...
 
void set_outputs (const std::vector< std::string > &outputs)
 Sets the output names of the lines in a circuit. More...
 
const std::vector< std::string > & outputs () const
 Returns the output names of the lines in a circuit. More...
 
void set_constants (const std::vector< constant > &constants)
 Sets the constant input line specifications. More...
 
const std::vector< constant > & constants () const
 Returns the constant input line specification. More...
 
void set_garbage (const std::vector< bool > &garbage)
 Sets whether outputs are garbage or not. More...
 
const std::vector< bool > & garbage () const
 Returns whether outputs are garbage or not. More...
 
void set_circuit_name (const std::string &name)
 Sets a name of the circuit. More...
 
const std::string & circuit_name () const
 Returns the name of the circuit. More...
 
const bus_collectioninputbuses () const
 Constant access to the input buses. More...
 
bus_collectioninputbuses ()
 Mutable access to the input buses. More...
 
const bus_collectionoutputbuses () const
 Constant access to the output buses. More...
 
bus_collectionoutputbuses ()
 Mutable access to the output buses. More...
 
const bus_collectionstatesignals () const
 Constant access to the state signals. More...
 
bus_collectionstatesignals ()
 Mutable access to the state signals. More...
 
bool is_subcircuit () const
 Returns whether the circuit is a sub-circuit or not. More...
 
std::pair< unsigned,
std::vector< unsigned > > 
filter () const
 Returns the filter of a sub-circuit. More...
 
unsigned offset () const
 Returns the offset of the circuit (sub-circuit) More...
 
void add_module (const std::string &name, const boost::shared_ptr< circuit > &module)
 Adds a module to the circuit. More...
 
void add_module (const std::string &name, const circuit &module)
 Adds a module to the circuit. More...
 
const std::map< std::string,
boost::shared_ptr< circuit > > & 
modules () const
 Returns all modules in the circuit. More...
 
const std::string & annotation (const gate &g, const std::string &key, const std::string &default_value=std::string()) const
 Returns the annotation for one gate and one key. More...
 
boost::optional< const
std::map< std::string,
std::string > & > 
annotations (const gate &g) const
 Returns all annotations for a given gate. More...
 
void annotate (const gate &g, const std::string &key, const std::string &value)
 Annotates a gate. More...
 

Public Attributes

boost::signal< void(gate &)> gate_added
 Signal which is emitted after adding a gate. More...
 

Detailed Description

Main circuit class.

This class represents a circuit and can be used generically for standard circuits and sub circuits.

Author
RevKit
Since
1.0

Constructor & Destructor Documentation

circuit ( )
inline

Default constructor.

This constructor initializes a standard_circuit with 0 lines, also called an empty circuit. Empty circuits are usually used as parameters for parsing functions, optimization algorithms, etc.

Author
RevKit
Since
1.0
circuit ( const standard_circuit std_circ)
inline

Cast Constructor for a standard_circuit.

With this constructor the standard_circuit constructor is automatically converted to a circuit, e.g. by calling

circuit circ( 3 );

a circuit with 3 lines is created.

Parameters
std_circstandard_circuit implementation
Author
RevKit
Since
1.0
circuit ( standard_circuit std_circ)
inline

Cast Constructor for a standard_circuit.

With this constructor the standard_circuit constructor is automatically converted to a circuit, e.g. by calling

circuit circ( 3 );

a circuit with 3 lines is created.

Parameters
std_circstandard_circuit implementation
Author
RevKit
Since
1.0
circuit ( const subcircuit sub_circ)
inline

Cast Constructor for a subcircuit.

This constructor is used, so that subcircuits are detected as circuits in algorithms and can passed as circuit parameter to other functions and algorithms.

Parameters
sub_circsubcircuit implementation
Author
RevKit
Since
1.0
circuit ( subcircuit sub_circ)
inline

Cast Constructor for a subcircuit.

This constructor is used, so that subcircuits are detected as circuits in algorithms and can passed as circuit parameter to other functions and algorithms.

Parameters
sub_circsubcircuit implementation
Author
RevKit
Since
1.0
circuit ( const circuit other)
inline

Copy Constructor.

This constructor is used by some algorithms, but should not be used directly.

It copies the underlying circuit, but it does not copy the signals, so that this information gets lost.

Parameters
otherCircuit to be copied
Author
RevKit
Since
1.0

Member Function Documentation

void add_module ( const std::string &  name,
const boost::shared_ptr< circuit > &  module 
)

Adds a module to the circuit.

This function adds a module to the circuit. It does not create a gate calling the module, but the module itself as a reference for further use, e.g. with append_module.

This method uses smart pointer to a circuit wich already exists and is managed by another object. If it cannot be assured that the module is saved, the method add_module(const std::string&, const circuit&) should be used.

Parameters
nameName of the module
moduleReference to an existing module
Author
RevKit
Since
1.1
void add_module ( const std::string &  name,
const circuit module 
)

Adds a module to the circuit.

This function adds a module to the circuit. It does not create a gate calling the module, but the module itself as a reference for further use, e.g. with append_module.

In this method the module is copied first and thus assured that is managed by this circuit.

Parameters
nameName of the module
moduleModule to be copied
Author
RevKit
Since
1.1
void annotate ( const gate g,
const std::string &  key,
const std::string &  value 
)

Annotates a gate.

With this method a gate can be annotated using a key and a value. If there is an annotation with the same key, it will be overwritten.

Parameters
gGate
keyKey of the annotation
valueValue of the annotation
Author
RevKit
Since
1.1
const std::string& annotation ( const gate g,
const std::string &  key,
const std::string &  default_value = std::string() 
) const

Returns the annotation for one gate and one key.

This method returns the value for one particular annotation for a given gate. If no annotation with that key exists, the a default value is given.

Parameters
gGate
keyKey of the annotation
default_valueDefault value, in case the key does not exist
Returns
Value of the annotation or the default value
Author
RevKit
Since
1.1
boost::optional<const std::map<std::string, std::string>& > annotations ( const gate g) const

Returns all annotations for a given gate.

This method returns all annotations for a given gate. For the purpose of efficiency, this method returns an optional data type containing the property map. So, first check whether there are items by assierting the optional, and then go through the map by dereferencing the optional:

boost::optional<const std::map<std::string, std::string>& > annotations = circ.annotations( g );
if ( annotations )
{
// annotations exists
typedef std::pair<std::string, std::string> pair_t;
foreach ( const pair_t& p, *annotations )
{
const std::string& key = p.first;
const std::string& value = p.second;
// do something with key and value
}
}
Parameters
gGate
Returns
Map of annotations encapsulated in an optional
Author
RevKit
Since
1.1
gate& append_gate ( )

Inserts a gate at the end of the circuit.

This method inserts a gate at the end of the circuit.

Returns
Reference to the newly created empty gate
Author
RevKit
Since
1.0
const_iterator begin ( ) const

Constant begin iterator pointing to gates.

Returns
Constant begin iterator
Author
RevKit
Since
1.0
iterator begin ( )

Mutable begin iterator pointing to gates.

Returns
Mutable begin iterator
Author
RevKit
Since
1.0
const std::string& circuit_name ( ) const

Returns the name of the circuit.

Returns the name of the circuit which is empty initially.

Returns
Name of the circuit
Author
RevKit
Since
1.0
const std::vector<constant>& constants ( ) const

Returns the constant input line specification.

This method returns the constant input line specification.

Returns
Constant input line specification
Author
RevKit
Since
1.0
const_iterator end ( ) const

Constant end iterator pointing to gates.

Returns
Constant end iterator
Author
RevKit
Since
1.0
iterator end ( )

Mutable end iterator pointing to gates.

Returns
Mutable end iterator
Author
RevKit
Since
1.0
std::pair<unsigned, std::vector<unsigned> > filter ( ) const

Returns the filter of a sub-circuit.

This method returns a pair (l, f). In case the circuit is sub-circuit restricted on the lines, l is the original number of lines of the base circuit and f is the filter, i.e. a vector of lines which are used for the sub-circuit. In other cases s is always 0 and f is empty.

Returns
Pair of information about the sub-circuit's base or empty pair
Author
RevKit
Since
1.0
const std::vector<bool>& garbage ( ) const

Returns whether outputs are garbage or not.

This method returns the garbage line specification.

Returns
Garbage output line specification
Author
RevKit
Since
1.0
const bus_collection& inputbuses ( ) const

Constant access to the input buses.

This method gives constant access to the input buses.

Returns
Input bus collection
Author
RevKit
Since
1.1
bus_collection& inputbuses ( )

Mutable access to the input buses.

This method gives mutable access to the input buses.

Returns
Input bus collection
Author
RevKit
Since
1.1
const std::vector<std::string>& inputs ( ) const

Returns the input names of the lines in a circuit.

This method returns the input names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.

Returns
Input names
Author
RevKit
Since
1.0
gate& insert_gate ( unsigned  pos)

Inserts a gate into the circuit.

This method inserts a gate at an arbitrary position in the circuit

Parameters
posPosition where to insert the gate
Returns
Reference to the newly created empty gate
Author
RevKit
Since
1.0
bool is_subcircuit ( ) const

Returns whether the circuit is a sub-circuit or not.

Both standard_circuit and subcircuit are used in the context as a circuit in other algorithms. To determine what kind of circuit it is, this method returns true if the circuit is a sub-circuit, false otherwise.

Returns
true, if circuit is a sub-circuit, false otherwise
Author
RevKit
Since
1.0
unsigned lines ( ) const

Returns the number of lines.

This method returns the number of lines.

Returns
Number of lines
Author
RevKit
Since
1.0
const std::map<std::string, boost::shared_ptr<circuit> >& modules ( ) const

Returns all modules in the circuit.

This method returns a map of all modules, whereby the keys are the names of the modules.

Returns
Map of modules
Author
RevKit
Since
1.1
unsigned num_gates ( ) const

Returns the number of gates.

This method returns the number of gates in the circuit.

Returns
Number of gates
Author
RevKit
Since
1.0
unsigned offset ( ) const

Returns the offset of the circuit (sub-circuit)

For a standard_circuit, the offset is always 0, but for a sub-circuit, the offset is the index of the starting gate in respect to its base circuit.

Returns
Offset of the circuit
Author
RevKit
Since
1.0
const gate& operator[] ( unsigned  index) const

Random access operator for access to gates by index.

Parameters
indexIndex of the gate, starting from 0
Returns
constant access to the index gate in the circuit
Author
RevKit
Since
1.1
gate& operator[] ( unsigned  index)

Random access operator for access to gates by index.

Parameters
indexIndex of the gate, starting from 0
Returns
mutable access to the index gate in the circuit
Author
RevKit
Since
1.1
const bus_collection& outputbuses ( ) const

Constant access to the output buses.

This method gives constant access to the output buses.

Returns
Output bus collection
Author
RevKit
Since
1.1
bus_collection& outputbuses ( )

Mutable access to the output buses.

This method gives mutable access to the output buses.

Returns
Output bus collection
Author
RevKit
Since
1.1
const std::vector<std::string>& outputs ( ) const

Returns the output names of the lines in a circuit.

This method returns the output names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.

Returns
Output names
Author
RevKit
Since
1.0
gate& prepend_gate ( )

Inserts a gate at the beginning of the circuit.

This method inserts a gate at the beginning of the circuit.

Returns
Reference to the newly created empty gate
Author
RevKit
Since
1.0
const_reverse_iterator rbegin ( ) const

Constant begin reverse iterator pointing to gates.

Returns
Constant begin reverse iterator
Author
RevKit
Since
1.0
reverse_iterator rbegin ( )

Mutable begin reverse iterator pointing to gates.

Returns
Mutable begin reverse iterator
Author
RevKit
Since
1.0
void remove_gate_at ( unsigned  pos)

Removes a gate at a given index.

If the index is not valid, no gate is removed.

Parameters
posIndex
Author
RevKit
Since
1.0
const_reverse_iterator rend ( ) const

Constant end reverse iterator pointing to gates.

Returns
Constant end reverse iterator
Author
RevKit
Since
1.0
reverse_iterator rend ( )

Mutable end reverse iterator pointing to gates.

Returns
Mutable end reverse iterator
Author
RevKit
Since
1.0
void set_circuit_name ( const std::string &  name)

Sets a name of the circuit.

Sets a name for the circuit which is empty initially.

Parameters
nameName
Author
RevKit
Since
1.0
void set_constants ( const std::vector< constant > &  constants)

Sets the constant input line specifications.

This method sets the constant input line specification.

Lines are by default not constant. If less values are given than lines exist, the last ones will be not constant. If more values are given than lines exist, they will be truncated.

See Also
constant
Parameters
constantsConstant Lines
Author
RevKit
Since
1.0
void set_garbage ( const std::vector< bool > &  garbage)

Sets whether outputs are garbage or not.

If an output is garbage it means, that the resulting output value is not necessary for the function.

Lines are by default not garbage. If less values are given than lines exist, the last ones will be not garbage. If more values are given than lines exist, they will be truncated.

Parameters
garbageGarbage line specification
Author
RevKit
Since
1.0
void set_inputs ( const std::vector< std::string > &  inputs)

Sets the input names of the lines in a circuit.

This method sets the input names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.

Parameters
inputsInput names
Author
RevKit
Since
1.0
void set_lines ( unsigned  lines)

Sets the number of line.

This method sets the number of lines of the circuit.

Changing this number will not affect the data in the gates. For example: If there is a gate with a control on line 3, and the number of lines is reduced to 2 in the circuit, then the control is still on line 3 but not visible in this circuit.

So, changing the lines after already adding gates can lead to invalid gates.

Parameters
linesNumber of lines
Author
RevKit
Since
1.0
void set_outputs ( const std::vector< std::string > &  outputs)

Sets the output names of the lines in a circuit.

This method sets the output names of the lines in a circuit. This is useful for functions when writing them to a file, printing them, or creating images.

Parameters
outputsOutput names
Author
RevKit
Since
1.0
const bus_collection& statesignals ( ) const

Constant access to the state signals.

This method gives constant access to the state signals.

Returns
State signal collection
Author
RevKit
Since
1.1
bus_collection& statesignals ( )

Mutable access to the state signals.

This method gives mutable access to the state signals.

Returns
State signal collection
Author
RevKit
Since
1.1

Member Data Documentation

boost::signal<void(gate&)> gate_added

Signal which is emitted after adding a gate.

The gate is always empty, since when adding a gate to the circuit an empty gate is returned as reference and then further processed by functions such as append_toffoli.


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

Generated on Tue Apr 16 2013 08:12:02 for RevKit by doxygen 1.8.3.1