1 | /*
|
---|
2 | * Zombie.hpp
|
---|
3 | *
|
---|
4 | * Created on: Sep 5, 2013
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef ZOMBIE_HPP_
|
---|
9 | #define ZOMBIE_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "CodePatterns/Observer/Observable.hpp"
|
---|
17 |
|
---|
18 | #include <boost/shared_ptr.hpp>
|
---|
19 |
|
---|
20 | class Graveyard;
|
---|
21 |
|
---|
22 | /** Zombie wraps an Observable and is allowed to set the graveyard.
|
---|
23 | *
|
---|
24 | */
|
---|
25 | class Zombie
|
---|
26 | {
|
---|
27 | //!> only Graveyard may create zombies
|
---|
28 | friend class Graveyard;
|
---|
29 |
|
---|
30 | typedef boost::shared_ptr<Zombie> ptr;
|
---|
31 | friend class boost::shared_ptr<Zombie>;
|
---|
32 | private:
|
---|
33 | /** Constructor of class Zombie.
|
---|
34 | *
|
---|
35 | * Is private to allow only Graveyard to instantiate them.
|
---|
36 | *
|
---|
37 | * \param _observable observable to wrap, ptr is NULL'd
|
---|
38 | * \param _graveyard_informer callback when Observers are signOff()'ing
|
---|
39 | */
|
---|
40 | Zombie(
|
---|
41 | Observable *& _observable,
|
---|
42 | Observable::graveyard_informer_t *_graveyard_informer) :
|
---|
43 | m_observable(_observable)
|
---|
44 | {
|
---|
45 | m_observable->setGraveyardInformer(_graveyard_informer);
|
---|
46 | _observable = NULL;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** Returns the wrapped ptr.
|
---|
50 | *
|
---|
51 | * \param ptr to wrapped up Observable instance
|
---|
52 | */
|
---|
53 | const Observable * getPtr() const
|
---|
54 | { return m_observable; }
|
---|
55 |
|
---|
56 | public:
|
---|
57 | /** Destructor of class Zombie.
|
---|
58 | *
|
---|
59 | * Is made public for convenience, to allow boost::shared_ptr access to it.
|
---|
60 | * We could pass shared_ptr a befriended deleteFunction but this is overkill
|
---|
61 | * as long as cstor is private.
|
---|
62 | */
|
---|
63 | virtual ~Zombie()
|
---|
64 | { delete m_observable; m_observable = NULL; }
|
---|
65 |
|
---|
66 | size_t getNumberOfObservers() const
|
---|
67 | { return m_observable->getNumberOfObservers(); }
|
---|
68 |
|
---|
69 | private:
|
---|
70 | Observable *m_observable;
|
---|
71 | };
|
---|
72 |
|
---|
73 | #endif /* ZOMBIE_HPP_ */
|
---|