diff --git a/headers/private/shared/AutoDeleter.h b/headers/private/shared/AutoDeleter.h index 6288f3041b..45cc8107d6 100644 --- a/headers/private/shared/AutoDeleter.h +++ b/headers/private/shared/AutoDeleter.h @@ -1,35 +1,16 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: AutoDeleter.h -// Author(s): Ingo Weinhold (bonefish@users.sf.net) -// Description: Scope-based automatic deletion of objects/arrays. -// ObjectDeleter - deletes an object -// ArrayDeleter - deletes an array -// MemoryDeleter - free()s malloc()ed memory -//------------------------------------------------------------------------------ - +/* + * Copyright 2001-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _AUTO_DELETER_H #define _AUTO_DELETER_H +/*! Scope-based automatic deletion of objects/arrays. + ObjectDeleter - deletes an object + ArrayDeleter - deletes an array + MemoryDeleter - free()s malloc()ed memory +*/ + #include namespace BPrivate { diff --git a/src/servers/registrar/Referenceable.h b/headers/private/shared/Referenceable.h similarity index 73% rename from src/servers/registrar/Referenceable.h rename to headers/private/shared/Referenceable.h index 9acf2d29bd..8a3c17071e 100644 --- a/src/servers/registrar/Referenceable.h +++ b/headers/private/shared/Referenceable.h @@ -1,24 +1,29 @@ -/* - * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. +/* + * Copyright 2004-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. * Distributed under the terms of the MIT License. */ +#ifndef _REFERENCEABLE_H +#define _REFERENCEABLE_H -#ifndef REFERENCABLE_H -#define REFERENCABLE_H #include -// Referenceable + +namespace BPrivate { + class Referenceable { public: Referenceable( - bool deleteWhenUnreferenced = false); + bool deleteWhenUnreferenced = true); virtual ~Referenceable(); - void AddReference(); + void AddReference() + { atomic_add(&fReferenceCount, 1); } + bool RemoveReference(); // returns true after last - int32 CountReferences() const; + int32 CountReferences() const + { return fReferenceCount; } protected: vint32 fReferenceCount; @@ -26,7 +31,7 @@ protected: }; // Reference -template +template class Reference { public: Reference() @@ -109,4 +114,9 @@ private: Type* fObject; }; -#endif // REFERENCABLE_H +} // namespace BPrivate + +using BPrivate::Referenceable; +using BPrivate::Reference; + +#endif // _REFERENCEABLE_H diff --git a/src/kits/support/Jamfile b/src/kits/support/Jamfile index 918032363b..c8970a9167 100644 --- a/src/kits/support/Jamfile +++ b/src/kits/support/Jamfile @@ -22,6 +22,7 @@ MergeObject support_kit.o : List.cpp Locker.cpp PointerList.cpp + Referenceable.cpp StopWatch.cpp String.cpp # StreamIO.cpp diff --git a/src/servers/registrar/Referenceable.cpp b/src/kits/support/Referenceable.cpp similarity index 60% rename from src/servers/registrar/Referenceable.cpp rename to src/kits/support/Referenceable.cpp index deada549e7..2bbd6ff7fd 100644 --- a/src/servers/registrar/Referenceable.cpp +++ b/src/kits/support/Referenceable.cpp @@ -1,10 +1,11 @@ -/* - * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. +/* + * Copyright 2005-2007, Ingo Weinhold, bonefish@users.sf.net. All rights reserved. * Distributed under the terms of the MIT License. */ -#include "Debug.h" -#include "Referenceable.h" + +#include + // constructor Referenceable::Referenceable(bool deleteWhenUnreferenced) @@ -18,13 +19,6 @@ Referenceable::~Referenceable() { } -// AddReference -void -Referenceable::AddReference() -{ - atomic_add(&fReferenceCount, 1); -} - // RemoveReference bool Referenceable::RemoveReference() @@ -34,11 +28,3 @@ Referenceable::RemoveReference() delete this; return unreferenced; } - -// CountReferences -int32 -Referenceable::CountReferences() const -{ - return fReferenceCount; -} - diff --git a/src/servers/registrar/Jamfile b/src/servers/registrar/Jamfile index 3f2cf549f2..3ac4b4a7b5 100644 --- a/src/servers/registrar/Jamfile +++ b/src/servers/registrar/Jamfile @@ -25,7 +25,6 @@ Server registrar PriorityMessageQueue.cpp RecentApps.cpp RecentEntries.cpp - Referenceable.cpp Registrar.cpp RosterAppInfo.cpp RosterSettingsCharStream.cpp