Skip to content

Commit 61ce8ae

Browse files
Merge pull request #1 from connectivecpp/develop
Merge develop to main
2 parents af59582 + dccc623 commit 61ce8ae

File tree

11 files changed

+3929
-2
lines changed

11 files changed

+3929
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Build, run unit tests
2+
name: CMake build and run unit test matrix
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
env:
10+
BUILD_TYPE: Release
11+
jobs:
12+
build_matrix:
13+
strategy:
14+
matrix:
15+
# os: [ubuntu-latest, windows-latest, macos-14]
16+
os: [ubuntu-latest]
17+
runs-on: ${{ matrix.os }}
18+
defaults:
19+
run:
20+
shell: bash
21+
steps:
22+
- name: checkout
23+
uses: actions/checkout@v4
24+
- name: create-build-dir
25+
run: mkdir build
26+
- name: configure-cmake
27+
run: cd build && cmake -D SHARED_BUFFER_BUILD_TESTS:BOOL=ON -D SHARED_BUFFER_BUILD_EXAMPLES:BOOL=ON ..
28+
- name: build
29+
run: cd build && cmake --build . --config $BUILD_TYPE
30+
- name: run-unit-test
31+
run: cd build && ctest -C $BUILD_TYPE

.github/workflows/gen_docs.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Build, run unit tests
2+
name: Generate documentation
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
build_matrix:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest]
13+
runs-on: ${{ matrix.os }}
14+
defaults:
15+
run:
16+
shell: bash
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v4
20+
- name: run-doxygen
21+
uses: mattnotmitt/doxygen-action@v1.9.8
22+
with:
23+
working-directory: doc
24+
- name: deploy-pages
25+
uses: peaceiris/actions-gh-pages@v4
26+
with:
27+
github_token: ${{ secrets.GITHUB_TOKEN }}
28+
publish_dir: ./doc/doc_output/html

CMakeLists.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2024 by Cliff Green
2+
#
3+
# https://github.com/connectivecpp/shared-buffer
4+
#
5+
# I'm still learning CMake, so improvement suggestions are always welcome.
6+
#
7+
# Distributed under the Boost Software License, Version 1.0.
8+
# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9+
10+
cmake_minimum_required ( VERSION 3.14 FATAL_ERROR )
11+
12+
project ( shared_buffer
13+
LANGUAGES CXX
14+
DESCRIPTION "Reference counted character buffer classes"
15+
HOMEPAGE_URL "https://github.com/connectivecpp/shared-buffer/" )
16+
17+
option ( SHARED_BUFFER_BUILD_TESTS "Build unit tests" OFF )
18+
option ( SHARED_BUFFER_BUILD_EXAMPLES "Build examples" OFF )
19+
option ( SHARED_BUFFER_INSTALL "Install header only library" OFF )
20+
21+
# add library targets
22+
23+
add_library ( shared_buffer INTERFACE )
24+
add_library ( chops::shared_buffer ALIAS shared_buffer )
25+
26+
# configure library target
27+
28+
target_include_directories ( shared_buffer INTERFACE
29+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
30+
$<INSTALL_INTERFACE:include/> )
31+
target_compile_features ( shared_buffer INTERFACE cxx_std_20 )
32+
33+
# check to build unit tests
34+
if ( ${SHARED_BUFFER_BUILD_TESTS} )
35+
enable_testing()
36+
add_subdirectory ( test )
37+
endif ()
38+
39+
# check to build example code
40+
if ( ${SHARED_BUFFER_BUILD_EXAMPLES} )
41+
add_subdirectory ( example )
42+
endif ()
43+
44+
# check to install
45+
if ( ${SHARED_BUFFER_INSTALL} )
46+
set ( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt )
47+
include ( CPack )
48+
endif ()
49+
50+
# end of file
51+

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,66 @@
1-
# shared-buffer
2-
A reference counted character buffer class template
1+
# Shared Buffer, Header-Only C++ 20 Reference Counted Byte Buffer Classes
2+
3+
#### Unit Test and Documentation Generation Workflow Status
4+
5+
![GH Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/connectivecpp/shared-buffer/build_run_unit_test_cmake.yml?branch=main&label=GH%20Actions%20build,%20unit%20tests%20on%20main)
6+
7+
![GH Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/connectivecpp/shared-buffer/build_run_unit_test_cmake.yml?branch=develop&label=GH%20Actions%20build,%20unit%20tests%20on%20develop)
8+
9+
![GH Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/connectivecpp/shared-buffer/gen_docs.yml?branch=main&label=GH%20Actions%20generate%20docs)
10+
11+
![GH Tag](https://img.shields.io/github/v/tag/connectivecpp/shared-buffer?label=GH%20tag)
12+
13+
## Overview
14+
15+
The `shared_buffer` classes are reference counted `std::byte` buffer classes useful for asynchronous networking. In particular, the Asio asynchronous networking library requires a buffer to be kept alive and valid until the outstanding IO operation (e.g. a network write) is completed. A straightforward and idiomatic way to achieve this is by using reference counted buffers.
16+
17+
There are two classes - `const_shared_buffer` for outgoing buffers (which should not be modified), and `mutable_shared_buffer` for incoming buffers (mutable and expandable as data arrives). There are efficient (move) operations for creating a `const_shared_buffer` from a `mutable_shared_buffer`, which allows the use case of creating a message and serializing its contents, then sending it out over the network.
18+
19+
While internally all data is kept in `std::byte` buffers, convenience methods are provided for converting between traditional buffer types (such as `char *` or `unsigned char*` or similar).
20+
21+
## Generated Documentation
22+
23+
The generated Doxygen documentation for `shared_buffer` is [here](https://connectivecpp.github.io/shared-buffer/).
24+
25+
## Dependencies
26+
27+
The `shared_buffer` header file does not have any third-party dependencies. It uses C++ standard library headers only. The unit test code does have dependencies as noted below.
28+
29+
## C++ Standard
30+
31+
`shared_buffer` uses C++ 20 features, including the "spaceship" operator (`<=>`), `std::span`, and `concepts` / `requires`.
32+
33+
## Supported Compilers
34+
35+
Continuous integration workflows build and unit test on g++ (through Ubuntu), MSVC (through Windows), and clang (through macOS).
36+
37+
## Unit Test Dependencies
38+
39+
The unit test code uses [Catch2](https://github.com/catchorg/Catch2). If the `SHARED_BUFFER_BUILD_TESTS` flag is provided to Cmake (see commands below) the Cmake configure / generate will download the Catch2 library as appropriate using the [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) dependency manager. If Catch2 (v3 or greater) is already installed using a different package manager (such as Conan or vcpkg), the `CPM_USE_LOCAL_PACKAGES` variable can be set which results in `find_package` being attempted. Note that v3 (or later) of Catch2 is required.
40+
41+
The unit test uses utilities from Connective C++'s [utility-rack](https://github.com/connectivecpp/utility-rack).
42+
43+
Specific version (or branch) specs for the dependenies are in `test/CMakeLists.txt`.
44+
45+
## Build and Run Unit Tests
46+
47+
To build and run the unit test program:
48+
49+
First clone the `shared-buffer` repository, then create a build directory in parallel to the `shared-buffer` directory (this is called "out of source" builds, which is recommended), then `cd` (change directory) into the build directory. The CMake commands:
50+
51+
```
52+
cmake -D SHARED_BUFFER_BUILD_TESTS:BOOL=ON ../shared-buffer
53+
54+
cmake --build .
55+
56+
ctest
57+
```
58+
59+
For additional test output, run the unit test individually, for example:
60+
61+
```
62+
test/shared_buffer_test -s
63+
```
64+
65+
The example can be built by adding `-D SHARED_BUFFER_BUILD_EXAMPLES:BOOL=ON` to the CMake configure / generate step.
66+

cmake/download_cpm.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# copied from CPM.cmake GitHub site
3+
# download CPM.cmake
4+
5+
file(
6+
DOWNLOAD
7+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.39.0/CPM.cmake
8+
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
9+
)
10+
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

0 commit comments

Comments
 (0)