KSquare Utilities
KKObservable.cpp
Go to the documentation of this file.
1 /* KKObservable.cpp -- Used to manage call-back functions in a multi-threaded environment.
2  * Copyright (C) 2012 - 2014 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 #include "FirstIncludes.h"
6 #include <fstream>
7 #include <iostream>
8 #include <map>
9 #include <ostream>
10 #include <string>
11 #include <vector>
12 #include "MemoryDebug.h"
13 using namespace std;
14 
15 #if defined(WIN32)
16 #include <windows.h>
17 #else
18 #include <pthread.h>
19 #endif
20 
21 #include "KKBaseTypes.h"
22 #include "GlobalGoalKeeper.h"
23 #include "OSservices.h"
24 #include "KKObserver.h"
25 #include "KKObservable.h"
26 using namespace KKB;
27 
28 
30 {
31 }
32 
33 
34 
36 {
37 }
38 
39 
40 
42 {
43  return sizeof (*this);
44 }
45 
46 
47 
48 void KKObservable::RegisterObserver (KKObserverPtr observer)
49 {
51 
52  observers.insert (pair<KKObserverPtr,KKObserverPtr>(observer, observer));
53  observer->RegisterObservable (this);
54 
56 } /* RegisterObserver */
57 
58 
59 
60 void KKObservable::UnRegisterObserver (KKObserverPtr observer)
61 {
63 
64  observersIdx = observers.find (observer);
65  if (observersIdx != observers.end ())
66  observers.erase (observersIdx);
67 
68  observer->UnRegisterObservable (this);
69 
71 } /* RegisterObserver */
72 
73 
74 
75 
77 {
78  for (observersIdx = observers.begin (); observersIdx != observers.end (); ++observersIdx)
79  observersIdx->first->Notify (this);
80 
81 }
virtual void UnRegisterObserver(KKObserverPtr observer)
virtual ~KKObservable()
virtual void RegisterObserver(KKObserverPtr observer)
__int32 kkint32
Definition: KKBaseTypes.h:88
virtual void NotifyObservers()
KKTHread * KKTHreadPtr
friend class KKObserver
Definition: KKObservable.h:46
kkint32 MemoryConsumedEstimated()
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.