Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
observer.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//bertini2/detail/observer.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//bertini2/detail/observer.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with bertini2/detail/observer.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2021 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin-eau claire
24//
25
34
35#ifndef BERTINI_DETAIL_OBSERVER_HPP
36#define BERTINI_DETAIL_OBSERVER_HPP
37
38#include <tuple>
39#include <utility>
40
41#include <boost/fusion/adapted/std_tuple.hpp>
42
43#include <boost/fusion/algorithm/iteration/for_each.hpp>
44#include <boost/fusion/include/for_each.hpp>
45
47
48namespace bertini{
49
50
57 { BOOST_TYPE_INDEX_REGISTER_CLASS
58 public:
59 virtual ~AnyObserver() = default;
60
68 virtual void Observe(AnyEvent const& e) = 0;
69 };
70
71
80 template<class ObservedT>
81 class Observer : public AnyObserver
82 { BOOST_TYPE_INDEX_REGISTER_CLASS
83 public:
84 virtual ~Observer() = default;
85
86
87 };
88
89
90
91
102 template<class ObservedT, template<class> class... ObserverTypes>
103 class MultiObserver : public Observer<ObservedT>
104 { BOOST_TYPE_INDEX_REGISTER_CLASS
105 public:
106
112 void Observe(AnyEvent const& e) override
113 {
114 using namespace boost::fusion;
115 auto f = [&e](auto &obs) { obs.Observe(e); };
116 for_each(observers_, f);
117 }
118
119 std::tuple<ObserverTypes<ObservedT>...> observers_;
120 virtual ~MultiObserver() = default;
121 };
122
123
124}
125
126#endif
Strawman Event type, enabling polymorphism.
Definition detail/events.hpp:47
Strawman base class for Observer objects.
Definition observer.hpp:57
virtual void Observe(AnyEvent const &e)=0
Observe the observable object being observed. This is probably in response to NotifyObservers.
A class which can glob together observer types into a new, single observer type.
Definition observer.hpp:104
void Observe(AnyEvent const &e) override
Observe override which calls the overrides for the types you glued together.
Definition observer.hpp:112
Actual observer type, which you should derive from to extract custom information from observable type...
Definition observer.hpp:82
Contains the detail/events base types.