AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
observable.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <mutex>
23#include <set>
24#include <map>
25#include <string>
26
27#include "events/observer.hpp"
28#include "events/event.hpp"
29#include "lessPtrCompare.hpp"
30
31
32namespace anch::events {
33
43 template<typename T>
44 class Observable {
45
46 private:
47 // Attributes +
49 std::set<anch::events::Observer<T>*, anch::LessPtrCompare<anch::events::Observer<T> > > _observers;
50
52 std::mutex _mutex;
53 // Attributes -
54
55 public:
56 // Constructors +
61 // Constructors -
62
63 // Destructor +
67 virtual ~Observable();
68 // Destructor -
69
70 public:
71 // Methods +
80
87
94 void notifyObservers(const T& event, const std::map<std::string,std::string>& headers = {});
95
102 // Methods -
103
104 };
105
106}
107
108#include "events/impl/observable.hpp"
void removeObserver(anch::events::Observer< T > &observer)
void notifyObservers(const T &event, const std::map< std::string, std::string > &headers={})
bool addObserver(anch::events::Observer< T > &observer)
void notifyObservers(const anch::events::Event< T > &event)
An observer interface of the observers/observable design pattern.
Definition observer.hpp:39
Events management namespace.
Definition event.hpp:25
Less comparator based on object address.
Definition lessPtrCompare.hpp:34
Event representation.
Definition event.hpp:37