-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.cpp
More file actions
108 lines (77 loc) · 4.42 KB
/
main.cpp
File metadata and controls
108 lines (77 loc) · 4.42 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* main.cpp
* Notification Center CPP
*
* Created by Jonathan Goodman on 11/23/13.
* Copyright (c) 2013 Jonathan Goodman. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <iostream>
#include "NotificationCenter.hpp"
class Foo {
public:
void func()
{
printf("Hello std::bind!\n");
}
};
void runNotification()
{
auto i1 = NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 1);}, "Poster");
auto i2 = NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 2);}, "Poster");
auto i3 = NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 3);}, "Poster");
auto i4 = NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 4);}, "Poster");
auto i5 = NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 5);}, "Poster");
NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 6);}, "Poster");
NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 7);}, "Poster");
NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Recieved notification %d!\n", 8);}, "Poster");
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->removeObserver("Poster", i1);
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->removeObserver("Poster", i2);
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->removeObserver("Poster", i3);
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->removeObserver("Poster", i4);
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->removeObserver("Poster", i5);
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->removeAllObservers("Poster");
NotificationCenter::defaultNotificationCenter()->postNotification("Poster");
printf("============\n");
NotificationCenter::defaultNotificationCenter()->addObserver([=]{printf("Called by iterator!\n");}, "Second Poster");
NotificationCenter::notification_const_itr_t itr = NotificationCenter::defaultNotificationCenter()->getNotificationIterator("Second Poster");
NotificationCenter::defaultNotificationCenter()->postNotification(itr);
printf("============\n");
Foo myFoo;
NotificationCenter::defaultNotificationCenter()->addObserver(std::bind(&Foo::func, myFoo), "Second Poster");
NotificationCenter::defaultNotificationCenter()->postNotification("Second Poster");
}
int main(int argc, const char * argv[])
{
runNotification();
return 0;
}