Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.

License

NotificationsYou must be signed in to change notification settings

Tracktion/choc

Repository files navigation

A random grab-bag of header-only, dependency-free C++ classes.

When you start trying to write a C++ project of any size, you'll soon start finding gaping holes in what the C++ standard library provides. To fill them, you'll end up either writing lots of helper functions yourself, or trawling the web for awful 3rd-party libraries which come with all kinds of baggage like messy build requirements, scads of stupid compiler warnings, awkward licenses, etc.

I got tired of re-implementing many of the same little helper classes and functions in different projects, so CHOC is an attempt at preventing future wheel-reinvention, by providing some commonly-needed things in a format that makes it as frictionless as possible for anyone to use this code in any kind of project.

So with that goal in mind, the rules for everything in CHOC are:

  • It's strictly header-only. Just#include the file you want, and you're done. Nothing needs adding to your build system to use any of this stuff.
  • It's all permissively ISC licensed. It should pass silently under the noses of even the most zealous legal teams.
  • Each file is as self-contained as possible. If you only need a couple of these classes, you should be able to cherry-pick at most a few CHOC headers into your project and not need to drag the whole repo along.
  • Clean, consistent, concise, modern C++. Not too simple. Not too over-generic or fancy. Easy to skim-read and find what you're looking for. Self-documenting where possible, with decent comments.

Basically CHOC is aimed at people (like me) who just want to use some decent library code without also spending their afternoon fighting CMake or looking up the right compiler flags to make the dratted thing work.


Highlights

The library is getting quite big now! Some of its many delights include:

Miscellaneous

  • A tinyplatform-detection header.
  • A fast, round-trip-accuratefloat/double to string converter.
  • Some headers which willdisable and reenable warnings for times when you have to include messy 3rd-party code in your otherwise faultless codebase.
  • The world's simplestunit test framework. I mainly wrote this so that CHOC can self-host its own unit-tests without any external dependencies, but have found it surprisingly useful for something that's about 100 lines of code.
  • Cross-platformdynamic library loading.
  • A tempting-but-probably-perilousin-memory DLL loader which can load a DLL from memory instead of a file (Windows only).
  • Various maths and bit-twiddlingbits and bobs.
  • A system for easily adding and collecting all theopen-source licenses that your project uses into a single string for displaying to a user (for license compliance).
  • A one-file header-onlyencapsulation of zlib, exposingstd::iostream compatible classes for compressing and decompressing data.
  • AZip file reader and decompressor class.
  • AHTTP and WebSocket server class. Life is too short to learn howboost::beast works and write all the boilerplate required just to serve some content and talk down a web-socket, so this class hides all the horribleness behind a very simple API.

Text and Files

  • Utterly basic string stuff like trimming, splitting, joining, comparisons, etc. For god's sake, I shouldn't need to write my own library just to trim a string...
  • Somemore esoteric string utilities like pretty-printing durations and sizes, URI encoding, etc.
  • SomeUTF8 validation and iteration classes.
  • Somefile utilities to provide single-function-call ways to do obvious things like loading a file's content, or saving a string into a file, creating self-deleting temp files, etc.
  • Afile watcher class for monitoring changes to a file or folder.
  • ACodePrinter class to help creating indented code listings.
  • AHTML generator for creating a tree of DOM objects and generating HTML text for it
  • Atext table generator, which can take an array of strings and tabulate it to align the columns nicely.
  • Afile wildcard matcher. I claim this is the cleanest possible implementation of this algorithm - I challenge you to prove me wrong!
  • A simplecommand-line argumment helper which simplifies a lot of basic command-line arg parsing tasks.

Containers

  • Aspan class to fill the gap until we can finally usestd::span.
  • Sometype and value classes which can represent typed values, but also build them dynamically, serialise them to a compact binary format (or as JSON).
  • A handySmallVector class which offers a std::vector interface but has pre-allocated internal storage.
  • Everyone hates COM, but sometimes you need someCOM helper classes to hide the ugliness.

Memory

GUI

  • Some bare-bonesmessage loop control functions.

  • Atimer class for cross-platform message loop timer callbacks.

  • The world's most hassle-free single-headerWebView class!

    This lets you create an embedded browser view (either as a desktop window or added to an existing window), and interact with it by invoking javascript code and binding callback C++ functions to be called by javascript. Something that makes this particularly special compared to other web-view libraries is that on Windows, it provides the modern Edge browser without you needing to install extra SDKs to compile it, and without any need to link or redistribute the Microsoft loader DLLs - it's literally adependency-free single-header Edge implementation. (Internally, some absolutely hideous shenanegans are involved to make this possible!)

    To try it out, if you compile the choc/tests project and run it with the command-line arg "webview", it pops up an example page and shows how to do some event-handling.

Javascript and JSON

  • A cross-engineJavascript API, with implementations for V8, QuickJS and Duktape!

    Both QuickJS and Duktape have been squashed into single-file header-only implementations, so are trivially easy to add to any project. V8 unfortunately requires you to link to their enormous static libraries, but obviously provides optimum performance.All these engines are abstracted behind the samechoc::#"auto">AJSON parser that uses choc::value::Value objects.

Audio

Threading


Hopefully some people will find some of these things useful! If you like it, please tell your friends! If you think you're up to contributing, that's great, but be aware that anything other than an utterly immaculate pull request will be given short shrift :)

-- Jules

Footnotes

  1. ...or maybe "Clean Header-Only Classes" ...or "Cuddly Header-Only Classes"... It's just a backronym, so feel free to pick whatever C-word feels right to you. I may change the word occasionally on a whim, just to cause annoying diffs in the codebase.

About

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors7

Languages


[8]ページ先頭

©2009-2026 Movatter.jp