ta.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 _ta_hh_
00018 #define _ta_hh_
00019 
00087 //#include <algorithm>
00088 #include <ostream>
00089 #include <set>
00090 #include <string>
00091 #include <vector>
00092 
00093 #include <boost/optional/optional.hpp>
00094 #include <boost/shared_ptr.hpp>
00095 #include <boost/tuple/tuple.hpp>
00096 #include <boost/variant.hpp>
00097 
00098 #include <ceta/export.h>
00099 
00101 namespace ceta {
00103   class CETA_DSO_EXPORT kind_t {
00104   public:
00106     explicit kind_t(const std::string& name)
00107       : name_(new std::string(name)) {
00108     }
00109   private:
00110     friend const std::string& name(const kind_t& kind);
00112     boost::shared_ptr<std::string> name_;
00113   };
00118   inline
00119   const std::string& name(const kind_t& kind) {
00120     return *(kind.name_);
00121   }
00126   inline
00127   bool operator==(const kind_t& lhs, const kind_t& rhs) {
00128     return &name(lhs) == &name(rhs);
00129   }
00134   inline
00135   bool operator!=(const kind_t& lhs, const kind_t& rhs) {
00136     return !(lhs == rhs);
00137   }
00142   inline
00143   bool operator<(const kind_t& lhs, const kind_t& rhs) {
00144     return &name(lhs) < &name(rhs);
00145   }
00150   inline
00151   std::ostream& operator<<(std::ostream& o, const kind_t& kind) {
00152     return o << name(kind);
00153   }
00154 
00156   class CETA_DSO_EXPORT op_t {
00157   public:
00162     typedef std::vector<kind_t>::const_iterator input_iterator;
00172     template<typename InputIterator>
00173     op_t(const std::string& name, InputIterator inputs_begin,
00174          InputIterator inputs_end, const kind_t& output)
00175       : impl_(new impl_t(name,
00176                          std::vector<kind_t>(inputs_begin, inputs_end),
00177                          output)) {
00178     }
00179   private:
00180     friend const std::string& name(const op_t& op);
00181     friend const op_t::input_iterator inputs_begin(const op_t& op);
00182     friend const op_t::input_iterator inputs_end(const op_t& op);
00183     friend const kind_t& output(const op_t& op);
00184     friend bool operator==(const op_t& lhs, const op_t& rhs);
00185     friend bool operator<( const op_t& lhs, const op_t& rhs);
00187     typedef boost::tuple<std::string, std::vector<kind_t>, kind_t> impl_t;
00189     boost::shared_ptr<impl_t> impl_;
00190   };
00195   inline
00196   const std::string& name(const op_t& op) {
00197     return op.impl_->get<0>();
00198   }
00203   inline
00204   const op_t::input_iterator inputs_begin(const op_t& op) {
00205     return op.impl_->get<1>().begin();
00206   }
00212   inline
00213   const op_t::input_iterator inputs_end(const op_t& op) {
00214     return op.impl_->get<1>().end();
00215   }
00220   inline
00221   const kind_t& output(const op_t& op) {
00222     return op.impl_->get<2>();
00223   }
00228   inline
00229   bool operator==(const op_t& lhs, const op_t& rhs) {
00230     return lhs.impl_ == rhs.impl_;
00231   }
00236   inline
00237   bool operator<(const op_t& lhs, const op_t& rhs) {
00238     return lhs.impl_ < rhs.impl_;
00239   }
00244   inline
00245   bool operator!=(const op_t& lhs, const op_t& rhs) {
00246     return !(lhs == rhs);
00247   }
00252   inline
00253   const kind_t& input(const op_t& op, size_t i) {
00254     return inputs_begin(op)[i];
00255   }
00260   inline
00261   size_t input_count(const op_t& op) {
00262     return std::distance(inputs_begin(op), inputs_end(op));
00263   }
00268   inline
00269   bool is_constant(const op_t& op) {
00270     return inputs_begin(op) == inputs_end(op);
00271   }
00276   inline
00277   bool is_binary(const op_t& op) {
00278     return (input_count(op) == 2)
00279         && (input(op, 0) == output(op))
00280         && (input(op, 1) == output(op));
00281   }
00286   inline
00287   op_t make_constant(const std::string& name, const kind_t& output) {
00288     const kind_t* end = NULL;
00289     return op_t(name, end, end, output);
00290   }
00295   inline
00296   op_t make_unary_op(const std::string& name, const kind_t& input1,
00297                      const kind_t& output) {
00298     const kind_t inputs[] = { input1, };
00299     return op_t(name, inputs, inputs + 1, output);
00300   }
00305   inline
00306   op_t make_binary_op(const std::string& name,
00307                       const kind_t& input1, const kind_t& input2,
00308                       const kind_t& output) {
00309     const kind_t inputs[] = { input1, input2 };
00310     return op_t(name, inputs, inputs + 2, output);
00311   }
00316   inline
00317   std::ostream& operator<<(std::ostream& o, const op_t& op) {
00318     return o << name(op);
00319   }
00320 
00321   class term_t;
00322 
00327   void check_constant(const op_t& term) CETA_DSO_EXPORT;
00332   void check_equal(const kind_t& kind, const kind_t& kind) CETA_DSO_EXPORT;
00338   void check_well_formed(const op_t& op,
00339           const std::vector<term_t>& subterms) CETA_DSO_EXPORT;
00344   class CETA_DSO_EXPORT term_t {
00345   public:
00350     typedef std::vector<term_t>::const_iterator subterm_iterator;
00362     template<typename I>
00363     term_t(const op_t& op, I subterms_begin, I subterms_end)
00364       : impl_(new impl_t(op, std::vector<term_t>(subterms_begin,
00365                                                  subterms_end))) {
00370       //check_well_formed(op, impl_->get<1>(*impl_));
00371     }
00372   private:
00373     friend const op_t& root(const term_t& term);
00374     friend term_t::subterm_iterator subterms_begin(const term_t& term);
00375     friend term_t::subterm_iterator subterms_end(const term_t& term);
00377     typedef boost::tuple<op_t, std::vector<term_t> > impl_t;
00379     boost::shared_ptr<impl_t> impl_;
00380   };
00385   inline
00386   const op_t& root(const term_t& term) {
00387     return term.impl_->get<0>();
00388   }
00393   inline
00394   term_t::subterm_iterator subterms_begin(const term_t& term) {
00395     return term.impl_->get<1>().begin();
00396   }
00401   inline
00402   term_t::subterm_iterator subterms_end(const term_t& term) {
00403     return term.impl_->get<1>().end();
00404   }
00410   inline
00411   term_t make_constant(const op_t& op) {
00412     const term_t* end = NULL;
00413     return term_t(op, end, end);
00414   }
00419   inline
00420   size_t subterm_count(const term_t& term) {
00421     return subterms_end(term) - subterms_begin(term);
00422   }
00427   inline
00428   const term_t& subterm(const term_t& term, size_t i) {
00429     return subterms_begin(term)[i];
00430   }
00435   inline
00436   const kind_t& kind(const term_t& term) {
00437     return output(root(term));
00438   }
00443   inline
00444   bool is_constant(const term_t& term) {
00445     return subterms_begin(term) == subterms_end(term);
00446   }
00451   std::ostream&
00452         operator<<(std::ostream& o, const term_t& term) CETA_DSO_EXPORT;
00453 
00455   enum id_type_t {
00456     id_none,  
00457     id_left,  
00458     id_right, 
00459     id_both   
00460   };
00461 
00472   class axiom_set_t {
00473   public:
00475     axiom_set_t& operator|=(const axiom_set_t& rhs);
00476   private:
00477     friend bool is_assoc(const axiom_set_t& axiom);
00478     friend bool is_comm(const axiom_set_t& axiom);
00479     friend id_type_t id_type(const axiom_set_t& axiom);
00480     friend const boost::optional<op_t>& id_symbol(const axiom_set_t& axiom);
00481     friend const axiom_set_t& none();
00482     friend const axiom_set_t& assoc();
00483     friend const axiom_set_t& comm();
00484     friend const axiom_set_t left_id(const op_t& id);
00485     friend const axiom_set_t right_id(const op_t& id);
00486     friend const axiom_set_t id(const op_t& id);
00488     axiom_set_t(bool is_assoc, bool is_comm, id_type_t id_type = id_none,
00489                 const boost::optional<op_t>& id_symbol
00490                     = boost::optional<op_t>())
00491       : is_assoc_(is_assoc),
00492         is_comm_(is_comm),
00493         id_type_(id_type),
00494         id_symbol_(id_symbol) {
00495     }
00496     bool is_assoc_;
00497     bool is_comm_;
00498     id_type_t id_type_;
00499     boost::optional<op_t> id_symbol_;
00500   };
00505   inline
00506   bool is_assoc(const axiom_set_t& axiom) {
00507     return axiom.is_assoc_;
00508   }
00513   inline
00514   bool is_comm(const axiom_set_t& axiom) {
00515     return axiom.is_comm_;
00516   }
00521   inline
00522   id_type_t id_type(const axiom_set_t& axiom) {
00523     return axiom.id_type_;
00524   }
00529   inline
00530   const boost::optional<op_t>& id_symbol(const axiom_set_t& axiom) {
00531     return axiom.id_symbol_;
00532   }
00537   inline
00538   const axiom_set_t& none() {
00539     static axiom_set_t r(false, false);
00540     return r;
00541   }
00546   inline
00547   const axiom_set_t& assoc() {
00548     static axiom_set_t r(true, false);
00549     return r;
00550   }
00555   inline
00556   const axiom_set_t& comm() {
00557     static axiom_set_t r(false, true);
00558     return r;
00559   }
00564   inline
00565   const axiom_set_t left_id(const op_t& id) {
00566     check_constant(id);
00567     return axiom_set_t(false, false, id_left, id);
00568   }
00573   inline
00574   const axiom_set_t right_id(const op_t& id) {
00575     check_constant(id);
00576     return axiom_set_t(false, false, id_right, id);
00577   }
00582   inline
00583   const axiom_set_t id(const op_t& id) {
00584     check_constant(id);
00585     return axiom_set_t(false, false, id_both, id);
00586   }
00591   inline
00592   bool operator==(const axiom_set_t& x, const axiom_set_t& y) {
00593     return ( is_assoc(x) == is_assoc(y))
00594         && (  is_comm(x) == is_comm(y))
00595         && (  id_type(x) == id_type(y))
00596         && (id_symbol(x) == id_symbol(y));
00597   }
00602   inline
00603   bool operator!=(const axiom_set_t& x, const axiom_set_t& y) {
00604     return !(x == y);
00605   }
00610   inline
00611   const axiom_set_t operator|(const axiom_set_t& x, const axiom_set_t& y) {
00612     return axiom_set_t(x) |= y;
00613   }
00618   std::ostream&
00619   operator<<(std::ostream& o, const axiom_set_t& axioms) CETA_DSO_EXPORT;
00620 
00621   class theory_impl;
00622 
00647   class theory_t {
00648     friend class axiom_set_proxy_t;
00649   public:
00655     typedef std::set<kind_t>::const_iterator kind_iterator;
00661     typedef std::set<op_t>::const_iterator op_iterator;
00662 
00664     theory_t();
00665   private:
00666     friend const kind_iterator add_kind(theory_t& theory,
00667                                         const kind_t& kind);
00668     friend const op_iterator add_op(theory_t& theory, const op_t& op);
00669     friend void  set_axioms(theory_t& theory, const op_t& bin_op,
00670                             const axiom_set_t& axioms);
00671     friend const axiom_set_t& axioms(const theory_t& theory, const op_t& op);
00672     friend theory_t::kind_iterator kinds_begin(const theory_t& theory);
00673     friend theory_t::kind_iterator kinds_end(const theory_t& theory);
00674     friend bool member(const theory_t& theory, const kind_t& kind);
00675     friend bool member(const theory_t& theory, const op_t& op);
00676     friend theory_t::op_iterator ops_begin(const theory_t& theory);
00677     friend theory_t::op_iterator ops_end(const theory_t& theory);
00678     friend bool operator==(const theory_t& x, const theory_t& y);
00679     friend theory_t::op_iterator id_contexts_begin(
00680             const theory_t& theory, const op_t& id_symbol);
00681     friend theory_t::op_iterator id_contexts_end(
00682             const theory_t& theory, const op_t& id_symbol);
00683     friend bool is_identity(const theory_t& theory, const op_t& id_symbol);
00685     boost::shared_ptr<theory_impl> impl_;
00686   };
00691   const axiom_set_t&
00692     axioms(const theory_t& theory, const op_t& op) CETA_DSO_EXPORT;
00697   theory_t::kind_iterator kinds_begin(const theory_t& theory) CETA_DSO_EXPORT;
00702   theory_t::kind_iterator kinds_end(const theory_t& theory) CETA_DSO_EXPORT;
00707   bool member(const theory_t& theory, const kind_t& kind) CETA_DSO_EXPORT;
00712   bool member(const theory_t& theory, const op_t& op) CETA_DSO_EXPORT;
00717   theory_t::op_iterator ops_begin(const theory_t& theory) CETA_DSO_EXPORT;
00722   theory_t::op_iterator ops_end(const theory_t& theory) CETA_DSO_EXPORT;
00728   theory_t::op_iterator id_contexts_begin(
00729           const theory_t& theory, const op_t& id_symbol) CETA_DSO_EXPORT;
00735   theory_t::op_iterator id_contexts_end(
00736           const theory_t& theory, const op_t& id_symbol) CETA_DSO_EXPORT;
00737 
00742   const theory_t::kind_iterator add_kind(theory_t& theory,
00743                                          const kind_t& kind);
00748   const theory_t::op_iterator add_op(theory_t& theory, const op_t& op);
00753   void set_axioms(theory_t& theory, const op_t& bin_op,
00754                   const axiom_set_t& axioms) CETA_DSO_EXPORT;
00755 
00760   bool operator==(const theory_t& x, const theory_t& y) CETA_DSO_EXPORT;
00765   inline
00766   bool operator!=(const theory_t& lhs, const theory_t& rhs) {
00767     return !(lhs == rhs);
00768   }
00773   std::ostream&
00774   operator<<(std::ostream& o, const theory_t& theory) CETA_DSO_EXPORT;
00775 
00777   class CETA_DSO_EXPORT state_t {
00778   public:
00780     state_t(const kind_t& kind, const std::string& name)
00781       : impl_(new impl_t(kind, name)) {
00782     }
00783   private:
00784     friend const kind_t& kind(const state_t& state);
00785     friend const std::string& name(const state_t& state);
00786     friend bool operator==(const state_t& lhs, const state_t& rhs);
00787     friend bool operator<(const state_t& lhs, const state_t& rhs);
00789     typedef boost::tuple<kind_t, std::string> impl_t;
00791     boost::shared_ptr<impl_t> impl_;
00792   };
00797   inline
00798   const kind_t& kind(const state_t& state) {
00799     return state.impl_->get<0>();
00800   }
00805   inline
00806   const std::string& name(const state_t& state) {
00807     return state.impl_->get<1>();
00808   }
00813   inline
00814   bool operator==(const state_t& lhs, const state_t& rhs) {
00815     return lhs.impl_ == rhs.impl_;
00816   }
00821   inline
00822   bool operator<(const state_t& lhs, const state_t& rhs) {
00823     return lhs.impl_ < rhs.impl_;
00824   }
00829   inline
00830   bool operator!=(const state_t& lhs, const state_t& rhs) {
00831     return !(lhs == rhs);
00832   }
00837   inline
00838   std::ostream& operator<<(std::ostream& o, const state_t& state) {
00839     return o << name(state);
00840   }
00845   inline
00846   std::ostream& operator<<(std::ostream& o, const std::set<state_t>& s) {
00847     o << "{";
00848     typedef std::set<state_t>::const_iterator set_iter;
00849     set_iter i = s.begin();
00850     set_iter end = s.end();
00851     if (i != end) {
00852       o << *(i++);
00853       while (i != end)
00854         o << ", " << *(i++);
00855     }
00856     return o << "}";
00857   }
00858 
00862   void check_kinds(const kind_t& kind,
00863                    const std::set<state_t>& states) CETA_DSO_EXPORT;
00864 
00866   struct not_predicate_t;
00868   struct and_predicate_t;
00870   struct or_predicate_t;
00872   class CETA_DSO_EXPORT state_predicate_t {
00873   public:
00874     state_predicate_t(const kind_t& kind, bool value);
00875     state_predicate_t(const state_t& state);
00876   private:
00878     state_predicate_t(const not_predicate_t& p);
00880     state_predicate_t(const and_predicate_t& p);
00882     state_predicate_t(const or_predicate_t& p);
00883     typedef boost::variant<bool, state_t, not_predicate_t, and_predicate_t,
00884             or_predicate_t> variant_t;
00885     typedef boost::tuple<kind_t, variant_t> impl_t;
00886 
00887     friend
00888     const state_predicate_t operator!(const state_predicate_t& arg);
00889     friend
00890     const state_predicate_t operator&(const state_predicate_t& lhs,
00891                                       const state_predicate_t& rhs);
00892     friend
00893     const state_predicate_t operator|(const state_predicate_t& lhs,
00894                                       const state_predicate_t& rhs);
00895 
00896     friend const kind_t& kind(const state_predicate_t& pred);
00897     template<typename Visitor>
00898 
00899     friend
00900     typename Visitor::result_type
00901       apply_visitor(const Visitor& visitor, const state_predicate_t& pred);
00902 
00903     friend
00904     bool operator==(const state_predicate_t& lhs,
00905                     const state_predicate_t& rhs);
00906 
00908     boost::shared_ptr<impl_t> impl_;
00909   };
00911   struct not_predicate_t {
00913     not_predicate_t(const state_predicate_t& new_arg)
00914       : arg(new_arg) {
00915     }
00917     state_predicate_t arg;
00918   };
00920   struct and_predicate_t {
00922     and_predicate_t(const state_predicate_t& new_lhs,
00923                     const state_predicate_t& new_rhs)
00924       : lhs(new_lhs), rhs(new_rhs) {
00925       check_equal(kind(lhs), kind(rhs));
00926     }
00928     state_predicate_t lhs;
00930     state_predicate_t rhs;
00931   };
00933   struct or_predicate_t {
00935     or_predicate_t(const state_predicate_t& new_lhs,
00936                    const state_predicate_t& new_rhs)
00937       : lhs(new_lhs), rhs(new_rhs) {
00938       check_equal(kind(lhs), kind(rhs));
00939     }
00941     state_predicate_t lhs;
00943     state_predicate_t rhs;
00944   };
00946   inline
00947   state_predicate_t::state_predicate_t(const kind_t& kind, bool value)
00948     : impl_(new impl_t(kind, value)) {
00949   }
00951   inline
00952   state_predicate_t::state_predicate_t(const state_t& state)
00953     : impl_(new impl_t(kind(state), state)) {
00954   }
00956   inline
00957   state_predicate_t::state_predicate_t(const not_predicate_t& p)
00958     : impl_(new impl_t(kind(p.arg), p)) {
00959   }
00961   inline
00962   state_predicate_t::state_predicate_t(const and_predicate_t& p)
00963     : impl_(new impl_t(kind(p.lhs), p)) {
00964   }
00966   inline
00967   state_predicate_t::state_predicate_t(const or_predicate_t& p)
00968     : impl_(new impl_t(kind(p.lhs), p)) {
00969   }
00974   inline
00975   const kind_t& kind(const state_predicate_t& pred) {
00976     return pred.impl_->get<0>();
00977   }
00985   template<typename Visitor>
00986   typename Visitor::result_type
00987     apply_visitor(const Visitor& visitor, const state_predicate_t& pred) {
00988     return boost::apply_visitor(visitor, pred.impl_->get<1>());
00989   }
00994   inline
00995   const state_predicate_t operator!(const state_predicate_t& arg) {
00996     return state_predicate_t(not_predicate_t(arg));
00997   }
01002   inline
01003   const state_predicate_t operator&(const state_predicate_t& lhs,
01004                                     const state_predicate_t& rhs) {
01005     return state_predicate_t(and_predicate_t(lhs, rhs));
01006   }
01011   inline
01012   const state_predicate_t operator|(const state_predicate_t& lhs,
01013                                     const state_predicate_t& rhs) {
01014     return state_predicate_t(or_predicate_t(lhs, rhs));
01015   }
01020   inline
01021   state_predicate_t& operator&=(state_predicate_t& lhs,
01022                           const state_predicate_t& rhs) {
01023     return lhs = lhs & rhs;
01024   }
01029   inline
01030   state_predicate_t& operator|=(state_predicate_t& lhs,
01031                           const state_predicate_t& rhs) {
01032     return lhs = lhs | rhs;
01033   }
01038   inline
01039   bool operator==(const state_predicate_t& lhs,
01040                   const state_predicate_t& rhs) {
01041     return lhs.impl_ == rhs.impl_;
01042   }
01047   inline
01048   bool operator!=(const state_predicate_t& lhs,
01049                   const state_predicate_t& rhs) {
01050     return !(lhs == rhs);
01051   }
01056   bool models(const state_predicate_t& pred,
01057               const std::set<state_t>& model) CETA_DSO_EXPORT;
01062   std::ostream&
01063   operator<<(std::ostream& o, const state_predicate_t& p) CETA_DSO_EXPORT;
01064 
01066   class CETA_DSO_EXPORT erule_t {
01067   public:
01069     erule_t(const state_t& lhs, const state_t& rhs)
01070       : lhs_(lhs),
01071         rhs_(rhs) {
01072       check_equal(kind(lhs), kind(rhs));
01073     }
01074   private:
01075     friend const state_t& lhs(const erule_t& erule);
01076     friend const state_t& rhs(const erule_t& erule);
01078     state_t lhs_;
01080     state_t rhs_;
01081   };
01086   inline
01087   const state_t& lhs(const erule_t& erule) {
01088     return erule.lhs_;
01089   }
01094   inline
01095   const state_t& rhs(const erule_t& erule) {
01096     return erule.rhs_;
01097   }
01102   inline
01103   bool operator==(const erule_t& x, const erule_t& y) {
01104     return (lhs(x) == lhs(y)) && (rhs(x) == rhs(y));
01105   }
01110   inline
01111   bool operator!=(const erule_t& lhs, const erule_t& rhs) {
01112     return !(lhs == rhs);
01113   }
01118   inline
01119   bool operator<(const erule_t& x, const erule_t& y) {
01120     return (lhs(x) <  lhs(y))
01121         || (lhs(x) == lhs(y)) && (rhs(x) < rhs(y));
01122   }
01123 
01124   void check_well_formed(const op_t& op,
01125                          const std::vector<state_t>& lhs_states,
01126                          const state_t& rhs) CETA_DSO_EXPORT;
01127 
01137   class CETA_DSO_EXPORT rule_t {
01138   public:
01143     typedef std::vector<state_t>::const_iterator lhs_state_iterator;
01153     template <typename InputIterator>
01154     rule_t(const op_t& op, InputIterator lhs_states_begin,
01155            InputIterator lhs_states_end, const state_t& rhs)
01156       : op_(op),
01157         lhs_states_(lhs_states_begin, lhs_states_end),
01158         rhs_(rhs) {
01159       //check_well_formed(op, lhs_states_, rhs);
01160     }
01161   private:
01162     friend const op_t& op(const rule_t& rule);
01163     friend const lhs_state_iterator lhs_states_begin(const rule_t& rule);
01164     friend const lhs_state_iterator lhs_states_end(const rule_t& rule);
01165     friend const state_t& rhs(const rule_t& rule);
01166     friend bool operator==(const rule_t& lhs, const rule_t& rhs);
01167     friend bool operator<(const rule_t& lhs, const rule_t& rhs);
01169     op_t op_;
01171     std::vector<state_t> lhs_states_;
01173     state_t rhs_;
01174   };
01179   inline
01180   const op_t& op(const rule_t& rule)  {
01181     return rule.op_;
01182   }
01188   inline
01189   const rule_t::lhs_state_iterator lhs_states_begin(const rule_t& rule) {
01190     return rule.lhs_states_.begin();
01191   }
01197   inline
01198   const rule_t::lhs_state_iterator lhs_states_end(const rule_t& rule) {
01199     return rule.lhs_states_.end();
01200   }
01205   inline
01206   const state_t& rhs(const rule_t& rule) {
01207     return rule.rhs_;
01208   }
01213   inline
01214   bool operator==(const rule_t& x, const rule_t& y) {
01215     return (op(x) == op(x))
01216         && (x.lhs_states_ == y.lhs_states_)
01217         && (rhs(x) == rhs(y));
01218   }
01223   inline
01224   bool operator!=(const rule_t& lhs, const rule_t& rhs) {
01225     return !(lhs == rhs);
01226   }
01231   inline
01232   bool operator<(const rule_t& x, const rule_t& y) {
01233     return (op(x)  < op(y))
01234         || (op(x) == op(y)) && (rhs(x)  < rhs(y))
01235         || (op(x) == op(y)) && (rhs(x) == rhs(y))
01236                             && (x.lhs_states_ < y.lhs_states_);
01237   }
01244   inline
01245   const state_t& lhs_state(const rule_t& rule, size_t i) {
01246     return lhs_states_begin(rule)[i];
01247   }
01252   inline
01253   size_t lhs_state_count(const rule_t& rule) {
01254     return std::distance(lhs_states_begin(rule), lhs_states_end(rule));
01255   }
01260   inline
01261   rule_t make_constant_rule(const op_t& lhs_op, const state_t& rhs) {
01262     const state_t* lhs_states = NULL;
01263     return rule_t(lhs_op, lhs_states, lhs_states, rhs);
01264   }
01269   inline
01270   rule_t make_unary_rule(const op_t& lhs_op, const state_t& lhs,
01271                          const state_t& rhs) {
01272     return rule_t(lhs_op, &lhs, &lhs + 1, rhs);
01273   }
01278   inline
01279   rule_t make_binary_rule(const op_t& lhs_op, const state_t& lhs1,
01280                           const state_t& lhs2, const state_t& rhs) {
01281     const state_t lhs_states[] = { lhs1, lhs2 };
01282     return rule_t(lhs_op, lhs_states, lhs_states + 2, rhs);
01283   }
01284 
01285   class ta_impl;
01286 
01310   class CETA_DSO_EXPORT ta_t {
01311   public:
01317     typedef std::set<state_t>::const_iterator state_iterator;
01323     typedef std::vector<erule_t>::const_iterator erule_iterator;
01329     typedef std::vector<rule_t>::const_iterator rule_iterator;
01334     ta_t(const theory_t& theory);
01335   private:
01336     friend const theory_t& theory(const ta_t& ta);
01337     friend bool member(const ta_t& theory, const state_t& state);
01338     friend const state_iterator states_begin(const ta_t& ta);
01339     friend const state_iterator states_end(const ta_t& ta);
01340     friend const state_iterator add_state(ta_t& ta, const state_t& state);
01341     friend const state_predicate_t&
01342             predicate(const ta_t& ta, const kind_t& kind);
01343     friend void set_predicate(ta_t& ta, const state_predicate_t& pred);
01344     friend const erule_iterator erules_begin(const ta_t& ta);
01345     friend const erule_iterator erules_end(const ta_t& ta);
01346     friend void add_erule(ta_t& ta, const erule_t& erule);
01347     friend const rule_iterator rules_begin(const ta_t& ta);
01348     friend const rule_iterator rules_end(const ta_t& ta);
01349     friend void add_rule(ta_t& ta, const rule_t& rule);
01351     boost::shared_ptr<ta_impl> impl_;
01352   };
01357   const theory_t& theory(const ta_t& ta) CETA_DSO_EXPORT;
01362   bool member(const ta_t& ta, const state_t& state) CETA_DSO_EXPORT;
01367   const ta_t::state_iterator states_begin(const ta_t& ta) CETA_DSO_EXPORT;
01372   const ta_t::state_iterator states_end(const ta_t& ta) CETA_DSO_EXPORT;
01377   const ta_t::state_iterator
01378     add_state(ta_t& ta, const state_t& state) CETA_DSO_EXPORT;
01383   const state_predicate_t&
01384     predicate(const ta_t& ta, const kind_t& kind) CETA_DSO_EXPORT;
01389   void set_predicate(ta_t& ta,
01390                      const state_predicate_t& pred) CETA_DSO_EXPORT;
01395   const ta_t::erule_iterator erules_begin(const ta_t& ta) CETA_DSO_EXPORT;
01401   const ta_t::erule_iterator erules_end(const ta_t& ta) CETA_DSO_EXPORT;
01406   void add_erule(ta_t& ta, const erule_t& erule) CETA_DSO_EXPORT;
01411   const ta_t::rule_iterator rules_begin(const ta_t& ta) CETA_DSO_EXPORT;
01416   const ta_t::rule_iterator rules_end(const ta_t& ta) CETA_DSO_EXPORT;
01421   void add_rule(ta_t& ta, const rule_t& rule) CETA_DSO_EXPORT;
01426   std::ostream& operator<<(std::ostream& o, const ta_t& ta) CETA_DSO_EXPORT;
01431   const ta_t operator!(const ta_t& ta) CETA_DSO_EXPORT;
01437   ta_t& operator&=(ta_t& lhs, const ta_t& rhs) CETA_DSO_EXPORT;
01443   ta_t& operator|=(ta_t& lhs, const ta_t& rhs) CETA_DSO_EXPORT;
01449   inline
01450   const ta_t operator&(const ta_t& lhs, const ta_t& rhs) {
01451     ta_t result = lhs;
01452     result &= rhs;
01453     return result;
01454   }
01460   inline
01461   const ta_t operator|(const ta_t& lhs, const ta_t& rhs) {
01462     ta_t result = lhs;
01463     result |= rhs;
01464     return result;
01465   }
01466 }
01467 #endif

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