List of all members | Public Types | Public Member Functions
truth_table< T > Class Template Reference

Represents a truth table. More...

Public Types

typedef T value_type
 Typedef reference to the given template type. More...
 
typedef std::vector< T > cube_type
 Type representing a cube. More...
 
typedef std::map< cube_type,
cube_type
cube_vector
 Represents a map from input to output cube. More...
 
typedef cube_type::const_iterator in_const_iterator
 Constant Iterator of input cubes. More...
 
typedef
boost::permutation_iterator
< typename
cube_type::const_iterator,
std::vector< unsigned >
::const_iterator
out_const_iterator
 Constant Iterator of output cubes. More...
 
typedef
boost::transform_iterator
< transform_cube< T >
, typename
cube_vector::const_iterator > 
const_iterator
 Truth Table's constant iterator. More...
 

Public Member Functions

unsigned num_inputs () const
 Returns the number of inputs. More...
 
unsigned num_outputs () const
 Returns the number of outputs. More...
 
const_iterator begin () const
 Returns constant begin iterator of the cube list. More...
 
const_iterator end () const
 Returns constant end iterator of the cube list. More...
 
bool add_entry (const cube_type &input, const cube_type &output)
 Adds a new entry to the truth table. More...
 
void clear ()
 Clears the truth table. More...
 
const std::vector< unsigned > & permutation () const
 Returns current permutation. More...
 
bool set_permutation (const std::vector< unsigned > &perm)
 Sets the permutation. More...
 
bool permute ()
 Permutes the current permutation. More...
 
void set_inputs (const std::vector< std::string > &ins)
 Sets the inputs of the specification. More...
 
const std::vector< std::string > & inputs () const
 Returns the inputs of the specification. More...
 
void set_outputs (const std::vector< std::string > &outs)
 Sets the outputs of the specification. More...
 
std::vector< std::string > outputs () const
 Returns the outputs of the specification. More...
 
void set_constants (const std::vector< constant > &constants)
 Sets the constant lines of the specification. More...
 
const std::vector< constant > & constants () const
 Returns the constant line information of the specification. More...
 
void set_garbage (const std::vector< bool > &garbage)
 Sets the garbage lines of the specification. More...
 
std::vector< bool > garbage () const
 Returns the garbage line information of the specification. More...
 

Detailed Description

template<typename T>
class revkit::truth_table< T >

Represents a truth table.

This class helps mapping input assignments to their corresponding output assignments.

Assignments are thereby cubes (type truth_table<T>::cube_type) are vectors of values T, which type is given as template parameter to the class.

For the tristate value 1, 0, and don't care the type binary_truth_table is predefined with T = boost::optional<bool>.

You can use read_specification(binary_truth_table&, const std::string&, std::string*) for reading a RevLib specification file into a truth_table.

Example

This example shows how to iterate through the values of a binary_truth_table, which is not that convenient on the first sight. This code works also for a generic truth_table.

binary_truth_table tt = // obtained from somewhere
for ( binary_truth_table::const_iterator it = tt.begin(); it != tt.end(); ++it )
{
// iterate through input cube (bit by bit)
foreach ( const binary_truth_table::value_type& in_bit, it->first )
{
// do something with in_bit
}
// iterate through output cube (bit by bit)
foreach ( const binary_truth_table::value_type& out_bit, it->second )
{
// do something with out_bit
}
}
Author
RevKit
Since
1.0

Member Typedef Documentation

typedef boost::transform_iterator<transform_cube<T>, typename cube_vector::const_iterator> const_iterator

Truth Table's constant iterator.

A transform iterator which transforms the cube_tuple objects to a pair of iterator pairs of each input and output cube.

Author
RevKit
Since
1.0
typedef std::vector<T> cube_type

Type representing a cube.

Implemented as a vector over the basic type T

Author
RevKit
Since
1.0
typedef std::map<cube_type, cube_type> cube_vector

Represents a map from input to output cube.

Implemented as a tuple

Author
RevKit
Since
1.0
typedef cube_type::const_iterator in_const_iterator

Constant Iterator of input cubes.

Default constant iterator is used.

Author
RevKit
Since
1.0
typedef boost::permutation_iterator<typename cube_type::const_iterator, std::vector<unsigned>::const_iterator> out_const_iterator

Constant Iterator of output cubes.

A permutation iterator from Boost.Iterators is used which makes use of the truth table's permutation.

Author
RevKit
Since
1.0
typedef T value_type

Typedef reference to the given template type.

Author
RevKit
Since
1.0

Member Function Documentation

bool add_entry ( const cube_type input,
const cube_type output 
)
inline

Adds a new entry to the truth table.

With adding the first entry the dimension of inputs and outputs is set. When adding further entries it has to make sure that the dimensions fit, else an assertion is thrown and false is returned.

Parameters
inputInput assignment
outputOutput assignment
Returns
Returns whether the assignment could be added or not
Author
RevKit
Since
1.0
const_iterator begin ( ) const
inline

Returns constant begin iterator of the cube list.

Returns
Constant begin iterator of the cube list
Author
RevKit
Since
1.0
void clear ( )
inline

Clears the truth table.

Clears the truth table, as well as the current permutation and constant and garbage information.

Author
RevKit
Since
1.0
const std::vector<constant>& constants ( ) const
inline

Returns the constant line information of the specification.

Use copy_metadata to assign specification meta-data to a circuit.

Returns
Vector of constant line information
Author
RevKit
Since
1.0
const_iterator end ( ) const
inline

Returns constant end iterator of the cube list.

Returns
Constant end iterator of the cube list
Author
RevKit
Since
1.0
std::vector<bool> garbage ( ) const
inline

Returns the garbage line information of the specification.

The garbage line information is permuted in respect to the current permutation.

Use copy_metadata to assign specification meta-data to a circuit.

Returns
Vector of garbage line information
Author
RevKit
Since
1.0
const std::vector<std::string>& inputs ( ) const
inline

Returns the inputs of the specification.

Use copy_metadata to assign specification meta-data to a circuit.

Returns
Vector of input names
Author
RevKit
Since
1.0
unsigned num_inputs ( ) const
inline

Returns the number of inputs.

If the truth table contains no cube tuple, then 0 is returned, otherwise the length of the first input assignment is returned.

Returns
Number of inputs
Author
RevKit
Since
1.0
unsigned num_outputs ( ) const
inline

Returns the number of outputs.

If the truth table contains no cube tuple, then 0 is returned, otherwise the length of the first output assignment is returned.

Returns
Number of outputs
Author
RevKit
Since
1.0
std::vector<std::string> outputs ( ) const
inline

Returns the outputs of the specification.

The outputs are permuted in respect to the current permutation.

Use copy_metadata to assign specification meta-data to a circuit.

Returns
Vector of output names
Author
RevKit
Since
1.0
const std::vector<unsigned>& permutation ( ) const
inline

Returns current permutation.

The permutation is initializes when the first entry is added to the truth table and is initially the sequence from 0 to n - 1, where n is the size of the output cubes.

Returns
Current permutation
Author
RevKit
Since
1.0
bool permute ( )
inline

Permutes the current permutation.

This methods calls std::next_permutation on the current permutation. It returns false, when all permutations were considered.

Returns
False, when all permutations were considered, true otherwise.
Author
RevKit
Since
1.0
void set_constants ( const std::vector< constant > &  constants)
inline

Sets the constant lines of the specification.

Use copy_metadata to assign specification meta-data to a circuit.

Parameters
constantsVector of constant values
Author
RevKit
Since
1.0
void set_garbage ( const std::vector< bool > &  garbage)
inline

Sets the garbage lines of the specification.

Use copy_metadata to assign specification meta-data to a circuit.

Parameters
garbageVector of garbage values
Author
RevKit
Since
1.0
void set_inputs ( const std::vector< std::string > &  ins)
inline

Sets the inputs of the specification.

Use copy_metadata to assign specification meta-data to a circuit.

Parameters
insVector of input names
Author
RevKit
Since
1.0
void set_outputs ( const std::vector< std::string > &  outs)
inline

Sets the outputs of the specification.

Use copy_metadata to assign specification meta-data to a circuit.

Parameters
outsVector of output names
Author
RevKit
Since
1.0
bool set_permutation ( const std::vector< unsigned > &  perm)
inline

Sets the permutation.

This method can set a specific permutation. This method should not be used in combination with permute which provides a dynamic change of the permutation.

Parameters
permNew permutation
Returns
True, if successful. It can be unsuccessful, when the size of perm is not suitable.
Author
RevKit
Since
1.0

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