From c6e1a2c7e4221d580876e5ec5b37802618382a29 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 10 Feb 2009 00:18:07 +0000 Subject: [PATCH] added refptr::operator=(const T * ptr) method, including refptr in parser git-svn-id: svn://anubis/fart/trunk@93 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- parser/parser.yy | 3 +++ test/tests.cc | 2 ++ util/refptr.h | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/parser/parser.yy b/parser/parser.yy index ab8c97c..13286eb 100644 --- a/parser/parser.yy +++ b/parser/parser.yy @@ -3,7 +3,10 @@ #include #include #include "main/Scene.h" +#include "main/Material.h" #include "util/Vector.h" +#include "util/refptr.h" +#include "shapes/Shape.h" /* includes all shape types */ using namespace std; extern "C" { diff --git a/test/tests.cc b/test/tests.cc index 1edd2fc..f2fb312 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -30,6 +30,8 @@ int main() refptr brp(b); cout << "Going to assign brp to arp" << endl; arp = brp; + cout << "Going to assign a new S to arp" << endl; + arp = new S(21); cout << "ok, exiting" << endl; return 0; } diff --git a/util/refptr.h b/util/refptr.h index ebd59e5..d6a07be 100644 --- a/util/refptr.h +++ b/util/refptr.h @@ -12,6 +12,7 @@ class refptr refptr(const T * ptr); refptr(const refptr & orig); refptr & operator=(const refptr & orig); + refptr & operator=(const T * ptr); ~refptr(); private: @@ -47,6 +48,15 @@ template refptr & refptr::operator=(const refptr & orig) return *this; } +template refptr & refptr::operator=(const T * ptr) +{ + destroy(); + m_ptr = ptr; + m_refCount = new int; + *m_refCount = 1; + return *this; +} + template void refptr::cloneFrom(const refptr & orig) { this->m_ptr = orig.m_ptr;