Skip to content

Commit ffff24e

Browse files
committed
Initial commit.
0 parents  commit ffff24e

27 files changed

Lines changed: 65327 additions & 0 deletions

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build
2+
3+
on: push
4+
5+
concurrency:
6+
group: ${{ github.ref }}
7+
cancel-in-progress: true
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
- name: Configure
16+
run: |
17+
mkdir build
18+
cmake -B build
19+
- name: Build
20+
run: cmake --build build
21+
- name: Install
22+
run: sudo cmake --build build --target install

.github/workflows/doxygen.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: doxygen
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: true
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
environment:
21+
name: github-pages
22+
url: ${{ steps.deployment.outputs.page_url }}
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v3
26+
- name: Generate documentation
27+
uses: mattnotmitt/doxygen-action@1.9.5
28+
with:
29+
working-directory: docs
30+
- name: Setup pages
31+
uses: actions/configure-pages@v3
32+
- name: Upload artifact
33+
uses: actions/upload-pages-artifact@v1
34+
with:
35+
path: docs/html
36+
- name: Deploy to GitHub Pages
37+
id: deployment
38+
uses: actions/deploy-pages@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/

.vscode/c_cpp_properties.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": 4,
3+
"configurations": [
4+
{
5+
"name": "g++",
6+
"compilerPath": "/usr/bin/g++",
7+
"cStandard": "c11",
8+
"cppStandard": "c++17",
9+
"intelliSenseMode": "gcc-x64",
10+
"includePath": [
11+
"${workspaceFolder}/include"
12+
]
13+
}
14+
]
15+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.detectIndentation": true,
3+
"editor.insertSpaces": false,
4+
"editor.tabSize": 4,
5+
"editor.useTabStops": true,
6+
"files.exclude": {
7+
"build/": true
8+
},
9+
}

CMakeLists.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(
4+
cppwrap
5+
VERSION 1.3.0
6+
DESCRIPTION "A collection of C++ wrappers for native APIs")
7+
8+
option(ENABLE_LINUX "Build wrappers for non-POSIX Linux functions" ON)
9+
option(ENABLE_POSIX "Build wrappers for POSIX functions" ON)
10+
option(ENABLE_SOCKETS "Build wrappers for BSD sockets functions" ON)
11+
option(ENABLE_WX_IPV6 "Build the IPv6 extensions (requires sockets)" ON)
12+
option(ENABLE_WX_SLURP "Build the slurp and spew extensions" ON)
13+
14+
set(SOURCES
15+
$<$<STREQUAL:$<UPPER_CASE:${ENABLE_LINUX}>,ON>:src/w/linux.cpp>
16+
$<$<STREQUAL:$<UPPER_CASE:${ENABLE_POSIX}>,ON>:src/w/posix.cpp>
17+
$<$<STREQUAL:$<UPPER_CASE:${ENABLE_SOCKETS}>,ON>:src/w/sockets.cpp>
18+
$<$<STREQUAL:$<UPPER_CASE:${ENABLE_WX_IPV6}>,ON>:src/wx/ipv6.cpp>
19+
$<$<STREQUAL:$<UPPER_CASE:${ENABLE_WX_SLURP}>,ON>:src/wx/slurp.cpp>
20+
)
21+
22+
add_library(${PROJECT_NAME} SHARED ${SOURCES})
23+
24+
set_target_properties(${PROJECT_NAME} PROPERTIES
25+
CXX_STANDARD 17
26+
CXX_STANDARD_REQUIRED yes
27+
CXX_EXTENSIONS no
28+
SOVERSION ${CMAKE_PROJECT_VERSION}
29+
)
30+
31+
target_include_directories(${PROJECT_NAME}
32+
PUBLIC
33+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
34+
$<INSTALL_INTERFACE:include>)
35+
36+
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME})
37+
install(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*.hpp")
38+
install(EXPORT ${PROJECT_NAME} DESTINATION lib/cmake/${PROJECT_NAME})
39+
install(FILES cmake/${PROJECT_NAME}Config.cmake DESTINATION lib/cmake/${PROJECT_NAME})

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
libcppwrap - A collection of C++ wrappers for native APIs
2+
Copyright 2021-2023 David A. Norris <danorris@gmail.com>
3+
Published under the MIT license - https://opensource.org/licenses/MIT
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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2+
[![build](https://github.com/dvnrrs/libcppwrap/actions/workflows/build.yml/badge.svg)](https://github.com/dvnrrs/libcppwrap/actions/workflows/build.yml)
3+
[![doxygen](https://github.com/dvnrrs/libcppwrap/actions/workflows/doxygen.yml/badge.svg)](https://github.com/dvnrrs/libcppwrap/actions/workflows/doxygen.yml)
4+
5+
# libcppwrap<br><small><sub>A collection of C++ wrappers for native APIs</sub></small>
6+
7+
`libcppwrap` is a collection of low-level C++ wrappers around native C APIs such as POSIX
8+
functions and BSD sockets. It provides the following features on top of the native functions,
9+
while duplicating the function signatures as closely as possible:
10+
11+
* Errors are thrown as `std::system_error` exceptions instead of returning error codes.
12+
* Since return values are no longer used for error reporting, output parameters can be returned as
13+
values instead, wherever practical.
14+
* The [RAII](https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization) pattern is
15+
applied to resources such as file handles, preventing leaks, using a sophisticated and flexible
16+
`w::handle` type.
17+
* Functions such as `fcntl()` and `ioctl()`, which can take input and/or output parameters of
18+
arbitrary type, are implemented as type-safe templates.
19+
* Derived POD structures for types such as `sockaddr_in` are provided with useful constructors for
20+
initialization. Use of the derived structures is always optional.
21+
22+
The philosophy of the library is to stay as faithful as possible to the native API, while ensuring
23+
type- and exception-safety and resource management as robustly as possible. Some helper functions
24+
which deviate from the native APIs or add missing functionality are implemented in a separate,
25+
optional namespace, which can be disabled.
26+
27+
The library is currently very POSIX-centric, being developed for and tested on Linux. It could and
28+
may eventually be extended to include native APIs for other platforms like Windows.
29+
30+
# Usage
31+
32+
`libcppwrap` exposes two namespaces, `w` and `wx`. The `w` namespace contains the core wrappers,
33+
which follow the native APIs as closely as possible. The `wx` namespace contains useful extensions
34+
which deviate from the native API but provide low-level functionality that would not necessarily
35+
justify a separate library.
36+
37+
#include <w/posix.hpp>
38+
39+
auto fd = w::open("file.txt", "at");
40+
w::write(fd, "hello", 5);
41+
// fd is automatically closed when it goes out of scope
42+
43+
See the **[Doxygen API reference](https://dvnrrs.github.io/libcppwrap/)** for details.
44+
45+
# Building
46+
47+
`libcppwrap` has no dependencies, requiring only a C++ compiler that supports C++17.
48+
49+
It can be built easily with [CMake](https://cmake.org/):
50+
51+
mkdir build
52+
cd build
53+
cmake ..
54+
make
55+
sudo make install
56+
57+
# License
58+
59+
`libcppwrap` is published under the [MIT License](https://opensource.org/license/mit/). See
60+
[LICENSE.txt](LICENSE.txt) for the full license text.

cmake/cppwrapConfig.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
2+
include(${SELF_DIR}/cppwrap.cmake)

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/html/

0 commit comments

Comments
 (0)