atomic_prop.cc 2.57 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
// dpartement Systmes Rpartis Coopratifs (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
#include "atomic_prop.hh"
#include "visitor.hh"
24
#include <cassert>
25
#include <ostream>
26
27
28
29
30

namespace spot
{
  namespace ltl
  {
31

32
33
    atomic_prop::atomic_prop(const std::string& name, environment& env)
      : name_(name), env_(&env)
34
35
36
37
38
    {
    }

    atomic_prop::~atomic_prop()
    {
39
40
41
42
43
      // Get this instance out of the instance map.
      pair p(name(), &env());
      map::iterator i = instances.find(p);
      assert (i != instances.end());
      instances.erase(i);
44
45
    }

46
    void
47
48
49
50
    atomic_prop::accept(visitor& v)
    {
      v.visit(this);
    }
51

52
53
54
55
    void
    atomic_prop::accept(const_visitor& v) const
    {
      v.visit(this);
56
    }
57
58
59
60
61
62

    const std::string&
    atomic_prop::name() const
    {
      return name_;
    }
63
64

    environment&
65
66
67
68
69
    atomic_prop::env() const
    {
      return *env_;
    }

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    atomic_prop::map atomic_prop::instances;

    atomic_prop*
    atomic_prop::instance(const std::string& name, environment& env)
    {
      pair p(name, &env);
      map::iterator i = instances.find(p);
      if (i != instances.end())
	{
	  return static_cast<atomic_prop*>(i->second->ref());
	}
      atomic_prop* ap = new atomic_prop(name, env);
      instances[p] = ap;
      return static_cast<atomic_prop*>(ap->ref());
    }

86
87
88
89
90
91
    unsigned
    atomic_prop::instance_count()
    {
      return instances.size();
    }

92
93
94
95
96
97
98
99
100
101
102
103
104
    std::ostream&
    atomic_prop::dump_instances(std::ostream& os)
    {

      for (map::iterator i = instances.begin(); i != instances.end(); ++i)
	{
	  os << i->second << " = " << i->second->ref_count_()
	     << " * atomic_prop(" << i->first.first << ", "
	     << i->first.second->name() << ")" << std::endl;
	}
      return os;
    }

105
106
  }
}