Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Observer/Observable to utils #2782

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/NeuronFileLists.cmake
Expand Up @@ -421,7 +421,7 @@ set(NMODL_FILES_LIST
units.cpp
version.cpp)

set(IVOS_FILES_LIST observe.cpp resource.cpp)
set(IVOS_FILES_LIST resource.cpp)

set(MPI_DYNAMIC_INCLUDE nrnmpi_dynam.h nrnmpi_dynam_cinc nrnmpi_dynam_wrappers.inc)

Expand Down
2 changes: 1 addition & 1 deletion src/ivoc/objcmd.h
Expand Up @@ -3,7 +3,7 @@

#include <memory>

#include <InterViews/observe.h>
#include "utils/observe.hpp"
#if HAVE_IV
#include <InterViews/action.h>
#include "rubband.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ivoc/oclist.h
Expand Up @@ -4,7 +4,7 @@
#include <vector>

#include <InterViews/resource.h>
#include <InterViews/observe.h>
#include "utils/observe.hpp"
struct Object;
class OcListBrowser;
struct cTemplate;
Expand Down
2 changes: 1 addition & 1 deletion src/ivoc/ocnotify.h
@@ -1,5 +1,5 @@
#pragma once
#include <InterViews/observe.h>
#include "utils/observe.hpp"
#include "neuron/container/data_handle.hpp"

#include <cstddef> // std::size_t
Expand Down
2 changes: 1 addition & 1 deletion src/ivoc/ocobserv.h
Expand Up @@ -3,7 +3,7 @@

#include "oc_ansi.h"

#include <InterViews/observe.h>
#include "utils/observe.hpp"

struct Object;
struct cTemplate;
Expand Down
2 changes: 1 addition & 1 deletion src/ivoc/ocpointer.cpp
Expand Up @@ -9,7 +9,7 @@
assignment. It will be executed (and p.val assigned) when
p.assign(val)
*/
#include <InterViews/observe.h>
#include "utils/observe.hpp"
#include <string.h>
#include "classreg.h"
#include "oc_ansi.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ivoc/ocpointer.h
@@ -1,7 +1,7 @@
#ifndef ocpointer_h
#define ocpointer_h

#include <InterViews/observe.h>
#include "utils/observe.hpp"
#include "oc2iv.h"
class StmtInfo;

Expand Down
3 changes: 0 additions & 3 deletions src/ivos/InterViews/_defines.h
Expand Up @@ -185,9 +185,6 @@
#define OLDialogKit _lib_iv(OLDialogKit)
#define OLKit _lib_iv(OLKit)
#define OLKitImpl _lib_iv(OLKitImpl)
#define Observable _lib_iv(Observable)
#define Observer _lib_iv(Observer)
#define ObserverList _lib_iv(ObserverList)
#define OptionDesc _lib_iv(OptionDesc)
#define PSFont _lib_iv(PSFont)
#define PSFontImpl _lib_iv(PSFontImpl)
Expand Down
3 changes: 0 additions & 3 deletions src/ivos/InterViews/_undefs.h
Expand Up @@ -185,9 +185,6 @@
#undef OLDialogKit
#undef OLKit
#undef OLKitImpl
#undef Observable
#undef Observer
#undef ObserverList
#undef OptionDesc
#undef PSFont
#undef PSFontImpl
Expand Down
57 changes: 0 additions & 57 deletions src/ivos/observe.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/nrncvode/netcon.h
Expand Up @@ -10,7 +10,7 @@
#include "pool.hpp"
#include "tqitem.hpp"

#include <InterViews/observe.h>
#include "utils/observe.hpp"

#include <memory>
#include <unordered_map>
Expand Down
2 changes: 1 addition & 1 deletion src/nrncvode/vrecitem.h
@@ -1,7 +1,7 @@
#ifndef vrecitem_h
#define vrecitem_h

#include <InterViews/observe.h>
#include "utils/observe.hpp"
#include <netcon.h>
#include <ivocvect.h>

Expand Down
2 changes: 1 addition & 1 deletion src/nrniv/linmod1.cpp
@@ -1,6 +1,6 @@
#include <../../nrnconf.h>
#include <stdio.h>
#include <InterViews/observe.h>
#include "utils/observe.hpp"
#include "ocnotify.h"
#if HAVE_IV
#include "ivoc.h"
Expand Down
6 changes: 3 additions & 3 deletions src/nrniv/nrncore_write/io/nrncore_io.cpp
Expand Up @@ -549,7 +549,7 @@ void nrn_write_mapping_info(const char* path, int gid, NrnMappingInfo& minfo) {
/** number of gids in NrnThread */
int count;
nrnthread_dat3_cell_count(count);
fprintf(f, "%zd\n", count);
fprintf(f, "%d\n", count);

/** all cells mapping information in NrnThread */
for (size_t i = 0; i < count; i++) {
Expand All @@ -559,7 +559,7 @@ void nrn_write_mapping_info(const char* path, int gid, NrnMappingInfo& minfo) {
int n_seclist;
nrnthread_dat3_cellmapping(i, cgid, t_sec, t_seg, n_seclist);
/** gid, #section, #compartments, #sectionlists */
fprintf(f, "%d %d %d %zd\n", cgid, t_sec, t_seg, n_seclist);
fprintf(f, "%d %d %d %d\n", cgid, t_sec, t_seg, n_seclist);

for (size_t j = 0; j < n_seclist; j++) {
std::string sclname;
Expand All @@ -582,7 +582,7 @@ void nrn_write_mapping_info(const char* path, int gid, NrnMappingInfo& minfo) {
data_lfp);
/** section list name, number of sections, number of segments */
fprintf(f,
"%s %d %zd %zd %d\n",
"%s %d %d %zd %d\n",
sclname.c_str(),
nsec,
nseg,
Expand Down
74 changes: 44 additions & 30 deletions src/ivos/InterViews/observe.h → src/utils/observe.hpp 100755 → 100644
Expand Up @@ -2,62 +2,76 @@
* Copyright (c) 1992 Stanford University
* Copyright (c) 1992 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Stanford and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Stanford and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/

/*
* Observable - object to observe
*/

#ifndef iv_observe_h
#define iv_observe_h

#include <InterViews/enter-scope.h>
#pragma once

#include <InterViews/_enter.h>
#include <vector>

class Observer;

class Observable {
public:
Observable() = default;
virtual ~Observable();
#include "enumerate.h"

virtual void attach(Observer*);
virtual void detach(Observer*);
virtual void notify();
private:
std::vector<Observer*> observers_;
};
class Observable;

class Observer {
protected:
protected:
Observer() = default;
public:

public:
virtual ~Observer() = default;

virtual void update(Observable*) {};
virtual void disconnect(Observable*) {};
virtual void update(Observable*){};
virtual void disconnect(Observable*){};
};

#include <InterViews/_leave.h>
class Observable {
public:
Observable() = default;
virtual ~Observable() {
// in case a disconnect removes items from the observers
for (long long i = static_cast<long long>(observers_.size()) - 1; i >= 0; --i) {
observers_[i]->disconnect(this);
if (i > observers_.size()) {
i = observers_.size();
}
}
}

virtual void attach(Observer* o) {
observers_.push_back(o);
}

virtual void detach(Observer* o) {
erase_first(observers_, o);
}

#endif
virtual void notify() {
for (auto& obs: observers_) {
obs->update(this);
}
}

private:
std::vector<Observer*> observers_;
};