mCRL2
Loading...
Searching...
No Matches
function_symbol_generator.h
Go to the documentation of this file.
1// Author(s): Wieger Wesselink, Jan Friso Groote
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_ATERMPP_FUNCTION_SYMBOL_GENERATOR_H
13#define MCRL2_ATERMPP_FUNCTION_SYMBOL_GENERATOR_H
14
16
17#include <cctype>
18
19namespace atermpp {
20
21static inline std::mutex& function_symbol_generator_mutex()
22{
23 static std::mutex m_function_symbol_generator_mutex;
24 return m_function_symbol_generator_mutex;
25}
26
27static inline std::size_t& generator_sequence_number()
28{
29 static size_t n=0;
30 return n;
31}
32
33
35class function_symbol_generator // : private mcrl2::utilities::noncopyable
36{
37protected:
38 std::string m_prefix;
39
41 std::size_t m_initial_index;
42
44 std::string m_string_buffer;
45
47 std::size_t m_index;
48
50 std::shared_ptr<std::size_t> m_central_index;
51
52public:
56 function_symbol_generator(const std::string& prefix)
57 {
59
60 m_prefix=prefix + (generator_sequence_number()>0?std::to_string(generator_sequence_number()) + "_":"");
63 assert(!prefix.empty() && !(std::isdigit(*prefix.rbegin())));
64
65 // Obtain a reference to the first index possible.
68
70
72 }
73
75
76 void clear()
77 {
79 }
80
82 {
86 }
87
89 function_symbol operator()(std::size_t arity = 0)
90 {
91 // Check whether in the meantime other variables have been used with the same prefix.
92 // if (m_index<=*detail::g_term_pool().get_symbol_pool().register_prefix(m_prefix))
94 {
95 // m_index=*detail::g_term_pool().get_symbol_pool().register_prefix(m_prefix);
98 }
99 // Put the number m_index after the prefix in the string buffer.
101
102 // Increase the index.
103 ++m_index;
104
105 // Generate a new function symbol with prefix + index.
106 function_symbol f(m_string_buffer, arity, false);
107 return f;
108 }
109};
110
111} // namespace atermpp
112
113#endif // MCRL2_ATERMPP_FUNCTION_SYMBOL_GENERATOR_H
function_symbol_pool & get_symbol_pool()
Definition aterm_pool.h:132
void deregister(const std::string &prefix)
Restore the index back to index before registering this prefix. \threadsafe.
std::shared_ptr< std::size_t > register_prefix(const std::string &prefix)
Generates unique function symbols with a given prefix.
std::size_t m_initial_index
Cache the value that is set in the constructor.
void clear()
Restores the index back to the value that was initially assigned in the constructor.
std::size_t m_index
A reference to the index as present in the function symbol generator.
std::string m_string_buffer
A local string cache to prevent allocating new strings for every function symbol generated.
function_symbol operator()(std::size_t arity=0)
Generates a unique function symbol with the given prefix followed by a number.
function_symbol_generator(const std::string &prefix)
Constructor.
std::shared_ptr< std::size_t > m_central_index
The address of the central index for this prefix.
aterm_pool & g_term_pool()
obtain a reference to the global aterm pool.
The main namespace for the aterm++ library.
Definition algorithm.h:21
static std::size_t & generator_sequence_number()
static std::mutex & function_symbol_generator_mutex()
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
void number2string(std::size_t number, std::string &buffer, std::size_t start_position)
Convert a number to a string in the buffer starting at position start_position.