assumptions_value.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file assumptions_value.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Dec 10 00:37:49 GMT 2002
00008  *
00009  * <hr>
00010  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  */
00027 /*****************************************************************************/
00028 
00029 #ifndef _CVC_lite__assumptions_value_h_
00030 #define _CVC_lite__assumptions_value_h_
00031 
00032 #include "theorem.h"
00033 
00034 namespace CVCL {
00035 
00036   class AssumptionsValue;
00037 
00038   class AVHash {
00039     std::hash<size_t> h;
00040   public:
00041     AVHash() {
00042       IF_DEBUG(if(sizeof(void*) != sizeof(size_t)) {
00043         debugger.flag("WARNING: sizeof(void*) != sizeof(size_t)")++;
00044       });
00045     }
00046     size_t operator()(const AssumptionsValue* p) const { return h((size_t)p); }
00047   };
00048 
00049   class AssumptionsValue {
00050     friend class Assumptions;
00051   private:
00052     int d_refcount;
00053     // When this flag is set, the set of assumptions cannot be changed
00054     bool d_const;
00055     std::vector<Theorem> d_vector;
00056 
00057   private:
00058     //! Constructor
00059     AssumptionsValue(int refcount=0): d_refcount(refcount), d_const(false) { }
00060     //! Copy constructor: reset d_const flag and refcount
00061     AssumptionsValue(const AssumptionsValue& a)
00062       : d_refcount(0), d_const(false), d_vector(a.d_vector) { }
00063     /*!
00064      * Creates the set of assumptions from a vector of theorems.  Theorems that
00065      * do not have premises are not included, since they are valid without any
00066      * context and thus do not add any information in the assumption tracking.
00067      */
00068     AssumptionsValue(const std::vector<Theorem>& v);
00069     //! Constructor from two theorems (optimized for common case)
00070     AssumptionsValue(const Theorem& t1, const Theorem& t2);
00071   
00072     static void mergeVectors(const std::vector<Theorem>& v1,
00073                              const std::vector<Theorem>& v2,
00074                              std::vector<Theorem>& v);
00075 
00076     // Add a new assumption.  If label is not supplied, generate new one.
00077     void add(const Theorem& t);
00078     // Add a whole set of assumptions
00079     void add(const AssumptionsValue& a);
00080     // Return the assumption for the given formula.  It may be Null if
00081     // the assumption is not in the set.
00082     // find only searches through current set of assumptions, will not recurse
00083     const Theorem& find(const Expr& e) const;
00084 
00085   public:
00086     std::string toString() const;
00087 
00088     friend std::ostream& operator<<(std::ostream& os,
00089                                     const AssumptionsValue &assump);
00090       
00091     friend bool operator==(const AssumptionsValue& a1, const AssumptionsValue& a2);
00092     friend bool operator!=(const AssumptionsValue& a1, const AssumptionsValue& a2);
00093 
00094   }; // end of class AssumptionsValue
00095 
00096   // comparison operators
00097   inline bool operator==(const AssumptionsValue& a1, const AssumptionsValue& a2) {
00098     return (a1.d_vector == a2.d_vector);
00099   }
00100 
00101   inline bool operator!=(const AssumptionsValue& a1, const AssumptionsValue& a2) { 
00102     return !(a1.d_vector == a2.d_vector);
00103   }
00104 
00105 } // end of namespace CVCL
00106 
00107 #endif

Generated on Thu Apr 13 16:57:29 2006 for CVC Lite by  doxygen 1.4.4