Base class for actions on the revlib_parser. More...
Public Member Functions | |
revlib_processor () | |
Default constructor. | |
virtual | ~revlib_processor () |
Default deconstructor. | |
Protected Member Functions | |
virtual void | on_comment (const std::string &comment) const |
Called when parsing comments. | |
virtual void | on_version (const std::string &version) const |
Called when parsing .version command. | |
virtual void | on_numvars (unsigned numvars) const |
Called when parsing .numvars command. | |
virtual void | on_variables (std::vector< std::string >::const_iterator first, std::vector< std::string >::const_iterator last) const |
Called when parsing .variables command. | |
virtual void | on_inputs (std::vector< std::string >::const_iterator first, std::vector< std::string >::const_iterator last) const |
Called when parsing .inputs command. | |
virtual void | on_outputs (std::vector< std::string >::const_iterator first, std::vector< std::string >::const_iterator last) const |
Called when parsing .outputs command. | |
virtual void | on_constants (std::vector< constant >::const_iterator first, std::vector< constant >::const_iterator last) const |
Called when parsing the .constants command. | |
virtual void | on_garbage (std::vector< bool >::const_iterator first, std::vector< bool >::const_iterator last) const |
Called when parsing .garbage command. | |
virtual void | on_begin () const |
Called when parsing .begin command. | |
virtual void | on_end () const |
Called when parsing .begin command. | |
virtual void | on_gate (const boost::any &target_type, const std::vector< unsigned > &line_indices) const |
Called when a gate is parsed. | |
virtual void | on_truth_table_line (unsigned line_index, const std::vector< boost::optional< bool > >::const_iterator first, const std::vector< boost::optional< bool > >::const_iterator last) const |
Called when a truth table line is parsed. | |
const std::string & | variable (std::vector< std::string >::size_type index) const |
Returns the variable name to a given line index. | |
Friends | |
bool | revlib_parser (std::istream &in, revlib_processor &reader, std::string *error) |
A parser for the RevLib file format. |
Base class for actions on the revlib_parser.
The RevLib file parser revlib_parser(std::istream&, revlib_processor&, std::string*) gets an instance of a revlib_processor object as parameter.
For creating a circuit a circuit_processor already exists. Other processors can be implemented by inhereting from this class.
The base class provides virtual functions for each command in a RevLib file with corresponding parameters.
Only the methods which data is needed must be overriden.
revlib_processor | ( | ) |
Default constructor.
Initializes private data
virtual ~revlib_processor | ( | ) | [virtual] |
Default deconstructor.
Clears private data
virtual void on_begin | ( | ) | const [protected, virtual] |
Called when parsing .begin command.
This method is called when a .begin command is parsed.
virtual void on_comment | ( | const std::string & | comment | ) | const [protected, virtual] |
Called when parsing comments.
This method is called when a comment (starting with a #) is parsed. The comment (text after the #) is stored in the parameter comment
.
comment | Comment (single line) |
virtual void on_constants | ( | std::vector< constant >::const_iterator | first, | |
std::vector< constant >::const_iterator | last | |||
) | const [protected, virtual] |
Called when parsing the .constants command.
This method is called when a .constants command is parsed. The constant in a std::vector can be accessed via their first
and last
iterator. A optional boolean value indicates whether the line is constant or not and in case it is constant, which constant line is represented.
first | Begin iterator of constants vector | |
last | End iterator of constants vector |
Reimplemented in circuit_processor, and specification_processor.
virtual void on_end | ( | ) | const [protected, virtual] |
Called when parsing .begin command.
This method is called when a .begin command is parsed.
virtual void on_garbage | ( | std::vector< bool >::const_iterator | first, | |
std::vector< bool >::const_iterator | last | |||
) | const [protected, virtual] |
Called when parsing .garbage command.
This method is called when a .garbage command is parsed. The garbage in a std::vector can be accessed via their first
and last
iterator. A boolean value indicates whether the line has a garbage output or not.
first | Begin iterator of garbage vector | |
last | End iterator of garbage vector |
Reimplemented in circuit_processor, and specification_processor.
virtual void on_gate | ( | const boost::any & | target_type, | |
const std::vector< unsigned > & | line_indices | |||
) | const [protected, virtual] |
Called when a gate is parsed.
This method is called when a gate is parsed providing the gate type in parameter target_type
and all connected line via their zero-index indices.
The last indices in the list line_indices
are the target lines. The number of target lines depends on the corresponding gate type.
target_type | Target type of the target line(s). | |
line_indices | All connected lines, both control and target lines. |
Reimplemented in circuit_processor.
virtual void on_inputs | ( | std::vector< std::string >::const_iterator | first, | |
std::vector< std::string >::const_iterator | last | |||
) | const [protected, virtual] |
Called when parsing .inputs command.
This method is called when a .inputs command is parsed. The inputs in a std::vector can be accessed via their first
and last
iterator.
first | Begin iterator of inputs vector | |
last | End iterator of inputs vector |
Reimplemented in circuit_processor, and specification_processor.
virtual void on_numvars | ( | unsigned | numvars | ) | const [protected, virtual] |
Called when parsing .numvars command.
This method is called when a .numvars command is parsed. The number of variables is stored in the parameter numvars
.
numvars | Number of variables |
Reimplemented in circuit_processor.
virtual void on_outputs | ( | std::vector< std::string >::const_iterator | first, | |
std::vector< std::string >::const_iterator | last | |||
) | const [protected, virtual] |
Called when parsing .outputs command.
This method is called when a .outputs command is parsed. The outputs in a std::vector can be accessed via their first
and last
iterator.
first | Begin iterator of outputs vector | |
last | End iterator of outputs vector |
Reimplemented in circuit_processor, and specification_processor.
virtual void on_truth_table_line | ( | unsigned | line_index, | |
const std::vector< boost::optional< bool > >::const_iterator | first, | |||
const std::vector< boost::optional< bool > >::const_iterator | last | |||
) | const [protected, virtual] |
Called when a truth table line is parsed.
This method is called when a truth table line is parsed. A truth table line is parsed in a specification file.
The truth table line is given as first and last iterator over boost::optional<bool> values and as additional parameter the corresponding truth table line is given.
line_index | The corresponding truth table line | |
first | Begin iterator over truth table output value | |
last | End iterator over truth table output value |
Reimplemented in specification_processor.
virtual void on_variables | ( | std::vector< std::string >::const_iterator | first, | |
std::vector< std::string >::const_iterator | last | |||
) | const [protected, virtual] |
Called when parsing .variables command.
This method is called when a .variables command is parsed. The variables in a std::vector can be accessed via their first
and last
iterator.
first | Begin iterator of variables vector | |
last | End iterator of variables vector |
virtual void on_version | ( | const std::string & | version | ) | const [protected, virtual] |
Called when parsing .version command.
This method is called when a .version command is parsed. The version (as a std::string) is stored in the parameter version
.
version | Version |
const std::string& variable | ( | std::vector< std::string >::size_type | index | ) | const [protected] |
Returns the variable name to a given line index.
The RevLib realization file format uses variable names for line indices, introduced via the .variables command.
This method can be useful when overriding the on_gate method, to translate line indices to their variable names.
index | Line index |
index
bool revlib_parser | ( | std::istream & | in, | |
revlib_processor & | reader, | |||
std::string * | error | |||
) | [friend] |
A parser for the RevLib file format.
This function can read a circuit realization and truth table specifications in a format as proposed on RevLib. The function itself just realizes the parser and uses a revlib_processor instance which provides methods for implementation details.
For example, when reading the realization into a circuit structure, the read_realization_circuit_processor class can be used as instance.
in | Input stream containing the file | |
reader | An instance of the revlib_processor | |
error | A pointer to a string. In case the parsing fails, and error is not null, a error message is stored |