home *** CD-ROM | disk | FTP | other *** search
- /*******************************<+>***************************
- ** DTA
- *************************************************************
- **
- ** $Id: Ref.h,v 1.6 1994/03/01 23:01:26 dta Exp $
- **
- ** $Source: /cvs/lib/odmg/Ref.h,v $
- **
- ** What @(#):
- **
- ** Author: Dale T. Anderson
- **
- *******************************<+>***************************/
-
- #ifndef Ref_h
- #define Ref_h
-
- #include <iostream.h>
- #include <assert.h>
-
- typedef short Position;
- typedef int boolean;
-
- #define FALSE 0
- #define TRUE !0
-
- template <class T>
- class Ref
- {
- T * m_ref;
-
- public:
-
- Ref (const T *ref = NULL);
- Ref (const Ref <T> &);
-
- Ref <T> & operator = (T *);
- Ref <T> & operator = (const Ref <T> &);
-
- T * operator -> (void);
- const T * operator -> (void) const;
-
- operator T * ();
- operator const T * ();
-
- boolean operator == (const Ref <T> &) const;
- boolean operator == (const T *) const;
- boolean operator != (const Ref <T> &) const;
- boolean operator != (const T *) const;
-
- T &operator * ();
- const T &operator * () const;
- T &operator [] (int);
-
- virtual ~Ref (void);
-
- boolean is_deleted (void) const;
- boolean is_active (void) const;
-
- void destroy (void);
-
- //
- // Additions
- //
-
- Ref (T &ref);
-
- void set_ref (T *ref);
- };
-
- //
- // Methods
- //
-
- template <class T>
- Ref <T>::Ref (const T *ref) :
- m_ref ((T *) ref)
- {
- }
-
- template <class T>
- Ref <T>::Ref (const Ref <T> &ref) :
- m_ref (ref.m_ref)
- {
- }
-
- template <class T>
- Ref <T> &Ref <T>::operator = (T * ref)
- {
- m_ref = ref;
- return *this;
- }
-
- template <class T>
- Ref <T> &Ref <T>::operator = (const Ref <T> &ref)
- {
- m_ref = ref.m_ref;
- return *this;
- }
-
- template <class T>
- T * Ref <T>::operator -> ()
- {
- return (T *) m_ref;
- }
-
- template <class T>
- const T * Ref <T>::operator -> () const
- {
- return m_ref;
- }
-
- template <class T>
- Ref <T>::operator T * ()
- {
- return m_ref;
- }
-
- template <class T>
- Ref <T>::operator const T * ()
- {
- return m_ref;
- }
-
- template <class T>
- T &Ref <T>::operator * ()
- {
- return *m_ref;
- }
-
- template <class T>
- const T &Ref <T>::operator * () const
- {
- return *m_ref;
- }
-
- template <class T>
- T &Ref <T>::operator[] (int index)
- {
- return (m_ref[index]);
- }
-
- template <class T>
- boolean Ref <T>::operator== (const Ref <T> &ref) const
- {
- return (m_ref == ref.m_ref);
- }
-
- template <class T>
- boolean Ref <T>::operator == (const T * ref) const
- {
- return (m_ref == ref);
- }
-
- template <class T>
- boolean Ref <T>::operator != (const Ref <T> &ref) const
- {
- return (m_ref != ref.m_ref);
- }
-
- template <class T>
- boolean Ref <T>::operator != (const T * ref) const
- {
- return (m_ref != ref);
- }
-
- template <class T>
- Ref <T>::~Ref()
- {
- }
-
- template <class T>
- boolean Ref <T>::is_deleted() const
- {
- return (m_ref == NULL);
- }
-
- template <class T>
- boolean Ref <T>::is_active() const
- {
- return (m_ref != NULL);
- }
-
- template <class T>
- void Ref <T>::destroy()
- {
- delete m_ref;
- m_ref = NULL;
- }
-
- //
- // Additions
- //
-
- template <class T>
- Ref <T>::Ref (T &ref)
- {
- m_ref = &ref;
- }
-
- template <class T>
- void Ref<T>::set_ref (T *ref)
- {
- m_ref = ref;
- }
-
- #endif
-