Skip to content

Commit 1d232e4

Browse files
authored
Merge pull request #6 from TheLartians/refactor
refactor event and observable value
2 parents 1528d4c + 666e807 commit 1d232e4

File tree

11 files changed

+410
-406
lines changed

11 files changed

+410
-406
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ before_install:
3434
# Update compilers
3535
- eval "${MATRIX_EVAL}"
3636
- echo "CC=$CC CXX=$CXX"
37-
# Install a supported cmake version (>= 3.5)
38-
- wget -O cmake.sh https://cmake.org/files/v3.10/cmake-3.10.0-rc1-Linux-x86_64.sh
37+
# Install a supported cmake version (>= 3.14)
38+
- wget -O cmake.sh https://cmake.org/files/v3.14/cmake-3.14.0-Linux-x86_64.sh
3939
- sudo sh cmake.sh --skip-license --exclude-subdir --prefix=/usr/local
40+
- export PATH=/usr/local/bin:$PATH
41+
- cmake --version
4042

4143
install:
4244
- cmake -H. -Bbuild

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
33
# ---- Project ----
44

55
project(LarsEvent
6-
VERSION 1.0
6+
VERSION 2.0
77
LANGUAGES CXX
88
)
99

1010
# ---- Configuration variables ----
1111

12-
option(ENABLE_LARS_EVENT_TESTS "Enable tests" OFF)
13-
option(BUILD_LARS_EVENT_EXAMPLES "Enable examples" OFF)
12+
option(LARS_EVENT_ENABLE_TESTS "Enable tests" OFF)
13+
option(LARS_EVENT_BUILD_EXAMPLES "Enable examples" OFF)
1414

1515
# ---- Include guards ----
1616

@@ -86,13 +86,13 @@ install(
8686

8787
# ---- Examples ----
8888

89-
IF(${BUILD_LARS_EVENT_EXAMPLES})
89+
IF(${LARS_EVENT_BUILD_EXAMPLES})
9090
add_subdirectory(examples)
9191
ENDIF()
9292

9393
# ---- Test ----
9494

95-
if(${ENABLE_LARS_EVENT_TESTS})
95+
if(${LARS_EVENT_ENABLE_TESTS})
9696
ENABLE_TESTING()
9797
add_subdirectory(tests)
9898
endif()

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
11
[![Build Status](https://travis-ci.com/TheLartians/Event.svg?branch=master)](https://travis-ci.com/TheLartians/Event)
22

3-
# lars::event
3+
# lars::Event
44

5-
A c++11 event-listener system template. See [Examples](https://github.com/TheLartians/Event/tree/master/examples) for usage.
5+
A thread-safe event-listener template and observable value implementation for C++17.
6+
7+
# Examples
8+
9+
Full examples can be found in the [examples directory](https://github.com/TheLartians/Event/tree/master/examples).
10+
11+
## lars::Event
12+
13+
```c++
14+
lars::Event<float,float> onClick;
15+
auto observer = onClick.createObserver([](auto x, auto y){ handleClick(x,y); });
16+
onClick.emit(0,0); // emits event to all observers
17+
observer.reset(); // removes observer from event
18+
```
19+
20+
## lars::ObservableValue
21+
22+
```c++
23+
lars::ObservableValue a = 1;
24+
lars::ObservableValue b = 2;
25+
lars::DependentObservableValue sum([](auto a, auto b){ return a+b; },a,b);
26+
sum.onChange.connect([](auto &v){ std::cout << "The result is " << r << std::endl; });
27+
a.set(3); // -> "The result is 5"
28+
```
29+
30+
# Installation and usage
31+
32+
With [CPM](https://github.com/TheLartians/CPM), lars::Event can be added to your project by adding the following to your projects' `CMakeLists.txt`.
33+
34+
```cmake
35+
CPMAddPackage(
36+
NAME LarsEvent
37+
VERSION 2.0
38+
GIT_REPOSITORY https://github.com/TheLartians/Event.git
39+
)
40+
41+
target_link_libraries(myProject LarsEvent)
42+
```
43+
44+
Alternatively, download the repository include it via `add_subdirectory`. Installing lars::Event will make it findable in CMake's `find_package`.

examples/mouse_events.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)