Rename to SharedObject

This commit is contained in:
Vinnie Falco
2013-07-11 15:01:56 -07:00
parent 17f93a3a8e
commit 1c1d9a9926
20 changed files with 185 additions and 186 deletions

View File

@@ -144,7 +144,7 @@
<ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryAlignment.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryAlignment.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryBlock.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_MemoryBlock.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_OptionalScopedPointer.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_OptionalScopedPointer.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_ReferenceCountedObject.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_SharedObject.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_ScopedPointer.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_ScopedPointer.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_SharedSingleton.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_SharedSingleton.h" />
<ClInclude Include="..\..\modules\beast_core\memory\beast_StaticObject.h" /> <ClInclude Include="..\..\modules\beast_core\memory\beast_StaticObject.h" />

View File

@@ -229,9 +229,6 @@
<ClInclude Include="..\..\modules\beast_core\memory\beast_OptionalScopedPointer.h"> <ClInclude Include="..\..\modules\beast_core\memory\beast_OptionalScopedPointer.h">
<Filter>beast_core\memory</Filter> <Filter>beast_core\memory</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\beast_ReferenceCountedObject.h">
<Filter>beast_core\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\beast_ScopedPointer.h"> <ClInclude Include="..\..\modules\beast_core\memory\beast_ScopedPointer.h">
<Filter>beast_core\memory</Filter> <Filter>beast_core\memory</Filter>
</ClInclude> </ClInclude>
@@ -608,6 +605,9 @@
<ClInclude Include="..\..\modules\beast_basics\events\beast_DeadlineTimer.h"> <ClInclude Include="..\..\modules\beast_basics\events\beast_DeadlineTimer.h">
<Filter>beast_basics\events</Filter> <Filter>beast_basics\events</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\memory\beast_SharedObject.h">
<Filter>beast_core\memory</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\modules\beast_core\beast_core.cpp"> <ClCompile Include="..\..\modules\beast_core\beast_core.cpp">

View File

@@ -112,7 +112,7 @@ private:
class Manager; class Manager;
Listener* const m_listener; Listener* const m_listener;
ReferenceCountedObjectPtr <Manager> m_manager; SharedObjectPtr <Manager> m_manager;
bool m_isActive; bool m_isActive;
Time m_notificationTime; Time m_notificationTime;
double m_secondsRecurring; // non zero if recurring double m_secondsRecurring; // non zero if recurring

View File

@@ -48,7 +48,7 @@ protected:
private: private:
class TimerSingleton; class TimerSingleton;
typedef ReferenceCountedObjectPtr <TimerSingleton> TimerPtr; typedef SharedObjectPtr <TimerSingleton> TimerPtr;
struct Elem : List <Elem>::Node struct Elem : List <Elem>::Node
{ {

View File

@@ -103,10 +103,10 @@ private:
// Each Entry holds a group and the current Call (which can be updated). // Each Entry holds a group and the current Call (which can be updated).
// //
struct ListenersBase::Proxy::Entry : Entries::Node, struct ListenersBase::Proxy::Entry : Entries::Node,
ReferenceCountedObject, SharedObject,
AllocatedBy <AllocatorType> AllocatedBy <AllocatorType>
{ {
typedef ReferenceCountedObjectPtr <Entry> Ptr; typedef SharedObjectPtr <Entry> Ptr;
explicit Entry (Group* g) explicit Entry (Group* g)
: group (g) : group (g)

View File

@@ -214,11 +214,11 @@ public:
typedef GlobalFifoFreeStore <ListenersBase> CallAllocatorType; typedef GlobalFifoFreeStore <ListenersBase> CallAllocatorType;
class Call : public ReferenceCountedObject, class Call : public SharedObject,
public AllocatedBy <CallAllocatorType> public AllocatedBy <CallAllocatorType>
{ {
public: public:
typedef ReferenceCountedObjectPtr <Call> Ptr; typedef SharedObjectPtr <Call> Ptr;
virtual void operator () (void* const listener) = 0; virtual void operator () (void* const listener) = 0;
}; };
@@ -238,11 +238,11 @@ private:
// Maintains a list of listeners registered on the same CallQueue // Maintains a list of listeners registered on the same CallQueue
// //
class Group : public Groups::Node, class Group : public Groups::Node,
public ReferenceCountedObject, public SharedObject,
public AllocatedBy <AllocatorType> public AllocatedBy <AllocatorType>
{ {
public: public:
typedef ReferenceCountedObjectPtr <Group> Ptr; typedef SharedObjectPtr <Group> Ptr;
explicit Group (CallQueue& callQueue); explicit Group (CallQueue& callQueue);
~Group (); ~Group ();

View File

@@ -20,9 +20,7 @@
#ifndef BEAST_SHAREDDATA_H_INCLUDED #ifndef BEAST_SHAREDDATA_H_INCLUDED
#define BEAST_SHAREDDATA_H_INCLUDED #define BEAST_SHAREDDATA_H_INCLUDED
/*============================================================================*/ /** Structured access to a shared state.
/**
Structured access to a shared state.
This template wraps an object containing members representing state This template wraps an object containing members representing state
information shared between multiple threads of execution, where any thread information shared between multiple threads of execution, where any thread
@@ -35,22 +33,23 @@
- ReadAccess - ReadAccess
Allows read access to the underlying object as `const`. ReadAccess may be Allows read access to the underlying object as `const`. ReadAccess may
granted to one or more threads simultaneously. If one or more threads have be granted to one or more threads simultaneously. If one or more
ReadAccess, requests to obtain WriteAccess are blocked. threads have ReadAccess, requests to obtain WriteAccess are blocked.
- WriteAccess - WriteAccess
Allows exclusive read/write access the underlying object. A WriteAccess Allows exclusive read/write access the underlying object. A WriteAccess
request blocks until all existing ReadAccess and WriteAccess requests are request blocks until all existing ReadAccess and WriteAccess requests
released. While a WriteAccess exists, requests for ReadAccess will block. are released. While a WriteAccess exists, requests for ReadAccess
will block.
- UnlockedAccess - UnlockedAccess
Allows read access to the underlying object without using the lock. This Allows read access to the underlying object without using the lock.
can be helpful when designing concurrent structures through composition. This can be helpful when designing concurrent structures through
It also makes it easier to search for places in code which use unlocked composition. It also makes it easier to search for places in code
access. which use unlocked access.
This code example demonstrates various forms of access to a SharedData: This code example demonstrates various forms of access to a SharedData:
@@ -109,9 +108,9 @@
@warning Recursive calls are not supported. It is generally not possible for @warning Recursive calls are not supported. It is generally not possible for
a thread of execution to acquire write access while it already has a thread of execution to acquire write access while it already has
read access. Such an attempt will result in undefined behavior. Calling into read access. Such an attempt will result in undefined behavior.
unknown code while holding a lock can cause deadlock. See Calling into unknown code while holding a lock can cause deadlock.
@ref CallQueue::queue(). See @ref CallQueue::queue().
*/ */
template <class Object> template <class Object>
class SharedData : Uncopyable class SharedData : Uncopyable

View File

@@ -255,7 +255,7 @@ namespace beast
#include "memory/beast_Memory.h" #include "memory/beast_Memory.h"
#include "memory/beast_MemoryBlock.h" #include "memory/beast_MemoryBlock.h"
#include "memory/beast_OptionalScopedPointer.h" #include "memory/beast_OptionalScopedPointer.h"
#include "memory/beast_ReferenceCountedObject.h" #include "memory/beast_SharedObject.h"
#include "memory/beast_ScopedPointer.h" #include "memory/beast_ScopedPointer.h"
#include "threads/beast_SpinLock.h" #include "threads/beast_SpinLock.h"
#include "memory/beast_SharedSingleton.h" #include "memory/beast_SharedSingleton.h"

View File

@@ -25,7 +25,7 @@
#define BEAST_DYNAMICOBJECT_BEASTHEADER #define BEAST_DYNAMICOBJECT_BEASTHEADER
#include "beast_NamedValueSet.h" #include "beast_NamedValueSet.h"
#include "../memory/beast_ReferenceCountedObject.h" #include "../memory/beast_SharedObject.h"
//============================================================================== //==============================================================================
@@ -40,7 +40,7 @@
methods. methods.
*/ */
class BEAST_API DynamicObject class BEAST_API DynamicObject
: public ReferenceCountedObject : public SharedObject
, LeakChecked <DynamicObject> , LeakChecked <DynamicObject>
{ {
public: public:
@@ -50,7 +50,7 @@ public:
/** Destructor. */ /** Destructor. */
virtual ~DynamicObject(); virtual ~DynamicObject();
typedef ReferenceCountedObjectPtr<DynamicObject> Ptr; typedef SharedObjectPtr<DynamicObject> Ptr;
//============================================================================== //==============================================================================
/** Returns true if the object has a property with this name. /** Returns true if the object has a property with this name.

View File

@@ -24,7 +24,7 @@
#ifndef BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER #ifndef BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER
#define BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER #define BEAST_REFERENCECOUNTEDARRAY_BEASTHEADER
#include "../memory/beast_ReferenceCountedObject.h" #include "../memory/beast_SharedObject.h"
#include "beast_ArrayAllocationBase.h" #include "beast_ArrayAllocationBase.h"
#include "beast_ElementComparator.h" #include "beast_ElementComparator.h"
#include "../threads/beast_CriticalSection.h" #include "../threads/beast_CriticalSection.h"
@@ -32,9 +32,9 @@
//============================================================================== //==============================================================================
/** /**
Holds a list of objects derived from ReferenceCountedObject. Holds a list of objects derived from SharedObject.
A ReferenceCountedArray holds objects derived from ReferenceCountedObject, A ReferenceCountedArray holds objects derived from SharedObject,
and takes care of incrementing and decrementing their ref counts when they and takes care of incrementing and decrementing their ref counts when they
are added and removed from the array. are added and removed from the array.
@@ -47,11 +47,11 @@ template <class ObjectClass, class TypeOfCriticalSectionToUse = DummyCriticalSec
class ReferenceCountedArray class ReferenceCountedArray
{ {
public: public:
typedef ReferenceCountedObjectPtr<ObjectClass> ObjectClassPtr; typedef SharedObjectPtr<ObjectClass> ObjectClassPtr;
//============================================================================== //==============================================================================
/** Creates an empty array. /** Creates an empty array.
@see ReferenceCountedObject, Array, OwnedArray @see SharedObject, Array, OwnedArray
*/ */
ReferenceCountedArray() noexcept ReferenceCountedArray() noexcept
: numUsed (0) : numUsed (0)

View File

@@ -156,10 +156,10 @@ public:
} }
private: private:
class Data : public ReferenceCountedObject class Data : public SharedObject
{ {
public: public:
typedef ReferenceCountedObjectPtr <Data> Ptr; typedef SharedObjectPtr <Data> Ptr;
explicit Data (int numEntries) explicit Data (int numEntries)
: m_numEntries (numEntries) : m_numEntries (numEntries)
@@ -200,7 +200,7 @@ private:
{ {
} }
ReferenceCountedObjectPtr <Data> m_data; SharedObjectPtr <Data> m_data;
}; };
template <class ElementType> template <class ElementType>

View File

@@ -45,7 +45,7 @@ public:
virtual double toDouble (const ValueUnion&) const noexcept { return 0; } virtual double toDouble (const ValueUnion&) const noexcept { return 0; }
virtual String toString (const ValueUnion&) const { return String::empty; } virtual String toString (const ValueUnion&) const { return String::empty; }
virtual bool toBool (const ValueUnion&) const noexcept { return false; } virtual bool toBool (const ValueUnion&) const noexcept { return false; }
virtual ReferenceCountedObject* toObject (const ValueUnion&) const noexcept { return nullptr; } virtual SharedObject* toObject (const ValueUnion&) const noexcept { return nullptr; }
virtual Array<var>* toArray (const ValueUnion&) const noexcept { return nullptr; } virtual Array<var>* toArray (const ValueUnion&) const noexcept { return nullptr; }
virtual MemoryBlock* toBinary (const ValueUnion&) const noexcept { return nullptr; } virtual MemoryBlock* toBinary (const ValueUnion&) const noexcept { return nullptr; }
@@ -243,7 +243,7 @@ public:
String toString (const ValueUnion& data) const { return "Object 0x" + String::toHexString ((int) (pointer_sized_int) data.objectValue); } String toString (const ValueUnion& data) const { return "Object 0x" + String::toHexString ((int) (pointer_sized_int) data.objectValue); }
bool toBool (const ValueUnion& data) const noexcept { return data.objectValue != 0; } bool toBool (const ValueUnion& data) const noexcept { return data.objectValue != 0; }
ReferenceCountedObject* toObject (const ValueUnion& data) const noexcept { return data.objectValue; } SharedObject* toObject (const ValueUnion& data) const noexcept { return data.objectValue; }
bool isObject() const noexcept { return true; } bool isObject() const noexcept { return true; }
bool equals (const ValueUnion& data, const ValueUnion& otherData, const VariantType& otherType) const noexcept bool equals (const ValueUnion& data, const ValueUnion& otherData, const VariantType& otherType) const noexcept
@@ -388,7 +388,7 @@ var::var (const wchar_t* const v) : type (&VariantType_String::instance) { n
var::var (const void* v, size_t sz) : type (&VariantType_Binary::instance) { value.binaryValue = new MemoryBlock (v, sz); } var::var (const void* v, size_t sz) : type (&VariantType_Binary::instance) { value.binaryValue = new MemoryBlock (v, sz); }
var::var (const MemoryBlock& v) : type (&VariantType_Binary::instance) { value.binaryValue = new MemoryBlock (v); } var::var (const MemoryBlock& v) : type (&VariantType_Binary::instance) { value.binaryValue = new MemoryBlock (v); }
var::var (ReferenceCountedObject* const object) : type (&VariantType_Object::instance) var::var (SharedObject* const object) : type (&VariantType_Object::instance)
{ {
value.objectValue = object; value.objectValue = object;
@@ -416,7 +416,7 @@ var::operator float() const noexcept { return (float) type->t
var::operator double() const noexcept { return type->toDouble (value); } var::operator double() const noexcept { return type->toDouble (value); }
String var::toString() const { return type->toString (value); } String var::toString() const { return type->toString (value); }
var::operator String() const { return type->toString (value); } var::operator String() const { return type->toString (value); }
ReferenceCountedObject* var::getObject() const noexcept { return type->toObject (value); } SharedObject* var::getObject() const noexcept { return type->toObject (value); }
Array<var>* var::getArray() const noexcept { return type->toArray (value); } Array<var>* var::getArray() const noexcept { return type->toArray (value); }
MemoryBlock* var::getBinaryData() const noexcept { return type->toBinary (value); } MemoryBlock* var::getBinaryData() const noexcept { return type->toBinary (value); }
DynamicObject* var::getDynamicObject() const noexcept { return dynamic_cast <DynamicObject*> (getObject()); } DynamicObject* var::getDynamicObject() const noexcept { return dynamic_cast <DynamicObject*> (getObject()); }
@@ -437,7 +437,7 @@ var& var::operator= (const char* const v) { type->cleanUp (value); type =
var& var::operator= (const wchar_t* const v) { type->cleanUp (value); type = &VariantType_String::instance; new (value.stringValue) String (v); return *this; } var& var::operator= (const wchar_t* const v) { type->cleanUp (value); type = &VariantType_String::instance; new (value.stringValue) String (v); return *this; }
var& var::operator= (const String& v) { type->cleanUp (value); type = &VariantType_String::instance; new (value.stringValue) String (v); return *this; } var& var::operator= (const String& v) { type->cleanUp (value); type = &VariantType_String::instance; new (value.stringValue) String (v); return *this; }
var& var::operator= (const Array<var>& v) { var v2 (v); swapWith (v2); return *this; } var& var::operator= (const Array<var>& v) { var v2 (v); swapWith (v2); return *this; }
var& var::operator= (ReferenceCountedObject* v) { var v2 (v); swapWith (v2); return *this; } var& var::operator= (SharedObject* v) { var v2 (v); swapWith (v2); return *this; }
var& var::operator= (MethodFunction v) { var v2 (v); swapWith (v2); return *this; } var& var::operator= (MethodFunction v) { var v2 (v); swapWith (v2); return *this; }
#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS

View File

@@ -30,7 +30,7 @@
#include "../containers/beast_Array.h" #include "../containers/beast_Array.h"
#ifndef DOXYGEN #ifndef DOXYGEN
class ReferenceCountedObject; class SharedObject;
class DynamicObject; class DynamicObject;
#endif #endif
@@ -39,7 +39,7 @@
A variant class, that can be used to hold a range of primitive values. A variant class, that can be used to hold a range of primitive values.
A var object can hold a range of simple primitive values, strings, or A var object can hold a range of simple primitive values, strings, or
any kind of ReferenceCountedObject. The var class is intended to act like any kind of SharedObject. The var class is intended to act like
the kind of values used in dynamic scripting languages. the kind of values used in dynamic scripting languages.
You can save/load var objects either in a small, proprietary binary format You can save/load var objects either in a small, proprietary binary format
@@ -73,7 +73,7 @@ public:
var (const wchar_t* value); var (const wchar_t* value);
var (const String& value); var (const String& value);
var (const Array<var>& value); var (const Array<var>& value);
var (ReferenceCountedObject* object); var (SharedObject* object);
var (MethodFunction method) noexcept; var (MethodFunction method) noexcept;
var (const void* binaryData, size_t dataSize); var (const void* binaryData, size_t dataSize);
var (const MemoryBlock& binaryData); var (const MemoryBlock& binaryData);
@@ -87,7 +87,7 @@ public:
var& operator= (const wchar_t* value); var& operator= (const wchar_t* value);
var& operator= (const String& value); var& operator= (const String& value);
var& operator= (const Array<var>& value); var& operator= (const Array<var>& value);
var& operator= (ReferenceCountedObject* object); var& operator= (SharedObject* object);
var& operator= (MethodFunction method); var& operator= (MethodFunction method);
#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS
@@ -125,7 +125,7 @@ public:
*/ */
MemoryBlock* getBinaryData() const noexcept; MemoryBlock* getBinaryData() const noexcept;
ReferenceCountedObject* getObject() const noexcept; SharedObject* getObject() const noexcept;
DynamicObject* getDynamicObject() const noexcept; DynamicObject* getDynamicObject() const noexcept;
//============================================================================== //==============================================================================
@@ -275,7 +275,7 @@ private:
bool boolValue; bool boolValue;
double doubleValue; double doubleValue;
char stringValue [sizeof (String)]; char stringValue [sizeof (String)];
ReferenceCountedObject* objectValue; SharedObject* objectValue;
Array<var>* arrayValue; Array<var>* arrayValue;
MemoryBlock* binaryValue; MemoryBlock* binaryValue;
MethodFunction methodValue; MethodFunction methodValue;

View File

@@ -78,7 +78,7 @@ void LeakCheckedBase::CounterBase::checkForLeaks ()
If you're leaking, it's probably because you're using old-fashioned, If you're leaking, it's probably because you're using old-fashioned,
non-RAII techniques for your object management. Tut, tut. Always, non-RAII techniques for your object management. Tut, tut. Always,
always use ScopedPointers, OwnedArrays, ReferenceCountedObjects, always use ScopedPointers, OwnedArrays, SharedObjects,
etc, and avoid the 'delete' operator at all costs! etc, and avoid the 'delete' operator at all costs!
*/ */
DBG ("Leaked objects: " << count << " of " << getClassName ()); DBG ("Leaked objects: " << count << " of " << getClassName ());
@@ -104,7 +104,7 @@ void LeakCheckedBase::reportDanglingPointer (char const* objectName)
Most errors like this are caused by using old-fashioned, Most errors like this are caused by using old-fashioned,
non-RAII techniques for your object management. Tut, tut. non-RAII techniques for your object management. Tut, tut.
Always, always use ScopedPointers, OwnedArrays, Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator SharedObjects, etc, and avoid the 'delete' operator
at all costs! at all costs!
*/ */
DBG ("Dangling pointer deletion: " << objectName); DBG ("Dangling pointer deletion: " << objectName);

View File

@@ -22,7 +22,7 @@
//============================================================================== //==============================================================================
class Expression::Term class Expression::Term
: public SingleThreadedReferenceCountedObject : public SingleThreadedSharedObject
{ {
public: public:
Term() {} Term() {}
@@ -30,20 +30,20 @@ public:
virtual Type getType() const noexcept = 0; virtual Type getType() const noexcept = 0;
virtual Term* clone() const = 0; virtual Term* clone() const = 0;
virtual ReferenceCountedObjectPtr<Term> resolve (const Scope&, int recursionDepth) = 0; virtual SharedObjectPtr<Term> resolve (const Scope&, int recursionDepth) = 0;
virtual String toString() const = 0; virtual String toString() const = 0;
virtual double toDouble() const { return 0; } virtual double toDouble() const { return 0; }
virtual int getInputIndexFor (const Term*) const { return -1; } virtual int getInputIndexFor (const Term*) const { return -1; }
virtual int getOperatorPrecedence() const { return 0; } virtual int getOperatorPrecedence() const { return 0; }
virtual int getNumInputs() const { return 0; } virtual int getNumInputs() const { return 0; }
virtual Term* getInput (int) const { return nullptr; } virtual Term* getInput (int) const { return nullptr; }
virtual ReferenceCountedObjectPtr<Term> negated(); virtual SharedObjectPtr<Term> negated();
virtual ReferenceCountedObjectPtr<Term> createTermToEvaluateInput (const Scope&, const Term* /*inputTerm*/, virtual SharedObjectPtr<Term> createTermToEvaluateInput (const Scope&, const Term* /*inputTerm*/,
double /*overallTarget*/, Term* /*topLevelTerm*/) const double /*overallTarget*/, Term* /*topLevelTerm*/) const
{ {
bassertfalse; bassertfalse;
return ReferenceCountedObjectPtr<Term>(); return SharedObjectPtr<Term>();
} }
virtual String getName() const virtual String getName() const
@@ -76,7 +76,7 @@ public:
//============================================================================== //==============================================================================
struct Expression::Helpers struct Expression::Helpers
{ {
typedef ReferenceCountedObjectPtr<Term> TermPtr; typedef SharedObjectPtr<Term> TermPtr;
static void checkRecursionDepth (const int depth) static void checkRecursionDepth (const int depth)
{ {
@@ -929,13 +929,13 @@ Expression& Expression::operator= (const Expression& other)
#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS
Expression::Expression (Expression&& other) noexcept Expression::Expression (Expression&& other) noexcept
: term (static_cast <ReferenceCountedObjectPtr<Term>&&> (other.term)) : term (static_cast <SharedObjectPtr<Term>&&> (other.term))
{ {
} }
Expression& Expression::operator= (Expression&& other) noexcept Expression& Expression::operator= (Expression&& other) noexcept
{ {
term = static_cast <ReferenceCountedObjectPtr<Term>&&> (other.term); term = static_cast <SharedObjectPtr<Term>&&> (other.term);
return *this; return *this;
} }
#endif #endif
@@ -1077,7 +1077,7 @@ int Expression::getNumInputs() const { return term->getNumInp
Expression Expression::getInput (int index) const { return Expression (term->getInput (index)); } Expression Expression::getInput (int index) const { return Expression (term->getInput (index)); }
//============================================================================== //==============================================================================
ReferenceCountedObjectPtr<Expression::Term> Expression::Term::negated() SharedObjectPtr<Expression::Term> Expression::Term::negated()
{ {
return new Helpers::Negate (this); return new Helpers::Negate (this);
} }

View File

@@ -24,7 +24,7 @@
#ifndef BEAST_EXPRESSION_BEASTHEADER #ifndef BEAST_EXPRESSION_BEASTHEADER
#define BEAST_EXPRESSION_BEASTHEADER #define BEAST_EXPRESSION_BEASTHEADER
#include "../memory/beast_ReferenceCountedObject.h" #include "../memory/beast_SharedObject.h"
#include "../containers/beast_Array.h" #include "../containers/beast_Array.h"
#include "../memory/beast_ScopedPointer.h" #include "../memory/beast_ScopedPointer.h"
@@ -260,8 +260,8 @@ private:
friend class Term; friend class Term;
friend struct Helpers; friend struct Helpers;
friend class ScopedPointer<Term>; friend class ScopedPointer<Term>;
friend class ReferenceCountedObjectPtr<Term>; friend class SharedObjectPtr<Term>;
ReferenceCountedObjectPtr<Term> term; SharedObjectPtr<Term> term;
explicit Expression (Term*); explicit Expression (Term*);
}; };

View File

@@ -32,16 +32,16 @@
Adds reference-counting to an object. Adds reference-counting to an object.
To add reference-counting to a class, derive it from this class, and To add reference-counting to a class, derive it from this class, and
use the ReferenceCountedObjectPtr class to point to it. use the SharedObjectPtr class to point to it.
e.g. @code e.g. @code
class MyClass : public ReferenceCountedObject class MyClass : public SharedObject
{ {
void foo(); void foo();
// This is a neat way of declaring a typedef for a pointer class, // This is a neat way of declaring a typedef for a pointer class,
// rather than typing out the full templated name each time.. // rather than typing out the full templated name each time..
typedef ReferenceCountedObjectPtr<MyClass> Ptr; typedef SharedObjectPtr<MyClass> Ptr;
}; };
MyClass::Ptr p = new MyClass(); MyClass::Ptr p = new MyClass();
@@ -50,16 +50,16 @@
p2->foo(); p2->foo();
@endcode @endcode
Once a new ReferenceCountedObject has been assigned to a pointer, be Once a new SharedObject has been assigned to a pointer, be
careful not to delete the object manually. careful not to delete the object manually.
This class uses an Atomic<int> value to hold the reference count, so that it This class uses an Atomic<int> value to hold the reference count, so that it
the pointers can be passed between threads safely. For a faster but non-thread-safe the pointers can be passed between threads safely. For a faster but non-thread-safe
version, use SingleThreadedReferenceCountedObject instead. version, use SingleThreadedSharedObject instead.
@see ReferenceCountedObjectPtr, ReferenceCountedArray, SingleThreadedReferenceCountedObject @see SharedObjectPtr, ReferenceCountedArray, SingleThreadedSharedObject
*/ */
class BEAST_API ReferenceCountedObject : Uncopyable class BEAST_API SharedObject : Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -92,12 +92,12 @@ public:
protected: protected:
//============================================================================== //==============================================================================
/** Creates the reference-counted object (with an initial ref count of zero). */ /** Creates the reference-counted object (with an initial ref count of zero). */
ReferenceCountedObject() SharedObject()
{ {
} }
/** Destructor. */ /** Destructor. */
virtual ~ReferenceCountedObject() virtual ~SharedObject()
{ {
// it's dangerous to delete an object that's still referenced by something else! // it's dangerous to delete an object that's still referenced by something else!
bassert (getReferenceCount() == 0); bassert (getReferenceCount() == 0);
@@ -121,14 +121,14 @@ private:
/** /**
Adds reference-counting to an object. Adds reference-counting to an object.
This is effectively a version of the ReferenceCountedObject class, but which This is effectively a version of the SharedObject class, but which
uses a non-atomic counter, and so is not thread-safe (but which will be more uses a non-atomic counter, and so is not thread-safe (but which will be more
efficient). efficient).
For more details on how to use it, see the ReferenceCountedObject class notes. For more details on how to use it, see the SharedObject class notes.
@see ReferenceCountedObject, ReferenceCountedObjectPtr, ReferenceCountedArray @see SharedObject, SharedObjectPtr, ReferenceCountedArray
*/ */
class BEAST_API SingleThreadedReferenceCountedObject : public Uncopyable class BEAST_API SingleThreadedSharedObject : public Uncopyable
{ {
public: public:
//============================================================================== //==============================================================================
@@ -161,10 +161,10 @@ public:
protected: protected:
//============================================================================== //==============================================================================
/** Creates the reference-counted object (with an initial ref count of zero). */ /** Creates the reference-counted object (with an initial ref count of zero). */
SingleThreadedReferenceCountedObject() : refCount (0) {} SingleThreadedSharedObject() : refCount (0) {}
/** Destructor. */ /** Destructor. */
virtual ~SingleThreadedReferenceCountedObject() virtual ~SingleThreadedSharedObject()
{ {
// it's dangerous to delete an object that's still referenced by something else! // it's dangerous to delete an object that's still referenced by something else!
bassert (getReferenceCount() == 0); bassert (getReferenceCount() == 0);
@@ -181,26 +181,26 @@ private:
A smart-pointer class which points to a reference-counted object. A smart-pointer class which points to a reference-counted object.
The template parameter specifies the class of the object you want to point to - the easiest The template parameter specifies the class of the object you want to point to - the easiest
way to make a class reference-countable is to simply make it inherit from ReferenceCountedObject, way to make a class reference-countable is to simply make it inherit from SharedObject,
but if you need to, you could roll your own reference-countable class by implementing a pair of but if you need to, you could roll your own reference-countable class by implementing a pair of
mathods called incReferenceCount() and decReferenceCount(). mathods called incReferenceCount() and decReferenceCount().
When using this class, you'll probably want to create a typedef to abbreviate the full When using this class, you'll probably want to create a typedef to abbreviate the full
templated name - e.g. templated name - e.g.
@code typedef ReferenceCountedObjectPtr<MyClass> MyClassPtr;@endcode @code typedef SharedObjectPtr<MyClass> MyClassPtr;@endcode
@see ReferenceCountedObject, ReferenceCountedObjectArray @see SharedObject, SharedObjectArray
*/ */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
class ReferenceCountedObjectPtr class SharedObjectPtr
{ {
public: public:
/** The class being referenced by this pointer. */ /** The class being referenced by this pointer. */
typedef ReferenceCountedObjectClass ReferencedType; typedef SharedObjectClass ReferencedType;
//============================================================================== //==============================================================================
/** Creates a pointer to a null object. */ /** Creates a pointer to a null object. */
inline ReferenceCountedObjectPtr() noexcept inline SharedObjectPtr() noexcept
: referencedObject (nullptr) : referencedObject (nullptr)
{ {
} }
@@ -209,7 +209,7 @@ public:
This will increment the object's reference-count if it is non-null. This will increment the object's reference-count if it is non-null.
*/ */
inline ReferenceCountedObjectPtr (ReferenceCountedObjectClass* const refCountedObject) noexcept inline SharedObjectPtr (SharedObjectClass* const refCountedObject) noexcept
: referencedObject (refCountedObject) : referencedObject (refCountedObject)
{ {
if (refCountedObject != nullptr) if (refCountedObject != nullptr)
@@ -219,7 +219,7 @@ public:
/** Copies another pointer. /** Copies another pointer.
This will increment the object's reference-count (if it is non-null). This will increment the object's reference-count (if it is non-null).
*/ */
inline ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr& other) noexcept inline SharedObjectPtr (const SharedObjectPtr& other) noexcept
: referencedObject (other.referencedObject) : referencedObject (other.referencedObject)
{ {
if (referencedObject != nullptr) if (referencedObject != nullptr)
@@ -228,7 +228,7 @@ public:
#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS
/** Takes-over the object from another pointer. */ /** Takes-over the object from another pointer. */
inline ReferenceCountedObjectPtr (ReferenceCountedObjectPtr&& other) noexcept inline SharedObjectPtr (SharedObjectPtr&& other) noexcept
: referencedObject (other.referencedObject) : referencedObject (other.referencedObject)
{ {
other.referencedObject = nullptr; other.referencedObject = nullptr;
@@ -239,8 +239,8 @@ public:
This will increment the object's reference-count (if it is non-null). This will increment the object's reference-count (if it is non-null).
*/ */
template <class DerivedClass> template <class DerivedClass>
inline ReferenceCountedObjectPtr (const ReferenceCountedObjectPtr<DerivedClass>& other) noexcept inline SharedObjectPtr (const SharedObjectPtr<DerivedClass>& other) noexcept
: referencedObject (static_cast <ReferenceCountedObjectClass*> (other.get())) : referencedObject (static_cast <SharedObjectClass*> (other.get()))
{ {
if (referencedObject != nullptr) if (referencedObject != nullptr)
referencedObject->incReferenceCount(); referencedObject->incReferenceCount();
@@ -251,7 +251,7 @@ public:
The reference count of the old object is decremented, and it might be The reference count of the old object is decremented, and it might be
deleted if it hits zero. The new object's count is incremented. deleted if it hits zero. The new object's count is incremented.
*/ */
ReferenceCountedObjectPtr& operator= (const ReferenceCountedObjectPtr& other) SharedObjectPtr& operator= (const SharedObjectPtr& other)
{ {
return operator= (other.referencedObject); return operator= (other.referencedObject);
} }
@@ -262,14 +262,14 @@ public:
deleted if it hits zero. The new object's count is incremented. deleted if it hits zero. The new object's count is incremented.
*/ */
template <class DerivedClass> template <class DerivedClass>
ReferenceCountedObjectPtr& operator= (const ReferenceCountedObjectPtr<DerivedClass>& other) SharedObjectPtr& operator= (const SharedObjectPtr<DerivedClass>& other)
{ {
return operator= (static_cast <ReferenceCountedObjectClass*> (other.get())); return operator= (static_cast <SharedObjectClass*> (other.get()));
} }
#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS #if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS
/** Takes-over the object from another pointer. */ /** Takes-over the object from another pointer. */
ReferenceCountedObjectPtr& operator= (ReferenceCountedObjectPtr&& other) SharedObjectPtr& operator= (SharedObjectPtr&& other)
{ {
std::swap (referencedObject, other.referencedObject); std::swap (referencedObject, other.referencedObject);
return *this; return *this;
@@ -281,14 +281,14 @@ public:
The reference count of the old object is decremented, and it might be The reference count of the old object is decremented, and it might be
deleted if it hits zero. The new object's count is incremented. deleted if it hits zero. The new object's count is incremented.
*/ */
ReferenceCountedObjectPtr& operator= (ReferenceCountedObjectClass* const newObject) SharedObjectPtr& operator= (SharedObjectClass* const newObject)
{ {
if (referencedObject != newObject) if (referencedObject != newObject)
{ {
if (newObject != nullptr) if (newObject != nullptr)
newObject->incReferenceCount(); newObject->incReferenceCount();
ReferenceCountedObjectClass* const oldObject = referencedObject; SharedObjectClass* const oldObject = referencedObject;
referencedObject = newObject; referencedObject = newObject;
if (oldObject != nullptr) if (oldObject != nullptr)
@@ -303,7 +303,7 @@ public:
This will decrement the object's reference-count, and may delete it if it This will decrement the object's reference-count, and may delete it if it
gets to zero. gets to zero.
*/ */
inline ~ReferenceCountedObjectPtr() inline ~SharedObjectPtr()
{ {
if (referencedObject != nullptr) if (referencedObject != nullptr)
referencedObject->decReferenceCount(); referencedObject->decReferenceCount();
@@ -312,13 +312,13 @@ public:
/** Returns the object that this pointer references. /** Returns the object that this pointer references.
The pointer returned may be zero, of course. The pointer returned may be zero, of course.
*/ */
inline operator ReferenceCountedObjectClass*() const noexcept inline operator SharedObjectClass*() const noexcept
{ {
return referencedObject; return referencedObject;
} }
// the -> operator is called on the referenced object // the -> operator is called on the referenced object
inline ReferenceCountedObjectClass* operator->() const noexcept inline SharedObjectClass* operator->() const noexcept
{ {
return referencedObject; return referencedObject;
} }
@@ -326,7 +326,7 @@ public:
/** Returns the object that this pointer references. /** Returns the object that this pointer references.
The pointer returned may be zero, of course. The pointer returned may be zero, of course.
*/ */
inline ReferenceCountedObjectClass* get() const noexcept inline SharedObjectClass* get() const noexcept
{ {
return referencedObject; return referencedObject;
} }
@@ -334,55 +334,55 @@ public:
/** Returns the object that this pointer references. /** Returns the object that this pointer references.
The pointer returned may be zero, of course. The pointer returned may be zero, of course.
*/ */
inline ReferenceCountedObjectClass* getObject() const noexcept inline SharedObjectClass* getObject() const noexcept
{ {
return referencedObject; return referencedObject;
} }
private: private:
//============================================================================== //==============================================================================
ReferenceCountedObjectClass* referencedObject; SharedObjectClass* referencedObject;
}; };
/** Compares two ReferenceCountedObjectPointers. */ /** Compares two SharedObjectPointers. */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
bool operator== (const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object1, ReferenceCountedObjectClass* const object2) noexcept bool operator== (const SharedObjectPtr<SharedObjectClass>& object1, SharedObjectClass* const object2) noexcept
{ {
return object1.get() == object2; return object1.get() == object2;
} }
/** Compares two ReferenceCountedObjectPointers. */ /** Compares two SharedObjectPointers. */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
bool operator== (const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object1, const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object2) noexcept bool operator== (const SharedObjectPtr<SharedObjectClass>& object1, const SharedObjectPtr<SharedObjectClass>& object2) noexcept
{ {
return object1.get() == object2.get(); return object1.get() == object2.get();
} }
/** Compares two ReferenceCountedObjectPointers. */ /** Compares two SharedObjectPointers. */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
bool operator== (ReferenceCountedObjectClass* object1, ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object2) noexcept bool operator== (SharedObjectClass* object1, SharedObjectPtr<SharedObjectClass>& object2) noexcept
{ {
return object1 == object2.get(); return object1 == object2.get();
} }
/** Compares two ReferenceCountedObjectPointers. */ /** Compares two SharedObjectPointers. */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
bool operator!= (const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object1, const ReferenceCountedObjectClass* object2) noexcept bool operator!= (const SharedObjectPtr<SharedObjectClass>& object1, const SharedObjectClass* object2) noexcept
{ {
return object1.get() != object2; return object1.get() != object2;
} }
/** Compares two ReferenceCountedObjectPointers. */ /** Compares two SharedObjectPointers. */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
bool operator!= (const ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object1, ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object2) noexcept bool operator!= (const SharedObjectPtr<SharedObjectClass>& object1, SharedObjectPtr<SharedObjectClass>& object2) noexcept
{ {
return object1.get() != object2.get(); return object1.get() != object2.get();
} }
/** Compares two ReferenceCountedObjectPointers. */ /** Compares two SharedObjectPointers. */
template <class ReferenceCountedObjectClass> template <class SharedObjectClass>
bool operator!= (ReferenceCountedObjectClass* object1, ReferenceCountedObjectPtr<ReferenceCountedObjectClass>& object2) noexcept bool operator!= (SharedObjectClass* object1, SharedObjectPtr<SharedObjectClass>& object2) noexcept
{ {
return object1 != object2.get(); return object1 != object2.get();
} }

View File

@@ -107,7 +107,7 @@ protected:
} }
public: public:
typedef ReferenceCountedObjectPtr <Object> Ptr; typedef SharedObjectPtr <Object> Ptr;
/** Retrieve a reference to the singleton. /** Retrieve a reference to the singleton.
*/ */

View File

@@ -24,7 +24,7 @@
#ifndef BEAST_WEAKREFERENCE_BEASTHEADER #ifndef BEAST_WEAKREFERENCE_BEASTHEADER
#define BEAST_WEAKREFERENCE_BEASTHEADER #define BEAST_WEAKREFERENCE_BEASTHEADER
#include "beast_ReferenceCountedObject.h" #include "beast_SharedObject.h"
//============================================================================== //==============================================================================
@@ -75,7 +75,7 @@
@see WeakReference::Master @see WeakReference::Master
*/ */
template <class ObjectType, class ReferenceCountingType = ReferenceCountedObject> template <class ObjectType, class ReferenceCountingType = SharedObject>
class WeakReference class WeakReference
{ {
public: public:
@@ -142,7 +142,7 @@ public:
ObjectType* volatile owner; ObjectType* volatile owner;
}; };
typedef ReferenceCountedObjectPtr<SharedPointer> SharedRef; typedef SharedObjectPtr<SharedPointer> SharedRef;
//============================================================================== //==============================================================================
/** /**

View File

@@ -48,11 +48,11 @@ Thread::~Thread()
//============================================================================== //==============================================================================
// Use a ref-counted object to hold this shared data, so that it can outlive its static // Use a ref-counted object to hold this shared data, so that it can outlive its static
// shared pointer when threads are still running during static shutdown. // shared pointer when threads are still running during static shutdown.
struct CurrentThreadHolder : public ReferenceCountedObject struct CurrentThreadHolder : public SharedObject
{ {
CurrentThreadHolder() noexcept {} CurrentThreadHolder() noexcept {}
typedef ReferenceCountedObjectPtr <CurrentThreadHolder> Ptr; typedef SharedObjectPtr <CurrentThreadHolder> Ptr;
ThreadLocalValue<Thread*> value; ThreadLocalValue<Thread*> value;
}; };