Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
Standard: c++11
BasedOnStyle: Google
IndentWidth: 4
Language: Cpp
PointerAlignment: Left
BreakBeforeBraces: Stroustrup
ColumnLimit: 120
IncludeCategories:
# Header file associated with cpp file (default)

# gtest/gmock headers
- Regex: "^<gtest/.*>"
Priority: 1
- Regex: "^<gmock/.*>"
Priority: 1

# Local/private headers included with ""
- Regex: '^"([^/]+/)*[^/]+\.hpp"$'
Priority: 2
- Regex: '^"([^/]+/)*[^/]+\.h"$'
Priority: 2

# External headers included with <>
- Regex: '^<.*\.hpp>$'
Priority: 3
- Regex: '^<.*\.h>$'
Priority: 3

# Standard library headers
- Regex: "^<.*>$"
Priority: 4
37 changes: 37 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
bash-completion \
build-essential \
cmake \
clang \
clangd \
clang-format \
clang-tidy \
curl \
doxygen \
gdb \
git \
graphviz \
lcov \
lldb \
llvm \
nano \
software-properties-common \
sudo \
unzip \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ARG USERNAME=ubuntu
RUN passwd -d ${USERNAME} \
&& mkdir -p /home/${USERNAME}/.cache && chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.cache \
&& SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/home/${USERNAME}/.cache/.bash_history" \
&& echo "$SNIPPET" >> "/home/${USERNAME}/.bashrc"

USER $USERNAME

WORKDIR /workspace
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "C++ Channel",
"dockerFile": "Dockerfile",
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cmake-tools",
"streetsidesoftware.code-spell-checker",
"DavidAnson.vscode-markdownlint",
"xaver.clang-format",
"twxs.cmake",
"fredericbonnet.cmake-test-adapter",
"llvm-vs-code-extensions.vscode-clangd",
"vadimcn.vscode-lldb"
]
}
},
"mounts": [
"source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
"source=${env:HOME}/.ssh,target=/home/ubuntu/.ssh,type=bind,consistency=cached",
"source=cache,target=/home/ubuntu/.cache,type=volume"
],
"workspaceFolder": "/workspace",
"remoteUser": "ubuntu"
}
6 changes: 5 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ on:
branches:
- master
paths-ignore:
- '.devcontainer/**'
- '.vscode/**'
- 'LICENSE'
- 'Makefile'
- '**/README.md'
pull_request:
paths-ignore:
- '.devcontainer/**'
- '.vscode/**'
- 'LICENSE'
- 'Makefile'
- '**/README.md'
workflow_dispatch:

Expand Down Expand Up @@ -129,7 +133,7 @@ jobs:
- uses: actions/checkout@v4

- name: Run Clang Format
run: clang-format --dry-run --Werror $(find include -type f)
run: clang-format --dry-run --Werror $(find include tests examples -type f -name *.*pp)

clang-tidy:
name: Clang Tidy
Expand Down
8 changes: 1 addition & 7 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"recommendations": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"xaver.clang-format",
"twxs.cmake",
"fredericbonnet.cmake-test-adapter",
"ms-vscode.cmake-tools",
"notskm.clang-tidy",
"ms-vscode-remote.remote-containers",
]
}
24 changes: 6 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"name": "Launch (LLDB)",
"type": "lldb",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "PATH",
"value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
}
"args": [
"--gtest_color=yes"
],
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
"cwd": "${workspaceFolder}",
"terminal": "integrated"
}
]
}
14 changes: 10 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
"-DCPP_CHANNEL_SANITIZERS=ON",
"-DCPP_CHANNEL_SANITIZE_THREADS=OFF",
"-DCMAKE_CXX_STANDARD=11",
"-DCMAKE_INSTALL_PREFIX=${workspaceFolder}/install",
"-DCMAKE_INSTALL_PREFIX=${workspaceFolder}/install"
],
"clang-tidy.fixOnSave": false,
"clang-tidy.lintOnSave": false,
"editor.formatOnSave": true,
"clang-format.executable": "clang-format",
"clang-format.style": "file",
"editor.defaultFormatter": "xaver.clang-format",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
"files.trimFinalNewlines": true,
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}/build",
"--background-index",
"--clang-tidy"
]
}
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
all:

bench:
- sudo cpupower frequency-set --governor performance

mkdir -p build/bench && cd build/bench \
&& cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCPP_CHANNEL_BUILD_TESTS=ON \
&& cmake --build . --config Release --target channel_benchmark -j \
&& ./tests/channel_benchmark

- sudo cpupower frequency-set --governor powersave

coverage:
mkdir -p build/coverage && cd build/coverage \
&& cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCPP_CHANNEL_BUILD_TESTS=ON -DCPP_CHANNEL_COVERAGE=ON \
&& cmake --build . --config Debug --target channel_tests -j \
&& ctest -C Debug --verbose -L channel_tests --output-on-failure -j \
&& lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch \
&& lcov --remove coverage.info "*/usr/*" -o coverage.info \
&& lcov --remove coverage.info "*/gtest/*" -o coverage.info \
&& genhtml coverage.info --output-directory coverage-report \
&& cd coverage-report \
&& python3 -m http.server 8000

doc:
doxygen
cd docs && python3 -m http.server 8000
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ Exceptions:
* Range-based for loop supported.
* Close to prevent pushing and stop waiting to fetch.
* Integrates with some of the STL algorithms. Eg:
* `std::move(ch.begin(), ch.end(), ...)`
* `std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan))`.
* `std::copy_if(chan.begin(), chan.end(), ...);`
* `std::move(ch.begin(), ch.end(), ...)`
* `std::transform(input_chan.begin(), input_chan.end(), msd::back_inserter(output_chan))`.
* `std::copy_if(chan.begin(), chan.end(), ...);`

## Installation

Expand All @@ -63,6 +63,7 @@ Choose one of the methods:
* Copy the [include](https://github.com/andreiavrammsd/cpp-channel/tree/master/include) directory into your project and add it to your include path.
* [CMake FetchContent](https://github.com/andreiavrammsd/cpp-channel/tree/master/examples/cmake-project)
* [CMake install](https://cmake.org/cmake/help/latest/command/install.html) - choose a [version](https://github.com/andreiavrammsd/cpp-channel/releases), then run:

```shell
VERSION=X.Y.Z \
&& wget https://github.com/andreiavrammsd/cpp-channel/archive/refs/tags/v$VERSION.zip \
Expand All @@ -72,6 +73,7 @@ VERSION=X.Y.Z \
&& cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local \
&& sudo cmake --install .
```

* [Bazel](https://github.com/andreiavrammsd/cpp-channel/tree/master/examples/bazel-project)

## Usage
Expand All @@ -84,16 +86,17 @@ VERSION=X.Y.Z \
int main() {
msd::channel<int> chan; // Unbuffered

int in = 1;
int out = 0;

// Send to channel
chan << in;
chan << 1 << 2;

// Read from channel
chan >> out;
int first{};
int second{};

chan >> first >> second;

assert(out == 1);
assert(first == 1);
assert(second == 2);
}
```

Expand Down Expand Up @@ -178,6 +181,6 @@ See [examples](https://github.com/andreiavrammsd/cpp-channel/tree/master/example

* In some cases, the integration with some STL algorithms does not compile with MSVC. See the [Transform test](https://github.com/andreiavrammsd/cpp-channel/blob/master/tests/channel_test.cpp).

<br>
---

Developed with [CLion](https://www.jetbrains.com/?from=serializer) and [Visual Studio Code](https://code.visualstudio.com/).
10 changes: 10 additions & 0 deletions examples/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
InheritParentConfig: true

Checks: >
-cppcoreguidelines-avoid-magic-numbers,
-readability-magic-numbers,
-fuchsia-default-arguments-calls

CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-length.MinimumVariableNameLength, value: '1' }
22 changes: 8 additions & 14 deletions examples/basic.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
#include <iostream>
#include <msd/channel.hpp>

#include "msd/channel.hpp"
#include <iostream>

int main()
{
msd::channel<int> ch{10};

int in{};

in = 1;
ch << in;
constexpr std::size_t capacity = 10;
msd::channel<int> channel{capacity};

in = 2;
ch << in;
channel << 1;

in = 3;
ch << in;
channel << 2 << 3;

for (auto out : ch) {
for (auto out : channel) {
std::cout << out << '\n';

if (ch.empty()) {
if (channel.empty()) {
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/bazel-project/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ archive_override(
"echo '" + msd_channel_module + "' > MODULE.bazel",
"echo '" + msd_channel_build + "' > BUILD.bazel",
],
urls = ["https://github.com/andreiavrammsd/cpp-channel/archive/refs/tags/v1.2.1.zip"],
strip_prefix = "cpp-channel-1.2.1",
integrity = "sha256-fGew8OKF/gWyjkupXFiu+nPxTHgOfI2Ixs8wSxv9+gA=",
urls = ["https://github.com/andreiavrammsd/cpp-channel/archive/refs/tags/v1.3.0.zip"],
strip_prefix = "cpp-channel-1.3.0",
integrity = "sha256-qHLwQP0jeLguWgUxuOHmZ6kXiRCuDYmIUBfl1R1bF2E=",
)
3 changes: 2 additions & 1 deletion examples/bazel-project/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Bazel project

Example of using C++ Channel in a project with Bazel.
Example of using C++ Channel in a project with Bazel.

## Requirements

* C++11 compiler
* Bazel

Expand Down
8 changes: 4 additions & 4 deletions examples/bazel-project/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <msd/channel.hpp>

#include <cstddef>
#include <iostream>

#include "msd/channel.hpp"

int main()
{
constexpr std::size_t kChannelSize = 10;
msd::channel<int> chan{kChannelSize};
constexpr std::size_t channel_size = 10;
msd::channel<int> chan{channel_size};

int input{};

Expand Down
Loading