PetaVision  Alpha
Subject.hpp
1 /*
2  * Subject.hpp
3  *
4  * Created on: Jul 30, 2016
5  * Author: pschultz
6  */
7 
8 #ifndef SUBJECT_HPP_
9 #define SUBJECT_HPP_
10 
11 #include "observerpattern/BaseMessage.hpp"
12 #include "observerpattern/ObserverTable.hpp"
13 
14 namespace PV {
15 
28 class Subject {
29  public:
30  Subject() {}
31  virtual ~Subject() {}
32 
37  virtual void addObserver(Observer *observer) { return; }
38 
39  protected:
80  Response::Status notify(
81  ObserverTable const &table,
82  std::vector<std::shared_ptr<BaseMessage const>> messages,
83  bool printFlag);
84 
90  inline Response::Status
91  notify(ObserverTable const &table, std::shared_ptr<BaseMessage const> message, bool printFlag) {
92  return notify(table, std::vector<std::shared_ptr<BaseMessage const>>{message}, printFlag);
93  }
94 
104  void notifyLoop(
105  ObserverTable const &table,
106  std::vector<std::shared_ptr<BaseMessage const>> messages,
107  bool printFlag,
108  std::string const &description);
109 
114  inline void notifyLoop(
115  ObserverTable const &table,
116  std::shared_ptr<BaseMessage const> message,
117  bool printFlag,
118  std::string const &description) {
119  notifyLoop(
120  table,
121  std::vector<std::shared_ptr<BaseMessage const>>{message},
122  printFlag,
123  description);
124  }
125 };
126 
127 } /* namespace PV */
128 
129 #endif /* SUBJECT_HPP_ */
void notifyLoop(ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag, std::string const &description)
Definition: Subject.cpp:57
Response::Status notify(ObserverTable const &table, std::shared_ptr< BaseMessage const > message, bool printFlag)
Definition: Subject.hpp:91
virtual void addObserver(Observer *observer)
Definition: Subject.hpp:37
void notifyLoop(ObserverTable const &table, std::shared_ptr< BaseMessage const > message, bool printFlag, std::string const &description)
Definition: Subject.hpp:114
Response::Status notify(ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag)
Definition: Subject.cpp:15