TuringSim
C++ framework to simulate abstract computing models
Public Member Functions | Friends | List of all members
TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType > Class Template Reference

A dynamic symbol pattern where accepted/rejected letters are identified by keys, and interpreted in a context. More...

#include <symbol/turingMachineSymbolPattern.h>

Inheritance diagram for TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >:
Inheritance graph
[legend]
Collaboration diagram for TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >:
Collaboration graph
[legend]

Public Member Functions

constexpr DynamicSymbolPattern (bool neg)
 Produce a trivial pattern. More...
 
constexpr DynamicSymbolPattern (const KeyType &key)
 Make a dynamic pattern that accepts a single key. More...
 
constexpr DynamicSymbolPattern (const std::set< KeyType > &keys)
 Make a dynamic pattern that accepts a set of keys. More...
 
constexpr DynamicSymbolPattern (const std::set< KeyType > &keys, bool neg)
 Make a dynamic pattern that accepts or rejects a set of keys. More...
 
constexpr bool matchAccordingToPredicate (const std::map< KeyType, ValueType > &context, const std::function< bool(const ValueType &)> &predicate) const
 Test if a key match a given predicate in a given context. More...
 
constexpr bool operator== (const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other) const
 Equality operator. More...
 
constexpr bool operator!= (const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other) const
 Non-equality operator. More...
 
constexpr bool operator< (const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other) const
 Less than operator. More...
 
constexpr bool isAlphaEquivalent (const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other, const std::map< KeyType, KeyType > &rewriting) const
 Test if, given a renaming of keys, *this is alpha-equivalent to another DynamicSymbolPattern. More...
 
- Public Member Functions inherited from TuringSim::Symbol::SymbolPattern< SymbolType, std::map< KeyType, ValueType > >
 SymbolPattern ()=default
 The default constructor.
 
 SymbolPattern (const SymbolPattern &)=default
 The default copy constructor.
 
 SymbolPattern (SymbolPattern &&)=default
 The default move constructor.
 
SymbolPatternoperator= (const SymbolPattern &)=default
 The default copy assignment operator. More...
 
SymbolPatternoperator= (SymbolPattern &&)=default
 The default move assignment operator. More...
 
virtual ~SymbolPattern ()=default
 The default virtual destructor.
 
virtual bool match (const SymbolType &symbol, const Context &context) const noexcept=0
 Test whether a symbol match the pattern, given a context. More...
 

Friends

template<typename CharT = char, typename Traits = std::char_traits<CharT>>
std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &os, const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &pattern)
 Debug printer for DynamicSymbolPattern. More...
 

Additional Inherited Members

- Public Types inherited from TuringSim::Symbol::SymbolPattern< SymbolType, std::map< KeyType, ValueType > >
typedef SymbolType SymbolType
 The type of symbols.
 
typedef std::map< KeyType, ValueType > Context
 The type of context.
 

Detailed Description

template<typename KeyType, typename ValueType, typename SymbolType>
class TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >

A dynamic symbol pattern where accepted/rejected letters are identified by keys, and interpreted in a context.

Template Parameters
KeyTypeThe type of keys.
ValueTypeThe type to which keys map.
SymbolTypeThe type of symbols.

Definition at line 124 of file turingMachineSymbolPattern.h.

Constructor & Destructor Documentation

◆ DynamicSymbolPattern() [1/4]

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::DynamicSymbolPattern ( bool  neg)
inlineexplicitconstexpr

Produce a trivial pattern.

Parameters
[in]negif true, accepts everything. If false, rejects everything.

Definition at line 129 of file turingMachineSymbolPattern.h.

◆ DynamicSymbolPattern() [2/4]

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::DynamicSymbolPattern ( const KeyType &  key)
inlineconstexpr

Make a dynamic pattern that accepts a single key.

Parameters
[in]keythe key to accept.

Definition at line 134 of file turingMachineSymbolPattern.h.

◆ DynamicSymbolPattern() [3/4]

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::DynamicSymbolPattern ( const std::set< KeyType > &  keys)
inlineconstexpr

Make a dynamic pattern that accepts a set of keys.

Parameters
[in]keyskeys to accept.

Definition at line 139 of file turingMachineSymbolPattern.h.

◆ DynamicSymbolPattern() [4/4]

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::DynamicSymbolPattern ( const std::set< KeyType > &  keys,
bool  neg 
)
inlineconstexpr

Make a dynamic pattern that accepts or rejects a set of keys.

Parameters
[in]keyskeys to accept/reject.
[in]negif true, keys are rejected rather than accepted.

Definition at line 145 of file turingMachineSymbolPattern.h.

Member Function Documentation

◆ isAlphaEquivalent()

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr bool TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::isAlphaEquivalent ( const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &  other,
const std::map< KeyType, KeyType > &  rewriting 
) const
inlineconstexpr

Test if, given a renaming of keys, *this is alpha-equivalent to another DynamicSymbolPattern.

Parameters
[in]otherthe other pattern to compare.
[in]rewritingthe renaming of keys, must be injective.
Returns
whether the two pattern are equivalent.

Definition at line 200 of file turingMachineSymbolPattern.h.

◆ matchAccordingToPredicate()

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr bool TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::matchAccordingToPredicate ( const std::map< KeyType, ValueType > &  context,
const std::function< bool(const ValueType &)> &  predicate 
) const
inlineconstexpr

Test if a key match a given predicate in a given context.

Parameters
[in]contexta map from KeyType to ValueType, that gives a meaning to each key.
[in]predicatea predicate that recognizes values of type ValueType.
Returns
Whether the pattern is accepted.

The pattern matches if a key of *this maps to a value (according to context) that is recognized by predicate. If the pattern matches, and the pattern is positive, the pattern is accepted. If the pattern matches and is negative, it is rejected. Conversely if the pattern does not match, it is accepted if and only if the pattern is negative.

Definition at line 157 of file turingMachineSymbolPattern.h.

◆ operator!=()

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr bool TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::operator!= ( const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &  other) const
inlineconstexpr

Non-equality operator.

Parameters
[in]otherthe value to compare.
Returns
Whether the comparison is true.

Definition at line 179 of file turingMachineSymbolPattern.h.

◆ operator<()

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr bool TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::operator< ( const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &  other) const
inlineconstexpr

Less than operator.

Parameters
[in]otherthe value to compare.
Returns
Whether the comparison is true.

Definition at line 185 of file turingMachineSymbolPattern.h.

◆ operator==()

template<typename KeyType , typename ValueType , typename SymbolType >
constexpr bool TuringSim::Symbol::DynamicSymbolPattern< KeyType, ValueType, SymbolType >::operator== ( const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &  other) const
inlineconstexpr

Equality operator.

Parameters
[in]otherthe value to compare.
Returns
Whether the comparison is true.

Definition at line 173 of file turingMachineSymbolPattern.h.

Friends And Related Function Documentation

◆ operator<<

template<typename KeyType , typename ValueType , typename SymbolType >
template<typename CharT = char, typename Traits = std::char_traits<CharT>>
std::basic_ostream<CharT, Traits>& operator<< ( std::basic_ostream< CharT, Traits > &  os,
const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &  pattern 
)
friend

Debug printer for DynamicSymbolPattern.

Template Parameters
CharTchar type.
Traitsstd::basic_ostream traits.
Parameters
osoutput stream.
patternpattern to print.
Returns
a reference to os.

Definition at line 227 of file turingMachineSymbolPattern.h.


The documentation for this class was generated from the following file: