aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmedia/llmediaemitter.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llmedia/llmediaemitter.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llmedia/llmediaemitter.h80
1 files changed, 36 insertions, 44 deletions
diff --git a/linden/indra/llmedia/llmediaemitter.h b/linden/indra/llmedia/llmediaemitter.h
index 658486d..e06a5ff 100644
--- a/linden/indra/llmedia/llmediaemitter.h
+++ b/linden/indra/llmedia/llmediaemitter.h
@@ -1,6 +1,8 @@
1/** 1/**
2 * @file llmediaemitter.h 2 * @file llmediaemitter.h
3 * @brief LLMedia support - templatized emitter class. 3 * @author Callum Prentice
4 * @date 2007-10-22 00:00:00
5 * @brief Manages and emits events to observers
4 * 6 *
5 * $LicenseInfo:firstyear=2005&license=viewergpl$ 7 * $LicenseInfo:firstyear=2005&license=viewergpl$
6 * 8 *
@@ -29,83 +31,73 @@
29 * $/LicenseInfo$ 31 * $/LicenseInfo$
30 */ 32 */
31 33
32// header guard 34#ifndef LLMEDIAEMITTER_H
33#ifndef llmediaemitter_h 35#define LLMEDIAEMITTER_H
34#define llmediaemitter_h
35 36
36// standard headers 37#include <list>
37#include <algorithm> 38#include <algorithm>
38#include <typeinfo> 39#include <typeinfo>
39#include <iostream>
40#include <list>
41
42#include "stdtypes.h"
43 40
44/////////////////////////////////////////////////////////////////////////////// 41///////////////////////////////////////////////////////////////////////////////
45// templatized emitter class 42//
46template < class T > 43template< class T >
47class LLMediaEmitter 44class LLMediaEmitter
48{ 45{
49 public: 46 public:
47 LLMediaEmitter() { };
48 ~LLMediaEmitter() { };
49
50 typedef typename T::EventType EventType; 50 typedef typename T::EventType EventType;
51 typedef std::list< T* > ObserverContainer; 51 typedef std::list< T* > ObserverContainer;
52 typedef void ( T::*observerMethod )( const EventType& ); 52 typedef void( T::*observerMethod )( const EventType& );
53
54 protected:
55 ObserverContainer observers;
56
57 public:
58 LLMediaEmitter()
59 {
60 };
61
62 ~LLMediaEmitter()
63 {
64 };
65 53
66 /////////////////////////////////////////////////////////////////////////////// 54 ///////////////////////////////////////////////////////////////////////////////
67 // 55 //
68 BOOL addObserver ( T* observerIn ) 56 bool addObserver( T* observer_in )
69 { 57 {
70 if ( ! observerIn ) 58 if ( ! observer_in )
71 return FALSE; 59 return false;
72 60
73 // check if observer already exists 61 if ( std::find( observers.begin(), observers.end(), observer_in) != observers.end() )
74 if ( std::find ( observers.begin (), observers.end (), observerIn ) != observers.end () ) 62 return false;
75 return FALSE;
76 63
77 // save it 64 observers.push_back( observer_in );
78 observers.push_back ( observerIn );
79 65
80 return true; 66 return true;
81 }; 67 };
82 68
83 /////////////////////////////////////////////////////////////////////////////// 69 ///////////////////////////////////////////////////////////////////////////////
84 // 70 //
85 BOOL remObserver ( T* observerIn ) 71 bool remObserver( T* observer_in )
86 { 72 {
87 if ( ! observerIn ) 73 if ( ! observer_in )
88 return FALSE; 74 return false;
75
76 observers.remove( observer_in );
77 observers.remove( observer_in );
78 observers.remove( observer_in );
89 79
90 observers.remove ( observerIn );
91 80
92 return TRUE; 81
82 return true;
93 }; 83 };
94 84
95 /////////////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////////////
96 // 86 //
97 void update ( observerMethod method, const EventType& msgIn ) 87 void update( observerMethod method, const EventType& msgIn )
98 { 88 {
99 typename std::list< T* >::iterator iter = observers.begin (); 89 typename std::list< T* >::iterator iter = observers.begin();
100 90
101 while ( iter != observers.end () ) 91 while( iter != observers.end() )
102 { 92 {
103 ( ( *iter )->*method ) ( msgIn ); 93 ( ( *iter )->*method )( msgIn );
104 94
105 ++iter; 95 ++iter;
106 }; 96 };
107 }; 97 };
108 };
109 98
99 protected:
100 ObserverContainer observers;
101};
110 102
111#endif // llmediaemitter_h 103#endif // LLMEDIAEMITTER_H