expr_op.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file expr_op.h
00004  * \brief Class Op representing the Expr's operator.
00005  * 
00006  * Author: Sergey Berezin
00007  * 
00008  * Created: Fri Feb  7 15:14:42 2003
00009  *
00010  * <hr>
00011  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00012  * Junior University and by New York University. 
00013  *
00014  * License to use, copy, modify, sell and/or distribute this software
00015  * and its documentation for any purpose is hereby granted without
00016  * royalty, subject to the terms and conditions defined in the \ref
00017  * LICENSE file provided with this distribution.  In particular:
00018  *
00019  * - The above copyright notice and this permission notice must appear
00020  * in all copies of the software and related documentation.
00021  *
00022  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00023  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00024  * 
00025  * <hr>
00026  * 
00027  */
00028 /*****************************************************************************/
00029 
00030 // expr.h Has to be included outside of #ifndef, since it sources us
00031 // recursively (read comments in expr_value.h).
00032 #ifndef _CVC_lite__expr_h_
00033 #include "expr.h"
00034 #endif
00035 
00036 #ifndef _CVC_lite__expr_op_h_
00037 #define _CVC_lite__expr_op_h_
00038 
00039 namespace CVCL {
00040 
00041   class ExprManager;
00042 
00043 ///////////////////////////////////////////////////////////////////////////////
00044 //                                                                           //
00045 // Class: Op                                                                 //
00046 // Author: Clark Barrett                                                     //
00047 // Created: Wed Nov 27 15:50:38 2002                                         //
00048 // Description: Encapsulates all possible Expr operators (including UFUNC)   //
00049 //              and allows switching on the kind.                            //
00050 //              Kinds should be registered with ExprManager.                 //
00051 // 
00052 // Technically, class Op is not part of Expr; it is provided as an
00053 // abstraction for the user.  So, building an Expr from an Op is less
00054 // efficient than building the same Expr directly from the kind.
00055 ///////////////////////////////////////////////////////////////////////////////
00056 class Op {
00057   friend class Expr;
00058   friend class ExprApply;
00059   friend class ::CInterface;
00060 
00061   int d_kind;
00062   Expr d_expr;
00063 
00064   // Disallow silent conversion of expr to op
00065   //! Constructor for operators
00066   Op(const Expr& e): d_kind(APPLY), d_expr(e) { }
00067 
00068 public:
00069 /////////////////////////////////////////////////////////////////////////
00070 // Public methods
00071 /////////////////////////////////////////////////////////////////////////
00072 
00073   Op() : d_kind(NULL_KIND) { }
00074   // Construct an operator from a kind.
00075   Op(int kind) : d_kind(kind), d_expr()
00076     { DebugAssert(kind != APPLY, "APPLY cannot be an operator on its own"); }
00077   // Copy constructor
00078   Op(const Op& op): d_kind(op.d_kind), d_expr(op.d_expr) { }
00079   // A constructor that rebuilds the Op for the given ExprManager
00080   Op(ExprManager* em, const Op& op);
00081   // Destructor (does nothing)
00082   ~Op() { }
00083   // Assignment operator
00084   Op& operator=(const Op& op);
00085 
00086   // Return the kind of the operator
00087   int getKind() const { return d_kind; }
00088   // Return the expr associated with this operator if applicable.
00089   const Expr& getExpr() const { return d_expr; }
00090 
00091   // Printing functions.
00092 
00093   std::string toString() const;
00094   friend std::ostream& operator<<(std::ostream& os, const Op& op) {
00095     return os << "Op(" << op.d_kind << " " << op.d_expr << ")";
00096   }
00097   friend bool operator==(const Op& op1, const Op& op2) {
00098     return op1.d_kind == op2.d_kind && op1.d_expr == op2.d_expr;
00099   }
00100 
00101 }; // end of class Op
00102 
00103 
00104 } // end of namespace CVCL
00105 
00106 #endif

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