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 "utils/enumerate.h"
34 
36  // in case a disconnect removes items from the observers
37  for (long long i = static_cast<long long>(observers_.size()) - 1; i >= 0; --i) {
38  observers_[i]->disconnect(this);
39  if (i > observers_.size()) {
40  i = observers_.size();
41  }
42  }
43 }
44 
46  observers_.push_back(o);
47 }
48 
51 }
52 
54  for (auto& obs: observers_) {
55  obs->update(this);
56  }
57 }
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
#define i
Definition: md1redef.h:19
void erase_first(T &&iterable, value_type &&value)
Definition: enumerate.h:22