added dereference and indirection operators to util/refptr, converted parser to use refptr<Node> as YYSTYPE

git-svn-id: svn://anubis/fart/trunk@94 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-02-10 00:37:49 +00:00
1 parent c6e1a2c7e4
commit 0181e82653
2 files changed
+42 -22

No files matched your search

+17 -5
View File
@@ -9,17 +9,19 @@ class refptr
{
public:
refptr<T>();
refptr<T>(const T * ptr);
refptr<T>(T * ptr);
refptr<T>(const refptr<T> & orig);
refptr<T> & operator=(const refptr<T> & orig);
refptr<T> & operator=(const T * ptr);
refptr<T> & operator=(T * ptr);
~refptr<T>();
T & operator*();
T * operator->();
private:
void cloneFrom(const refptr<T> & orig);
void destroy();
const T * m_ptr;
T * m_ptr;
int * m_refCount;
};
@@ -29,7 +31,7 @@ template <typename T> refptr<T>::refptr()
m_refCount = NULL;
}
template <typename T> refptr<T>::refptr(const T * ptr)
template <typename T> refptr<T>::refptr(T * ptr)
{
m_ptr = ptr;
m_refCount = new int;
@@ -48,7 +50,7 @@ template <typename T> refptr<T> & refptr<T>::operator=(const refptr<T> & orig)
return *this;
}
template <typename T> refptr<T> & refptr<T>::operator=(const T * ptr)
template <typename T> refptr<T> & refptr<T>::operator=(T * ptr)
{
destroy();
m_ptr = ptr;
@@ -86,5 +88,15 @@ template <typename T> void refptr<T>::destroy()
}
}
template <typename T> T & refptr<T>::operator*()
{
return *m_ptr;
}
template <typename T> T * refptr<T>::operator->()
{
return m_ptr;
}
#endif