libsemigroups  v3.0.0
C++ library for semigroups and monoids
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Loading...
Searching...
No Matches
ToString

Defined in word-range.hpp.

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

Example
ToString tostring("bac");
tostring(word_type({1, 0, 2})); // returns "abc"
tostring(word_type({0, 1, 1, 0, 1, 1, 0, 2})); // returns "baabaabc"
tostring.init();
tostring(word_type({1, 0, 2})); // returns "bac"
ToString()
Default constructor.
Definition word-range.hpp:1140
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101

Public Member Functions

 ToString ()
 Default constructor.
 
 ToString (std::string const &alphabet)
 Construct with given alphabet.
 
 ToString (ToString &&)
 Default move constructor.
 
 ToString (ToString const &)
 Default copy constructor.
 
std::string alphabet () const
 Return the alphabet used for conversion.
 
void call_no_checks (std::string &output, word_type const &input) const
 Convert a word_type to a std::string.
 
std::string call_no_checks (word_type const &input) const
 Convert a word_type to a std::string.
 
bool can_convert_letter (letter_type const &l) const
 
bool empty () const noexcept
 Check if the alphabet is defined.
 
ToStringinit () noexcept
 Initialize an existing ToString object.
 
ToStringinit (std::string const &alphabet)
 Initialize an existing Tostring object.
 
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.
 
template<typename Int>
std::string operator() (std::initializer_list< Int > input) const
 Convert a std::initializer_list to a std::string.
 
void operator() (std::string &output, word_type const &input) const
 Convert a word_type to a std::string.
 
std::string operator() (word_type const &input) const
 Convert a word_type to a std::string.
 
ToStringoperator= (ToString &&)
 Default move assignment.
 
ToStringoperator= (ToString const &)
 Default copy assignment.
 

Constructor & Destructor Documentation

◆ ToString() [1/4]

ToString ( )
inline

Constructs an empty object with no alphabet set.

◆ ToString() [2/4]

ToString ( ToString const & )

Default copy constructor.

◆ ToString() [3/4]

Default move constructor.

◆ ToString() [4/4]

ToString ( std::string const & alphabet)
inlineexplicit

Construct a ToString 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 {a0,a1,an1} that the initialised ToString object will use to convert from a word_type to a std::string. Specifically, iai where i will correspond to a letter in a word_type, and ai is a char.

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/2]

void call_no_checks ( std::string & output,
word_type const & input ) const

This function converts its second argument input into a std::string 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_letter if empty returns true.

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

Parameters
outputstd::string to hold the result.
inputthe word_type to convert.
Warning
This functions performs no checks on its arguments. In particular, if the alphabet used to define an instance of ToString 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/2]

std::string call_no_checks ( word_type const & input) const
inlinenodiscard

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

Parameters
inputthe word_type to convert.
Warning
This functions performs no checks on its arguments. In particular, if the alphabet used to define an instance of ToString 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 ( letter_type const & l) const
inlinenodiscard

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

This function returns true if l can can be converted to a char using this ToString instance, and false otherwise.

Parameters
lthe letter 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 return 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]

ToString & init ( )
inlinenoexcept

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

Returns
A reference to *this.
Exceptions
This function is noexcept and is guaranteed never to throw.
See also
ToString()

◆ init() [2/2]

ToString & init ( std::string const & alphabet)

This function puts a ToString 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
ToString(std::string const& alphabet)

◆ operator()() [1/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 WordRange object into std::string, that can be combined with other combinators using operator|.

Example
words.alphabet_size(1).min(0).max(10);
auto strings = (words | ToString("a"));
// Contains the strings
// {"", "a", "aa", "aaa", "aaaa", "aaaaa", "aaaaaa", "aaaaaaa",
// "aaaaaaaa", "aaaaaaaaa"};
Class for generating words in a given range and in a particular order.
Definition word-range.hpp:318
Namespace containing some operators for creating words.
Definition word-range.hpp:2072

◆ operator()() [2/4]

template<typename Int>
std::string operator() ( std::initializer_list< Int > input) const
inlinenodiscard

This function converts its argument input into a std::string, by first converting it to 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_letter if empty returns true.

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

◆ operator()() [3/4]

void operator() ( std::string & output,
word_type const & input ) const

This function converts its second argument input into a std::string 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_letter 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 ToString is not empty and input contains letters that do not correspond to letters of the alphabet.
See also

◆ operator()() [4/4]

std::string operator() ( word_type const & input) const
inlinenodiscard

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

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

◆ operator=() [1/2]

ToString & operator= ( ToString && )

Default move assignment.

◆ operator=() [2/2]

ToString & operator= ( ToString const & )

Default copy assignment.


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