Skip to content

Commit

Permalink
Add 'lager' package (cpp-pm#118)
Browse files Browse the repository at this point in the history
* 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
Bjoe authored and rbsheth committed Jan 7, 2020
1 parent 58dbf64 commit 417ed71
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ hunter_default_version(JsonSpirit VERSION 0.0.4-hunter)
hunter_default_version(LAPACK VERSION 3.7.1)
hunter_default_version(LLVM VERSION 6.0.1-p0) # Clang
hunter_default_version(LLVMCompilerRT VERSION 6.0.1) # Clang
hunter_default_version(Lager VERSION 0.0.0-dbc1fde-p0)
hunter_default_version(Leathers VERSION 0.1.8)
hunter_default_version(Leptonica VERSION 1.74.2-p4)
hunter_default_version(LibCDS VERSION 2.3.1)
Expand Down
33 changes: 33 additions & 0 deletions cmake/projects/Lager/hunter.cmake
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"
)
21 changes: 21 additions & 0 deletions docs/packages/pkg/Lager.rst
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 }
18 changes: 18 additions & 0 deletions examples/Lager/CMakeLists.txt
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 }
81 changes: 81 additions & 0 deletions examples/Lager/boo.cpp
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);
}
}

0 comments on commit 417ed71

Please sign in to comment.