CppUtils
C++ Utilities Library
Project Health
Project Activity
Library Features
Containers
BidirectionalMap- Two-way key-value mappingBTree- Balanced tree for large sorted datasets with efficient range queries and low memory accessDependencyGraph- Dependency graph for managing dependencies between objectsMeshNetwork- Graph of shared objects without hierarchySize- Semantic wrapper aroundstd::size_tfor representing 2D (Size2: width/height) and 3D (Size3: width/height/depth) sizesStack- Type-specific stack without predefined type list (unlikeTypedStack)Tree- Hierarchical node structure with parent-child linksTypedStack- Multi-type stack with exact object size layout, suitable for argument passing and VM stacksVec2/Vec3- 2D/3D math vectors with operators and common functions
Execution
Event- An event for thread synchronizationEventDispatcher- Event system to subscribe functions and trigger actions by event nameEventQueue- Thread-safe event queue running on a dedicated thread for asynchronous event processing (preserves event order)ScopeGuard- RAII utility to execute a function when leaving a scope, ensuring resource cleanup
File System
Watcher- File modification watcher
Functional
LambdaCalculus- Compile-time utilities for lambda calculus manipulation
Languages (Parsers, Compilers, VM)
- Tools to create parsers and compilers (CSS, INI, HTML, JSON, Markdown, XML) (work in progress )
CSV Mapping- Type-safe CSV to struct mapping with support for custom conversion functionsCLikeCompiler- Compiler for C-inspired languageGrammarParser- A parser for defining and interpreting custom grammars, used for building language parsersMetaEvaluator- Homoiconic meta-circular evaluator with extensible reflexivityASTParser- AST parser (work in progress )VirtualMachine- Generic virtual machine
Logging & Benchmarking
Logger- Asynchronous, configurable and formattable logger with support for colors and customizable log typesFileSink- Pluggable sink for automated file logging with integrated rotation and file size managementLogRotate- Log file rotation based on maximum file sizeChronoLogger- RAII timer that logs elapsed time at scope exit
Math
Easing- Collection of easing functions for smooth animationRandom- Pseudorandom number generationUtility- Floating-point comparison with epsilon tolerance
String
Encoding- UTF-8 and UTF-32 conversion and character display width utilitiesHash- Hashing utilities for strings
Networking
Client- TCP client with synchronous and asynchronous modesServer- TCP server with multi-client support
Patterns
Singleton- Generic Meyers Singleton implementation (thread-safe and lazy)Multiton- Generic Multiton implementation based on the Meyers Singleton
Terminal
Canvas- Terminal-based 2D drawing surfaceCursor- Terminal cursor manipulationPrimitive- Basic drawing primitives for terminal (lines, rectangles, circles, ellipses)ProgressBar- Dynamically updating terminal progress barRawTerminal- Raw input handling (no buffering or echo)Size- Terminal size utilitiesTextColor- Terminal text color utilitiesTextModifier- Utilities to style and color terminal textTitle- Terminal title utilities
Multithreading & Synchronization
Scheduler- Simple scheduler to run delayed functions on separate threadScheduledEventDispatcher- Dispatches events asynchronously with timed (delay/when) executionAsyncEventDispatcher- Event dispatcher that uses a ThreadPool for immediate asynchronous event executionThreadLoop- Thread loop with exception handlingThreadPool- Fixed-size thread pool for parallel task executionTryAsync- Launches a function asynchronously, forwards exception to callerUniqueLocker- RAII wrapper holding a value with exclusive accessSharedLocker- RAII wrapper holding a value with shared/exclusive accessAccessor- RAII accessor for reading/writing anUniqueLockeror exclusive access to aSharedLockerReadOnlyAccessor- RAII accessor for shared (non-exclusive) reading of aSharedLocker, allowing parallel accessMultipleAccessor- RAII accessor for multiple lockers, safely acquiring them to avoid deadlocks and data races
Type
Concept- Extensions toandproviding additional compile-time checks and utilitiesEnum- Generic enum-to-string conversionMapping- Generic compile-time mapping between valuesTuple- Visitor forstd::tupleVariadicTemplate- Metaprogramming on variadic parametersVariant- Generic print and comparison operators forstd::variant
Unit Testing
DummyObject- Dummy object that prints construction, destruction, copy and move operations, while counting copies and moves for test verificationUnitTest- Minimal test framework with assertions and filters
Miscellaneous
- Many other functions
Getting Started
This library is used in my C++ projects, but you can also use it in your projects. Just follow the installation steps and consult the documentation for each feature you need.
Prerequisites
- A C++26 compliant compiler with std module support
- XMake
Installation
In your XMake projects:
add_repositories("xmake-repo git@github.com:MorganCaron/xmake-repo.git")
add_requires("CppUtils")
target("YourProject", function()
add_packages("CppUtils", {public = true})
end)
add_requires("CppUtils")
target("YourProject", function()
add_packages("CppUtils", {public = true})
end)
Configure the build via the xmake menu
xmake f [--toolchain=llvm] --runtimes="c++_shared" [--sdk=/opt/llvm-git] --menu
Configure the build manually
xmake f [--toolchain=llvm] --runtimes="c++_shared" [--sdk=/opt/llvm-git] [-y|--yes] [--enable_tests=y] [--sanitize_memory=y] [--sanitize_thread=y]
Build command
xmake [b|build] [-vD]
Build & Run tests
xmake [r|run] [-d|--debug]
Watch tests
xmake watch -r [-d|--debug]