https://github.com/henriktrom/cpp_utils
A lightweight C++ utility module for multithreaded pipeline components and JSON handling. Includes a flexible StageBase class for real-time data processing and tools for loading, validating, and writing structured JSON files using RapidJSON.
https://github.com/henriktrom/cpp_utils
cpp json multithreading utils-library
Last synced: about 1 month ago
JSON representation
A lightweight C++ utility module for multithreaded pipeline components and JSON handling. Includes a flexible StageBase class for real-time data processing and tools for loading, validating, and writing structured JSON files using RapidJSON.
- Host: GitHub
- URL: https://github.com/henriktrom/cpp_utils
- Owner: HenrikTrom
- License: cc0-1.0
- Created: 2025-05-27T12:37:30.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-18T14:08:54.000Z (about 1 year ago)
- Last Synced: 2025-06-20T06:07:44.259Z (12 months ago)
- Topics: cpp, json, multithreading, utils-library
- Language: C++
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
- Citation: Citation.cff
Awesome Lists containing this project
README
# 🧰 cpp-utils
[](https://zenodo.org/badge/latestdoi/991307682)
A lightweight C++ utility module for multithreaded pipeline components and JSON handling.
Includes a flexible `StageBase` class for real-time data processing and tools for loading, validating, and writing structured JSON files using [RapidJSON](https://github.com/Tencent/rapidjson).
This module is part of my **ROS/ROS2** [real-time 3D tracker](https://github.com/HenrikTrom/real-time-3D-tracking) and its [docker-implementation](https://github.com/HenrikTrom/ROSTrack-RT-3D).
## 📑 Citation
If you use this software, please use the GitHub **“Cite this repository”** button at the top(-right) of this page.
## 🔧 Features
### ✅ JSON Tools (`jsontools.h`)
- Load and validate JSON documents with optional schema support
- Save structured JSON objects to disk
- Automatically timestamp JSON metadata
- Scan directories for JSON or config files
### 💻 Cli Tools (`clitools.h`)
- Simple status bar
### 📷 OpenCV Tools (`opencvtools.h`)
- Batch Video Iterator, iterate over a batch of videos frame-by-frame
### 🧵 StageBase Template
A generic, thread-safe, multi-stage processing base class for building C++ pipelines.
Features:
- Threaded input/output FIFOs
- Customizable `ProcessFunction`
- Hooks for completion callbacks
- Runtime-safe termination and thread joining
> **Note**: The general layout of `StageBase` was developed as part of Cheng Minghao's PhD work.
## Integration
Include this repo as a submodule or CMake interface library in larger projects, such as:
- [flirmulticamera](https://github.com/HenrikTrom/flirmulticamera)
- [detection-inference](https://github.com/HenrikTrom/detection_inference)
- [pose-inference](https://github.com/HenrikTrom/pose_inference)
## Dependencies
- C++17
- OpenCV 4.10.0
- spdlog
- [RapidJSON](https://github.com/Tencent/rapidjson) (included or linked)
- Standard C++ libraries (``, ``, ``, ``, etc.)
## Example Usage
### Load and validate JSON
```cpp
cpp_utils::Document config;
cpp_utils::load_json_with_schema("config.json", "schema.json", 8192, config);
````
### Use the pipeline base
```cpp
class MyStage : public cpp_utils::StageBase {
bool ProcessFunction(MyInput& input, MyOutput& output) override {
// process input -> output
return true;
}
};
```
## 👥 Acknowledgments
* JSON loading and schema support based on [RapidJSON](https://github.com/Tencent/rapidjson)
* Stage Base Template was initially designed in **Cheng Minghao's** PhD and adjusted for online-tracking.