libcubescript/include/cubescript/cubescript_conf.hh

146 lines
4.5 KiB
C++
Raw Permalink Normal View History

/** @file cubescript_conf.hh
*
* @brief Library configuration.
*
2021-04-15 20:40:34 +02:00
* While you can technically modify this directly, it is better if you use
* a custom file `cubescript_conf_user.hh` in the same location. Most of the
* time you will not want to override anything, but should you need to change
* the integer, float or span types for a specific purpose, this allows you to.
*
* @copyright See COPYING.md in the project tree for further information.
*/
2016-08-21 02:34:03 +02:00
#ifndef LIBCUBESCRIPT_CUBESCRIPT_CONF_HH
#define LIBCUBESCRIPT_CUBESCRIPT_CONF_HH
2021-04-03 05:46:05 +02:00
#include <type_traits>
2021-04-15 20:40:34 +02:00
#if __has_include("cubescript_conf_user.hh")
# include "cubescript_conf_user.hh"
#endif
2021-04-20 02:52:27 +02:00
#if !defined(LIBCUBESCRIPT_CONF_USER_SPAN)
# include <span>
#endif
2021-03-23 23:32:25 +01:00
namespace cubescript {
2021-04-15 20:40:34 +02:00
#if !defined(LIBCUBESCRIPT_CONF_USER_INTEGER)
/** @brief The integer type used.
*
* While Cubescript is a stringly typed language, it uses integers and
* floats internally in a transparent manner where possible, and allows
* you to retrieve and pass integers and floats in commands and so on.
*
* This is the integer type used. By default, it's `int`, which is a
* 32-bit signed integer on most platforms. Keep in mind that is is
* necessary for this type to be a signed integer type.
*
2021-04-15 20:40:34 +02:00
* Define `LIBCUBESCRIPT_CONF_USER_INTEGER` in your custom conf file
* to disable the builtin.
*
* @see float_type
* @see INTEGER_FORMAT
*/
2021-03-23 23:29:32 +01:00
using integer_type = int;
2021-04-15 20:40:34 +02:00
#endif
2021-04-15 20:40:34 +02:00
#if !defined(LIBCUBESCRIPT_CONF_USER_FLOAT)
/** @brief The floating point type used.
*
* By default, this is `float`, which is on most platforms an IEEE754
* binary32 data type.
*
2021-04-15 20:40:34 +02:00
* Define `LIBCUBESCRIPT_CONF_USER_FLOAT` in your custom conf file
* to disable the builtin.
*
* @see integer_type
* @see FLOAT_FORMAT
* @see ROUND_FLOAT_FORMAT
*/
2021-03-23 23:29:32 +01:00
using float_type = float;
2021-04-15 20:40:34 +02:00
#endif
2016-08-21 02:34:03 +02:00
2021-04-15 20:40:34 +02:00
#if !defined(LIBCUBESCRIPT_CONF_USER_SPAN)
/** @brief The span type used.
*
* By default, this is `std::span`. You will almost never want to override
* this, but an alternative implementation can be supplied if your standard
* library does not support it.
2021-04-15 20:40:34 +02:00
*
* Define `LIBCUBESCRIPT_CONF_USER_SPAN` in your custom conf file to
* disable the builtin.
*/
template<typename T>
using span_type = std::span<T>;
2021-04-15 20:40:34 +02:00
#endif
2021-04-15 20:40:34 +02:00
#if !defined(LIBCUBESCRIPT_CONF_USER_INTEGER)
/** @brief The integer format used.
*
* This is a formatting specifier as in `printf`, corresponding to the
* `integer_type` used. It is used to handle conversions from the type
* to strings, as well as in the default integer variable handler when
* printing.
*
* There are no special restrictions imposed on the floating point type
* other than that it actually has to be floating point.
*
2021-04-15 20:40:34 +02:00
* Define `LIBCUBESCRIPT_CONF_USER_INTEGER` in your custom conf file
* to disable the builtin.
*
* @see integer_type
* @see FLOAT_FORMAT
*/
constexpr auto const INTEGER_FORMAT = "%d";
2021-04-15 20:40:34 +02:00
#endif
2021-04-15 20:40:34 +02:00
#if !defined(LIBCUBESCRIPT_CONF_USER_FLOAT)
/** @brief The float format used.
*
* This is a formatting specifier as in `printf`, corresponding to the
* `float_type` used. It is used to handle conversions from the type to
* strings, as well as in the default float variable handler when printing.
*
* When the floating point value is equivalent to its integer value (i.e.
* it has no decimal point), ROUND_FLOAT_FORMAT is used.
*
2021-04-15 20:40:34 +02:00
* Define `LIBCUBESCRIPT_CONF_USER_FLOAT` in your custom conf file
* to disable the builtin.
*
* @see float_type
* @see ROUND_FLOAT_FORMAT
* @see INTEGER_FORMAT
*/
2021-03-23 23:29:32 +01:00
constexpr auto const FLOAT_FORMAT = "%.7g";
/** @brief The round float format used.
*
* This is a formatting specifier as in `printf`, corresponding to the
* `float_type` used. It's like `FLOAT_FORMAT` but used when the value
* has no decimal point.
*
* @see float_type
* @see FLOAT_FORMAT
*/
2021-03-23 23:29:32 +01:00
constexpr auto const ROUND_FLOAT_FORMAT = "%.1f";
2021-04-15 20:40:34 +02:00
#endif
2021-03-23 23:32:25 +01:00
} /* namespace cubescript */
2016-08-21 02:34:03 +02:00
2021-04-03 05:46:05 +02:00
/* conf verification */
namespace cubescript {
static_assert(
std::is_integral_v<integer_type>, "integer_type must be integral"
);
static_assert(
std::is_signed_v<integer_type>, "integer_type must be signed"
);
static_assert(
std::is_floating_point_v<float_type>, "float_type must be floating point"
);
} /* namespace cubescript */
#endif /* LIBCUBESCRIPT_CUBESCRIPT_CONF_HH */