Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
objectref.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
18
#include "
core/refcounted.h
"
19
20
//------------------------------------------------------------------------------
21
namespace
Threading
22
{
23
class
ObjectRef
:
public
Core::RefCounted
24
{
25
__DeclareClass
(
ObjectRef
);
26
public
:
28
ObjectRef
();
30
virtual
~ObjectRef
();
31
33
bool
IsValid
()
const
;
35
template
<
class
TYPE>
void
Validate
(TYPE* obj);
37
void
Invalidate
();
39
template
<
class
TYPE> TYPE*
Ref
()
const
;
40
41
private
:
42
Core::RefCounted
*
volatile
ref
;
43
};
44
45
//------------------------------------------------------------------------------
48
inline
bool
49
ObjectRef::IsValid
()
const
50
{
51
return
(0 != this->
ref
);
52
}
53
54
//------------------------------------------------------------------------------
57
template
<
class
TYPE>
inline
void
58
ObjectRef::Validate
(TYPE* obj)
59
{
60
n_assert
(0 != obj);
61
n_assert
(obj->IsA(TYPE::RTTI));
62
n_assert
(0 == this->
ref
);
63
obj->AddRef();
64
Interlocked::ExchangePointer
((
void
*
volatile
*)&this->
ref
, obj);
65
}
66
67
//------------------------------------------------------------------------------
70
inline
void
71
ObjectRef::Invalidate
()
72
{
73
n_assert
(0 != this->
ref
);
74
this->
ref
->Release();
75
Interlocked::ExchangePointer
((
void
*
volatile
*)&this->
ref
, 0);
76
}
77
78
//------------------------------------------------------------------------------
81
template
<
class
TYPE>
inline
TYPE*
82
ObjectRef::Ref
()
const
83
{
84
n_assert
(0 != this->
ref
);
85
n_assert
(this->
ref
->IsA(TYPE::RTTI));
86
return
(TYPE*) this->
ref
;
87
}
88
89
}
// namespace Threading
90
//------------------------------------------------------------------------------
91
Core::RefCounted
The common base class of Nebula.
Definition
refcounted.h:38
Threading::ObjectRef::__DeclareClass
__DeclareClass(ObjectRef)
Threading::ObjectRef::IsValid
bool IsValid() const
return true if the ObjectRef points to a valid object
Definition
objectref.h:49
Threading::ObjectRef::Invalidate
void Invalidate()
invalidate the ref
Definition
objectref.h:71
Threading::ObjectRef::ObjectRef
ObjectRef()
constructor
Definition
objectref.cc:15
Threading::ObjectRef::Ref
TYPE * Ref() const
get pointer to object
Definition
objectref.h:82
Threading::ObjectRef::ref
Core::RefCounted *volatile ref
Definition
objectref.h:42
Threading::ObjectRef::Validate
void Validate(TYPE *obj)
validate the ref with a pointer to a target object (must be RefCounted)
Definition
objectref.h:58
Threading::ObjectRef::~ObjectRef
virtual ~ObjectRef()
destructor
Definition
objectref.cc:24
n_assert
#define n_assert(exp)
Definition
debug.h:50
Threading::Interlocked::ExchangePointer
void * ExchangePointer(void *volatile *dest, void *value)
interlocked exchange
Definition
gccinterlocked.cc:130
Threading
The Jobs2 system provides a set of threads and a pool of jobs from which threads can pickup work.
Definition
jobs2.h:16
refcounted.h
code
foundation
threading
objectref.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.