|
Last change
on this file since 44f368 was b324a3, checked in by Frederik Heber <heber@…>, 12 years ago |
|
Added Graveyard for to-be-destroyed Observables.
- also added Zombie class that wraps an Observable.
- Notification and Observable have new function getNumberOfObservers().
- added unit test for Graveyard.
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 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 | Zombie(
|
|---|
| 38 | Observable *& _observable,
|
|---|
| 39 | Observable::graveyard_informer_t _graveyard_informer) :
|
|---|
| 40 | m_observable(_observable)
|
|---|
| 41 | {
|
|---|
| 42 | m_observable->setGraveyardInformer(_graveyard_informer);
|
|---|
| 43 | _observable = NULL;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | /** Returns the wrapped ptr.
|
|---|
| 47 | *
|
|---|
| 48 | * \param ptr to wrapped up Observable instance
|
|---|
| 49 | */
|
|---|
| 50 | const Observable * getPtr() const
|
|---|
| 51 | { return m_observable; }
|
|---|
| 52 |
|
|---|
| 53 | public:
|
|---|
| 54 | /** Destructor of class Zombie.
|
|---|
| 55 | *
|
|---|
| 56 | * Is made public for convenience, to allow boost::shared_ptr access to it.
|
|---|
| 57 | * We could pass shared_ptr a befriended deleteFunction but this is overkill
|
|---|
| 58 | * as long as cstor is private.
|
|---|
| 59 | */
|
|---|
| 60 | virtual ~Zombie()
|
|---|
| 61 | { delete m_observable; m_observable = NULL; }
|
|---|
| 62 |
|
|---|
| 63 | size_t getNumberOfObservers() const
|
|---|
| 64 | { return m_observable->getNumberOfObservers(); }
|
|---|
| 65 |
|
|---|
| 66 | private:
|
|---|
| 67 | Observable *m_observable;
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | #endif /* ZOMBIE_HPP_ */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.