LCOV - code coverage report
Current view: top level - lts/include/mcrl2/lts - transition.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 20 20 100.0 %
Date: 2019-06-20 00:49:45 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Muck van Weerdenburg, 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 A header file defining a transition as a triple from,label,to.
      13             :  * \author Muck van Weerdenburg, Jan Friso Groote
      14             :  */
      15             : 
      16             : 
      17             : #ifndef MCRL2_LTS_TRANSITION_H
      18             : #define MCRL2_LTS_TRANSITION_H
      19             : 
      20             : #include <functional>
      21             : 
      22             : namespace mcrl2
      23             : {
      24             : namespace lts
      25             : {
      26             : 
      27             : /** \brief Transition sort styles.
      28             :  * \details This enumerated type defines sort styles for transitions.
      29             :  * They can be used to sort the transitions of an LTS based on various
      30             :  * criteria. */
      31             : enum transition_sort_style
      32             : {
      33             :   src_lbl_tgt, /**< Sort first on source state, then on label, then on target state */
      34             :   lbl_tgt_src /**< Sort first on label, then on target state, then on source state*/
      35             : };
      36             : 
      37             : /// \brief A class containing triples, source label and target representing transitions.
      38             : /// \details A transition consists of three indices, indicated by transition::size_type
      39             : ///          that refer to a source, label and target.
      40             : class transition
      41             : {
      42             :   public:
      43             :     /// \brief The type of the elements in a transition.
      44             :     typedef std::size_t size_type;
      45             : 
      46             :   private:
      47             :     size_type m_from;
      48             :     size_type m_label;
      49             :     size_type m_to;
      50             : 
      51             :   public:
      52             :     // There is no default constructor
      53             :     transition() = delete;
      54             : 
      55             :     /// \brief Constructor (there is no default constructor).
      56       18324 :     transition(const std::size_t f,
      57             :                const std::size_t l,
      58       18324 :                const std::size_t t):m_from(f),m_label(l),m_to(t)
      59       18324 :     {}
      60             : 
      61             :     /// \brief Copy constructor.
      62             :     transition(const transition& t) = default;
      63             :     /* {
      64             :       m_from = t.m_from;
      65             :       m_label = t.m_label;
      66             :       m_to = t.m_to;
      67             :     } */
      68             : 
      69             :     /// \brief The source of the transition.
      70             :     size_type
      71       92608 :     from() const
      72             :     {
      73       92608 :       return m_from;
      74             :     }
      75             : 
      76             :     /// \brief The label of the transition.
      77      100030 :     size_type label() const
      78             :     {
      79      100030 :       return m_label;
      80             :     }
      81             : 
      82             :     ///\brief The target of the transition.
      83             :     size_type
      84       95383 :     to() const
      85             :     {
      86       95383 :       return m_to;
      87             :     }
      88             : 
      89             :     /// \brief Set the source of the transition.
      90             :     void
      91             :     set_from(const size_type from)
      92             :     {
      93             :       m_from = from;
      94             :     }
      95             : 
      96             :     /// \brief Set the label of the transition.
      97             :     void
      98         604 :     set_label(const size_type label)
      99             :     {
     100         604 :       m_label = label;
     101         604 :     }
     102             : 
     103             :     ///\brief Set the target of the transition.
     104             :     void
     105             :     set_to(const size_type to)
     106             :     {
     107             :       m_to = to;
     108             :     }
     109             : 
     110             :     ///\brief Standard equality on transitions.
     111             :     bool
     112         475 :     operator ==(const transition& t) const
     113             :     {
     114         475 :       return m_from == t.m_from && m_label == t.m_label && m_to == t.m_to;
     115             :     }
     116             : 
     117             :     ///\brief Standard inequality on transitions.
     118             :     bool
     119             :     operator !=(const transition& t) const
     120             :     {
     121             :       return !(*this==t);
     122             :     }
     123             : 
     124             :     ///\brief Standard lexicographic ordering on transitions.
     125             :     ///\details The ordering is lexicographic from left to right.
     126             :     ///         First t.from are compared, then the label, and
     127             :     ///         if these do not determine the ordering, to is investigated.
     128             :     bool
     129       14388 :     operator <(const transition& t) const
     130             :     {
     131       25717 :       return m_from < t.m_from || (m_from == t.m_from && (m_label
     132       22710 :                                    < t.m_label || (m_label == t.m_label && m_to < t.m_to)));
     133             :     }
     134             : };
     135             : 
     136             : } // namespace lts
     137             : } // namespace mcrl2
     138             : 
     139             : namespace std
     140             : {
     141             : 
     142             : /// \brief specialization of the standard std::hash function.
     143             : template<>
     144         223 : struct hash<mcrl2::lts::transition>
     145             : {
     146        2345 :   std::size_t operator()(const mcrl2::lts::transition& t) const
     147             :   {
     148        2345 :     return t.from() << 2 ^ t.label() << 1 ^ t.to();
     149             :   }
     150             : };
     151             : 
     152             : } // namespace std
     153             : 
     154             : 
     155             : #include "mcrl2/lts/detail/transition.h"
     156             : 
     157             : #endif // MCRL2_LTS_TRANSITION_H

Generated by: LCOV version 1.12