Classes | Functions

keyvalue::pattern Namespace Reference

Key-value pattern recognition class are members of this namespace. More...

Classes

class  KeyInSingle
 Pattern where a value::Single object, recognised as a key, is followed by any value::Value. More...
class  KeysInMatrix
 Pattern made by a value::Matrix where all elements either in the first row or in the first column are keys. More...
class  KeysInVector
 Pattern made by a value::Vector whose entries are keys followed by a value::Vector or value::Matrix. More...
class  Pattern
 Protocol class which defines the interface for pattern recognition classes. More...
class  Table
 Pattern where a value::Matrix contains the row, column and table keys. More...

Functions

bool isKey (const value::Variant &variant)
 Checks if variant may be considered as a key.
string getKey (const value::Variant &variant)
 Gets the key held by variant.

Detailed Description

Key-value pattern recognition class are members of this namespace.


Function Documentation

bool keyvalue::pattern::isKey ( const value::Variant &  variant  ) 

Checks if variant may be considered as a key.

The check is successful if the following conditions hold:

  • it contains a value::Single holding a string S;
  • excluding trailing spaces, S ends in " =" (space + equal sign);
  • excluding the ending '=', S has a non space character.
Parameters:
variant : value::Variant to be checked.
Returns:
If variant may be considered as a key, then this method returns true. Otherwise it returns false.
string keyvalue::pattern::getKey ( const value::Variant &  variant  ) 

Gets the key held by variant.

More precisely, the key is what remains after the following operations are performed in the string held by variant :

  • the last '=' (equal sign) is replaced by ' ' (space);
  • trailing spaces are removed;
  • leading spaces are removed.

The debug version of this method checks if variant may be considered as a key (by calling isKey()) and throws an exception when the check fails. The release version of this method has undefined behavior when variant may not be considered as a key.

Parameters:
variant : value::Variant to be checked.
Returns:
The key held by variant.
Exceptions:
LogicError : (Debug built only) If variant may not be considered as a key.