acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
util.h
1
#pragma once
2
3
6
template
<
typename
T,
typename
T2 >
class
observer
:
7
virtual
public
::array_particle < address_array_base < T * > >
8
{
9
public
:
10
11
12
using
base_type = address_array_base < T * >;
13
14
15
16
17
T2 * m_point2This;
18
19
virtual
~observer
()
20
{
21
22
for
(
auto
p : *
this
)
23
{
24
25
try
26
{
27
28
p->detach_observer(m_point2This);
29
30
}
31
catch
(...)
32
{
33
34
35
}
36
37
}
38
39
}
40
41
bool
attach_observer(T * p)
42
{
43
if
(this->contains(p))
44
return
false
;
45
this->add(p);
46
m_point2This =
dynamic_cast <
T2 *
>
(
this
);
47
p->attach_observer(m_point2This);
48
return
true
;
49
}
50
51
bool
detach_observer(T * p)
52
{
53
if
(!this->contains(p))
54
return
false
;
55
this->erase(p);
56
p->detach_observer(m_point2This);
57
return
true
;
58
}
59
60
};
61
62
65
class
CTimer
66
{
67
public
:
68
69
70
class ::time m_time;
71
72
73
CTimer() {
Restart
(); }
74
76
void
Restart
() { m_time.Now(); }
77
79
class ::time
GetElapsedTime
()
const
80
{
81
82
return
m_time.elapsed();
83
84
}
85
86
};
87
88
89
CTimer::Restart
void Restart()
Restarts the timer.
Definition
util.h:76
CTimer::GetElapsedTime
class::time GetElapsedTime() const
Get the elapsed time.
Definition
util.h:79
observer
Definition
util.h:8
prototype
prototype
util.h
Generated by
1.17.0