xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbert...@apache.org
Subject cvs commit: xml-xalan/c/src/xalanc/Include XalanMemMgrAutoPtr.hpp
Date Thu, 12 May 2005 04:51:39 GMT
dbertoni    2005/05/11 21:51:39

  Modified:    c/src/xalanc/Include XalanMemMgrAutoPtr.hpp
  Log:
  Fix for Jira issue XALANC-466.
  
  Revision  Changes    Path
  1.8       +350 -341  xml-xalan/c/src/xalanc/Include/XalanMemMgrAutoPtr.hpp
  
  Index: XalanMemMgrAutoPtr.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/xalanc/Include/XalanMemMgrAutoPtr.hpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XalanMemMgrAutoPtr.hpp	10 Nov 2004 23:24:20 -0000	1.7
  +++ XalanMemMgrAutoPtr.hpp	12 May 2005 04:51:39 -0000	1.8
  @@ -37,397 +37,406 @@
   
   
   
  -// We're using our own auto_ptr-like class due to wide
  -// variations amongst the varous platforms we have to
  -// support
  -template<	class	Type, 
  -			bool	toCallDestructor = true>
  +XALAN_USING_XERCES(MemoryManager)
  +
  +// An auto_ptr-like class that supports the MemoryManager class.
  +template<
  +            class   Type, 
  +            bool    toCallDestructor = true>
   class XalanMemMgrAutoPtr
   {
   public:
   
  -	typedef XALAN_STD_QUALIFIER pair<MemoryManagerType*, Type*> AutoPtrPairType;
  +    typedef XALAN_STD_QUALIFIER pair<MemoryManager*, Type*> AutoPtrPairType;
  +
  +    class MemMgrAutoPtrData : public AutoPtrPairType
  +    {
  +    public:
  +        MemMgrAutoPtrData():
  +            AutoPtrPairType(0,0)
  +        {
  +        }
  +
  +        MemMgrAutoPtrData(  
  +                MemoryManager*  memoryManager,
  +                Type*           dataPointer): 
  +            AutoPtrPairType(memoryManager, dataPointer)
  +        {
  +            invariants();
  +        }
  +        
  +        bool
  +        isInitilized()const
  +        {
  +            return this->first != 0 && this->second != 0;
  +        }
  +
  +        void
  +        deallocate()
  +        {
  +            invariants();
  +
  +            if ( isInitilized() )
  +            {       
  +                if ( toCallDestructor ) 
  +                {
  +                    this->second->~Type();
  +                }
  +
  +                this->first->deallocate(this->second);
  +            }
  +        }
  +
  +        void 
  +        reset(
  +                MemoryManager*      memoryManager ,
  +                Type*               dataPointer)
  +        {   
  +            invariants();
  +
  +            this->first = memoryManager;
  +
  +            this->second = dataPointer;
  +
  +            invariants();
  +        }
  +
  +    private:
  +
  +        void
  +        invariants() const
  +        {
  +            assert(
  +                isInitilized() ||
  +                (this->first == 0 && this->second == 0));
  +        }
  +    };
  +
  +
  +    XalanMemMgrAutoPtr(
  +            MemoryManager&  theManager, 
  +            Type*           ptr) : 
  +        m_pointerInfo(&theManager, ptr)
  +    {
  +    }
  +
  +    XalanMemMgrAutoPtr() :
  +        m_pointerInfo()
  +    {
  +    }
   
  -	class MemMgrAutoPtrData : public AutoPtrPairType
  -	{
  -	public:
  -		MemMgrAutoPtrData():
  -			AutoPtrPairType(0,0)
  -		{
  -		}
  -
  -		MemMgrAutoPtrData(	
  -			MemoryManagerType* memoryManager,
  -			Type* dataPointer): 
  -			AutoPtrPairType(memoryManager, dataPointer)
  -		{
  -			invariants();
  -		}
  -		
  -	
  -		bool
  -		isInitilized()const
  -		{
  -			return ( (this->first != 0) && (this->second != 0) )? true : false;
  -		}
  -	
  -		void
  -		deallocate()
  -		{
  -			invariants();
  -
  -			if ( isInitilized() )
  -			{		
  -				if ( toCallDestructor ) 
  -				{
  -					this->second->~Type();
  -				}
  -
  -				this->first->deallocate(this->second);
  -			}
  -		}
  -		
  -		void 
  -		reset(	MemoryManagerType* m_memoryManager ,
  -				Type*	m_dataPointer )
  -		{	
  -			invariants();
  -
  -			this->first = m_memoryManager;
  -			
  -			this->second = m_dataPointer;
  -
  -			invariants();
  -		}	
  -	private:
  -		void
  -		invariants()const
  -		{
  -			assert( isInitilized() ||
  -					( (this->first == 0) && (this->second ==0) ) );
  -		}
  -		
  -	};
  -	
  -	
  -	XalanMemMgrAutoPtr(
  -			MemoryManagerType&  theManager, 
  -			Type* ptr  ) : 
  -		m_pointerInfo(&theManager, ptr)
  -	{
  -	}	
  -
  -	XalanMemMgrAutoPtr() :
  -		m_pointerInfo()
  -	{
  -	}
  -	
  -	XalanMemMgrAutoPtr(const XalanMemMgrAutoPtr<Type,toCallDestructor>&	theSource)
:
  -		m_pointerInfo(((XalanMemMgrAutoPtr<Type>&)theSource).release())
  -	{
  -	}
  -
  -	XalanMemMgrAutoPtr<Type,toCallDestructor>&
  -	operator=(XalanMemMgrAutoPtr<Type,toCallDestructor>&	theRHS)
  -	{		
  -		if (this != &theRHS)
  -		{
  -			m_pointerInfo.deallocate();
  -
  -			m_pointerInfo = theRHS.release();
  -		}
  -
  -		return *this;
  -	}
  -
  -	~XalanMemMgrAutoPtr()
  -	{
  -		m_pointerInfo.deallocate();
  -	}
  -
  -	Type&
  -	operator*() const
  -	{
  -		return *m_pointerInfo.second;
  -	}
  -
  -	Type*
  -	operator->() const
  -	{
  -		return m_pointerInfo.second;
  -	}
  -
  -	Type*
  -	get() const
  -	{
  -		return m_pointerInfo.second;
  -	}
  +    XalanMemMgrAutoPtr(const XalanMemMgrAutoPtr<Type, toCallDestructor>&    theSource)
:
  +        m_pointerInfo(((XalanMemMgrAutoPtr<Type>&)theSource).release())
  +    {
  +    }
   
  -    MemoryManagerType*
  +    XalanMemMgrAutoPtr<Type,toCallDestructor>&
  +    operator=(XalanMemMgrAutoPtr<Type,toCallDestructor>&    theRHS)
  +    {       
  +        if (this != &theRHS)
  +        {
  +            m_pointerInfo.deallocate();
  +
  +            m_pointerInfo = theRHS.release();
  +        }
  +
  +        return *this;
  +    }
  +
  +    ~XalanMemMgrAutoPtr()
  +    {
  +        m_pointerInfo.deallocate();
  +    }
  +
  +    Type&
  +    operator*() const
  +    {
  +        return *m_pointerInfo.second;
  +    }
  +
  +    Type*
  +    operator->() const
  +    {
  +        return m_pointerInfo.second;
  +    }
  +
  +    Type*
  +    get() const
  +    {
  +        return m_pointerInfo.second;
  +    }
  +
  +    MemoryManager*
       getMemoryManager()
       {
           return m_pointerInfo.first;
       }
   
  -    const MemoryManagerType*
  +    const MemoryManager*
       getMemoryManager() const
       {
           return m_pointerInfo.first;
       }
   
  -	MemMgrAutoPtrData
  -	release()
  -	{		
  -		MemMgrAutoPtrData tmp = m_pointerInfo;
  -	
  -		m_pointerInfo.reset( 0 , 0 ); 
  -		
  -		return MemMgrAutoPtrData(tmp);
  -	}
  -
  -	Type*
  -	releasePtr()
  -	{		
  -		MemMgrAutoPtrData tmp = release();
  -	
  -		return tmp.second;
  -	}	
  -	
  -	void
  -	reset(	MemoryManagerType*  theManager = 0,
  -			Type*		thePointer = 0 )
  -	{		
  -		m_pointerInfo.deallocate();
  +    MemMgrAutoPtrData
  +    release()
  +    {       
  +        MemMgrAutoPtrData tmp = m_pointerInfo;
  +    
  +        m_pointerInfo.reset(0, 0); 
  +        
  +        return MemMgrAutoPtrData(tmp);
  +    }
   
  -		m_pointerInfo.reset ( theManager , thePointer );
  -	}
  +    Type*
  +    releasePtr()
  +    {       
  +        MemMgrAutoPtrData tmp = release();
  +    
  +        return tmp.second;
  +    }   
  +    
  +    void
  +    reset(
  +            MemoryManager*  theManager = 0,
  +            Type*           thePointer = 0)
  +    {       
  +        m_pointerInfo.deallocate();
   
  -private:
  +        m_pointerInfo.reset(theManager, thePointer);
  +    }
   
  +private:
   
  -// data member
  -	MemMgrAutoPtrData m_pointerInfo;
  +    // data member
  +    MemMgrAutoPtrData   m_pointerInfo;
   };
   
   
   
   
  -template<	class Type>
  +template<class Type>
   class XalanMemMgrAutoPtrArray
   {
   public:
   
  -	typedef unsigned int size_type;
  +    typedef unsigned int size_type;
   
  -	class MemMgrAutoPtrArrayData 
  -	{
  -	public:
  -		MemMgrAutoPtrArrayData():
  -			m_memoryManager(0),
  -			m_dataArray(0),
  -			m_size(0)
  -		{
  -		}
  -
  -		MemMgrAutoPtrArrayData(	
  -				MemoryManagerType*	memoryManager,
  -				Type*				dataPointer,
  -				size_type				size): 
  -			m_memoryManager(memoryManager),
  -			m_dataArray(dataPointer),
  -			m_size(size)
  -		{
  -			invariants();
  -		}
  -		
  -	
  -		bool
  -		isInitilized()const
  -		{
  -			return ( (m_memoryManager != 0) && (m_dataArray != 0)  && (m_size !=
0) )? true : false;
  -		}
  -	
  -		void
  -		deallocate()
  -		{
  -			invariants();
  -
  -			if ( isInitilized() )
  -			{			
  -				assert ( m_dataArray != 0 );
  -
  -				for ( size_type i = 0; i < m_size ; ++i )
  -				{
  -					m_dataArray[i].~Type();
  -				}
  -				m_memoryManager->deallocate ( m_dataArray);
  -			}
  -		}
  -		
  -		void 
  -		reset(	MemoryManagerType*	memoryManager ,
  -				Type*				dataPointer,
  -				size_type				size)
  -		{	
  -			invariants();
  -
  -			m_memoryManager = memoryManager;
  -			
  -			m_dataArray =	dataPointer;
  -
  -			m_size = size;
  -
  -			invariants();
  -		}	
  -
  -
  -		MemoryManagerType*		m_memoryManager;
  -		Type*					m_dataArray;
  -		size_type					m_size;
  -
  -	private:
  -		void
  -		invariants()const
  -		{
  -			assert( isInitilized() ||
  -					( (m_memoryManager == 0) && (m_dataArray ==0) && (m_size == 0)) );
  -		}		
  -	};
  -	
  -	XalanMemMgrAutoPtrArray(
  -			MemoryManagerType&  theManager, 
  -			Type*				ptr,
  -			size_type			size) : 
  -		m_pointerInfo(&theManager, ptr, size)
  -	{
  -	}	
  -
  -	XalanMemMgrAutoPtrArray() :
  -		m_pointerInfo()
  -	{
  -	}
  -	
  -	XalanMemMgrAutoPtrArray(const XalanMemMgrAutoPtrArray<Type>&	theSource) :
  -		m_pointerInfo(((XalanMemMgrAutoPtr<Type>&)theSource).release())
  -	{
  -	}
  -
  -
  -	XalanMemMgrAutoPtrArray<Type>&
  -	operator=(XalanMemMgrAutoPtrArray<Type>&	theRHS)
  -	{		
  -		if (this != &theRHS)
  -		{
  -			m_pointerInfo.deallocate();
  -
  -			m_pointerInfo = theRHS.release();
  -		}
  -
  -		return *this;
  -	}
  -
  -	~XalanMemMgrAutoPtrArray()
  -	{
  -		m_pointerInfo.deallocate();
  -	}
  -
  -	Type&
  -	operator*() const
  -	{
  -		return *m_pointerInfo.m_dataArray;
  -	}
  -
  -	Type*
  -	operator->() const
  -	{
  -		return m_pointerInfo.m_dataArray;
  -	}
  -
  -	Type*
  -	get() const
  -	{
  -		return m_pointerInfo.m_dataArray;
  -	}
  -
  -	size_type
  -	getSize()const
  -	{
  -		return m_pointerInfo.m_size;
  -	}
  +    class MemMgrAutoPtrArrayData 
  +    {
  +    public:
  +
  +        MemMgrAutoPtrArrayData():
  +            m_memoryManager(0),
  +            m_dataArray(0),
  +            m_size(0)
  +        {
  +        }
  +
  +        MemMgrAutoPtrArrayData( 
  +                MemoryManager*  memoryManager,
  +                Type*           dataPointer,
  +                size_type       size): 
  +            m_memoryManager(memoryManager),
  +            m_dataArray(dataPointer),
  +            m_size(size)
  +        {
  +            invariants();
  +        }
  +    
  +        bool
  +        isInitilized()const
  +        {
  +            return m_memoryManager != 0 && m_dataArray != 0  && m_size
!= 0;
  +        }
  +
  +        void
  +        deallocate()
  +        {
  +            invariants();
  +
  +            if ( isInitilized() )
  +            {           
  +                assert ( m_dataArray != 0 );
  +
  +                for ( size_type i = 0; i < m_size ; ++i )
  +                {
  +                    m_dataArray[i].~Type();
  +                }
  +
  +                m_memoryManager->deallocate(m_dataArray);
  +            }
  +        }
  +
  +        void 
  +        reset(  
  +                MemoryManager*  theMemoryManager,
  +                Type*           thePointer,
  +                size_type       size)
  +        {   
  +            invariants();
  +
  +            m_memoryManager = theMemoryManager;
  +
  +            m_dataArray =   thePointer;
  +
  +            m_size = size;
  +
  +            invariants();
  +        }   
  +
  +        MemoryManager*  m_memoryManager;
  +
  +        Type*           m_dataArray;
  +
  +        size_type       m_size;
  +
  +    private:
  +
  +        void
  +        invariants()const
  +        {
  +            assert(
  +                isInitilized() ||
  +                (m_memoryManager == 0 && m_dataArray == 0 && m_size ==
0));
  +        }
  +    };
  +
  +    XalanMemMgrAutoPtrArray(
  +            MemoryManager&  theManager, 
  +            Type*           ptr,
  +            size_type       size) : 
  +        m_pointerInfo(
  +            &theManager,
  +            ptr,
  +            size)
  +    {
  +    }   
   
  -    MemoryManagerType*
  +    XalanMemMgrAutoPtrArray() :
  +        m_pointerInfo()
  +    {
  +    }
  +
  +    XalanMemMgrAutoPtrArray(const XalanMemMgrAutoPtrArray<Type>&    theSource)
:
  +        m_pointerInfo(((XalanMemMgrAutoPtr<Type>&)theSource).release())
  +    {
  +    }
  +
  +    XalanMemMgrAutoPtrArray<Type>&
  +    operator=(XalanMemMgrAutoPtrArray<Type>&    theRHS)
  +    {       
  +        if (this != &theRHS)
  +        {
  +            m_pointerInfo.deallocate();
  +
  +            m_pointerInfo = theRHS.release();
  +        }
  +
  +        return *this;
  +    }
  +
  +    ~XalanMemMgrAutoPtrArray()
  +    {
  +        m_pointerInfo.deallocate();
  +    }
  +
  +    Type&
  +    operator*() const
  +    {
  +        return *m_pointerInfo.m_dataArray;
  +    }
  +
  +    Type*
  +    operator->() const
  +    {
  +        return m_pointerInfo.m_dataArray;
  +    }
  +
  +    Type*
  +    get() const
  +    {
  +        return m_pointerInfo.m_dataArray;
  +    }
  +
  +    size_type
  +    getSize()const
  +    {
  +        return m_pointerInfo.m_size;
  +    }
  +
  +    MemoryManager*
       getMemoryManager()
       {
           return m_pointerInfo.m_memoryManager;
       }
   
  -    const MemoryManagerType*
  +    const MemoryManager*
       getMemoryManager() const
       {
           return m_pointerInfo.m_memoryManager;
       }
   
  -	XalanMemMgrAutoPtrArray<Type>&
  -	operator++ ()
  -	{
  -		++m_pointerInfo.m_size;
  +    XalanMemMgrAutoPtrArray<Type>&
  +    operator++ ()
  +    {
  +        ++m_pointerInfo.m_size;
   
  -		return *this;
  -	}
  +        return *this;
  +    }
   
       /* Since this class is not reference-counted, I don't see how this
          could work, since the destruction of the temporary will free
          the controlled pointer.
  -	XalanMemMgrAutoPtrArray<Type>
  -	operator++ (int)
  -	{
  -		XalanMemMgrAutoPtrArray<Type> temp = *this;
  -		++*this;
  +    XalanMemMgrAutoPtrArray<Type>
  +    operator++ (int)
  +    {
  +        XalanMemMgrAutoPtrArray<Type> temp = *this;
  +        ++*this;
   
  -		return temp;
  -	}
  +        return temp;
  +    }
       */
   
  -	MemMgrAutoPtrArrayData
  -	release()
  -	{		
  -		MemMgrAutoPtrArrayData tmp = m_pointerInfo;
  -	
  -		m_pointerInfo.reset( 0 , 0 , 0); 
  -		
  -		return MemMgrAutoPtrArrayData(tmp);
  -	}
  -
  -	Type*
  -	releasePtr()
  -	{		
  -		MemMgrAutoPtrArrayData tmp = release();
  -	
  -		
  -		return tmp.dataPointer;
  -	}
  -	
  -	void
  -	reset(	MemoryManagerType*  theManager = 0,
  -			Type*				thePointer = 0 ,
  -			size_type				size = 0)
  -	{		
  -		m_pointerInfo.deallocate();
  -
  -		m_pointerInfo.reset ( theManager , thePointer , size );
  -	}
  -	
  -	Type&
  -	operator[](size_type	index) const
  -	{
  -		return m_pointerInfo.m_dataArray[index];
  -	}
  -	
  -private:
  +    MemMgrAutoPtrArrayData
  +    release()
  +    {       
  +        MemMgrAutoPtrArrayData tmp = m_pointerInfo;
  +    
  +        m_pointerInfo.reset( 0 , 0 , 0); 
  +        
  +        return MemMgrAutoPtrArrayData(tmp);
  +    }
   
  +    Type*
  +    releasePtr()
  +    {       
  +        MemMgrAutoPtrArrayData  tmp = release();
  +
  +        return tmp.m_dataPointer;
  +    }
  +
  +    void
  +    reset( 
  +            MemoryManager*  theManager = 0,
  +            Type*           thePointer = 0 ,
  +            size_type       size = 0)
  +    {       
  +        m_pointerInfo.deallocate();
  +
  +        m_pointerInfo.reset(theManager, thePointer, size);
  +    }
  +    
  +    Type&
  +    operator[](size_type    index) const
  +    {
  +        return m_pointerInfo.m_dataArray[index];
  +    }
  +
  +private:
   
  -	// data member
  -	MemMgrAutoPtrArrayData m_pointerInfo;
  +    // data member
  +    MemMgrAutoPtrArrayData m_pointerInfo;
   };
   
   
  @@ -437,4 +446,4 @@
   
   
   
  -#endif	// if !defined(XALANMEMMGRAUTOPTR_HEADER_GUARD_1357924680)
  +#endif  // if !defined(XALANMEMMGRAUTOPTR_HEADER_GUARD_1357924680)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message