LCOV - code coverage report
Current view: top level - lts/include/mcrl2/lts - action_label_string.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 11 11 100.0 %
Date: 2019-09-14 00:54:39 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): 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             : /** \file
      11             :  *
      12             :  * \brief This file contains a class that contains labelled transition systems in aut format.
      13             :  * \details A labelled transition system in aut format is a transition system
      14             :  * with as state labels vectors of strings, and as transition labels strings.
      15             :  * \author Jan Friso Groote
      16             :  */
      17             : 
      18             : 
      19             : #ifndef MCRL2_LTS_ACTION_LABEL_STRING_H
      20             : #define MCRL2_LTS_ACTION_LABEL_STRING_H
      21             : 
      22             : #include <algorithm>
      23             : #include <string>
      24             : #include <vector>
      25             : #include <iterator>
      26             : #include "mcrl2/utilities/exception.h"
      27             : #include "mcrl2/utilities/text_utility.h"
      28             : 
      29             : namespace mcrl2
      30             : {
      31             : namespace lts
      32             : {
      33             : 
      34             : /** \brief This class contains strings to be used as values for action labels in lts's.
      35             :  *  \details These action labels are used in the aut, fsm, and dot format to represent
      36             :  *           values for the action labels in transitions.
      37             :  */
      38       22828 : class action_label_string: public std::string
      39             : {
      40             :   public:
      41             : 
      42             :     /* \brief Default constructor. The label will contain the default string.
      43             :      */
      44             :     action_label_string()
      45             :     {}
      46             : 
      47             :     /** \brief Copy constructor. */
      48       18135 :     action_label_string(const action_label_string& )=default;
      49             : 
      50             :     /** \brief Copy assignment. */
      51             :     action_label_string& operator=(const action_label_string& )=default;
      52             : 
      53             :     /* \brief A constructor, where the string s is taken to become the action label.
      54             :      */
      55        3925 :     explicit action_label_string(const std::string& s):std::string(s)
      56        3925 :     {}
      57             : 
      58             :     /* \brief An auxiliary function to hide actions. Makes a best-effort attempt at
      59             :               parsing the string as an mCRL2 multi-action and hiding the actions
      60             :               with a name in string_vector. If all actions are hidden, the resulting
      61             :               action name will be "tau". The effects of this operation on action 
      62             :               labels that are not generated by the pretty printer are undefined. */
      63             :     void hide_actions(const std::vector<std::string>& string_vector)
      64             :     {
      65             :       std::string ns;                    // New label after hiding.
      66             :       std::string::iterator b = begin(); // Start position of current action.
      67             :       std::string::iterator c = begin(); // End position of current action.
      68             :       while (c != end())
      69             :       {
      70             :         std::string a;
      71             :         // Parse action name into a
      72             :         while (c != end() && *c != '(' && *c != '|')
      73             :         {
      74             :           a.append(1, *c++);
      75             :         }
      76             :         // Skip over parameters of a, if any
      77             :         if (c != end() && *c == '(')
      78             :         {
      79             :           std::size_t nd = 0;
      80             :           do 
      81             :           {
      82             :             switch (*c++)
      83             :             {
      84             :               case '(': ++nd; break;
      85             :               case ')': --nd; break;
      86             :             }
      87             :           }
      88             :           while (nd > 0 && c != end());
      89             :         }
      90             :         // Add the appropriate action to the new action label string
      91             :         if (std::find(string_vector.begin(), string_vector.end(), a) == string_vector.end())
      92             :         {
      93             :           if (!ns.empty())
      94             :           {
      95             :             ns.append("|");
      96             :           }
      97             :           ns.append(b, c);
      98             :         }
      99             :         // Skip the multi-action operator, if any
     100             :         if (c != end() && *c == '|')
     101             :         {
     102             :           ++c;
     103             :         }
     104             :         // The start of the next action is pointed to by c.
     105             :         b = c;
     106             :       }
     107             :       if (ns.empty())
     108             :       {
     109             :         assign(tau_action());
     110             :       }
     111             :       else
     112             :       {
     113             :         assign(ns);
     114             :       }
     115             :     }
     116             : 
     117             :     /* \brief A comparison operator comparing the action_label_strings in the same way as strings.
     118             :     */
     119        7558 :     bool operator<(const action_label_string& l) const
     120             :     {
     121        7558 :       return std::string(*this)<std::string(l);
     122             :     }
     123             : 
     124             :     /* \brief The action label string that represents the internal action.
     125             :     */
     126       70538 :     static const action_label_string& tau_action()
     127             :     {
     128       70538 :       static action_label_string tau_action("tau");
     129       70538 :       return tau_action;
     130             :     }
     131             : };
     132             : 
     133             : /* \brief A pretty print operator on action labels, returning it as a string.
     134             : */
     135        1596 : inline std::string pp(const action_label_string& l)
     136             : {
     137        1596 :   return l;
     138             : }
     139             : 
     140             : } // namespace lts
     141             : } // namespace mcrl2
     142             : 
     143             : #endif
     144             : 
     145             : 

Generated by: LCOV version 1.12