diff --git a/src/memory/SharedPtr.cpp b/src/memory/SharedPtr.cpp index e6d44dab15..757702c52e 100644 --- a/src/memory/SharedPtr.cpp +++ b/src/memory/SharedPtr.cpp @@ -37,22 +37,20 @@ namespace Sass { , dbg(false) #endif { - refcounter = 0; - #ifdef DEBUG_SHARED_PTR - if (taint) all.push_back(this); - #endif - }; - - SharedObj::~SharedObj() { - #ifdef DEBUG_SHARED_PTR - if (dbg) std::cerr << "Destruct " << this << "\n"; - if(!all.empty()) { // check needed for MSVC (no clue why?) - all.erase(std::remove(all.begin(), all.end(), this), all.end()); - } - #endif - }; - + refcounter = 0; + #ifdef DEBUG_SHARED_PTR + if (taint) all.push_back(this); + #endif + }; + SharedObj::~SharedObj() { + #ifdef DEBUG_SHARED_PTR + if (dbg) std::cerr << "Destruct " << this << "\n"; + if(!all.empty()) { // check needed for MSVC (no clue why?) + all.erase(std::remove(all.begin(), all.end(), this), all.end()); + } + #endif + }; void SharedPtr::decRefCount() { if (node) { diff --git a/src/memory/SharedPtr.hpp b/src/memory/SharedPtr.hpp index 2df55bc24f..995d6cc972 100644 --- a/src/memory/SharedPtr.hpp +++ b/src/memory/SharedPtr.hpp @@ -86,9 +86,9 @@ namespace Sass { class SharedPtr { - private: + protected: SharedObj* node; - private: + protected: void decRefCount(); void incRefCount(); public: @@ -97,16 +97,16 @@ namespace Sass { : node(NULL) {}; // the create constructor SharedPtr(SharedObj* ptr); - // copy assignment operator - SharedPtr& operator=(const SharedPtr& rhs); - // move assignment operator - /* SharedPtr& operator=(SharedPtr&& rhs); */ // the copy constructor SharedPtr(const SharedPtr& obj); // the move constructor - /* SharedPtr(SharedPtr&& obj); */ - // destructor - ~SharedPtr(); + SharedPtr(SharedPtr&& obj); + // copy assignment operator + SharedPtr& operator=(const SharedPtr& obj); + // move assignment operator + SharedPtr& operator=(SharedPtr&& obj); + // pure virtual destructor + virtual ~SharedPtr() = 0; public: SharedObj* obj () const { return node; @@ -146,6 +146,27 @@ namespace Sass { : SharedPtr(node) {}; SharedImpl(const T& node) : SharedPtr(node) {}; + // the copy constructor + SharedImpl(const SharedImpl& impl) + : SharedPtr(impl.node) {}; + // the move constructor + SharedImpl(SharedImpl&& impl) + : SharedPtr(impl.node) {}; + // copy assignment operator + SharedImpl& operator=(const SharedImpl& rhs) { + node = rhs.node; + incRefCount(); + return *this; + } + // move assignment operator + SharedImpl& operator=(SharedImpl&& rhs) { + // don't move our self + if (this != &rhs) { + node = std::move(rhs.node); + rhs.node = NULL; + } + return *this; + } ~SharedImpl() {}; public: operator T*() const {