subset_construction.hh

Go to the documentation of this file.
00001 /* Copyright 2006 University of Illinois at Urbana-Champaign
00002  *
00003  * Ceta is free software; you can redistribute it and/or modify
00004  * it under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00016  */
00017 #ifndef _subset_construction_hh_
00018 #define _subset_construction_hh_
00019 
00024 #include <ceta/export.h>
00025 #include <ceta/ta.hh>
00026 
00028 namespace ceta {
00030   class CETA_DSO_EXPORT test_result_t {
00031   public:
00033     test_result_t() {
00034     }
00039     test_result_t(const term_t& term, const std::set<state_t>& set)
00040       : impl_(make_pair(term, set)) {
00041       check_kinds(kind(term), set);
00042     }
00047     operator bool() {
00048       return !impl_;
00049     }
00050   private:
00051     typedef std::set<state_t> set_t;
00052     friend const term_t& counterexample(const test_result_t& result);
00053     friend
00054     const std::set<state_t>& reachable_set(const test_result_t& result);
00056     boost::optional< std::pair<term_t, set_t> > impl_;
00057   };
00058 
00063   inline
00064   const term_t& counterexample(const test_result_t& result) {
00065     return result.impl_->first;
00066   }
00071   inline
00072   const std::set<state_t>& reachable_set(const test_result_t& result) {
00073     return result.impl_->second;
00074   }
00075 
00076   class subset_constructor_impl;
00077 
00079   class CETA_DSO_EXPORT subset_constructor_t {
00080   public:
00081     subset_constructor_t(const ta_t& ta);
00083     void work(void);
00085     bool is_complete(void) const;
00087     bool has_next(void) const;
00089     const std::set<state_t>& next_set(void) const;
00091     const term_t& next_term(void) const;
00093     void pop_next(void);
00094   private:
00096     subset_constructor_t(const subset_constructor_t&);
00098     subset_constructor_t& operator=(const subset_constructor_t&);
00100     boost::shared_ptr<subset_constructor_impl> impl_;
00101   };
00102 
00107   inline
00108   const test_result_t test_emptiness(const ta_t& ta) {
00109     subset_constructor_t sc(ta);
00110     while (sc.has_next() || !sc.is_complete()) {
00111       if (!sc.has_next())
00112         sc.work();
00113       while (sc.has_next()) {
00114         const std::set<state_t>& set = sc.next_set();
00115         const term_t& term = sc.next_term();
00116         if (models(predicate(ta, kind(term)), set))
00117           return test_result_t(term, set);
00118         sc.pop_next();
00119       }
00120     }
00121     test_result_t accept_result;
00122     return accept_result;
00123   }
00124 }
00125 #endif

Generated on Fri Mar 3 14:38:58 2006 for libceta by  doxygen 1.4.6