/* * * Copyright (c) 1995 * Knowledge Science Institute, University of Calgary * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. The Knowledge Science Institute makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #ifndef MREF2_H #define MREF2_H #ifndef MERROR_H #include #endif #ifndef MDEBUG_H #include #endif #define NOTHING template class Ref2 { public: DECL_EXCEPT_CLASS(NOTHING,DefConstructorCalled,ErrorMsgException,"Illegal operation: Default Constructor Called"); Ref2(const T &s) {KillData = true; t = s.clone();} Ref2(T *s, bool ownIt=false) {MASSERT(s); KillData = ownIt; t = s;} Ref2(const Ref2 &r) //{KillData = true; // t = (r.t?r.t->clone():NULL);} {KillData = r.KillData; t = (r.t?(KillData?r.t->clone():r.t):NULL);} Ref2() {throw DefConstructorCalled();} ~Ref2() {if (t && KillData) delete t;} Ref2& operator=(const Ref2& r) { if (t && KillData) delete t; KillData = true; t = (r.t?r.t->clone():NULL); return *this; } T* operator->() const {return t;} int operator< (const Ref2& r) const {return t?(r.t?(*t) < (*r.t):false):true;} operator T&() const {return *t;} operator T*() const {return t;} T& operator*() const {return *t;} ostream& printOn(ostream& o) const {o << *t; return o;} protected: T *t; private: bool KillData; }; #endif