2 * Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef USERLAND_FS_OBJECT_TRACKER_H
6 #define USERLAND_FS_OBJECT_TRACKER_H
8 #include <util/DoublyLinkedList.h>
12 namespace UserlandFSUtil
{
15 class GetObjectTrackableLink
;
18 class ObjectTrackable
{
21 virtual ~ObjectTrackable();
24 friend class ObjectTracker
;
25 friend class GetObjectTrackableLink
;
27 DoublyLinkedListLink
<ObjectTrackable
> fLink
;
30 // GetObjectTrackableLink
31 struct GetObjectTrackableLink
{
32 inline DoublyLinkedListLink
<ObjectTrackable
> *operator()(
33 ObjectTrackable
* trackable
) const
35 return &trackable
->fLink
;
38 inline const DoublyLinkedListLink
<ObjectTrackable
> *operator()(
39 const ObjectTrackable
* trackable
) const
41 return &trackable
->fLink
;
53 static ObjectTracker
* InitDefault();
54 static void ExitDefault();
55 static ObjectTracker
* GetDefault();
58 friend class ObjectTrackable
;
60 void AddTrackable(ObjectTrackable
* trackable
);
61 void RemoveTrackable(ObjectTrackable
* trackable
);
65 DoublyLinkedList
<ObjectTrackable
, GetObjectTrackableLink
>
68 static ObjectTracker
* sTracker
;
71 } // namespace UserlandFSUtil
73 using UserlandFSUtil::ObjectTrackable
;
74 using UserlandFSUtil::ObjectTracker
;
76 #ifdef DEBUG_OBJECT_TRACKING
77 # define ONLY_OBJECT_TRACKABLE_BASE_CLASS : private ObjectTrackable
78 # define FIRST_OBJECT_TRACKABLE_BASE_CLASS private ObjectTrackable,
80 # define ONLY_OBJECT_TRACKABLE_BASE_CLASS
81 # define FIRST_OBJECT_TRACKABLE_BASE_CLASS
84 #endif // USERLAND_FS_OBJECT_TRACKER_H