Skip to content
A light-weight observer implementation in cpp
C++ CMake
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
include/nbobservable
.gitignore
CMakeLists.txt
LICENSE
README.md
main.cpp

README.md

Welcome to nbobservable

nbobservable is a light-weight implemention of observer pattern in cpp. It only contains a single header file and it's easy to integrate to your project.

"nb" can be pronounced as "NiuBi" in Chinese, and means strong and powerful. Hope it may be of some help.

Prerequisites

  1. Boost signals2

Usage

We provided a simple demo to demonstrate how to use observable module in main.cpp. You can build&run to have a quick view of it.

# build
cd {nbobservable_dir}

mkdir build && cd build
cmake ..

# run
./nbobservable_app
  • Define your custom class derived from nbobservable::Observable.

Observable is a template class, and T stands for function prototype of observer slot. Arguments passed to the slot are defined in your custom class, and observers should obey to it.

  • Call registerObserver interface to add observer by each operation.

A handler responding to newly created slot connection is returned after this call, and you can pass it to removeObserver function to disconnect this slot.

  • Call removeObserver to remove one observer, or clearAllObservers to disconnect all connections.
You can’t perform that action at this time.