An open-source thread-safe C++11 timer exposing APIs in C++, Python2 and Java programming language. It provides a simple to use and easy to understand interface. This project does not depends on any third-party library and uses modern C++.
git clone https://github.com/gmatesunny/watchcat.git
cd build
cmake ..
make
cd swig
bash ./generate.sh
cd build
./example/example
./test/testwatchcat/testwatchcat
-
Adapt
libwatchcat/CMkakeLists.txt
to buildSHARED
orSTATIC
library as per your custom project need and then addadd_subdirectory(libwatchcat)
to your rootCMkakeLists.txt
file -
It could be used as a header only library for C++11 without the need to create
SHARED
orSTATIC
library. You only need to includelibwatchcat/timer.hpp
andlibwatchcat/time.cpp
files in your custom project.
You can see the sample use of this library in example/main.cpp
. The client will register events as lambda functions or a function pointer and pass or catch a variable as reference. This variable shall be update by some other function or method. The registered event will be invoked at regular intervals or only once based on the flag isRepeated
- to check the status of the passed or catched variable.
The event can be deactivated/cancelled by the client if registered event need not to be invoked at regular interval or if there is no need to observe. In default setting, the event will be automatically deactivated/cancelled after it is invoked for the first time.
The Python2 and Java APIs are generated using swig interface file and will be available inside swig directory once generated.
Feel free to open any topic in Discussion
section of github for this watchcat repository.
├── build ├── CMakeLists.txt ├── example │ ├── CMakeLists.txt │ └── main.cpp ├── libwatchcat │ ├── CMakeLists.txt │ ├── timer.cpp │ └── timer.hpp ├── LICENSE ├── README.md ├── swig │ ├── generate.sh │ ├── main.java │ ├── main.py │ ├── timer.i └── test ├── CMakeLists.txt └── testwatchcat ├── CMakeLists.txt ├── main.cpp ├── testwatchcat.cpp └── testwatchcat.hpp
The followng diagram shows the class UML diagram.
The events are placed in the vector
. The id's and next invocation time of the events is maintained in a self ordered set
. The events are executed on a worker thread instead of spawning a new theread for each invocation.
Copyright (c) Kumar Roshan Mehta (gmate.sunny@gmail.com)
Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT)