Moonlight is a meta library toolbox for C++ projects. It is intended for use in my own projects, but made available in case it is useful for anyone else. It is a mixture of small header-only libraries I have built and submodules referring mostly to other third-party header only libraries.
Moonlight components written by me (Lain Musgrove) or other first-party contributors are released under the MIT license, see LICENSE. Third party submodules are released under their respective licenses.
These are the headers I've written with useful templates, macros, and tools.
Tools for printing ANSI escape sequences and colorful CLI text. See ansi.cpp
in the tests for usage examples.
Templates for finite-state automata, a.k.a. state machines, with states modeled as runnable object states that are tied together under a common context. I use this as the basis for experimenting with games, parsers, and other runtime engines.
Useful tools for building command line apps. Provides CommandLine
, which is
a very simple command line parser supporting short and long options similar to
getopt_long
.
Various tools for working with linear collections.
Methods for RGB<->HSV color conversions.
A set of ncurses wrappers for initialzation and usage. Greatly reduces the cognitive load for creating simple ncurses applications with windows and panels. Also addresses my biggest gripe by replacing Y,X indexing with X,Y indexing for functions referring to locations on the screen.
A datetime library utilizing Howard Hinnant's date
and providing an interface
more akin to Python's datetime
.
Some quirky debugging tools, enabled only if MOONLIGHT_DEBUG
is defined.
debugger
like in Javascript. Raises a segfault, useful for defining breakpoints in code.dbgprint
prints to stderr.
Defines a smarter base exception class derived from std::runtime_error
, along
with a few derived exception types for common use.
Includes utilities for working with files and byte streams. Includes
BufferedInput
which is quite useful for parsers.
Implements a pattern similar to Python's generators. Wraps lambda-based
sequence generation in a for-in
compatible standard iterator interface.
Also offers Queue
, a thread-safe queue, and methods for wrapping generators in
async queues.
Contains combine
which is copied from boost::hash_combine
. May be a home
for other useful hashing functions in the future.
NEW A standalone JSON parser and object model inspired by PicoJSON. This was originally a wrapper around PicoJSON but is now a full JSON parser and value serializer.
A generic recursive lexical scanner based on my lexex
Python module.
Provides a linked_map
which behaves just like unordered_map
except that
insertion order is preserved for iteration.
An optional free-function template make
, shorthand for std::make_shared
.
Various tools for working with associative containers.
Tools for template metaprogramming and compile-time static assertions for templates.
Functions for building and working with multimap containers.
POSIX specializations for Timer
.
SDL2 specializations for Timer
.
Implements slice
and slice_offset
which offer Python-style slicing and item
access for linear containers.
String utility functions such as join
, split
, trim
, and others.
Provides system utilities such as a version of getenv
which returns an
std::optional<std::string>
.
Provides the TestSuite
unit test harness where tests are defined by lambda
functions. For copious usage examples, see any of the tests for this library.
Defines Timer
, a generic accumulating timer, and RelativeTimer
based on
the tickes of another Timer
. I use this timer to keep framerate and pace in
games and other simulations.
From ("fileno(3) on C++ Streams: A Hacker's Lament")[https://www.ginac.de/~kreckel/fileno/]
by Richard B. Kreckel. Also includes a free-function template is_tty
which
can be used to determine if an std::basic_ios
stream represents a tty.
Provides utilities for variadic template parameter expansion such as pass
and
to_vector
.
- Author: Fabian Meyer
- License MIT
A simple header-only INI file reader and writer.
- Author: Howard Hinnant
- License: MIT License
Date and calendar libraries built atop the relatively new std::chrono
. Used
as the basis of the moonlight/date.h
library.
- Author: r-lyeh
- License: zlib/libpng License
An elegantly simple UUID v1+v4 generator/parser.
- Author: Chris Foster
- License: Boost Software License 1.0
- As specified here.
A type-safe printf replacement for C++. I use this all of the time, and it's an excellent option for folks who like working with C-style format strings.