-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cxx
69 lines (59 loc) · 1.47 KB
/
main.cxx
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
//
// main.cpp
// bufferlib
//
// Created by Alex Usbergo on 2016-12-24.
// Copyright © 2016 Alex Usbergo. All rights reserved.
//
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <thread>
#include <chrono>
#include "buffer.h"
#include "observer.h"
class Foo: public buffer::Subscriber<int> {
virtual void onBufferWillChange();
virtual void onBufferDidChange();
virtual void onBufferChange(buffer::DiffType type, size_t index, int value);
};
void Foo::onBufferWillChange() {
std::cout << "will change\n";
}
void Foo::onBufferDidChange() {
std::cout << "did change\n";
}
void Foo::onBufferChange(buffer::DiffType type, size_t index, int value) {
switch (type) {
case buffer::INSERT:
std::cout << "INSERT ";
break;
case buffer::DELETE:
std::cout << "DELETE ";
break;
case buffer::SUBSTITUTE:
std::cout << "SUBSTITUTE ";
break;
default:
break;
}
std::cout << value << " at index: " << index << "\n";
}
int main(int argc, const char * argv[]) {
std::vector<int> o = {1, 5, 3, 2};
std::vector<int> n = {1, 3, 2, 6, 6};
Foo sub;
buffer::Buffer<int> buffer;
auto sort = [](const std::vector<int> &v) {
auto s = std::vector<int>(v);
std::sort(s.begin(), s.end(), std::less_equal<int>());
return s;
};
buffer.setSortFunction(sort);
buffer.registerSubscriber(sub);
buffer.setCollection(o);
buffer.setCollection(n);
buffer.setCollection(o);
return 0;
}