70 { Pointer =
new int; }
114 template <
class Handle>
123 void Copy(Handle& StatefulHandle)
125 if(StatefulHandle.GetPointer()!=Target.GetPointer())
127 Target.Deconstruct();
128 Target=StatefulHandle;
129 Invalidate(StatefulHandle);
135 static void Invalidate(Handle& StatefulHandle)
136 { StatefulHandle.SetPointer(NULL); }
139 { Invalidate(Target); }
154 : Target( StatefulHandle )
166 Other.Target.SetPointer(NULL);
185 TargetPtrType Results=Target.GetPointer();
196 TargetPtrType Results=Target.GetPointer();
207 {
return Target.GetPointer(); }
217 {
return 0 != Target.GetPointer(); }
223 {
return Target.GetPointer() == Other.Target.GetPointer(); }
228 Target.Deconstruct();
229 Target.SetPointer(NULL);
236 #endif // Include guard
void SetPointer(TargetPtrType Value)
This is what ManagedPtr will use in copy and assignment operations as well as invaliding handles...
Handle::TargetType TargetType
Used to set the value and reference type for returns.
TargetPtrType Pointer
The ManagedPtr never access objects directly, so this is just an implementation detail.
bool Boole
Generally acts a single bit, true or false.
void Construct()
This is expected to leave Pointer in some valid state for dereferencing.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
All the definitions for datatypes as well as some basic conversion functions are defined here...
int * TargetPtrType
This is type ManagedPtr will use to work with a handle.
int TargetType
The Type this handle is pointer at.
TargetType & operator*()
Dereference operator.
Handle::TargetPtrType TargetPtrType
Used to set the return type of pointer like returns (could be a smartpointer)
This implements the exception hiearchy for Mezzanine.
This is used to get RAII semantics when not provided inherently.
void Deconstruct()
This can perform any cleanup, but should not fail if Pointer is NULL.
TargetPtrType GetPointer()
This is what the ManagedPtr with use for dereferencing.
TargetPtrType operator->()
The Structure dereference operator.
Sample implementation for a ManagedPtr.
The bulk of the engine components go in this namspace.
ManagedPtr(Handle StatefulHandle=Handle())
Constructs the target after passing it the desired state information.
~ManagedPtr()
Destroy the target and invalidate it.
TargetPtrType Get()
Get the raw pointer to the managed object.
ManagedPtr(ManagedPtr &Other)
Creates the Target from an already constructed one but invalidates Other ManagedPtr.
Thrown when an unknown memory management exception occurs.