Skip to content
skipbitPublic

About

A modern C++23 general-purpose library for self-contained applications

Topics

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

dross 🧱

A modern C++23 general-purpose library for self-contained applications

Check MIT License C++23 CMake

dross is a general-purpose C++23 library of building blocks for applications: value types held together by a dynamic value, including arbitrary precision numbers, TOML reading and writing, platform utilities for the environment, paths and XDG directories, per-thread run loops with the threads, timers and operation queue built on them, and typed notifications delivered on the thread each subscriber chose, within a process or from one process to another through a place such as a Unix domain socket, or, with the optional gRPC part, across machines over gRPC.

✨ Key Features

  • πŸ”’ Arbitrary Precision Arithmetic - String-based numbers that do not overflow; a quotient that does not terminate within 4096 digits keeps 34 significant digits
  • 🧡 Dynamic Type System - Unified value type using std::variant
  • πŸ”§ Platform Utilities - Environment, filesystem, and XDG support on Linux and macOS
  • ⚑ No Third-Party Dependencies - Only the C++ standard library and the system's threads
  • 🎯 Modern C++23 - Concepts for compile-time constraints, and failures returned through std::expected

πŸš€ Quick Start

Requirements

  • A C++23 compiler and standard library. On Linux, GCC 13–15, or Clang 20–22 with libstdc++ or libc++; on macOS, the Apple Clang of macOS 15 or 26. Getting Started lists the supported pairings and what CI builds.
  • CMake 3.20+, or 3.25+ to build with the presets
  • gRPC 1.51+ and protobuf 3.21+, for the optional gRPC part only, installed where CMake finds them; dross does not fetch or build them. CI builds the part against Ubuntu 24.04's gRPC 1.51 and against Homebrew's current release

Installation

From Source

git clone https://github.com/skipbit/dross.git
cd dross
With CMake
# Configure, build and test into build/release
cmake --workflow --preset release

# Install
sudo cmake --install build/release --prefix /usr/local

The presets are debug, release, static, sanitize-address and sanitize-thread, each building into build/<preset>. The library is shared by default; the static preset, or -DBUILD_SHARED_LIBS=OFF, builds a static one. CMake 3.20 to 3.24 has no presets: configure with cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release, then run cmake --build build/release.

The gRPC part, dross::grpc, is built only when asked for, and configuring stops with the reason when gRPC is missing or too old:

cmake --preset release -DDROSS_WITH_GRPC=ON
cmake --build --preset release

Using in Your Project

CMake Integration

# Option 1: find_package (after installation)
find_package(dross REQUIRED)
target_link_libraries(your_target PRIVATE dross::dross)

# Option 2: FetchContent (no installation needed)
include(FetchContent)
FetchContent_Declare(dross
    GIT_REPOSITORY https://github.com/skipbit/dross.git
    GIT_TAG <version>
)
FetchContent_MakeAvailable(dross)
target_link_libraries(your_target PRIVATE dross::dross)

# Option 3: CPM (no installation needed)
CPMAddPackage("gh:skipbit/dross#<version>")
target_link_libraries(your_target PRIVATE dross::dross)

Replace <version> with a tag from Releases. main is the development tip, and the ABI can change between 0.x releases.

The gRPC part, from a dross built with it, is asked for as a component, and gRPC is looked for only then:

find_package(dross REQUIRED COMPONENTS grpc)
target_link_libraries(your_target PRIVATE dross::grpc)

pkg-config Integration

# Compile flags
pkg-config --cflags dross

# Link flags
pkg-config --libs dross

# Check version
pkg-config --modversion dross

dross.pc names the prefix given at configure time. For an install written elsewhere with cmake --install --prefix, --define-prefix has pkg-config take the prefix from where it finds dross.pc in <prefix>/lib/pkgconfig:

PKG_CONFIG_PATH=<prefix>/lib/pkgconfig pkg-config --define-prefix --cflags --libs dross

dross.pc describes the library without the gRPC part, which is used through find_package.

Manual Compilation

# Using pkg-config
g++ -std=c++23 $(pkg-config --cflags dross) main.cpp $(pkg-config --libs dross)

# Or manually
g++ -std=c++23 -I/usr/local/include main.cpp -L/usr/local/lib -ldross

Basic Usage

#include <dross/dross.h>

int main()
{
    // Arbitrary precision arithmetic
    dross::number big_num{"99999999999999999999999999999999999999"};
    dross::number result = big_num * big_num;  // No overflow!

    // Dynamic typing. dictionary has no initializer-list constructor, so
    // entries are assigned after construction.
    dross::dictionary config;
    config["name"] = dross::string("dross");
    config["version"] = dross::string("0.1.0");
    config["features"] = dross::array{dross::string{"fast"}, dross::string{"safe"}};
    config["release_date"] = dross::timestamp{2024, 1, 21, 15, 30, 0, dross::timezone::utc()};

    dross::value root = config;

    // Platform utilities. The XDG accessors are instance methods, and the
    // application name is already part of what they return.
    dross::xdg app{"myapp"};
    if (auto config_dir = app.config_home()) {
        dross::path app_config = dross::path{*config_dir}.append("config.toml");
    }
}

πŸ“š Core Modules

Type System

  • boolean - Type-safe boolean operations with logical operators
  • number - Arbitrary precision arithmetic with string-based storage
  • string - UTF-8 text held as bytes, with byte-oriented operations
  • timestamp - Date and time handling with timezone support
  • timezone - Type-safe timezone representation with ISO 8601 support
  • array - Dynamic arrays with value semantics
  • dictionary - Key-value containers
  • data - Byte buffer, converted to and from strings byte for byte
  • value - Polymorphic type holding any supported type
  • value_traits - How a type becomes a value and comes back from one, given for dross's own types, numbers, std::string and standard containers
  • error - A std::error_code with its category, returned through std::expected

Format Layer

  • toml - TOML parsing into a dictionary and serialization back to TOML

Platform Layer

  • environment - Environment variable access
  • path - Filesystem operations with error handling
  • xdg - XDG Base Directory specification support

IPC Layer

  • ipc::unix_socket - A place where processes meet: a Unix domain socket at a path
  • ipc::grpc_address / ipc::grpc_target - In the optional gRPC part, a place to listen at and one to connect to over gRPC, each with the credentials the user gives; only dross talks to dross there
  • ipc::message_channel - One connection between two processes, carrying whole messages, and what it tells through message_channel_events
  • ipc::message_acceptor - What listens at a place, telling of each connection it takes through message_acceptor_events
  • ipc::message_connector - What connects to a place, one try at a time
  • ipc::message_listenable_place_type / ipc::message_connectable_place_type - Concepts for a place that can be listened at or connected to, so that a broadcaster can be published at, or a listener can hear through, a place of any type that satisfies them

Thread Layer

  • runloop - Per-thread task queue, so work can be handed to a specific thread
  • thread - A handle to an OS thread, running a loop the library drives, a one-shot body, or one its owner drives
  • timer - A callback installed on a run loop, firing once or on an interval
  • operation_queue - A fixed set of worker threads, each running its own loop, taking submitted tasks from one shared queue by priority, and in the order they were submitted within one priority, each only once the tasks it runs after have returned
  • operation_result - What a task given to operation_queue::enqueue() returned, to wait on and read as its own type

Notification Layer

  • topic - The name a notification is sent under and the type of value it carries
  • broadcaster - Sends notifications within the process, and, when published at a place, to listeners in other processes too; it does nothing else
  • listener - Subscribes to one broadcaster's notifications, in this process or in another, and does not send
  • link_event - What happened to a listener's connection to another process: connected, disconnected, or a value its type could not be made from
  • delivery - Where a subscriber's function runs: on a run loop, on the sending thread, or on an operation queue's worker
  • subscription - The right to go on receiving, which ends when it is reset or destroyed
  • notification - What one call to notify() sent, through which its deliveries not yet started can be cancelled
  • notify_options - How notify() sends, such as deferring the subscribers that run on the sending thread until it returns
  • observable - A value its owner thread changes, whose changes reach the functions given to when_changed(), and which other threads set through a proxy

πŸ“– Documentation

πŸ“˜ API Reference & User Guide

The documentation includes:

  • πŸ” API Reference - The type system and the platform layer
  • πŸ“š User Guide - An overview of the library's conventions
  • πŸ’‘ Examples - Code examples across the modules

πŸ—οΈ Architecture

dross follows modern C++ best practices:

  • Pimpl Idiom - Types keep their representation behind an opaque pointer, apart from error, path, xdg, ipc::unix_socket, ipc::grpc_address, ipc::grpc_target, timestamp, timezone and the data iterators, which hold theirs directly, and the ipc::message_* interfaces, which a part implements; the ABI can change in any 0.x release
  • Value Semantics - The value types are copyable and assignable; environment exposes only static members
  • Error Handling - Failures are returned through std::expected and std::optional. Where a call throws, lets an exception through, or reports its outcome another way, its comment in the public headers says so
  • Type Safety - Concepts for compile-time constraints

πŸ§ͺ Testing

The tests use GoogleTest:

# Run all tests, in the tree the release preset built
ctest --preset release

# Run specific test patterns
ctest --preset release -R number
./build/release/test/dross_test --gtest_filter="number_test.*"

# Verbose output
ctest --preset release -V

πŸ—ΊοΈ Roadmap

Planned Features

  • Format - JSON, XML, YAML
  • Concurrency - Coroutines
  • Multimedia - Image processing, color management, transformations
  • Application Support - CLI parsing, logging, preferences

🀝 Contributing

See the Contributing guide for the workflow, and CODINGSTYLE.md for coding guidelines.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❀️ by Yuma Endo

About

A modern C++23 general-purpose library for self-contained applications

Topics

Resources

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages