spot  0.9.2
symbol.hh
Go to the documentation of this file.
1 // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6),
2 // département Systèmes Répartis Coopératifs (SRC), Université Pierre
3 // et Marie Curie.
4 //
5 // This file is part of Spot, a model checking library.
6 //
7 // Spot is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // Spot is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with Spot; see the file COPYING. If not, write to the Free
19 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 // 02111-1307, USA.
21 
22 #ifndef SPOT_EVTGBA_SYMBOL_HH
23 # define SPOT_EVTGBA_SYMBOL_HH
24 
25 #include <string>
26 #include <iosfwd>
27 #include <map>
28 #include <set>
29 
30 namespace spot
31 {
32  class symbol
33  {
34  public:
35  static const symbol* instance(const std::string& name);
36  const std::string& name() const;
37 
39  static unsigned instance_count();
41  static std::ostream& dump_instances(std::ostream& os);
42 
43  void ref() const;
44  void unref() const;
45 
46  protected:
47  int ref_count_() const;
48  symbol(const std::string* name);
49  ~symbol();
50  typedef std::map<const std::string, const symbol*> map;
51  static map instances_;
52  private:
53  symbol(const symbol&);
54  const std::string* name_;
55  mutable int refs_;
56  };
57 
58  class rsymbol
59  {
60  public:
61  rsymbol(const symbol* s): s_(s)
62  {
63  }
64 
65  rsymbol(const std::string& s): s_(symbol::instance(s))
66  {
67  }
68 
69  rsymbol(const char* s): s_(symbol::instance(s))
70  {
71  }
72 
73  rsymbol(const rsymbol& rs): s_(rs.s_)
74  {
75  s_->ref();
76  }
77 
79  {
80  s_->unref();
81  }
82 
83  operator const symbol*() const
84  {
85  return s_;
86  }
87 
88  const rsymbol&
89  operator=(const rsymbol& rs)
90  {
91  if (this != &rs)
92  {
93  this->~rsymbol();
94  new (this) rsymbol(rs);
95  }
96  return *this;
97  }
98 
99  bool
100  operator==(const rsymbol& rs) const
101  {
102  return s_ == rs.s_;
103  }
104 
105  bool
106  operator!=(const rsymbol& rs) const
107  {
108  return s_ != rs.s_;
109  }
110 
111  bool
112  operator<(const rsymbol& rs) const
113  {
114  return s_ < rs.s_;
115  }
116 
117  private:
118  const symbol* s_;
119  };
120 
121  typedef std::set<const symbol*> symbol_set;
122  typedef std::set<rsymbol> rsymbol_set;
123 
124 }
125 
126 #endif // SPOT_EVTGBA_SYMBOL_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Jul 2 2012 17:35:47 for spot by doxygen 1.8.1.1