libsemigroups  v3.1.2
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
ToWord< From >
template<typename From>
class libsemigroups::v4::ToWord< From >

Defined in word-range.hpp.

An instance of this class is used to convert from std::string to word_type. The characters in the string are converted to integers according to their position in alphabet used to construct a ToWord instance if one is provided, or using human_readable_index otherwise.

Example
ToWord toword("bac");
toword("bac"); // returns {0, 1, 2}
toword("bababbbcbc"); // returns { 0, 1, 0, 1, 0, 0, 0, 2, 0, 2}
toword.init();
toword("bac"); // returns {1, 0, 2}
ToWord()
Default constructor.
Definition word-range.hpp:785

Public Types

using from_type = From
 The type of values an instance of ToWord will convert into word_type.
 

Public Member Functions

 ToWord ()
 Default constructor.
 
 ToWord (From const &alphabet)
 Construct with given alphabet.
 
 ToWord (ToWord &&)
 Default move constructor.
 
 ToWord (ToWord const &)
 Default copy constructor.
 
from_type alphabet () const
 Return the alphabet used for conversion.
 
word_type call_no_checks (From const &input) const
 Convert a string to a word_type.
 
letter_type call_no_checks (typename From::value_type input) const
 Convert a char to a letter_type.
 
void call_no_checks (word_type &output, From const &input) const
 Convert a string to a word_type.
 
bool can_convert_letter (typename from_type::value_type const &c) const
 
bool empty () const noexcept
 Check if the alphabet is defined.
 
ToWordinit ()
 Initialize an existing ToWord object.
 
ToWordinit (From const &alphabet)
 Initialize an existing ToWord object.
 
word_type operator() (From const &input) const
 Convert a string to a word_type.
 
template<typename InputRange, typename = std::enable_if_t<rx::is_input_or_sink_v<InputRange>>>
constexpr auto operator() (InputRange &&input) const
 Call operator for combining with other range objects.
 
letter_type operator() (typename From::value_type input) const
 Convert a char to a letter_type.
 
void operator() (word_type &output, From const &input) const
 Convert a string to a word_type.
 
ToWordoperator= (ToWord &&)
 Default move assignment.
 
ToWordoperator= (ToWord const &)
 Default copy assignment.
 

Constructor & Destructor Documentation

◆ ToWord() [1/4]

template<typename From>
ToWord ( )
inline

Constructs an empty object with no alphabet set.

◆ ToWord() [2/4]

template<typename From>
ToWord ( ToWord< From > const & )
default

Default copy constructor.

◆ ToWord() [3/4]

template<typename From>
ToWord ( ToWord< From > && )
default

Default move constructor.

◆ ToWord() [4/4]

template<typename From>
ToWord ( From const & alphabet)
inlineexplicit

Construct a ToWord object with the given alphabet.

Parameters
alphabetthe alphabet.
Exceptions
LibsemigroupsExceptionif there are repeated letters in alphabet.

Member Function Documentation

◆ alphabet()

template<typename From>
From alphabet ( ) const
nodiscard

This function returns a std::string corresponding to the ordered-set alphabet \(\{a_0, a_1, \dots, a_{n-1}\}\) that the initialised ToWord object will use to convert from std::string to word_type. Specifically, \(a_i \mapsto i\) where \(a_i\) will correspond to a letter in a std::string, and \(i\) is a letter_type.

If this function returns the empty string, then conversion will be performed using human_readable_index.

Returns
A value of type std::string.
Exceptions
This function guarantees not to throw a LibsemigroupsException..

◆ call_no_checks() [1/3]

template<typename From>
word_type call_no_checks ( From const & input) const
inlinenodiscard

This function converts its argument input into a word_type. The characters of input are converted using the alphabet used to construct the object or set via init(), or with human_readable_index if empty returns true.

Parameters
inputthe string to convert.
Warning
This functions performs no checks on its arguments. In particular, if the alphabet used to define an instance of ToWord is not empty, and input contains letters that do not correspond to letters of the alphabet, then bad things will happen.
See also

◆ call_no_checks() [2/3]

template<typename From>
letter_type call_no_checks ( typename From::value_type input) const
inlinenodiscard

This function converts its argument input into a letter_type. It is converted using the alphabet used to construct the object or set via init(), or with human_readable_index if empty returns true.

Parameters
inputthe character to convert.
Warning
This functions performs no checks on its arguments. In particular, if the alphabet used to define an instance of ToWord is not empty, and input does not correspond to a letter of the alphabet, then bad things will happen.
See also

◆ call_no_checks() [3/3]

template<typename From>
void call_no_checks ( word_type & output,
From const & input ) const

This function converts its second argument input into a word_type and stores the result in the first argument output. The characters of input are converted using the alphabet used to construct the object or set via init(), or with human_readable_index if empty returns true.

The contents of the first argument output, if any, is removed.

Parameters
outputword to hold the result.
inputthe string to convert.
Warning
This functions performs no checks on its arguments. In particular, if the alphabet used to define an instance of ToWord is not empty, and input contains letters that do not correspond to letters of the alphabet, then bad things will happen.
See also

◆ can_convert_letter()

template<typename From>
bool can_convert_letter ( typename from_type::value_type const & c) const
inlinenodiscard

Check if the current ToWord instance can convert a specified letter.

This function returns true if c can can be converted to a letter_type using this ToWord instance, and false otherwise.

Parameters
cthe char to check the convertibility of.
Returns
A value of type bool.
Exceptions
This function guarantees not to throw a LibsemigroupsException.

◆ empty()

template<typename From>
bool empty ( ) const
inlinenodiscardnoexcept

This function returns true if no alphabet has been defined, and false otherwise.

Returns
A value of type bool.
Exceptions
This function is noexcept and is guaranteed never to throw.

◆ init() [1/2]

template<typename From>
ToWord & init ( )
inline

This function puts a ToWord object back into the same state as if it had been newly default constructed.

Returns
A reference to *this.
Exceptions
This function guarantees not to throw a LibsemigroupsException.
See also
ToWord()

◆ init() [2/2]

template<typename From>
ToWord< From > & init ( From const & alphabet)

This function puts a ToWord object back into the same state as if it had been newly constructed from alphabet.

Parameters
alphabetthe alphabet.
Returns
A reference to *this.
Exceptions
LibsemigroupsExceptionif there are repeated letters in alphabet.
See also
ToWord(From const& alphabet)

◆ operator()() [1/4]

template<typename From>
word_type operator() ( From const & input) const
inlinenodiscard

This function converts its argument input into a word_type The characters of input are converted using the alphabet used to construct the object or set via init(), or with human_readable_index if empty returns true.

Parameters
inputthe string to convert.
Exceptions
LibsemigroupsExceptionif the alphabet used to define an instance of ToWord is not empty and input contains letters that do not correspond to letters of the alphabet.
See also

◆ operator()() [2/4]

template<typename From>
template<typename InputRange, typename = std::enable_if_t<rx::is_input_or_sink_v<InputRange>>>
auto operator() ( InputRange && input) const
inlinenodiscardconstexpr

A custom combinator for rx::ranges to convert the output of a StringRange object into word_type, that can be combined with other combinators using operator|.

Example
StringRange strings;
strings.alphabet("ab").first("a").last("bbbb");
auto words = (strings | ToWord("ba"));
// contains the words
// {1_w, 0_w, 11_w, 10_w, 01_w, 00_w, 111_w,
// 110_w, 101_w, 100_w, 011_w, 010_w, 001_w, 000_w,
// 1111_w, 1110_w, 1101_w, 1100_w, 1011_w, 1010_w, 1001_w,
// 1000_w, 0111_w, 0110_w, 0101_w, 0100_w, 0011_w, 0010_w,
// 0001_w}));
Class for generating strings in a given range and in a particular order.
Definition word-range.hpp:1606
StringRange & alphabet(std::string const &x)
Set the alphabet.
StringRange & first(std::string const &frst)
Set the first string in the range.
Definition word-range.hpp:1784
StringRange & last(std::string const &lst)
Set one past the last string in the range.
Definition word-range.hpp:1820
Namespace containing some operators for creating words.
Definition word-range.hpp:2095

◆ operator()() [3/4]

template<typename From>
letter_type operator() ( typename From::value_type input) const
inlinenodiscard

This function converts its argument input into a letter_type. It is converted using the alphabet used to construct the object or set via init(), or with human_readable_index if empty returns true.

Parameters
inputthe character to convert.
Exceptions
LibsemigroupsExceptionif the alphabet used to define an instance of ToWord is not empty and input does not correspond to a letter of the alphabet.
See also

◆ operator()() [4/4]

template<typename From>
void operator() ( word_type & output,
From const & input ) const

This function converts its second argument input into a word_type and stores the result in the first argument output. The characters of input are converted using the alphabet used to construct the object or set via init(), or with human_readable_index if empty returns true.

The contents of the first argument output, if any, is removed.

Parameters
outputword to hold the result.
inputthe string to convert.
Exceptions
LibsemigroupsExceptionif the alphabet used to define an instance of ToWord is not empty and input contains letters that do not correspond to letters of the alphabet.
See also

◆ operator=() [1/2]

template<typename From>
ToWord< From > & operator= ( ToWord< From > && )
default

Default move assignment.

◆ operator=() [2/2]

template<typename From>
ToWord< From > & operator= ( ToWord< From > const & )
default

Default copy assignment.


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