ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObsPattern_Sub.h
Go to the documentation of this file.
1 
12 #ifndef OBSPATTERN_SUB_H_
13 #define OBSPATTERN_SUB_H_
14 
15 #include <vector>
16 // necessary ??
17 #include <algorithm>
18 #include <iostream>
19 
20 //forward declaration
21 class Observer;
22 
30 class Subject
31 {
32 public:
33  virtual ~Subject() {} //{std::cout << "Destructor base subject" << std::endl;}
34 
36  virtual void attach(Observer *obs) {
37  vec_observer.push_back(obs);
38  }
40  virtual void detach(Observer *obs) {
41  vec_observer.erase(std::remove(vec_observer.begin(), vec_observer.end(), obs),
42  vec_observer.end());
43  }
44 
45 protected:
47  Subject() {} //{std::cout << "protected constructor of base subject";}
49  void notify();
51  void notify ( std::vector<std::string> & message );
52 
53 private:
55  std::vector<Observer *> vec_observer;
56 
57  // comment but maybe important to overwrite, not implemented, generated by compiler ??
58  // or overwrittem them ?? certainly
60  Subject(const Subject &);
61  Subject &operator=(const Subject &);
62 };
63 
64 #endif /* OBSPATTERN_SUB_H_ */
virtual void detach(Observer *obs)
function to detach, unregister, not used
Subject & operator=(const Subject &)
virtual void attach(Observer *obs)
function for subject to register
Subject()
constructor is protected
Receive notification from the python update.
void notify()
notify a message to all registered observer
std::vector< Observer * > vec_observer
vector of registered observer
virtual ~Subject()