mCRL2
Loading...
Searching...
No Matches
aterm_int.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/atermpp/aterm_int.h
10/// \brief Term containing an integer.
11
12#ifndef MCRL2_ATERMPP_ATERM_INT_H
13#define MCRL2_ATERMPP_ATERM_INT_H
14
15#include "mcrl2/atermpp/aterm.h"
16#include "mcrl2/atermpp/detail/global_aterm_pool.h"
17
18namespace atermpp
19{
20
21/// \brief An integer term stores a single std::size_t value. It carries
22/// no arguments.
23/// \details A special function symbol is used to identify integer terms
24/// internally.
25class aterm_int : public aterm
26{
27public:
28 /// \brief Default constructor.
29 aterm_int() noexcept = default;
30
31 /// \brief Constructs an integer term from a value.
32 /// \param value The value of the new integer.
33 explicit aterm_int(std::size_t value)
34 {
35 detail::g_thread_term_pool().create_int(*this, value);
36 }
37
38 /// \brief Constructs an integer term from an aterm.
39 explicit aterm_int(const aterm& t)
40 : aterm(t)
41 {
42 assert(!defined() || type_is_int());
43 }
44
45 /// \brief Provide the value stored in an aterm.
46 /// \returns The value of the integer term.
47 std::size_t value() const noexcept
48 {
49 assert(defined());
50 assert(type_is_int());
51 return reinterpret_cast<const detail::_aterm_int*>(m_term)->value();
52 }
53
54 /// \brief Swaps two integer terms without changing the protection.
55 /// \param t The term that is swapped with the current term.
56 void swap(aterm_int& t) noexcept
57 {
58 aterm::swap(t);
59 }
60};
61
62/// \brief Constructs an integer term from a value.
63/// \param target The term into which the term is constructed.
64inline void make_aterm_int(aterm_int& target, std::size_t value)
65{
66 detail::g_thread_term_pool().create_int(target, value);
67}
68
69} // namespace atermpp
70
71namespace std
72{
73
74/// \brief Swaps two aterm_ints.
75/// \details This operation is more efficient than exchanging terms by an assignment,
76/// as swapping does not require to change the protection of terms.
77/// In order to be used in the standard containers, the declaration must
78/// be preceded by an empty template declaration.
79/// \param t1 The first term
80/// \param t2 The second term
81template <>
82inline void swap(atermpp::aterm_int& t1, atermpp::aterm_int& t2) noexcept
83{
84 t1.swap(t2);
85}
86} // namespace std
87
88#endif // MCRL2_ATERMPP_ATERM_INT_H
An integer term stores a single std::size_t value. It carries no arguments.
Definition aterm_int.h:26
aterm_int(std::size_t value)
Constructs an integer term from a value.
Definition aterm_int.h:33
aterm_int(const aterm &t)
Constructs an integer term from an aterm.
Definition aterm_int.h:39
std::size_t value() const noexcept
Provide the value stored in an aterm.
Definition aterm_int.h:47
void swap(aterm_int &t) noexcept
Swaps two integer terms without changing the protection.
Definition aterm_int.h:56
aterm_int() noexcept=default
Default constructor.
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
Definition aterm_io.h:62
virtual void get(aterm &t)=0
Reads an aterm from this stream.
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
Definition aterm_io.h:51
virtual void put(const aterm &term)=0
Write the given term to the stream.
A helper class to restore the state of the aterm_{i,o}stream objects upon destruction....
Definition aterm_io.h:104
aterm_stream_state(aterm_stream_state &&)=delete
aterm_stream_state & operator=(aterm_stream_state &&)=delete
aterm_transformer * m_transformer
Definition aterm_io.h:123
aterm_stream_state(aterm_stream &stream)
Definition aterm_io.h:106
aterm_stream_state(const aterm_stream_state &)=delete
aterm_stream_state & operator=(const aterm_stream_state &)=delete
aterm_stream & m_stream
Definition aterm_io.h:122
The general aterm stream interface, which enables the use of a transformer to change the written/read...
Definition aterm_io.h:34
aterm_transformer * m_transformer
Definition aterm_io.h:45
aterm_transformer * get_transformer() const
Definition aterm_io.h:42
void set_transformer(aterm_transformer transformer)
Sets the given transformer to be applied to following writes.
Definition aterm_io.h:39
aterm(const aterm &other) noexcept=default
This class has user-declared copy constructor so declare default copy and move operators.
thread_aterm_pool(aterm_pool &global_pool)
std::stack< std::reference_wrapper< _aterm > > m_todo
A reusable todo stack.
A unordered_map class in which aterms can be stored.
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
aterm_pool & g_aterm_pool_instance()
A reference to the global term pool storage.
thread_aterm_pool * g_main_thread_pool
Pointer to the main thread's pool; set on its first access and used by ~thread_aterm_pool to transfer...
mcrl2::utilities::shared_guard lock_shared_aterm_pool()
Acquires a shared lock on the global thread aterm pool.
std::array< std::byte, sizeof(aterm_pool)> g_aterm_pool_storage
Storage for a global term pool that is not initialized.
The main namespace for the aterm++ library.
aterm identity(const aterm &x)
The default transformer that maps each term to itself.
Definition aterm_io.h:26
aterm_istream & operator>>(aterm_istream &stream, aterm &term)
Read the given term from the stream, but for aterm_list we want to use a specific one that performs v...
Definition aterm_io.h:93
void read_term_from_binary_stream(std::istream &is, aterm &t)
Reads a term from a stream in binary aterm format.
aterm read_appl_from_string(const std::string &s)
Reads an aterm from a string. The string can be in either binary or text format.
Definition aterm_io.h:232
aterm_int read_int_from_string(const std::string &s)
Reads an aterm_int from a string. The string can be in either binary or text format.
Definition aterm_io.h:222
aterm read_term_from_string(const std::string &s)
Reads an aterm from a string. The string can be in either binary or text format.
void add_deletion_hook(const function_symbol &, term_callback)
Check for reasonably sized aterm (32 bits, 4 bytes) This check might break on perfectly valid archite...
void write_term_to_text_stream(const aterm &t, std::ostream &os)
Writes term t to a stream in textual format.
aterm_istream & operator>>(aterm_istream &stream, aterm_transformer transformer)
Sets the given transformer to be applied to following reads.
Definition aterm_io.h:73
void make_aterm_int(aterm_int &target, std::size_t value)
Constructs an integer term from a value.
Definition aterm_int.h:64
void read_term_from_text_stream(std::istream &is, aterm &t)
Reads a term from a stream which contains the term in textual format.
aterm_list read_list_from_string(const std::string &s)
Reads an aterm_list from a string. The string can be in either binary or text format.
Definition aterm_io.h:212
void swap(atermpp::aterm_int &t1, atermpp::aterm_int &t2) noexcept
Swaps two aterm_ints.
Definition aterm_int.h:82