List of all members | Public Member Functions | Protected Member Functions | Friends
revlib_processor Class Reference

Base class for actions on the revlib_parser. More...

Inheritance diagram for revlib_processor:
circuit_processor specification_processor

Public Member Functions

 revlib_processor ()
 Default constructor. More...
 
virtual ~revlib_processor ()
 Default deconstructor. More...
 

Protected Member Functions

virtual void on_comment (const std::string &comment) const
 Called when parsing comments. More...
 
virtual void on_version (const std::string &version) const
 Called when parsing .version command. More...
 
virtual void on_numvars (unsigned numvars) const
 Called when parsing .numvars command. More...
 
virtual void on_variables (std::vector< std::string >::const_iterator first, std::vector< std::string >::const_iterator last) const
 Called when parsing .variables command. More...
 
virtual void on_inputs (std::vector< std::string >::const_iterator first, std::vector< std::string >::const_iterator last) const
 Called when parsing .inputs command. More...
 
virtual void on_outputs (std::vector< std::string >::const_iterator first, std::vector< std::string >::const_iterator last) const
 Called when parsing .outputs command. More...
 
virtual void on_constants (std::vector< constant >::const_iterator first, std::vector< constant >::const_iterator last) const
 Called when parsing the .constants command. More...
 
virtual void on_garbage (std::vector< bool >::const_iterator first, std::vector< bool >::const_iterator last) const
 Called when parsing .garbage command. More...
 
virtual void on_inputbus (const std::string &name, const std::vector< unsigned > &line_indices) const
 Called when parsing .inputbus command. More...
 
virtual void on_outputbus (const std::string &name, const std::vector< unsigned > &line_indices) const
 Called when parsing .outputbus command. More...
 
virtual void on_state (const std::string &name, const std::vector< unsigned > &line_indices, unsigned initial_value) const
 Called when parsing .state command. More...
 
virtual void on_module (const std::string &name, const boost::optional< std::string > &filename) const
 Called when parsing .module command. More...
 
virtual void on_begin () const
 Called when parsing .begin command. More...
 
virtual void on_end () const
 Called when parsing .end command. More...
 
virtual void on_gate (const boost::any &target_type, const std::vector< unsigned > &line_indices) const
 Called when a gate is parsed. More...
 
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. More...
 
void add_annotation (const std::string &key, const std::string &value)
 Adds an annotation to the processor. More...
 
void clear_annotations ()
 Clears the current annotations. More...
 
properties::ptr current_annotations () const
 Returns the current annotations. More...
 

Friends

bool revlib_parser (std::istream &in, revlib_processor &reader, const std::string &, std::string *error)
 A parser for the RevLib file format. More...
 

Detailed Description

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.

Author
RevKit
Since
1.0

Constructor & Destructor Documentation

Default constructor.

Initializes private data

Author
RevKit
Since
1.0
virtual ~revlib_processor ( )
virtual

Default deconstructor.

Clears private data

Author
RevKit
Since
1.0

Member Function Documentation

void add_annotation ( const std::string &  key,
const std::string &  value 
)
protected

Adds an annotation to the processor.

The parser adds all annotations in each step, i.e. every time it parses a line. Old annotations are removed before. The annotations can be read with current_annotation() when processing an action.

Parameters
keyKey of the annotation
valueValue of the annotation
Author
RevKit
Since
1.1
void clear_annotations ( )
protected

Clears the current annotations.

This method clears the current annotations, i.e. when a new line is processed by the parser.

Author
RevKit
Since
1.1
properties::ptr current_annotations ( ) const
protected

Returns the current annotations.

Returns
Properties structure with annotations
Author
RevKit
Since
1.1
virtual void on_begin ( ) const
protectedvirtual

Called when parsing .begin command.

This method is called when a .begin command is parsed.

Author
RevKit
Since
1.0
virtual void on_comment ( const std::string &  comment) const
protectedvirtual

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.

Parameters
commentComment (single line)
Author
RevKit
Since
1.0

Reimplemented in circuit_processor.

virtual void on_constants ( std::vector< constant >::const_iterator  first,
std::vector< constant >::const_iterator  last 
) const
protectedvirtual

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.

Parameters
firstBegin iterator of constants vector
lastEnd iterator of constants vector
Author
RevKit
Since
1.0

Reimplemented in circuit_processor, and specification_processor.

virtual void on_end ( ) const
protectedvirtual

Called when parsing .end command.

This method is called when a .end command is parsed.

Author
RevKit
Since
1.0

Reimplemented in circuit_processor.

virtual void on_garbage ( std::vector< bool >::const_iterator  first,
std::vector< bool >::const_iterator  last 
) const
protectedvirtual

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.

Parameters
firstBegin iterator of garbage vector
lastEnd iterator of garbage vector
Author
RevKit
Since
1.0

Reimplemented in circuit_processor, and specification_processor.

virtual void on_gate ( const boost::any &  target_type,
const std::vector< unsigned > &  line_indices 
) const
protectedvirtual

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.

Parameters
target_typeTarget type of the target line(s).
line_indicesAll connected lines, both control and target lines.
Author
RevKit
Since
1.0

Reimplemented in circuit_processor.

virtual void on_inputbus ( const std::string &  name,
const std::vector< unsigned > &  line_indices 
) const
protectedvirtual

Called when parsing .inputbus command.

This method is called when a .inputbus command is parsed. The first parameter name is the name of the bus, whereas the corresponding variables can be accessed via the second parameter line_indices, which already contains the indices rather than the variable names.

Parameters
nameName of the bus
line_indicesLine indices of the variables of the bus
Author
RevKit
Since
1.1

Reimplemented in circuit_processor.

virtual void on_inputs ( std::vector< std::string >::const_iterator  first,
std::vector< std::string >::const_iterator  last 
) const
protectedvirtual

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.

Parameters
firstBegin iterator of inputs vector
lastEnd iterator of inputs vector
Author
RevKit
Since
1.0

Reimplemented in circuit_processor, and specification_processor.

virtual void on_module ( const std::string &  name,
const boost::optional< std::string > &  filename 
) const
protectedvirtual

Called when parsing .module command.

This method is called when a .module command is parsed.

Parameters
nameName of the module (used later to add gates)
filenameFile-name of the module circuit
Author
RevKit
Since
1.1

Reimplemented in circuit_processor.

virtual void on_numvars ( unsigned  numvars) const
protectedvirtual

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.

Parameters
numvarsNumber of variables
Author
RevKit
Since
1.0

Reimplemented in circuit_processor.

virtual void on_outputbus ( const std::string &  name,
const std::vector< unsigned > &  line_indices 
) const
protectedvirtual

Called when parsing .outputbus command.

This method is called when a .outputbus command is parsed. The first parameter name is the name of the bus, whereas the corresponding variables can be accessed via the second parameter line_indices, which already contains the indices rather than the variable names.

Parameters
nameName of the bus
line_indicesLine indices of the variables of the bus
Author
RevKit
Since
1.1

Reimplemented in circuit_processor.

virtual void on_outputs ( std::vector< std::string >::const_iterator  first,
std::vector< std::string >::const_iterator  last 
) const
protectedvirtual

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.

Parameters
firstBegin iterator of outputs vector
lastEnd iterator of outputs vector
Author
RevKit
Since
1.0

Reimplemented in circuit_processor, and specification_processor.

virtual void on_state ( const std::string &  name,
const std::vector< unsigned > &  line_indices,
unsigned  initial_value 
) const
protectedvirtual

Called when parsing .state command.

This method is called when a .state command is parsed. The first parameter name is the name of the state (bus), whereas the corresponding variables can be accessed via the second parameter line_indices, which already contains the indices rather than the variable names.

A .state command is modeled like a bus since it can contain more than one line index. Even if the state contains only one signal, this pattern is used.

Parameters
nameName of the state (bus)
line_indicesLine indices of the variables of the state (bus)
initial_valueInitial value for the state signal
Author
RevKit
Since
1.1

Reimplemented in circuit_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
protectedvirtual

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.

Parameters
line_indexThe corresponding truth table line
firstBegin iterator over truth table output value
lastEnd iterator over truth table output value
Author
RevKit
Since
1.0

Reimplemented in specification_processor.

virtual void on_variables ( std::vector< std::string >::const_iterator  first,
std::vector< std::string >::const_iterator  last 
) const
protectedvirtual

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.

Note
When overriding this function, make sure to call the base method first, because private data is filled with the variable names already in this class to access variable names with the method variable(std::vector<std::string>::size_type).
Parameters
firstBegin iterator of variables vector
lastEnd iterator of variables vector
Author
RevKit
Since
1.0
virtual void on_version ( const std::string &  version) const
protectedvirtual

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.

Parameters
versionVersion
Author
RevKit
Since
1.0

Friends And Related Function Documentation

bool revlib_parser ( std::istream &  in,
revlib_processor reader,
const std::string &  ,
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.

Parameters
inInput stream containing the file
readerAn instance of the revlib_processor
base_directoryA base directory to look for included files. This is usually the directory of the loaded file-name. This member was introduced in RevKit version 1.1
errorA pointer to a string. In case the parsing fails, and error is not null, a error message is stored
Returns
true on success, false otherwise
Author
RevKit
Since
1.1

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