spot
0.9.1
|
00001 // Copyright (C) 2004 Laboratoire d'Informatique de Paris 6 (LIP6), 00002 // département Systèmes Répartis Coopératifs (SRC), Université Pierre 00003 // et Marie Curie. 00004 // 00005 // This file is part of Spot, a model checking library. 00006 // 00007 // Spot is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // Spot is distributed in the hope that it will be useful, but WITHOUT 00013 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00014 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00015 // License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with Spot; see the file COPYING. If not, write to the Free 00019 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00020 // 02111-1307, USA. 00021 00022 #ifndef SPOT_EVTGBA_SYMBOL_HH 00023 # define SPOT_EVTGBA_SYMBOL_HH 00024 00025 #include <string> 00026 #include <iosfwd> 00027 #include <map> 00028 #include <set> 00029 00030 namespace spot 00031 { 00032 class symbol 00033 { 00034 public: 00035 static const symbol* instance(const std::string& name); 00036 const std::string& name() const; 00037 00039 static unsigned instance_count(); 00041 static std::ostream& dump_instances(std::ostream& os); 00042 00043 void ref() const; 00044 void unref() const; 00045 00046 protected: 00047 int ref_count_() const; 00048 symbol(const std::string* name); 00049 ~symbol(); 00050 typedef std::map<const std::string, const symbol*> map; 00051 static map instances_; 00052 private: 00053 symbol(const symbol&); 00054 const std::string* name_; 00055 mutable int refs_; 00056 }; 00057 00058 class rsymbol 00059 { 00060 public: 00061 rsymbol(const symbol* s): s_(s) 00062 { 00063 } 00064 00065 rsymbol(const std::string& s): s_(symbol::instance(s)) 00066 { 00067 } 00068 00069 rsymbol(const char* s): s_(symbol::instance(s)) 00070 { 00071 } 00072 00073 rsymbol(const rsymbol& rs): s_(rs.s_) 00074 { 00075 s_->ref(); 00076 } 00077 00078 ~rsymbol() 00079 { 00080 s_->unref(); 00081 } 00082 00083 operator const symbol*() const 00084 { 00085 return s_; 00086 } 00087 00088 const rsymbol& 00089 operator=(const rsymbol& rs) 00090 { 00091 if (this != &rs) 00092 { 00093 this->~rsymbol(); 00094 new (this) rsymbol(rs); 00095 } 00096 return *this; 00097 } 00098 00099 bool 00100 operator==(const rsymbol& rs) const 00101 { 00102 return s_ == rs.s_; 00103 } 00104 00105 bool 00106 operator!=(const rsymbol& rs) const 00107 { 00108 return s_ != rs.s_; 00109 } 00110 00111 bool 00112 operator<(const rsymbol& rs) const 00113 { 00114 return s_ < rs.s_; 00115 } 00116 00117 private: 00118 const symbol* s_; 00119 }; 00120 00121 typedef std::set<const symbol*> symbol_set; 00122 typedef std::set<rsymbol> rsymbol_set; 00123 00124 } 00125 00126 #endif // SPOT_EVTGBA_SYMBOL_HH