twa.cc 3.08 KB
Newer Older
1
// -*- coding: utf-8 -*-
2
// Copyright (C) 2011, 2014, 2015 Laboratoire de Recherche et Developpement de
3
// l'EPITA (LRDE).
4
// Copyright (C) 2003, 2004, 2005  Laboratoire d'Informatique de Paris 6 (LIP6),
5
// département Systèmes Répartis Coopératifs (SRC), Université Pierre
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
6
7
8
9
10
11
// 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
12
// the Free Software Foundation; either version 3 of the License, or
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
13
14
15
16
17
18
19
20
// (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
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
22

23
24
#include "twa.hh"
#include "twagraph.hh"
25
26
#include "twaalgos/gtec/gtec.hh"
#include "twaalgos/remfin.hh"
27
#include <utility>
28
29
30

namespace spot
{
31
  twa::twa(const bdd_dict_ptr& d)
32
    : iter_cache_(nullptr),
33
      dict_(d),
34
      last_support_conditions_input_(0)
35
  {
36
    props = 0U;
37
  }
38

39
  twa::~twa()
40
  {
41
42
    if (last_support_conditions_input_)
      last_support_conditions_input_->destroy();
43
    delete iter_cache_;
44
    release_named_properties();
45
  }
46
47

  bdd
48
  twa::support_conditions(const state* state) const
49
  {
50
    if (!last_support_conditions_input_
51
52
	|| last_support_conditions_input_->compare(state) != 0)
      {
53
	last_support_conditions_output_ = compute_support_conditions(state);
54
55
	if (last_support_conditions_input_)
	  last_support_conditions_input_->destroy();
56
57
58
59
60
	last_support_conditions_input_ = state->clone();
      }
    return last_support_conditions_output_;
  }

61
  state*
62
  twa::project_state(const state* s,
63
		      const const_twa_ptr& t) const
64
  {
65
    if (t.get() == this)
66
67
68
69
      return s->clone();
    return 0;
  }

70
  std::string
71
  twa::transition_annotation(const twa_succ_iterator*) const
72
73
74
75
  {
    return "";
  }

76
  bool
77
  twa::is_empty() const
78
79
80
81
  {
    // FIXME: This should be improved based on properties of the
    // automaton.  For instance we do not need couvreur99 is we know
    // the automaton is weak.
82
83
84
    auto a = shared_from_this();
    if (a->acc().uses_fin_acceptance())
      {
85
	auto aa = std::dynamic_pointer_cast<const twa_graph>(a);
86
	if (!aa)
87
	  aa = make_twa_graph(a, prop_set::all());
88
89
90
	a = remove_fin(aa);
      }
    return !couvreur99(a)->check();
91
92
  }

93
  void
94
95
  twa::set_named_prop(std::string s,
		      void* val, std::function<void(void*)> destructor)
96
97
98
99
100
101
102
103
104
105
106
107
  {
    auto p = named_prop_.emplace(std::piecewise_construct,
				 std::forward_as_tuple(s),
				 std::forward_as_tuple(val, destructor));
    if (!p.second)
      {
	p.first->second.second(p.first->second.first);
	p.first->second = std::make_pair(val, destructor);
      }
  }

  void*
108
  twa::get_named_prop_(std::string s) const
109
110
111
112
113
114
115
116
117
118
  {
    auto i = named_prop_.find(s);
    if (i == named_prop_.end())
      return nullptr;
    return i->second.first;
  }




119
}