1 /* 2 * Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <Referenceable.h> 8 9 10 // constructor 11 Referenceable::Referenceable(bool deleteWhenUnreferenced) 12 : fReferenceCount(1), 13 fDeleteWhenUnreferenced(deleteWhenUnreferenced) 14 { 15 } 16 17 // destructor 18 Referenceable::~Referenceable() 19 { 20 } 21 22 // RemoveReference 23 bool 24 Referenceable::RemoveReference() 25 { 26 bool unreferenced = (atomic_add(&fReferenceCount, -1) == 1); 27 if (fDeleteWhenUnreferenced && unreferenced) 28 delete this; 29 return unreferenced; 30 } 31