Skip to content

Commit 0846c7b

Browse files
Bringing everything up
1 parent af59582 commit 0846c7b

File tree

5 files changed

+1055
-2
lines changed

5 files changed

+1055
-2
lines changed

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: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
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+
## Overview
12+
13+
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.
14+
15+
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).
16+
17+
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).
18+
19+
## Generated Documentation
20+
21+
The generated Doxygen documentation for `shared_buffer` is [here](https://connectivecpp.github.io/shared-buffer/).
22+
23+
## Dependencies
24+
25+
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.
26+
27+
## C++ Standard
28+
29+
`shared_buffer` uses C++ 20 features, including the "spaceship" operator (`<=>`), `std::span`, and `concepts` / `requires`.
30+
31+
## Supported Compilers
32+
33+
Continuous integration workflows build and unit test on g++ (through Ubuntu), MSVC (through Windows), and clang (through macOS).
34+
35+
## Unit Test Dependencies
36+
37+
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.
38+
39+
Specific version (or branch) specs for the Catch2 dependency is in `test/CMakeLists.txt`.
40+
41+
## Build and Run Unit Tests
42+
43+
To build and run the unit test program:
44+
45+
First clone the `shared-buffer` repository, then create a build directory in parallel to the `shared-queue` directory (this is called "out of source" builds, which is recommended), then `cd` (change directory) into the build directory. The CMake commands:
46+
47+
```
48+
cmake -D SHARED_BUFFER_BUILD_TESTS:BOOL=ON ../shared-buffer
49+
50+
cmake --build .
51+
52+
ctest
53+
```
54+
55+
For additional test output, run the unit test individually, for example:
56+
57+
```
58+
test/shared_buffer_test -s
59+
```
60+
61+
The example can be built by adding `-D SHARED_BUFFER_BUILD_EXAMPLES:BOOL=ON` to the CMake configure / generate step.
62+

0 commit comments

Comments
 (0)