Skip to content

Commit

Permalink
Merge pull request #6 from TheLartians/refactor
Browse files Browse the repository at this point in the history
refactor event and observable value
  • Loading branch information
TheLartians authored Apr 22, 2019
2 parents 1528d4c + 666e807 commit 1d232e4
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 406 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ before_install:
# Update compilers
- eval "${MATRIX_EVAL}"
- echo "CC=$CC CXX=$CXX"
# Install a supported cmake version (>= 3.5)
- wget -O cmake.sh https://cmake.org/files/v3.10/cmake-3.10.0-rc1-Linux-x86_64.sh
# Install a supported cmake version (>= 3.14)
- wget -O cmake.sh https://cmake.org/files/v3.14/cmake-3.14.0-Linux-x86_64.sh
- sudo sh cmake.sh --skip-license --exclude-subdir --prefix=/usr/local
- export PATH=/usr/local/bin:$PATH
- cmake --version

install:
- cmake -H. -Bbuild
Expand Down
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# ---- Project ----

project(LarsEvent
VERSION 1.0
VERSION 2.0
LANGUAGES CXX
)

# ---- Configuration variables ----

option(ENABLE_LARS_EVENT_TESTS "Enable tests" OFF)
option(BUILD_LARS_EVENT_EXAMPLES "Enable examples" OFF)
option(LARS_EVENT_ENABLE_TESTS "Enable tests" OFF)
option(LARS_EVENT_BUILD_EXAMPLES "Enable examples" OFF)

# ---- Include guards ----

Expand Down Expand Up @@ -86,13 +86,13 @@ install(

# ---- Examples ----

IF(${BUILD_LARS_EVENT_EXAMPLES})
IF(${LARS_EVENT_BUILD_EXAMPLES})
add_subdirectory(examples)
ENDIF()

# ---- Test ----

if(${ENABLE_LARS_EVENT_TESTS})
if(${LARS_EVENT_ENABLE_TESTS})
ENABLE_TESTING()
add_subdirectory(tests)
endif()
Expand Down
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
[![Build Status](https://travis-ci.com/TheLartians/Event.svg?branch=master)](https://travis-ci.com/TheLartians/Event)

# lars::event
# lars::Event

A c++11 event-listener system template. See [Examples](https://github.com/TheLartians/Event/tree/master/examples) for usage.
A thread-safe event-listener template and observable value implementation for C++17.

# Examples

Full examples can be found in the [examples directory](https://github.com/TheLartians/Event/tree/master/examples).

## lars::Event

```c++
lars::Event<float,float> onClick;
auto observer = onClick.createObserver([](auto x, auto y){ handleClick(x,y); });
onClick.emit(0,0); // emits event to all observers
observer.reset(); // removes observer from event
```
## lars::ObservableValue
```c++
lars::ObservableValue a = 1;
lars::ObservableValue b = 2;
lars::DependentObservableValue sum([](auto a, auto b){ return a+b; },a,b);
sum.onChange.connect([](auto &v){ std::cout << "The result is " << r << std::endl; });
a.set(3); // -> "The result is 5"
```

# Installation and usage

With [CPM](https://github.com/TheLartians/CPM), lars::Event can be added to your project by adding the following to your projects' `CMakeLists.txt`.

```cmake
CPMAddPackage(
NAME LarsEvent
VERSION 2.0
GIT_REPOSITORY https://github.com/TheLartians/Event.git
)
target_link_libraries(myProject LarsEvent)
```

Alternatively, download the repository include it via `add_subdirectory`. Installing lars::Event will make it findable in CMake's `find_package`.
49 changes: 0 additions & 49 deletions examples/mouse_events.cpp

This file was deleted.

Loading

0 comments on commit 1d232e4

Please sign in to comment.