-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisposable.hpp
53 lines (36 loc) · 1.09 KB
/
Disposable.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// Disposable.hpp
// Jako
//
// Created by John Zakharov on 20.03.16.
// Copyright © 2016 Outlaw Studio. All rights reserved.
//
#ifndef __VIPER_DISPOSABLE_H
#define __VIPER_DISPOSABLE_H
#include <mutex>
#include <vector>
#include <algorithm>
#include <iostream>
namespace Mitsoko{
struct Disposable{
/**
* Every disposable has unique id. Once disposed every observer receives callback with id
* of disposable which disposed.
*/
typedef unsigned Id;
const Id id;
struct Observer{
virtual void disposableDidDispose(Id id)=0;
virtual ~Observer();
};
Disposable();
virtual void dispose();
static void subscribe(Observer *observer);
static void unsubscribe(Observer *observer);
protected:
static std::mutex observersMutex;
static std::vector<Observer*> observers;
static Id generateId();
};
}
#endif /* __VIPER_DISPOSABLE_H */