putils icon indicating copy to clipboard operation
putils copied to clipboard

Phisko's C++ Utilities

putils

tests

Phisko's C++ Utilities

Reflection

A simple, stand-alone, header-only and easily pluggable reflection system.

This does not allow you to introspect any type provided by any library. It simply provides an API that you can implement in your own classes so that you can introspect them.

Good examples can be found in the imgui_helper and json_helper utilities.

Another example is the registerType function provided for lua, that inspects a type and registers all its attributes and methods to a lua state.

Utility classes

  • Color & NormalizedColor: helper classes to manipulate colors
  • Directory: An abstraction to Unix and Windows directories, which lets you iterate through a directory and get information about each file.
  • IniFile: .ini file parser
  • Observable: A minimalistic (but greatly sufficient) implementation of the Observer pattern.
  • Point: Simple abstraction to a 2D or 3D point.
  • Rect: Simple abstraction to a 2D or 3D rectangle.
  • RAII: A class template able to perform RAII on any type.
  • SpinLock: Spin lock implementation, "sleep-free" alternative to mutexes.
  • ThreadPool: Thread pool implementation
  • Timer: Simple timer based on std::chrono.

Standard library replacements

  • string: fixed-size drop-in replacement for std::string
  • vector: fixed-size drop-in replacement for std::vector
  • function: fixed-size drop-in replacement for std::function

Packages

  • Lua (enabled with the PUTILS_LUA CMake option)
  • Python (enabled with the PUTILS_PYTHON CMake option)
  • Mediator (enabled with the PUTILS_MEDIATOR CMake option)
  • Meta
  • OpenGL (enabled with the PUTILS_OPENGL CMake option)
  • PluginManager (enabled with the PUTILS_PLUGIN_MANAGER CMake option)
  • Reflection
  • Vulkan (enabled with the PUTILS_VULKAN CMake option)

Function-only headers

  • angle: helper functions when manipulating angles
  • anonymous_variable: macro to define an anonymous variable
  • casts: static and dynamic casts for std::unique_ptr
  • chop: function removing any initial or trailing whitespace, as well as surrounding quotes, from a string
  • clamp: function that clamps a value between two bounds
  • command_line_arguments: function that parses command-line arguments into a struct
  • concatenate: function taking any number of parameters and concatenating them into a string
  • curl: function that runs a curl request over CLI (to avoid having to install curl packages. This is NOT the optimal way to do an HTTP request)
  • epsilon: approximate comparison of floating point types
  • erase: function taking a container and a value and erasing the value from the container
  • file_extension: functions for working with file extensions
  • get_call_stack: function which returns a formatted call-stack
  • get_current_dir: function which returns the current working directory as a string
  • get_last_error_as_string: function for Windows
  • go_to_bin_dir: function which takes argv[0] as parameter and changes the current working directory to that containing the executed file.
  • hash: pre-defined hashers for enums and pairs
  • lengthof: template function returning the length of an array
  • macro_as_string: returns the value of a macro as a string
  • MagicaVoxel: structure declarations for the MagicaVoxel format
  • MagicaVoxelToPolyvoxLoader: conversion functions to parse the MagicaVoxel format into PolyVox objects
  • members: help with class members
  • on_scope_exit: returns an object that calls a function in its dtor
  • rand: function using C++ 11's random number generation facilities
  • read_stream: function which extracts an entire std::istream to a std::string
  • regex: utilities to easily construct and match regexes through literal operators
  • remove_if: function taking a container and a predicate and calling std::remove_if
  • same_sign: function indicating whether two scalars have the same sign
  • thread_name: sets or gets the OS-level name for the current thread
  • scoped_setter: sets the value of a variable for the duration of the current scope
  • sign: function returning -1, 0 or 1 depending on the sign of the parameter
  • static_assert: type template to let static_assert fail for a specific type
  • to_string: uses a std::stringstream to serialize an object
  • traits: type traits
  • url: URL encoder and decoder
  • universal_functor: macro for passing generic functions as functors
  • visit: overloaded type letting you pass multiple lambdas to std::visit
  • with: with macro mimicking the Kotlin construct

CMake tools

  • conan: lets you run conan commands directly from cmake
  • conan_helper: provides a helper macro to simply list conan dependencies
  • cotire: lets you easily set up precompiled-header and single-compilation-unit compilations to speed up builds