instance_ptr.cpp
Go to the documentation of this file.
1 #include "instance_ptr.hpp"
2 #include "Instance.hpp"
3 
4 namespace iv
5 {
6 
8 {
9  inst->instance_pointers.insert( this );
10 }
12 {
13  inst->instance_pointers.erase( this );
14 }
15 
17  inst( instance )
18 {
19  if( this->inst )
20  this->addSelfToSC( this->inst );
21 }
22 
24  inst( other.inst )
25 {
26  if( this->inst )
27  this->addSelfToSC( this->inst );
28 }
29 
31 {
32  if( this->inst )
33  this->removeSelfFromSC( this->inst );
34 }
35 
37 {
38  if( this->inst == other.inst )
39  return *this;
40 
41  if( this->inst )
42  this->removeSelfFromSC( this->inst );
43 
44  this->inst = other.inst;
45 
46  if( this->inst )
47  this->addSelfToSC( this->inst );
48 
49  return *this;
50 }
51 
53 {
54  if( this->inst == instance )
55  return *this;
56 
57  if( this->inst )
58  this->removeSelfFromSC( this->inst );
59 
60  this->inst = instance;
61 
62  if( this->inst )
63  this->addSelfToSC( this->inst );
64 
65  return *this;
66 }
67 
69 {
70  return this->inst == other.inst;
71 }
72 
74 {
75  return this->inst != other.inst;
76 }
77 
79 {
80  return this->inst < other.inst;
81 }
82 
84 {
85  return this->inst > other.inst;
86 }
87 
89 {
90  return this->inst <= other.inst;
91 }
92 
94 {
95  return this->inst >= other.inst;
96 }
97 
99 {
100  return this->inst;
101 }
102 
104 {
105  return *this->inst;
106 }
107 
109 {
110  return this->inst;
111 }
112 
113 instance_ptr::operator bool() const
114 {
115  return this->inst;
116 }
117 
119 {
120  this->inst = nullptr;
121 }
122 
123 
125 {
126  ( instance_ptr & )( *this ) = ( instance_ptr const & )other;
127  if( this->_change_callback )
128  this->_change_callback();
129  return *this;
130 }
131 
133 {
134  ( instance_ptr & )( *this ) = instance;
135  if( this->_change_callback )
136  this->_change_callback();
137  return *this;
138 }
139 
140 void callback_instance_ptr::set_change_callback( std::function< void() > const & cb )
141 {
142  this->_change_callback = cb;
143 }
144 
146 {
147  instance_ptr::invalidate( inst );
148  if( this->_change_callback )
149  this->_change_callback();
150 }
151 
152 }