2009-03-06 01:02:59 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2007-02-24 03:30:19 +03:00
|
|
|
#ifndef USERLAND_FS_OBJECT_TRACKER_H
|
|
|
|
#define USERLAND_FS_OBJECT_TRACKER_H
|
|
|
|
|
2009-03-06 01:02:59 +03:00
|
|
|
#include <util/DoublyLinkedList.h>
|
|
|
|
|
2007-02-24 03:30:19 +03:00
|
|
|
#include "Locker.h"
|
|
|
|
|
|
|
|
namespace UserlandFSUtil {
|
|
|
|
|
|
|
|
class ObjectTracker;
|
|
|
|
class GetObjectTrackableLink;
|
|
|
|
|
|
|
|
// ObjectTrackable
|
|
|
|
class ObjectTrackable {
|
|
|
|
public:
|
|
|
|
ObjectTrackable();
|
|
|
|
virtual ~ObjectTrackable();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ObjectTracker;
|
|
|
|
friend class GetObjectTrackableLink;
|
|
|
|
|
2009-03-06 01:02:59 +03:00
|
|
|
DoublyLinkedListLink<ObjectTrackable> fLink;
|
2007-02-24 03:30:19 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// GetObjectTrackableLink
|
|
|
|
struct GetObjectTrackableLink {
|
2009-03-06 01:02:59 +03:00
|
|
|
inline DoublyLinkedListLink<ObjectTrackable> *operator()(
|
2007-02-24 03:30:19 +03:00
|
|
|
ObjectTrackable* trackable) const
|
|
|
|
{
|
|
|
|
return &trackable->fLink;
|
|
|
|
}
|
|
|
|
|
2009-03-06 01:02:59 +03:00
|
|
|
inline const DoublyLinkedListLink<ObjectTrackable> *operator()(
|
2007-02-24 03:30:19 +03:00
|
|
|
const ObjectTrackable* trackable) const
|
|
|
|
{
|
|
|
|
return &trackable->fLink;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ObjectTracker
|
|
|
|
class ObjectTracker {
|
|
|
|
private:
|
|
|
|
ObjectTracker();
|
|
|
|
~ObjectTracker();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
static ObjectTracker* InitDefault();
|
|
|
|
static void ExitDefault();
|
|
|
|
static ObjectTracker* GetDefault();
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class ObjectTrackable;
|
|
|
|
|
|
|
|
void AddTrackable(ObjectTrackable* trackable);
|
|
|
|
void RemoveTrackable(ObjectTrackable* trackable);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Locker fLock;
|
2009-03-06 01:02:59 +03:00
|
|
|
DoublyLinkedList<ObjectTrackable, GetObjectTrackableLink>
|
|
|
|
fTrackables;
|
2007-02-24 03:30:19 +03:00
|
|
|
|
|
|
|
static ObjectTracker* sTracker;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace UserlandFSUtil
|
|
|
|
|
|
|
|
using UserlandFSUtil::ObjectTrackable;
|
|
|
|
using UserlandFSUtil::ObjectTracker;
|
|
|
|
|
|
|
|
#ifdef DEBUG_OBJECT_TRACKING
|
|
|
|
# define ONLY_OBJECT_TRACKABLE_BASE_CLASS : private ObjectTrackable
|
|
|
|
# define FIRST_OBJECT_TRACKABLE_BASE_CLASS private ObjectTrackable,
|
|
|
|
#else
|
|
|
|
# define ONLY_OBJECT_TRACKABLE_BASE_CLASS
|
|
|
|
# define FIRST_OBJECT_TRACKABLE_BASE_CLASS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // USERLAND_FS_OBJECT_TRACKER_H
|