multop.hh 3.91 KB
Newer Older
1
// Copyright (C) 2003, 2004  Laboratoire d'Informatique de Paris 6 (LIP6),
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
// et Marie Curie.
//
// This file is part of Spot, a model checking library.
//
// Spot is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Spot is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
// License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Spot; see the file COPYING.  If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.

22
23
/// \file ltlast/multop.hh
/// \brief LTL multi-operand operators
24
25
26
27
#ifndef SPOT_LTLAST_MULTOP_HH
# define SPOT_LTLAST_MULTOP_HH

#include <vector>
28
#include <map>
29
#include "refformula.hh"
30
31
32
33
34

namespace spot
{
  namespace ltl
  {
35

36
37
38
    /// \brief Multi-operand operators.
    ///
    /// These operators are considered commutative and associative.
39
    class multop : public ref_formula
40
41
42
43
    {
    public:
      enum type { Or, And };

44
45
      /// List of formulae.
      typedef std::vector<formula*> vec;
46

47
      /// \brief Build a spot::ltl::multop with two children.
48
      ///
49
50
51
      /// If one of the children itself is a spot::ltl::multop
      /// with the same type, it will be merged.  I.e., children
      /// if that child will be added, and that child itself will
52
53
54
55
56
57
58
59
      /// be destroyed.  This allows incremental building of
      /// n-ary ltl::multop.
      ///
      /// This functions can perform slight optimizations and
      /// may not return an ltl::multop objects.  For instance
      /// if \c first and \c second are equal, that formula is
      /// returned as-is.
      static formula* instance(type op, formula* first, formula* second);
60

61
      /// \brief Build a spot::ltl::multop with many children.
62
      ///
63
64
65
66
67
      /// Same as the other instance() function, but take a vector of
      /// formula in argument.  This vector is acquired by the
      /// spot::ltl::multop class, the caller should allocate it with
      /// \c new, but not use it (especially not destroy it) after it
      /// has been passed to spot::ltl::multop.
68
      ///
69
70
71
72
73
      /// This functions can perform slight optimizations and
      /// may not return an ltl::multop objects.  For instance
      /// if the vector contain only one unique element, this
      /// this formula will be returned as-is.
      static formula* instance(type op, vec* v);
74
75
76
77

      virtual void accept(visitor& v);
      virtual void accept(const_visitor& v) const;

78
      /// Get the number of children.
79
      unsigned size() const;
80
81
82
      /// \brief Get the nth children.
      ///
      /// Starting with \a n = 0.
83
      const formula* nth(unsigned n) const;
84
85
86
      /// \brief Get the nth children.
      ///
      /// Starting with \a n = 0.
87
      formula* nth(unsigned n);
88

89
      /// Get the type of this operator.
90
      type op() const;
91
      /// Get the type of this operator, as a string.
92
93
      const char* op_name() const;

94
95
96
      /// Number of instantiated multi-operand operators.  For debugging.
      static unsigned instance_count();

97
98
    protected:
      typedef std::pair<type, vec*> pair;
99
      /// Comparison functor used internally by ltl::multop.
100
101
102
103
104
105
106
107
108
109
110
      struct paircmp
      {
	bool
	operator () (const pair& p1, const pair& p2) const
	{
	  if (p1.first != p2.first)
	    return p1.first < p2.first;
	  return *p1.second < *p2.second;
	}
      };
      typedef std::map<pair, formula*, paircmp> map;
111
112
113
114
115
      static map instances;

      multop(type op, vec* v);
      virtual ~multop();

116
117
    private:
      type op_;
118
      vec* children_;
119
120
121
122
123
124
    };

  }
}

#endif // SPOT_LTLAST_MULTOP_HH