Toggle navigation
ivorium
iv_components
Example project
GitHub
Main Page
Modules
Classes
Files
File List
File Members
ivorium_core
Instancing
instance_ptr.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <functional>
4
5
namespace
iv
6
{
7
8
class
Instance;
9
13
class
instance_ptr_interface
14
{
15
friend
class
Instance
;
16
protected
:
17
virtual
void
invalidate
(
Instance
* inst ) = 0;
18
void
addSelfToSC
(
Instance
* inst );
19
void
removeSelfFromSC
(
Instance
* inst );
20
};
21
24
class
instance_ptr
:
public
instance_ptr_interface
25
{
26
public
:
27
instance_ptr
(
Instance
* inst =
nullptr
);
28
instance_ptr
(
instance_ptr
const
& other );
29
~instance_ptr
( );
30
31
instance_ptr
&
operator =
(
instance_ptr
const
& other );
32
instance_ptr
&
operator =
(
Instance
* instance );
33
34
35
bool
operator ==
(
instance_ptr
const
& other );
36
bool
operator !=
(
instance_ptr
const
& other );
37
bool
operator <
(
instance_ptr
const
& other );
38
bool
operator >
(
instance_ptr
const
& other );
39
bool
operator <=
(
instance_ptr
const
& other );
40
bool
operator >=
(
instance_ptr
const
& other );
41
42
Instance
*
get
( )
const
;
43
Instance
&
operator *
( )
const
;
44
Instance
*
operator ->
( )
const
;
45
operator
bool ( )
const
;
46
47
protected
:
48
virtual
void
invalidate
(
Instance
* inst )
override
;
49
50
private
:
51
Instance
* inst;
52
53
};
54
55
56
61
class
callback_instance_ptr
:
public
instance_ptr
62
{
63
public
:
64
using
instance_ptr::instance_ptr
;
65
66
callback_instance_ptr
&
operator=
(
callback_instance_ptr
const
& other );
67
callback_instance_ptr
&
operator=
(
Instance
* instance );
68
69
void
set_change_callback
( std::function<
void
() >
const
& );
70
71
protected
:
72
virtual
void
invalidate
(
Instance
* inst )
override
;
73
74
private
:
75
std::function< void() > _change_callback;
76
};
77
78
79
}
80
81
namespace
std
82
{
83
template
<>
84
struct
hash<
iv
::instance_ptr >
85
{
86
size_t
operator()
(
iv::instance_ptr
const
& v )
const
87
{
88
return
std::hash< iv::Instance * >()( v.
get
() );
89
}
90
};
91
}