Line data Source code
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 : 9 : 10 : #ifndef MCRL2_ATERMPP_FUNCTION_SYMBOL_H 11 : #define MCRL2_ATERMPP_FUNCTION_SYMBOL_H 12 : 13 : #include <utility> 14 : #include "mcrl2/atermpp/detail/function_symbol.h" 15 : 16 : namespace atermpp 17 : { 18 : namespace detail 19 : { 20 : class function_symbol_pool; 21 : class _aterm; 22 : } 23 : 24 : class function_symbol 25 : { 26 : friend class function_symbol_generator; 27 : friend class detail::function_symbol_pool; 28 : friend class detail::_aterm; 29 : 30 : friend struct std::hash<function_symbol>; 31 : 32 : public: 33 16127 : function_symbol() = default; 34 : 35 : /// \brief Defines a function symbol from a name and arity combination. 36 1044830 : function_symbol(const std::string& name, const std::size_t arity_) 37 1044830 : : function_symbol(name, arity_, true) 38 1044830 : {} 39 : 40 : /// \brief Defines a function symbol from a name and arity combination. 41 12572 : function_symbol(std::string&& name, const std::size_t arity_) 42 12572 : : function_symbol(std::forward<std::string>(name), arity_, true) 43 12572 : {} 44 : 45 : /// This class has non-trivial destructor so declare default copy and move operators. 46 2094474 : function_symbol(const function_symbol& other) noexcept = default; 47 2600 : function_symbol& operator=(const function_symbol& other) noexcept = default; 48 0 : function_symbol(function_symbol&& other) noexcept = default; 49 12817 : function_symbol& operator=(function_symbol&& other) noexcept = default; 50 : 51 2299379 : bool defined() const 52 : { 53 2299379 : return m_function_symbol.defined(); 54 : } 55 : 56 : /// \brief Return the name of the function_symbol. 57 : /// \return The name of the function symbol. 58 646794 : const std::string& name() const 59 : { 60 646794 : return m_function_symbol->name(); 61 : } 62 : 63 : /// \brief Return the arity (number of arguments) of the function symbol (function_symbol). 64 : /// \return The arity of the function symbol. 65 13121420579 : std::size_t arity() const 66 : { 67 13121420579 : return m_function_symbol->arity(); 68 : } 69 : 70 : /// \brief Equality test. 71 : /// \details This operator compares the indices of the function symbols. This means 72 : /// that this operation takes constant time. 73 : /// \returns True iff the function symbols are the same. 74 71230647476 : bool operator ==(const function_symbol& f) const 75 : { 76 71230647476 : return m_function_symbol == f.m_function_symbol; 77 : } 78 : 79 : /// \brief Inequality test. 80 : /// \details This operator takes constant time. 81 : /// \returns True iff the function symbols are not equal. 82 6467635168 : bool operator !=(const function_symbol& f) const 83 : { 84 6467635168 : return m_function_symbol != f.m_function_symbol; 85 : } 86 : 87 : /// \brief Comparison operation. 88 : /// \details This operator takes constant time. 89 : /// \returns True iff this function has a lower index than the argument. 90 : bool operator <(const function_symbol& f) const 91 : { 92 : return m_function_symbol < f.m_function_symbol; 93 : } 94 : 95 : /// \brief Comparison operation. 96 : /// \details This operator takes constant time. 97 : /// \returns True iff this function has a higher index than the argument. 98 : bool operator >(const function_symbol& f) const 99 : { 100 : return m_function_symbol > f.m_function_symbol; 101 : } 102 : 103 : /// \brief Comparison operation. 104 : /// \details This operator takes constant time. 105 : /// \returns True iff this function has a lower or equal index than the argument. 106 : bool operator <=(const function_symbol& f) const 107 : { 108 : return m_function_symbol <= f.m_function_symbol; 109 : } 110 : 111 : /// \brief Comparison operation. 112 : /// \details This operator takes constant time. 113 : /// \returns True iff this function has a larger or equal index than the argument. 114 : bool operator >=(const function_symbol& f) const 115 : { 116 : return m_function_symbol >= f.m_function_symbol; 117 : } 118 : 119 : /// \brief Swap this function with its argument. 120 : /// \details More efficient than assigning twice. 121 : /// \param f The function symbol with which the swap takes place. 122 : void swap(function_symbol& f) 123 : { 124 : using std::swap; 125 : swap(f.m_function_symbol, m_function_symbol); 126 : } 127 : 128 : private: 129 : /// \brief Constructor for internal use only. 130 1101693 : function_symbol(detail::_function_symbol::ref&& f) 131 1101693 : : m_function_symbol(std::forward<detail::_function_symbol::ref>(f)) 132 1101693 : {} 133 : 134 : /// \brief Constructor for internal use only 135 : function_symbol(const std::string& name, const std::size_t arity, const bool check_for_registered_functions); 136 : 137 : /// \brief Constructor for internal use only 138 : function_symbol(std::string&& name, const std::size_t arity, const bool check_for_registered_functions); 139 : 140 : /// \brief Calls the function symbol pool to free our used memory. 141 : void destroy(); 142 : 143 : /// \brief The shared reference to the underlying function symbol. 144 : detail::_function_symbol::ref m_function_symbol; 145 : }; 146 : 147 : class global_function_symbol : public function_symbol 148 : { 149 : public: 150 : /// \brief Defines a function symbol from a name and arity combination. 151 : /// \details This constructor should be used by global function symbols. 152 : global_function_symbol(const std::string& name, const std::size_t arity); 153 : }; 154 : 155 : namespace detail 156 : { 157 : /// \brief These function symbols are used to indicate integer, list and empty list terms. 158 : /// \details They are copied from the function_symbol_pool so that type_is_{int|list|appl} can be defined in the header. 159 : extern function_symbol g_as_int; 160 : extern function_symbol g_as_list; 161 : extern function_symbol g_as_empty_list; 162 : } 163 : 164 : } // namespace atermpp 165 : 166 : #endif // MCRL2_ATERMPP_FUNCTION_SYMBOL_H