forked from cpp-pm/hunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * First compiling version * Rename lager to Lager * Reorder hunter add in example * First build with gcc * Hunterized Lager, cleanup example * Add pull request number * Fix version number
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# !!! DO NOT PLACE HEADER GUARDS HERE !!! | ||
|
||
include(hunter_add_version) | ||
include(hunter_cacheable) | ||
include(hunter_cmake_args) | ||
include(hunter_download) | ||
include(hunter_pick_scheme) | ||
|
||
hunter_add_version( | ||
PACKAGE_NAME | ||
Lager | ||
VERSION | ||
0.0.0-dbc1fde-p0 | ||
URL | ||
"https://github.com/cpp-pm/lager/archive/v0.0.0-dbc1fde.tar.gz" | ||
SHA1 | ||
1b20b2d29d7886eed48d57fefdcb322885b84ae9 | ||
) | ||
|
||
hunter_cmake_args( | ||
Lager | ||
CMAKE_ARGS | ||
lager_BUILD_TESTS=OFF | ||
lager_BUILD_EXAMPLES=OFF | ||
lager_BUILD_DOCS=OFF | ||
) | ||
|
||
hunter_pick_scheme(DEFAULT url_sha1_cmake) | ||
hunter_cacheable(Lager) | ||
hunter_download( | ||
PACKAGE_NAME Lager | ||
PACKAGE_INTERNAL_DEPS_ID "1" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. spelling:: | ||
|
||
Lager | ||
|
||
.. index:: | ||
single: unsorted ; Lager | ||
|
||
.. _pkg.lager: | ||
|
||
Lager | ||
===== | ||
|
||
- `Official <https://github.com/arximboldi/lager>`__ | ||
- `Hunterized <https://github.com/cpp-pm/lager>`__ | ||
- `Example <https://github.com/cpp-pm/hunter/blob/master/examples/Lager/CMakeLists.txt>`__ | ||
- Added by `Joerg-Christian Boehme <https://github.com/Bjoe>`__ (`pr-118 <https://github.com/cpp-pm/hunter/pull/118>`__) | ||
|
||
.. literalinclude:: /../examples/Lager/CMakeLists.txt | ||
:language: cmake | ||
:start-after: # DOCUMENTATION_START { | ||
:end-before: # DOCUMENTATION_END } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) | ||
# All rights reserved. | ||
|
||
cmake_minimum_required(VERSION 3.2) | ||
|
||
# Emulate HunterGate: | ||
# * https://github.com/cpp-pm/gate | ||
include("../common.cmake") | ||
|
||
project(Lager) | ||
|
||
# DOCUMENTATION_START { | ||
hunter_add_package(Lager) | ||
find_package(Lager CONFIG REQUIRED) | ||
|
||
add_executable(boo boo.cpp) | ||
target_link_libraries(boo PUBLIC lager) | ||
# DOCUMENTATION_END } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// lager - library for functional interactive c++ programs | ||
// Copyright (C) 2017 Juan Pedro Bolivar Puente | ||
// | ||
// This file is part of lager. | ||
// | ||
// lager is free software: you can redistribute it and/or modify | ||
// it under the terms of the MIT License, as detailed in the LICENSE | ||
// file located at the root of this source code distribution, | ||
// or here: <https://github.com/arximboldi/lager/blob/master/LICENSE> | ||
// | ||
|
||
#include <iostream> | ||
#include <lager/event_loop/manual.hpp> | ||
#include <lager/store.hpp> | ||
|
||
#include <lager/util.hpp> | ||
|
||
#include <variant> | ||
|
||
namespace counter { | ||
|
||
struct model | ||
{ | ||
int value = 0; | ||
}; | ||
|
||
struct increment_action | ||
{}; | ||
struct decrement_action | ||
{}; | ||
struct reset_action | ||
{ | ||
int new_value = 0; | ||
}; | ||
|
||
using action = std::variant<increment_action, decrement_action, reset_action>; | ||
|
||
inline model update(model c, action action) | ||
{ | ||
return std::visit(lager::visitor{ | ||
[&](increment_action) { return model{c.value + 1}; }, | ||
[&](decrement_action) { return model{c.value - 1}; }, | ||
[&](reset_action a) { return model{a.new_value}; }, | ||
}, | ||
action); | ||
} | ||
|
||
} // namespace counter | ||
void draw(counter::model prev, counter::model curr) | ||
{ | ||
std::cout << "last value: " << prev.value << '\n'; | ||
std::cout << "current value: " << curr.value << '\n'; | ||
} | ||
|
||
std::optional<counter::action> intent(char event) | ||
{ | ||
switch (event) { | ||
case '+': | ||
return counter::increment_action{}; | ||
case '-': | ||
return counter::decrement_action{}; | ||
case '.': | ||
return counter::reset_action{}; | ||
default: | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
auto store = lager::make_store<counter::action>( | ||
counter::model{}, counter::update, lager::with_manual_event_loop{}); | ||
watch(store, draw); | ||
|
||
auto event = char{}; | ||
while (std::cin >> event) { | ||
if (auto act = intent(event)) | ||
store.dispatch(*act); | ||
} | ||
} |