CVC3

Object.h

Go to the documentation of this file.
00001 #ifndef OBJ_H_
00002 #define OBJ_H_
00003 
00004 #include "theory_core.h"
00005 #include "theorem_manager.h"
00006 #include "common_proof_rules.h"
00007 #include "command_line_flags.h"
00008 #include "theory_arith.h"
00009 #include <fstream>
00010 
00011 #define _CVC3_TRUSTED_
00012 
00013 using namespace std;
00014 using namespace CVC3;
00015 
00016 
00017 //#define DEBUG_MEM_STATS
00018 // flag for testing some cvc3 custom made prof rules
00019 //#define PRINT_MAJOR_METHODS
00020 //#define LRA2_PRIME
00021 //#define OPTIMIZE
00022 //#define IGNORE_NORMALIZE
00023 //#define IGNORE_LETPF_VARS
00024 //#define IGNORE_PRINT_MULTI_LAMBDA
00025 
00026 //smart pointer class
00027 template<class T>
00028 class RefPtr
00029 {
00030 public:
00031    typedef T element_type;
00032    RefPtr() :_ptr(0L) {}
00033    RefPtr(T* t):_ptr(t)              { if (_ptr) _ptr->Ref(); }
00034    RefPtr(const RefPtr& rp):_ptr(rp._ptr)  { if (_ptr) _ptr->Ref(); }
00035    ~RefPtr()                           { if (_ptr) _ptr->Unref(); _ptr=0; }
00036    inline RefPtr& operator = (const RefPtr& rp){
00037       if (_ptr==rp._ptr) return *this;
00038       T* tmp_ptr = _ptr;
00039       _ptr = rp._ptr;
00040       if (_ptr) _ptr->Ref();
00041       if (tmp_ptr) tmp_ptr->Unref();
00042       return *this;
00043    }
00044    inline RefPtr& operator = (T* ptr){
00045       if (_ptr==ptr) return *this;
00046       T* tmp_ptr = _ptr;
00047       _ptr = ptr;
00048       if (_ptr) _ptr->Ref();
00049       if (tmp_ptr) tmp_ptr->Unref();
00050       return *this;
00051    }
00052    inline T& operator*()  { return *_ptr; }
00053    inline const T& operator*() const { return *_ptr; }
00054    inline T* operator->() { return _ptr; }
00055    inline const T* operator->() const   { return _ptr; }
00056    inline T* get() { return _ptr; }
00057    inline const T* get() const { return _ptr; }
00058 private:
00059    T* _ptr;
00060 };
00061 
00062 //standard (reference pointer) object
00063 class Obj
00064 {
00065 protected:
00066   ostringstream oignore;
00067   int refCount;
00068 
00069   static bool errsInit;
00070   static ofstream errs;
00071   static bool indentFlag;
00072 
00073   void indent( std::ostream& s, int ind = 0 ){
00074     if( ind>0 )
00075       s << endl;
00076     if( indentFlag ){
00077       for( int a=0; a<ind; a++ )
00078         s << " ";
00079     }
00080   }
00081 public:
00082   Obj(): refCount( 1 ) {}
00083   virtual ~Obj() {}
00084   //! get ref count
00085   int GetRefCount() { return refCount; }
00086   //! reference
00087   void Ref(){ refCount++; }
00088   //! unreference
00089   void Unref(){
00090     refCount--;
00091     if( refCount==0 ){
00092       delete this;
00093     }
00094    }
00095   static void print_error( const char* c, std::ostream& s ){
00096     if( !errsInit ){
00097       errs.open( "errors.txt" );
00098       errsInit = true;
00099     }
00100     errs << c << std::endl;
00101     s << c;
00102     exit( 1 );
00103   }
00104   static void print_warning( const char* c ){
00105     if( !errsInit ){
00106       errs.open( "errors.txt" );
00107       errsInit = true;
00108     }
00109     errs << c << std::endl;
00110   }
00111   static void initialize(){
00112     errsInit = false;
00113   }
00114 };
00115 
00116 #endif