NEURON
observe.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1992 Stanford University
3  * Copyright (c) 1992 Silicon Graphics, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that (i) the above copyright notices and this permission notice appear in
8  * all copies of the software and related documentation, and (ii) the names of
9  * Stanford and Silicon Graphics may not be used in any advertising or
10  * publicity relating to the software without the specific, prior written
11  * permission of Stanford and Silicon Graphics.
12  *
13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 /*
26  * Observable - object to observe
27  */
28 
29 #pragma once
30 
31 #include <InterViews/enter-scope.h>
32 
33 #include <InterViews/_enter.h>
34 #include <vector>
35 
36 class Observer;
37 
38 class Observable {
39 public:
40  Observable() = default;
41  virtual ~Observable();
42 
43  virtual void attach(Observer*);
44  virtual void detach(Observer*);
45  virtual void notify();
46 private:
47  std::vector<Observer*> observers_;
48 };
49 
50 class Observer {
51 protected:
52  Observer() = default;
53 public:
54  virtual ~Observer() = default;
55 
56  virtual void update(Observable*) {};
57  virtual void disconnect(Observable*) {};
58 };
59 
60 #include <InterViews/_leave.h>
virtual void notify()
Definition: observe.cpp:53
std::vector< Observer * > observers_
Definition: observe.h:47
virtual void attach(Observer *)
Definition: observe.cpp:45
virtual ~Observable()
Definition: observe.cpp:35
virtual void detach(Observer *)
Definition: observe.cpp:49
Observable()=default
virtual ~Observer()=default
virtual void update(Observable *)
Definition: observe.h:56
virtual void disconnect(Observable *)
Definition: observe.h:57
Observer()=default