darts/common.h file

Common include files and various utility functions.

Classes

class DartsException
An exception storing a human-readable error description passed in using fmt:format-style arguments.
template<typename T>
class Range
Python-style range: iterates from min to max in range-based for loops.

Functions

template<typename T>
auto range(T end) -> Range<T>
Construct a Python-style range from a single parameter end.
template<typename T>
auto range(T start, T end, T step = T(1)) -> Range<T>
Construct a Python-style range from start, up to but excluding end, in increments of step.
auto get_file_resolver() -> filesystem::resolver&
Return the global file resolver instance.

Formatted printing and logging

Darts provides a convenient way to report information to the user.

This is all based on the spdlog and fmt libraries. You can find extensive documentation for both of these linked from the Code organization section, but in a nutshell:

Formatted printing to the console or to strings:

Darts includes the fmt library to provide a modern replacement for cout or printf.

The two most useful functions are:

fmt::print()
fmt::format()

See the fmt library website for complete documentation.

Logging

The spdlog library provides a number of functions:

  • spdlog::debug
  • spdlog::info
  • spdlog::warn
  • spdlog::err
  • spdlog::critical

These operate just like fmt::print, but colorize the output based on the type of message. Darts can also globally disable messages below a certain threshold to control the verbosity of the output (this is done in darts_init, and controlled by a command-line argument in src/darts.cpp).

Darts also allows you to print and update a nice progress bar (see Progress) for long operations.

#define put_your_code_here(txt)
Warning signaling unimplemented features.
void darts_init(int verbosity = spdlog::level::info)
Initialize darts before parsing or rendering a scene.
auto time_string(double time, int precision = 2) -> string
Convert a time value in milliseconds into a human-readable string.
auto indent(const std::string& string, int amount = 2) -> string
Indent a string by the specified number of spaces.