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//
11
12#ifndef MCRL2_DATA_XYZ_IDENTIFIER_GENERATOR_H
13#define MCRL2_DATA_XYZ_IDENTIFIER_GENERATOR_H
14
16
17namespace mcrl2
18{
19
20namespace data
21{
22
25{
26 protected:
29
31 char m_char; // character of last generated identifier
32
35 std::string next()
36 {
37 switch (m_char)
38 {
39 case 'X' :
40 {
41 m_char = 'Y';
42 break;
43 }
44 case 'Y' :
45 {
46 m_char = 'Z';
47 break;
48 }
49 case 'Z' :
50 {
51 m_char = 'X';
52 m_index++;
53 break;
54 }
55 }
56 return m_index < 0 ? std::string(1, m_char) : m_char + std::to_string(m_index);
57 }
58
59 public:
62 : m_index(-2), m_char('Z')
63 {}
64
67 xyz_identifier_generator(const std::set<core::identifier_string>& ids)
68 : m_index(-2), m_char('Z')
69 {
70 add_identifiers(ids);
71 }
72
79 core::identifier_string operator()(const std::string& hint, bool add_to_context = true)
80 {
81 core::identifier_string result(hint);
82
83 if (m_identifiers.find(hint) != m_identifiers.end())
84 {
85 m_index = -2;
86 m_char = 'Z';
87 do
88 {
89 result = core::identifier_string(next());
90 }
91 while (m_identifiers.find(result) != m_identifiers.end());
92 }
93
94 if (add_to_context)
95 {
96 add_identifier(result);
97 }
98 return result;
99 }
100};
101
102} // namespace data
103
104} // namespace mcrl2
105
106#endif // MCRL2_DATA_XYZ_IDENTIFIER_GENERATOR_H
Term containing a string.
void add_identifiers(const std::set< core::identifier_string > &ids)
Add a set of identifiers to the context.
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.
std::multiset< core::identifier_string > m_identifiers
The context of the identifier generator.
Identifier generator that generates names from the range X, Y, Z, X0, Y0, Z0, X1, ....
core::identifier_string operator()(const std::string &hint, bool add_to_context=true)
Returns hint if it isn't in the context yet. Else the next available identifier in the range X,...
xyz_identifier_generator(const std::set< core::identifier_string > &ids)
Constructor.
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.
atermpp::aterm_string identifier_string
String type of the LPS library. Identifier strings are represented internally as ATerms.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
The classes set_identifier_generator and multiset_identifier_generator.