NEURON
observe.cpp
Go to the documentation of this file.
1 #ifdef HAVE_CONFIG_H
2 #include <../../nrnconf.h>
3 #endif
4 /*
5  * Copyright (c) 1992 Stanford University
6  * Copyright (c) 1992 Silicon Graphics, Inc.
7  *
8  * Permission to use, copy, modify, distribute, and sell this software and
9  * its documentation for any purpose is hereby granted without fee, provided
10  * that (i) the above copyright notices and this permission notice appear in
11  * all copies of the software and related documentation, and (ii) the names of
12  * Stanford and Silicon Graphics may not be used in any advertising or
13  * publicity relating to the software without the specific, prior written
14  * permission of Stanford and Silicon Graphics.
15  *
16  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
21  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25  * OF THIS SOFTWARE.
26  */
27 
28 /*
29  * Observable - object to observe
30  */
31 
32 #include <InterViews/observe.h>
33 #include <OS/list.h>
34 
37 
39  observers_ = nil;
40 }
41 
43  ObserverList* list = observers_;
44  if (list != nil) {
45  // in case a disconnect removes items from the ObserverList
46  for (long i = list->count() - 1; i >= 0; --i) {
47  list->item(i)->disconnect(this);
48  if (i > list->count()) { i = list->count(); }
49  }
50  delete list;
51  }
52 }
53 
55  ObserverList* list = observers_;
56  if (list == nil) {
57  list = new ObserverList(5);
58  observers_ = list;
59  }
60  list->append(o);
61 }
62 
64  ObserverList* list = observers_;
65  if (list != nil) {
66  for (ListUpdater(ObserverList) i(*list); i.more(); i.next()) {
67  if (i.cur() == o) {
68  i.remove_cur();
69  break;
70  }
71  }
72  }
73 }
74 
76  ObserverList* list = observers_;
77  if (list != nil) {
78  for (ListItr(ObserverList) i(*list); i.more(); i.next()) {
79  i.cur()->update(this);
80  }
81  }
82 }
83 
#define ObserverList
Definition: _defines.h:192
#define nil
Definition: enter-scope.h:36
virtual void notify()
Definition: observe.cpp:75
virtual void attach(Observer *)
Definition: observe.cpp:54
virtual ~Observable()
Definition: observe.cpp:42
virtual void detach(Observer *)
Definition: observe.cpp:63
ObserverList * observers_
Definition: observe.h:48
Observer()
Definition: observe.cpp:84
virtual ~Observer()
Definition: observe.cpp:85
virtual void disconnect(Observable *)
Definition: observe.cpp:87
virtual void update(Observable *)
Definition: observe.cpp:86
#define implementPtrList(PtrList, T)
#define ListItr(List)
Definition: list.h:39
#define ListUpdater(List)
Definition: list.h:41
#define i
Definition: md1redef.h:12
declarePtrList(ObserverList, Observer) implementPtrList(ObserverList
o
Definition: seclist.cpp:175