spot
0.8.3
|
00001 // Copyright (C) 2008, 2009 Laboratoire de Recherche et Développement 00002 // de l'Epita (LRDE). 00003 // Copyright (C) 2003, 2004, 2005 Laboratoire d'Informatique de 00004 // Paris 6 (LIP6), département Systèmes Répartis Coopératifs (SRC), 00005 // Université Pierre et Marie Curie. 00006 // 00007 // This file is part of Spot, a model checking library. 00008 // 00009 // Spot is free software; you can redistribute it and/or modify it 00010 // under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // Spot is distributed in the hope that it will be useful, but WITHOUT 00015 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00016 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00017 // License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with Spot; see the file COPYING. If not, write to the Free 00021 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00022 // 02111-1307, USA. 00023 00026 #ifndef SPOT_LTLAST_FORMULA_HH 00027 # define SPOT_LTLAST_FORMULA_HH 00028 00029 #include <string> 00030 #include <cassert> 00031 #include "predecl.hh" 00032 00033 namespace spot 00034 { 00035 namespace ltl 00036 { 00040 00043 00046 00050 00053 00056 00059 00062 00065 00066 00073 class formula 00074 { 00075 public: 00076 formula() : count_(++max_count) {} 00077 00079 virtual void accept(visitor& v) = 0; 00081 virtual void accept(const_visitor& v) const = 0; 00082 00087 formula* clone() const; 00092 void destroy() const; 00093 00095 virtual std::string dump() const = 0; 00096 00098 size_t 00099 hash() const 00100 { 00101 return count_; 00102 } 00103 protected: 00104 virtual ~formula(); 00105 00107 virtual void ref_(); 00110 virtual bool unref_(); 00111 00113 size_t count_; 00114 00115 private: 00117 static size_t max_count; 00118 }; 00119 00133 struct formula_ptr_less_than: 00134 public std::binary_function<const formula*, const formula*, bool> 00135 { 00136 bool 00137 operator()(const formula* left, const formula* right) const 00138 { 00139 assert(left); 00140 assert(right); 00141 if (left == right) 00142 return false; 00143 size_t l = left->hash(); 00144 size_t r = right->hash(); 00145 if (l != r) 00146 return l < r; 00147 // Because the hash code assigned to each formula is the 00148 // number of formulae constructed so far, it is very unlikely 00149 // that we will ever reach a case were two different formulae 00150 // have the same hash. This will happen only ever with have 00151 // produced 256**sizeof(size_t) formulae (i.e. max_count has 00152 // looped back to 0 and started over). In that case we can 00153 // order two formulae by looking at their text representation. 00154 // We could be more efficient and look at their AST, but it's 00155 // not worth the burden. (Also ordering pointers is ruled out 00156 // because it breaks the determinism of the implementation.) 00157 return left->dump() < right->dump(); 00158 } 00159 }; 00160 00175 struct formula_ptr_hash: 00176 public std::unary_function<const formula*, size_t> 00177 { 00178 size_t 00179 operator()(const formula* that) const 00180 { 00181 assert(that); 00182 return that->hash(); 00183 } 00184 }; 00185 00186 00187 } 00188 } 00189 00190 #endif // SPOT_LTLAST_FORMULA_HH