ptr.hh

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 #ifndef lestes__std___ptr_hh___included
00029 #define lestes__std___ptr_hh___included
00030 
00031 /*! \file
00032   \brief Smart pointer template.
00033   
00034   Declaration of ptr class representing local, global and return pointer.
00035   Method bodies are in ptr_bodies.hh.
00036   \author pt
00037 */
00038 #include <lestes/std/mem/root_pointer.hh>
00039 #include <lestes/std/srp.hh>
00040 
00041 package(lestes);
00042 package(std);
00043 
00044 // forward declaration to avoid cycle
00045 template <typename T>
00046 class srp;
00047 
00048 /*!
00049   Represents structure pointer.
00050   \param T  The type of object pointed to.
00051 */
00052 template <typename T>
00053 class ptr : public mem::root_pointer {
00054 #ifdef LESTES_OLD_POINTER_CONDITION
00055 #else
00056         /*!
00057           \brief Condition class.
00058 
00059           Class for returning boolean conditions without
00060           the risk of unwanted implicit conversion to bool.
00061         */
00062         struct condition {
00063                 /*!
00064                   \brief Creates the condition.
00065 
00066                   Creates the static condition object,
00067                   used to get reference to non NULL pointer to condition.
00068                 */
00069                 condition(void) {
00070                 }
00071         private:
00072                 /*!
00073                   \brief Avoids deallocation.
00074 
00075                   Avoids calling delete on the pointer to the static condition object
00076                   returned from operator condition *(). Never defined.
00077                 */
00078                 void operator delete(void *);
00079         };
00080 #endif
00081 public:
00082         /*!
00083           \brief the type pointed to
00084 
00085           \author TMA
00086          */
00087         typedef T pointee_type; 
00088         //! Creates ptr, initializes with NULL pointer.
00089         inline ptr(void);
00090         //! Creates ptr, initializes with pointer .
00091         inline ptr(T *a_pointer);
00092         //! Creates ptr, initializes with pointer .
00093         template <typename U>
00094         inline ptr(U *a_pointer);
00095         //! Creates ptr, initializes with ptr to the same type.
00096         inline ptr(const ptr<T> &other);
00097         //! Creates ptr, initializes with ptr.
00098         template <typename U>
00099         inline ptr(const ptr<U> &other);
00100         //! Creates ptr, initializes with srp.
00101         template <typename U>
00102         inline ptr(const srp<U> &other);
00103         //! Destroys ptr.
00104         inline ~ptr(void);
00105         //! Returns the pointer.
00106         inline T *operator->(void) const;
00107         //! Returns dereferenced pointer.
00108         inline T &operator *(void) const;
00109         //! Assigns a pointer.
00110         inline ptr<T> &operator=(T *a_pointer);
00111         //! Assigns a pointer.
00112         template <typename U>
00113         inline ptr<T> &operator=(U *a_pointer);
00114         //! Assigns ptr of the same type.
00115         inline ptr<T> &operator=(const ptr<T> &other);
00116         //! Assigns ptr.
00117         template <typename U>
00118         inline ptr<T> &operator=(const ptr<U> &other);
00119         //! Assigns srp.
00120         template <typename U>
00121         inline ptr<T> &operator=(const srp<U> &other);
00122 #ifdef LESTES_OLD_POINTER_CONDITION
00123         //! Tests NULL pointer.
00124         inline operator bool(void) const;
00125 #else
00126         //! Tests NULL pointer.
00127         inline operator condition *(void) const;
00128 #endif
00129         //! Tests non NULL pointer.
00130         inline bool operator!(void) const;
00131         //! Compares to pointer.
00132         inline bool operator==(T *a_pointer) const;
00133         //! Compares to pointer.
00134         template <typename U>
00135         inline bool operator==(U *a_pointer) const;
00136         //! Compares to NULL.
00137         inline bool operator==(::std::ptrdiff_t a_pointer) const;
00138         //! Compares to ptr.
00139         template <typename U>
00140         inline bool operator==(const ptr<U> &other) const;
00141         //! Compares to srp.
00142         template <typename U>
00143         inline bool operator==(const srp<U> &other) const;
00144         //! Compares to pointer.
00145         inline bool operator!=(T *a_pointer) const;
00146         //! Compares to pointer.
00147         template <typename U>
00148         inline bool operator!=(U *a_pointer) const;
00149         //! Compares to NULL.
00150         inline bool operator!=(::std::ptrdiff_t a_pointer) const;
00151         //! Compares to ptr.
00152         template <typename U>
00153         inline bool operator!=(const ptr<U> &other) const;
00154         //! Compares to srp.
00155         template <typename U>
00156         inline bool operator!=(const srp<U> &other) const;
00157         //! Performs dynamic cast to other type.
00158         template <typename U>
00159         inline ptr<U> dncast(void) const;
00160         //! Returns the pointer.
00161         inline T *pointer_get(void) const;
00162         //! Compares two pointers for ordering.
00163         inline bool operator < (const ptr<T> &) const;
00164 private:
00165         //! Sets the pointer.
00166         inline void pointer_set(T *a_pointer);
00167 };
00168 
00169 end_package(std);
00170 end_package(lestes);
00171 
00172 #endif
00173 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:27:11 2007 for lestes by doxygen 1.5.1-20070107