KSquare Utilities
KKObserver.cpp
Go to the documentation of this file.
1 /* KKObserver.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 "KKException.h"
23 #include "GlobalGoalKeeper.h"
24 #include "OSservices.h"
25 #include "KKObservable.h"
26 #include "KKObserver.h"
27 using namespace KKB;
28 
29 
30 
31 
32 KKObserver::KKObserver (const KKStr& _name):
33  name (_name)
34 
35 {
36 }
37 
38 
39 
41 {
42  // Let KKObservable instances know that we are not observing them anymore.
43 
45  for (observablesIdx = observables.begin (); observablesIdx != observables.end (); ++observablesIdx)
46  {
47  KKObservablePtr p = observablesIdx->first;
49  }
51 }
52 
53 
54 
56 {
57  return sizeof (*this);
58 }
59 
60 
61 
62 void KKObserver::RegisterObservable (KKObservablePtr observable)
63 {
65  observables.insert (std::pair<KKObservablePtr,KKObservablePtr> (observable, observable));
67 } /* RegisterObservable */
68 
69 
70 
71 void KKObserver::UnRegisterObservable (KKObservablePtr observable)
72 {
74 
75  observablesIdx = observables.find (observable);
76  if (observablesIdx != observables.end ())
77  observables.erase (observablesIdx);
78 
80 } /* UnRegisterObservable */
81 
82 
83 
84 
85 void KKObserver::Notify (KKObservablePtr obj)
86 {
87 } /* Notify */
virtual void UnRegisterObserver(KKObserverPtr observer)
The base class to be used by Observer classes.
Definition: KKObserver.h:25
__int32 kkint32
Definition: KKBaseTypes.h:88
virtual void Notify(KKObservablePtr obj)
Definition: KKObserver.cpp:85
KKTHread * KKTHreadPtr
virtual ~KKObserver()
Definition: KKObserver.cpp:40
kkint32 MemoryConsumedEstimated()
Definition: KKObserver.cpp:55
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
KKObserver(const KKStr &_name)
Definition: KKObserver.cpp:32
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.