Public Member Functions | Private Member Functions | Private Attributes

KeysInMatrix Class Reference

Pattern made by a value::Matrix where all elements either in the first row or in the first column are keys. More...

#include <keyvalue/pattern/KeysInMatrix.h>

Inheritance diagram for KeysInMatrix:
Inheritance graph
[legend]

List of all members.

Public Member Functions

bool parse (frontend::Queue &queue)
 Parses the beginning of a frontend::Queue.
std::pair< string, value::Valuepop ()
 Gets and removes the next stored key-value pair.
bool isEmpty () const
 Checks if the list of recognized key-value pairs is empty.

Private Member Functions

bool check (const value::Matrix &matrix, bool transpose=false)
 This method does all the job explained in the class description.

Private Attributes

size_t next_
vector< std::pair< string,
value::Value > > 
data_

Detailed Description

Pattern made by a value::Matrix where all elements either in the first row or in the first column are keys.

More precisely, it is checked if the value::Matrix, M=M(i, j), has the following properties:

If M pass this check, then for each column of M, its first entry will be a key corresponding to the value given by the value::Vector (or value::Single, when M has only two rows) made by the other entries in this column. If M does not pass the check above, then the same test and key-value pattern parsing is performed on its transpose.


Member Function Documentation

bool parse ( frontend::Queue queue  )  [virtual]

Parses the beginning of a frontend::Queue.

When a pattern is recognized, the value::Value objects which make it are removed from frontend::Queue and all corresponding key-value pairs are stored inside the this class for later queries.

Parameters:
queue : frontend::Queue to be parsed.
Returns:
If the pattern is recognized, then this method returns true. Otherwise, it returns false.

Implements Pattern.

std::pair<string, value::Value> pop (  )  [virtual]

Gets and removes the next stored key-value pair.

The debug version checks if there is any key-value pair be popped (by calling isEmpty()) and throw an exception when the check fails. Release version has undefined behavior when the list is empty.

Returns:
The key-value pair.
Exceptions:
LogicError : (Debug build only) When the list is empty.

Implements Pattern.

bool isEmpty (  )  const [virtual]

Checks if the list of recognized key-value pairs is empty.

Returns:
If the list is empty, this method returns true. Otherwise, it returns false.

Implements Pattern.

bool check ( const value::Matrix matrix,
bool  transpose = false 
) [private]

This method does all the job explained in the class description.

Parameters:
matrix : Input matrix;
transpose : If true, the the test is performed on matrix transpose.
Returns:
This method returns true if the pattern is recognized. Otherwise it returns false.