LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp - aterm_string.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 24 27 88.9 %
Date: 2024-04-19 03:43:27 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      10             : #ifndef MCRL2_ATERMPP_ATERM_STRING_H
      11             : #define MCRL2_ATERMPP_ATERM_STRING_H
      12             : 
      13             : #include "mcrl2/atermpp/aterm_appl.h"
      14             : 
      15             : namespace atermpp
      16             : {
      17             : 
      18             : /// \brief Term containing a string.
      19             : class aterm_string: public aterm_appl
      20             : {
      21             : public:
      22             :   /// \brief Default constructor.
      23      554603 :   aterm_string()
      24      554603 :   {}
      25             : 
      26             :   /// \brief Constructor.
      27             :   /// \param t A term without arguments of type appl. The string is given by the function symbol.
      28    43187009 :   explicit aterm_string(const aterm& t)
      29    43187009 :     : aterm_appl(down_cast<aterm_appl>(t))
      30             :   {
      31    43187009 :     assert(size() == 0);
      32    43187009 :   }
      33             : 
      34             :   /// \brief Constructor.
      35             :   /// \param f A function symbol with arity 0.
      36       23637 :   aterm_string(const function_symbol& f)
      37       23637 :     : aterm_appl(f)
      38             :   {
      39       23637 :     assert(f.arity() == 0);
      40       23637 :     assert(size() == 0);
      41       23637 :   }
      42             : 
      43             :   /// \brief Constructor that allows construction from a string.
      44             :   /// \param s A string.
      45      830541 :   aterm_string(const std::string& s)
      46      830541 :     : aterm_appl(function_symbol(s,0))
      47             :   {
      48      830541 :     assert(size() == 0);
      49      830541 :   }
      50             : 
      51             :   /// Copy constructor.
      52             :   /// \param t An aterm_string.
      53     1417800 :   aterm_string(const aterm_string& t) noexcept = default;
      54             : 
      55             :   /// Move constructor.
      56             :   /// \param t An aterm_string.
      57       57220 :   aterm_string(aterm_string&& t) noexcept = default;
      58             : 
      59             :   /// Assignment operator.
      60             :   /// \param t An aterm_string.
      61      490022 :   aterm_string& operator=(const aterm_string& t) noexcept = default;
      62             : 
      63             :   /// Move assignment operator.
      64             :   /// \param t An aterm_string.
      65       18492 :   aterm_string& operator=(aterm_string&& t) noexcept = default;
      66             : 
      67             :   /// \brief Conversion operator
      68             :   /// \return The term converted to string
      69      396268 :   operator std::string() const
      70             :   {
      71      396268 :     return function().name();
      72             :   }
      73             : };
      74             : 
      75             : /// \brief Returns the empty aterm string
      76             : inline
      77  2848266933 : const aterm_string& empty_string()
      78             : {
      79  2848266933 :   static atermpp::aterm_string t("");
      80  2848266933 :   return t;
      81             : }
      82             : 
      83             : } // namespace atermpp
      84             : 
      85             : 
      86             : namespace std
      87             : {
      88             : 
      89             : /// \brief Swaps two aterm_strings.
      90             : /// \details This operation is more efficient than exchanging terms by an assignment,
      91             : ///          as swapping does not require to change the protection of terms.
      92             : ///          In order to be used in the standard containers, the declaration must
      93             : ///          be preceded by an empty template declaration.
      94             : /// \param t1 The first term
      95             : /// \param t2 The second term
      96             : 
      97             : template <>
      98           0 : inline void swap(atermpp::aterm_string& t1, atermpp::aterm_string& t2) noexcept
      99             : {
     100           0 :   t1.swap(t2);
     101           0 : }
     102             : } // namespace std
     103             : 
     104             : #endif // MCRL2_ATERMPP_ATERM_STRING_H

Generated by: LCOV version 1.14