Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lager::with_setter doc #209

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions doc/cursors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,34 @@ all the value types in the original cursors:
lager::reader<std::tuple<int, std::string>> dual_ro =
lager::with(num, str_ro);

.. _derive-a-read-write-cursor-from-a-read-only-one:

Derive a read-write cursor from a read-only one
---------------

You can use ``lager::with_setter`` to derive a read-write cursor from a
read-only cursor.

.. code-block:: c++

#include <lager/setter.hpp>

auto store = lager::make_store<int>(
0,
lager::with_manual_event_loop{},
lager::with_reducer([](int s, int a) { return a; }));
auto cursor = lager::with_setter(
store,
[&](int x) { store.dispatch(x); });

store.dispatch(42);
std::cout << store.get() << std::endl; // 42
std::cout << cursor.get() << std::endl; // 42

cursor.set(5);
std::cout << cursor.get() << std::endl; // 5
std::cout << store.get() << std::endl; // 5

.. _using-cursors:

Using cursors
Expand Down Expand Up @@ -451,15 +479,15 @@ room model and watch it for changes:
});
}
};

.. note:: A ``lager::watch(reader, ...)`` is bound to the
``reader`` object. It is simply an alias of
``reader.watch(...)``. This means that when the reader
object goes out of scope, the watch is disposed. For
example:

.. code-block:: c++

void setup_watch() {
auto reader = my_store[&my_model::foo];

Expand Down
Loading