michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This header will be included by headers that define refpointer and array classes michael@0: // in order to specialize CC helpers such as ImplCycleCollectionTraverse for them. michael@0: michael@0: #ifndef nsCycleCollectionNoteChild_h__ michael@0: #define nsCycleCollectionNoteChild_h__ michael@0: michael@0: #include "nsCycleCollectionTraversalCallback.h" michael@0: #include "mozilla/Likely.h" michael@0: #include "mozilla/TypeTraits.h" michael@0: michael@0: enum { michael@0: CycleCollectionEdgeNameArrayFlag = 1 michael@0: }; michael@0: michael@0: // Just a helper for appending "[i]". Didn't want to pull in string headers here. michael@0: void michael@0: CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback, michael@0: const char* aName, michael@0: uint32_t aFlags = 0); michael@0: michael@0: // Should be inlined so that in the no-debug-info case this is just a simple if(). michael@0: MOZ_ALWAYS_INLINE void michael@0: CycleCollectionNoteEdgeName(nsCycleCollectionTraversalCallback& aCallback, michael@0: const char* aName, michael@0: uint32_t aFlags = 0) michael@0: { michael@0: if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) { michael@0: CycleCollectionNoteEdgeNameImpl(aCallback, aName, aFlags); michael@0: } michael@0: } michael@0: michael@0: #define NS_CYCLE_COLLECTION_INNERCLASS \ michael@0: cycleCollection michael@0: michael@0: #define NS_CYCLE_COLLECTION_INNERNAME \ michael@0: _cycleCollectorGlobal michael@0: michael@0: #define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \ michael@0: _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant() michael@0: michael@0: template michael@0: nsISupports* ToSupports(T* p, typename T::NS_CYCLE_COLLECTION_INNERCLASS* dummy = 0) michael@0: { michael@0: return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(p); michael@0: } michael@0: michael@0: // The default implementation of this class template is empty, because it michael@0: // should never be used: see the partial specializations below. michael@0: template ::value> michael@0: struct CycleCollectionNoteChildImpl michael@0: { michael@0: }; michael@0: michael@0: template michael@0: struct CycleCollectionNoteChildImpl michael@0: { michael@0: static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) michael@0: { michael@0: aCallback.NoteXPCOMChild(ToSupports(aChild)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: struct CycleCollectionNoteChildImpl michael@0: { michael@0: static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) michael@0: { michael@0: aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T)); michael@0: } michael@0: }; michael@0: michael@0: template michael@0: inline void CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback, michael@0: T* aChild, michael@0: const char* aName, michael@0: uint32_t aFlags = 0) michael@0: { michael@0: CycleCollectionNoteEdgeName(aCallback, aName, aFlags); michael@0: CycleCollectionNoteChildImpl::Run(aCallback, aChild); michael@0: } michael@0: michael@0: #endif // nsCycleCollectionNoteChild_h__