Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

StrChunkPtrT.h

00001 #ifndef _STR_StrChunkPtrT_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by the Free Software Foundation; either version 2 of the License, or
00009  *     (at your option) any later version.
00010  * 
00011  *     This program is distributed in the hope that it will be useful, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #  pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/StrMod/StrMod/StrChunkPtrT.h,v 1.8 2002/08/29 00:58:05 hopper Exp $ */
00026 
00027 // For log see ../ChangeLog
00028 // 
00029 // Revision 1.1  1996/07/05 18:39:48  hopper
00030 // New type to handle StrChunkPtr's that need to point to more specific
00031 // types than StrChunk.
00032 //
00033 
00034 #ifndef _STR_StrChunkPtr_H_
00035 #  include <StrMod/StrChunkPtr.h>
00036 #endif
00037 #ifndef _STR_StrChunk_H_
00038 #  include <StrMod/StrChunk.h>
00039 #endif
00040 
00041 #define _STR_StrChunkPtrT_H_
00042 
00043 namespace strmod {
00044 namespace strmod {
00045 
00046 /** \class StrChunkPtrT StrChunkPtrT.h StrMod/StrChunkPtrT.h
00047  * A convenience template to point at things derived from StrChunk.
00048  *
00049  * This is nice to have since the inheritance relationship between
00050  * StrChunkPtrT and StrChunk mirrors the inheritance relationship between
00051  * StrChunk and any of it's subclasses.  This allows us to use a StrChunkPtrT
00052  * when we care about the type of a StrChunk and still pass it into methods
00053  * requiring a <code>const StrChunkPtr &</code> without a type conversion.
00054  *
00055  * Note that this class (and none of my other template classes) override the
00056  * various Protocol type identification methods.  This is because the LCore
00057  * type identification system doesn't handle templated types well, and also
00058  * because of the dubious value of identifying them precisely.  It will still
00059  * register as being a StrChunkPtr or RefCountPtr.
00060  */
00061 template <class Chunk>
00062 class StrChunkPtrT : public StrChunkPtr
00063 {
00064  public:
00065    //! An easier way to refer to StrChunkPtr.
00066    typedef StrChunkPtr super1;
00067 
00068    //@{
00069    /**
00070     * These all construct a StrChunkPtr from the appropriate type and maintain
00071     * the reference count to the pointed at StrChunk.
00072     */
00073    inline StrChunkPtrT(const StrChunkPtrT<Chunk> &b) : super1(b)            { }
00074    inline StrChunkPtrT(const lcore::RefCountPtrT<Chunk> &b) : super1(b.GetPtr())   { }
00075    inline StrChunkPtrT(Chunk *stptr = 0) : super1(stptr)                    { }
00076    //@}
00077 
00078    //@{
00079    /**
00080     * The methods you need to override to do a smart pointer.
00081     */
00082    inline Chunk &operator *() const;
00083    inline Chunk *operator ->() const;
00084    //@}
00085 
00086    //! A way to get the raw pointer value, just in case.
00087    inline Chunk *GetPtr() const;
00088 
00089    //@{
00090    /**
00091     * These all set a StrChunkPtrs value from the appropriate type and
00092     * maintain the reference count to the pointed at StrChunk.
00093     */
00094    inline const StrChunkPtrT<Chunk> &operator =(const StrChunkPtrT<Chunk> &b);
00095    inline const StrChunkPtrT<Chunk> &operator =(const lcore::RefCountPtrT<Chunk> &b);
00096    inline const StrChunkPtrT<Chunk> &operator =(Chunk *b);
00097    //@}
00098 
00099  protected:
00100    //! See class RefCountPtr.  Used in ensuring type safety.
00101    inline virtual lcore::ReferenceCounting *i_CheckType(lcore::ReferenceCounting *p) const;
00102 };
00103 
00104 //-----------------------------inline functions--------------------------------
00105 
00106 template <class Chunk>
00107 inline Chunk &StrChunkPtrT<Chunk>::operator *() const
00108 {
00109    return(*GetPtr());
00110 }
00111 
00112 template <class Chunk>
00113 inline Chunk *StrChunkPtrT<Chunk>::operator ->() const
00114 {
00115    return(GetPtr());
00116 }
00117 
00118 template <class Chunk>
00119 inline Chunk *StrChunkPtrT<Chunk>::GetPtr() const
00120 {
00121    return(static_cast<Chunk *>(super1::GetPtr()));
00122 }
00123 
00124 template <class Chunk>
00125 inline const StrChunkPtrT<Chunk> &
00126 StrChunkPtrT<Chunk>::operator =(const StrChunkPtrT<Chunk> &b)
00127 {
00128    super1::operator =(b);
00129    return(*this);
00130 }
00131 
00132 template <class Chunk>
00133 inline const StrChunkPtrT<Chunk> &
00134 StrChunkPtrT<Chunk>::operator =(const lcore::RefCountPtrT<Chunk> &b)
00135 {
00136    super1::operator =(b);
00137    return(*this);
00138 }
00139 
00140 template <class Chunk>
00141 inline const StrChunkPtrT<Chunk> &
00142 StrChunkPtrT<Chunk>::operator =(Chunk *b)
00143 {
00144    super1::operator =(b);
00145    return(*this);
00146 }
00147 
00148 template <class Chunk>
00149 inline lcore::ReferenceCounting *
00150 StrChunkPtrT<Chunk>::i_CheckType(lcore::ReferenceCounting *p) const
00151 {
00152    return(((p != 0) && p->AreYouA(Chunk::identifier)) ? p : 0);
00153 }
00154 
00155 }  // namespace strmod
00156 }  // namespace strmod
00157 
00158 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1