mCRL2
Loading...
Searching...
No Matches
xyz_identifier_generator.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9/// \file mcrl2/data/xyz_identifier_generator.h
10/// \brief Class that generates identifiers in the range X, Y, Z, X0, Y0, Z0, X1, ...
11
12#ifndef MCRL2_DATA_XYZ_IDENTIFIER_GENERATOR_H
13#define MCRL2_DATA_XYZ_IDENTIFIER_GENERATOR_H
14
15#include "mcrl2/data/set_identifier_generator.h"
16
17namespace mcrl2::data
18{
19
20/// \brief Identifier generator that generates names from the range X, Y, Z, X0, Y0, Z0, X1, ...
22{
23 protected:
24 /// \brief The index of the last generated identifier.
26
27 /// \brief The character of the last generated identifier.
28 char m_char; // character of last generated identifier
29
30 /// \brief Returns the next name in the range X, Y, Z, X0, Y0, Z0, X1, ...
31 /// \return The next name in the range X, Y, Z, X0, Y0, Z0, X1, ...
33 {
34 switch (m_char)
35 {
36 case 'X' :
37 {
38 m_char = 'Y';
39 break;
40 }
41 case 'Y' :
42 {
43 m_char = 'Z';
44 break;
45 }
46 case 'Z' :
47 {
48 m_char = 'X';
49 m_index++;
50 break;
51 }
52 default:
53 {
54 throw mcrl2::runtime_error("Unexpected character in xyz_identifier_generator: " + std::string(1, m_char));
55 }
56 }
57 return m_index < 0 ? std::string(1, m_char) : std::string(1, m_char) + std::to_string(m_index);
58 }
59
60 public:
61 /// \brief Constructor.
63 : m_index(-2), m_char('Z')
64 {}
65
66 /// \brief Constructor.
67 /// \param ids a set of identifiers to use as context
68 xyz_identifier_generator(const std::set<core::identifier_string>& ids)
69 : m_index(-2), m_char('Z')
70 {
71 add_identifiers(ids);
72 }
73
74 /// \brief Returns hint if it isn't in the context yet. Else the next available
75 /// identifier in the range X, Y, Z, X0, Y0, Z0, X1, ... is returned.
76 /// \param hint A string
77 /// \param add_to_context If true, the generated identifier is added to the context,
78 /// it is not added otherwise.
79 /// \return A fresh identifier.
80 core::identifier_string operator()(const std::string& hint, bool add_to_context = true) override
81 {
82 core::identifier_string result(hint);
83
84 if (m_identifiers.find(hint) != m_identifiers.end())
85 {
86 m_index = -2;
87 m_char = 'Z';
88 do
89 {
90 result = core::identifier_string(next());
91 }
92 while (m_identifiers.find(result) != m_identifiers.end());
93 }
94
95 if (add_to_context)
96 {
97 add_identifier(result);
98 }
99 return result;
100 }
101};
102
103} // namespace mcrl2::data
104
105
106
107#endif // MCRL2_DATA_XYZ_IDENTIFIER_GENERATOR_H
aterm(const aterm &other) noexcept=default
This class has user-declared copy constructor so declare default copy and move operators.
A unordered_map class in which aterms can be stored.
Identifier generator that stores the identifiers of the context in a multiset. If an identifier occur...
void add_identifier(const core::identifier_string &s) override
Adds the identifier s to the context.
Identifier generator that generates names from the range X, Y, Z, X0, Y0, Z0, X1, ....
xyz_identifier_generator(const std::set< core::identifier_string > &ids)
Constructor.
core::identifier_string operator()(const std::string &hint, bool add_to_context=true) override
Returns hint if it isn't in the context yet. Else the next available identifier in the range X,...
int m_index
The index of the last generated identifier.
std::string next()
Returns the next name in the range X, Y, Z, X0, Y0, Z0, X1, ...
char m_char
The character of the last generated identifier.
\brief The alt operator for regular formulas
alt(const atermpp::aterm &term)
const regular_formula & right() const
const regular_formula & left() const
\brief The seq operator for regular formulas
seq(const regular_formula &left, const regular_formula &right)
\brief Constructor Z14.
const regular_formula & right() const
const regular_formula & left() const
seq(const atermpp::aterm &term)
\brief The 'trans or nil' operator for regular formulas
trans_or_nil(const regular_formula &operand)
\brief Constructor Z14.
trans_or_nil(const atermpp::aterm &term)
const regular_formula & operand() const
\brief The trans operator for regular formulas
trans(const atermpp::aterm &term)
const regular_formula & operand() const
\brief The and operator for state formulas
const state_formula & right() const
and_(const atermpp::aterm &term)
and_(const state_formula &left, const state_formula &right)
\brief Constructor Z14.
const state_formula & left() const
\brief The multiply operator for state formulas with values
const state_formula & left() const
const_multiply_alt(const state_formula &left, const data::data_expression &right)
\brief Constructor Z14.
const data::data_expression & right() const
const_multiply_alt(const atermpp::aterm &term)
\brief The multiply operator for state formulas with values
const data::data_expression & left() const
const_multiply(const data::data_expression &left, const state_formula &right)
\brief Constructor Z14.
const_multiply(const atermpp::aterm &term)
const state_formula & right() const
\brief The existential quantification operator for state formulas
exists(const data::variable_list &variables, const state_formula &body)
\brief Constructor Z14.
const state_formula & body() const
exists(const atermpp::aterm &term)
const data::variable_list & variables() const
\brief The universal quantification operator for state formulas
const state_formula & body() const
forall(const atermpp::aterm &term)
const data::variable_list & variables() const
forall(const data::variable_list &variables, const state_formula &body)
\brief Constructor Z14.
\brief The implication operator for state formulas
imp(const state_formula &left, const state_formula &right)
\brief Constructor Z14.
const state_formula & left() const
const state_formula & right() const
imp(const atermpp::aterm &term)
\brief The infimum over a data type for state formulas
infimum(const data::variable_list &variables, const state_formula &body)
\brief Constructor Z14.
const data::variable_list & variables() const
const state_formula & body() const
infimum(const atermpp::aterm &term)
\brief The may operator for state formulas
const state_formula & operand() const
const regular_formulas::regular_formula & formula() const
may(const regular_formulas::regular_formula &formula, const state_formula &operand)
\brief Constructor Z14.
may(const atermpp::aterm &term)
\brief The minus operator for state formulas
minus(const state_formula &operand)
\brief Constructor Z14.
const state_formula & operand() const
\brief The mu operator for state formulas
const core::identifier_string & name() const
const data::assignment_list & assignments() const
mu(const core::identifier_string &name, const data::assignment_list &assignments, const state_formula &operand)
\brief Constructor Z14.
mu(const atermpp::aterm &term)
const state_formula & operand() const
\brief The must operator for state formulas
must(const atermpp::aterm &term)
must(const regular_formulas::regular_formula &formula, const state_formula &operand)
\brief Constructor Z14.
const regular_formulas::regular_formula & formula() const
const state_formula & operand() const
\brief The not operator for state formulas
const state_formula & operand() const
not_(const state_formula &operand)
\brief Constructor Z14.
\brief The nu operator for state formulas
nu(const atermpp::aterm &term)
nu(const core::identifier_string &name, const data::assignment_list &assignments, const state_formula &operand)
\brief Constructor Z14.
const core::identifier_string & name() const
const state_formula & operand() const
const data::assignment_list & assignments() const
\brief The or operator for state formulas
or_(const state_formula &left, const state_formula &right)
\brief Constructor Z14.
const state_formula & right() const
or_(const atermpp::aterm &term)
const state_formula & left() const
\brief The plus operator for state formulas with values
const state_formula & left() const
plus(const atermpp::aterm &term)
const state_formula & right() const
plus(const state_formula &left, const state_formula &right)
\brief Constructor Z14.
state_formula & operator=(state_formula &&) noexcept=default
\brief The sum over a data type for state formulas
sum(const atermpp::aterm &term)
sum(const data::variable_list &variables, const state_formula &body)
\brief Constructor Z14.
const data::variable_list & variables() const
const state_formula & body() const
\brief The supremum over a data type for state formulas
supremum(const atermpp::aterm &term)
const state_formula & body() const
const data::variable_list & variables() const
supremum(const data::variable_list &variables, const state_formula &body)
\brief Constructor Z14.
\brief The state formula variable
variable(const core::identifier_string &name, const data::data_expression_list &arguments)
\brief Constructor Z14.
bool is_data_expression(const atermpp::aterm &x)
Test for a data_expression expression.
bool is_assignment(const atermpp::aterm &x)
Definition assignment.h:152
The main namespace for the LPS library.
Definition constelm.h:18
bool is_multi_action(const atermpp::aterm &x)
state_formula translate_reg_frms(const state_formula &state_frm)
Translate regular formulas in terms of state and action formulas.
state_formula translate_reg_frms_appl(state_formula part, xyz_identifier_generator &xyz_generator)
bool is_alt(const atermpp::aterm &x)
bool is_trans(const atermpp::aterm &x)
bool is_trans_or_nil(const atermpp::aterm &x)
bool is_seq(const atermpp::aterm &x)
bool is_infimum(const atermpp::aterm &x)
bool is_and(const atermpp::aterm &x)
bool is_delay_timed(const atermpp::aterm &x)
bool is_const_multiply(const atermpp::aterm &x)
bool is_minus(const atermpp::aterm &x)
bool is_exists(const atermpp::aterm &x)
bool is_not(const atermpp::aterm &x)
bool is_supremum(const atermpp::aterm &x)
bool is_must(const atermpp::aterm &x)
bool is_yaled(const atermpp::aterm &x)
bool is_true(const atermpp::aterm &x)
bool is_variable(const atermpp::aterm &x)
bool is_may(const atermpp::aterm &x)
bool is_yaled_timed(const atermpp::aterm &x)
bool is_imp(const atermpp::aterm &x)
bool is_sum(const atermpp::aterm &x)
bool is_nu(const atermpp::aterm &x)
bool is_delay(const atermpp::aterm &x)
bool is_false(const atermpp::aterm &x)
bool is_plus(const atermpp::aterm &x)
bool is_mu(const atermpp::aterm &x)
bool is_forall(const atermpp::aterm &x)
bool is_const_multiply_alt(const atermpp::aterm &x)
bool is_or(const atermpp::aterm &x)
std::set< core::identifier_string > find_identifiers(const state_formulas::state_formula &x)