/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2004 by Christian Gagne and Marc Parizeau
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1V 4J7
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/PointerT.hpp
 *  \brief  Definition of class template PointerT.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.2 $
 *  $Date: 2004/01/15 21:08:57 $
 */

#ifndef Beagle_PointerT_hpp
#define Beagle_PointerT_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/Pointer.hpp"


namespace Beagle {

/*!
 *  \class PointerT beagle/PointerT.hpp "beagle/PointerT.hpp"
 *  \brief Templated class defining a T-type smart pointer.
 *  \param T Type pointed.
 *  \param BaseType Pointer type from which the actual type is derived.
 *  \ingroup OOF
 *  \ingroup ObjPt
 */
template <class T, class BaseType>
class PointerT : public BaseType {

public:

  /*!
   *  \brief Construct a NULL pointing smart pointer.
   */
  inline PointerT() { }

  /*!
   *  \brief Construct a smart pointer that refer to the T-type object pointed given.
   *  \param inObjPtr Pointer to the T-type object to be referenced.
   */
  inline PointerT(const T* inObjPtr) :
    BaseType(inObjPtr)
  { }

  /*!
   *  \brief Copy construct a smart pointer.
   *  \param inPointerT  Smart pointer to copy.
   */
  inline PointerT(const PointerT<T,BaseType>& inPointerT) :
    BaseType(inPointerT)
  { }

  /*!
   *  \brief Destructor.
   */
  inline ~PointerT() { }

  /*!
   *  \brief Affect the actual pointer to an object pointer.
   *  \param inObjPtr Pointer to the object to refer.
   *  \return Actual smart pointer.
   */
  inline PointerT<T,BaseType>& operator=(const T* inObjPtr)
  {
    BaseType::operator=(inObjPtr);
    return *this;
  }

  /*!
   *  \brief Affect the actual pointer to another smart pointer.
   *  \param inPointerT Smart pointer to copy.
   *  \return Actual smart pointer.
   */
  inline PointerT<T,BaseType>& operator=(const PointerT<T,BaseType>& inPointerT)
  {
    BaseType::operator=(inPointerT);
    return *this;
  }

  /*!
   *  \brief Get reference the T-type object pointed.
   *  \return Reference to the T-type object pointed.
   *  \throw Beagle::AssertException If the pointer to the T-type object is NULL.
   */
  inline T& operator*()
  {
    return static_cast<T&>(Beagle::Pointer::operator*());
  }

  /*!
   *  \brief Get constant reference the T-type object pointed.
   *  \return Constant reference to the T-type object pointed.
   *  \throw Beagle::AssertException If the pointer to the T-type object is NULL.
   */
  inline const T& operator*() const
  {
    return static_cast<const T&>(Beagle::Pointer::operator*());
  }

  /*!
   *  \brief Get reference the T-type object pointed.
   *  \return Pointer to the T-type object pointed.
   *  \throw Beagle::AssertException If the pointer to the T-type object is NULL.
   */
  inline T* operator->()
  {
    return static_cast<T*>(Beagle::Pointer::operator->());
  }

  /*!
   *  \brief Get constant reference the T-type object pointed.
   *  \return Constant pointer to the T-type object pointed.
   *  \throw Beagle::AssertException If the pointer to the T-type object is NULL.
   */
  inline const T* operator->() const
  {
    return static_cast<const T*>(Beagle::Pointer::operator->());
  }

  /*!
   *  \brief Compare a smart pointer to a T-type object pointer.
   *  \param inObjPtr Object pointer to compare.
   *  \return True if they both refer to the same T-type object (or are both NULL), false if not.
   */
  inline bool operator==(const T* inObjPtr) const
  {
    return Beagle::Pointer::operator==(inObjPtr);
  }

  /*!
   *  \brief  Compare two T-type smart pointers.
   *  \param inPointerT Smart pointer to compare.
   *  \return True if they both refer to the same T-type object (or are both NULL), false if not.
   */
  inline bool operator==(const PointerT<T,BaseType>& inPointerT) const
  {
    return Beagle::Pointer::operator==(inPointerT);
  }

  /*!
   *  \brief Compare a T-type smart pointer to an T-type object pointer.
   *  \param inObjPtr Object pointer to compare.
   *  \return False if they both refer to the same T-type object (or are both NULL), true if not.
   */
  inline bool operator!=(const T* inObjPtr) const
  {
    return Beagle::Pointer::operator!=(inObjPtr);
  }

  /*!
   *  \brief Compare two T-type smart pointers.
   *  \param inPointerT Smart pointer to compare.
   *  \return False if they both refer to the same T-type object (or are both NULL), true if not.
   */
  inline bool operator!=(const PointerT<T,BaseType>& inPointerT) const
  {
    return Beagle::Pointer::operator!=(inPointerT);
  }

  /*!
   *  \brief  Return T-type pointer to the referenced object.
   *  \return C++ pointer to the T-type object.
   */
  inline T* getPointer()
  {
    return static_cast<T*>(Beagle::Pointer::getPointer());
  }

  /*!
   *  \brief  Return constant T-type pointer to the referenced object.
   *  \return Constant C++ pointer to the T-type object.
   */
  inline const T* getPointer() const
  {
    return static_cast<const T*>(Beagle::Pointer::getPointer());
  }

};

}

#endif // Beagle_PointerT_hpp


