libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
ToWord

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:775

Public Member Functions

 ToWord ()
 Default constructor.
 
 ToWord (std::string const &alphabet)
 Construct with given alphabet.
 
 ToWord (ToWord &&)
 Default move constructor.
 
 ToWord (ToWord const &)
 Default copy constructor.
 
std::string alphabet () const
 Return the alphabet used for conversion.
 
letter_type call_no_checks (char input) const
 Convert a char to a letter_type.
 
word_type call_no_checks (std::string const &input) const
 Convert a string to a word_type.
 
void call_no_checks (word_type &output, std::string const &input) const
 Convert a string to a word_type.
 
bool can_convert_letter (char const &c) const
 
bool empty () const noexcept
 Check if the alphabet is defined.
 
ToWordinit ()
 Initialize an existing ToWord object.
 
ToWordinit (std::string const &alphabet)
 Initialize an existing ToWord object.
 
letter_type operator() (char input) const
 Convert a char to a letter_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.
 
word_type operator() (std::string const &input) const
 Convert a string to a word_type.
 
void operator() (word_type &output, std::string 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]

ToWord ( )
inline

Constructs an empty object with no alphabet set.

◆ ToWord() [2/4]

ToWord ( ToWord const & )

Default copy constructor.

◆ ToWord() [3/4]

ToWord ( ToWord && )

Default move constructor.

◆ ToWord() [4/4]

ToWord ( std::string 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()

std::string 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]

letter_type call_no_checks ( char 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() [2/3]

word_type call_no_checks ( std::string 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() [3/3]

void call_no_checks ( word_type & output,
std::string 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()

bool can_convert_letter ( char 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()

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]

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]

ToWord & init ( std::string 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(std::string const& alphabet)

◆ operator()() [1/4]

letter_type operator() ( char 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()() [2/4]

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:1583
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:1761
StringRange & last(std::string const &lst)
Set one past the last string in the range.
Definition word-range.hpp:1797
Namespace containing some operators for creating words.
Definition word-range.hpp:2072

◆ operator()() [3/4]

word_type operator() ( std::string 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()() [4/4]

void operator() ( word_type & output,
std::string 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]

ToWord & operator= ( ToWord && )

Default move assignment.

◆ operator=() [2/2]

ToWord & operator= ( ToWord const & )

Default copy assignment.


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