Skip to content

Commit 76b246c

Browse files
committed
add all files
0 parents  commit 76b246c

10 files changed

Lines changed: 469 additions & 0 deletions

File tree

.github/workflows/test-linux.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test (Linux)
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.cpp'
7+
- '**.hpp'
8+
- '**.sh'
9+
workflow_dispatch:
10+
pull_request:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v4
19+
20+
- name: Setup cmake
21+
uses: jwlawson/actions-setup-cmake@v2
22+
23+
- name: Ubuntu packages
24+
shell: bash
25+
run: |
26+
sudo apt update -y
27+
sudo apt install -y build-essential gcc g++
28+
29+
- name: Permissions
30+
shell: bash
31+
run: sudo chmod -R 777 .
32+
33+
- name: Build
34+
shell: bash
35+
run: ./build-linux.sh

.github/workflows/test-windows.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Test (Windows)
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.cpp'
7+
- '**.hpp'
8+
- '**.bat'
9+
workflow_dispatch:
10+
pull_request:
11+
12+
jobs:
13+
build:
14+
runs-on: windows-latest
15+
16+
steps:
17+
- name: Checkout repo
18+
uses: actions/checkout@v4
19+
20+
- name: Setup cmake
21+
uses: jwlawson/actions-setup-cmake@v2
22+
23+
- name: Add msbuild to PATH
24+
uses: microsoft/setup-msbuild@v2
25+
26+
- name: Build
27+
shell: cmd
28+
run: build-win.bat

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build*/
2+
.vscode/
3+
.vs/

CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
set(project_name "observable-queue-test")
4+
5+
project(${project_name})
6+
7+
file(GLOB_RECURSE src_files
8+
"test/*.cpp"
9+
)
10+
11+
file(GLOB_RECURSE inc_files
12+
"include/*.hpp"
13+
)
14+
15+
add_executable(${project_name}
16+
${src_files}
17+
${inc_files}
18+
)
19+
20+
target_include_directories(${project_name} PUBLIC
21+
"include/"
22+
)
23+
24+
set_target_properties(${project_name} PROPERTIES
25+
LINKER_LANGUAGE CXX
26+
CXX_STANDARD_REQUIRED ON
27+
CXX_EXTENSIONS OFF
28+
)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 forgotthepen (https://github.com/forgotthepen/observable-queue)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# observable-queue
2+
3+
A single header library implementing an observable queue.
4+
5+
## Features:
6+
* All subscribers to the queue will be notified once an element is pushed
7+
* Thread-safe
8+
* Supports both threaded and manual-polling modes
9+
* Compatible with C++11
10+
11+
Example
12+
```c++
13+
#include "observable/queue.hpp"
14+
#include <iostream>
15+
#include <string>
16+
17+
int main(int argc, char* *argv) {
18+
// create an observable queue
19+
obs::queue<std::string> queue{};
20+
21+
// subscribe to push events
22+
queue += [](std::string &str) {
23+
std::cout << " >> You typed: " << str << '\n';
24+
};
25+
26+
while (true) {
27+
std::cout << "Type anything and press Enter: ";
28+
29+
std::string ss{};
30+
std::getline(std::cin, ss);
31+
32+
if ("exit" == ss || "quit" == ss || "x" == ss || "q" == ss) {
33+
break;
34+
}
35+
36+
// add it to the queue
37+
queue.emplace_back(ss);
38+
}
39+
40+
std::cout << "\nDone... " << '\n';
41+
return 0;
42+
}
43+
```

build-linux.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /bin/bash
2+
3+
function build_cxx () {
4+
rm -rf "build-linux/cxx_$1"
5+
cmake -S . -B "build-linux/cxx_$1" -DCMAKE_CXX_STANDARD=$1 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF || return 1
6+
cmake --build "build-linux/cxx_$1" --clean-first -v -j || return 1
7+
return 0
8+
}
9+
10+
build_cxx 23 || exit 1
11+
build_cxx 20 || exit 1
12+
build_cxx 17 || exit 1
13+
build_cxx 14 || exit 1
14+
build_cxx 11 || exit 1
15+
16+
exit 0

build-win.bat

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@echo off
2+
pushd "%~dp0"
3+
setlocal
4+
5+
call :build_cxx 23 || exit /b 1
6+
call :build_cxx 20 || exit /b 1
7+
call :build_cxx 17 || exit /b 1
8+
call :build_cxx 14 || exit /b 1
9+
call :build_cxx 11 || exit /b 1
10+
11+
exit /b 0
12+
13+
14+
:build_cxx
15+
rmdir /s /q "build-win\cxx_%~1"
16+
cmake -S . -B "build-win/cxx_%~1" -DCMAKE_CXX_STANDARD=%~1 -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF || exit /b 1
17+
cmake --build "build-win/cxx_%~1" --clean-first -v -j || exit /b 1
18+
exit /b 0

0 commit comments

Comments
 (0)