Lagrange
|
Useful functions that don't have their place anywhere else. More...
Modules | |
function_ref | |
A lightweight non-owning reference to a callable. | |
Namespaces | |
namespace | lagrange |
Main namespace for Lagrange. | |
Classes | |
class | copy_on_write_ptr< T > |
A handle type with copy-on-write semantics. More... | |
struct | OrderedPairHash< T, Enable > |
Compute an order-dependent hash of a pair of values. More... | |
struct | OrderedPairHash< std::pair< U, V > > |
class | SharedSpan< T > |
Shared span with ownership tracking. More... | |
class | value_ptr< T, Cloner, Deleter > |
Smart pointer with value semantics. More... | |
Typedefs | |
template<class T , span_CONFIG_EXTENT_TYPE Extent = ::nonstd::dynamic_extent> | |
using | span = ::nonstd::span< T, Extent > |
A bounds-safe view for sequences of objects. More... | |
using | extent_t = span_CONFIG_EXTENT_TYPE |
Span extent type. | |
Functions | |
LA_CORE_API void | enable_fpe () |
Enable floating-point exceptions (useful for debugging). More... | |
LA_CORE_API void | disable_fpe () |
Disable previously-enabled fpe. More... | |
template<class T > | |
void | hash_combine (size_t &seed, const T &v) |
Hash an object v and combine it with an existing hash value seed. More... | |
template<typename T > | |
constexpr T | invalid () |
You can use invalid<T>() to get a value that can represent "invalid" values, such as invalid indices or invalid float data. More... | |
template<typename Index > | |
internal::Range< Index > | range (Index end) |
Returns an iterable object representing the range [0, end). More... | |
template<typename Index > | |
internal::Range< Index > | range (Index begin, Index end) |
Returns an iterable object representing the range [begin, end). More... | |
template<typename Index > | |
internal::SparseRange< Index > | range_sparse (Index max, const std::vector< Index > &active) |
Returns an iterable object representing a subset of the range [0, max). More... | |
template<typename TargetType , typename SourceType > | |
constexpr auto | safe_cast (SourceType value) -> std::enable_if_t<!std::is_same< SourceType, TargetType >::value, TargetType > |
Perform safe cast from SourceType to TargetType , where "safe" means: More... | |
template<typename T > | |
constexpr T | safe_cast (T value) |
Safe cast specialization for TargetType == SourceType. More... | |
template<typename TargetType > | |
constexpr TargetType | safe_cast (bool value) |
Safe cast specialization for bool. More... | |
template<typename T , typename U > | |
constexpr T | safe_cast_enum (const U u) |
Casting an enum to scalar and vice versa. More... | |
template<typename Callback > | |
sg_detail::scope_guard< Callback > | make_scope_guard (Callback &&callback) noexcept(std::is_nothrow_constructible< Callback, Callback && >::value) |
Creates a scope guard around a callable object. More... | |
template<typename T , typename Y > | |
SharedSpan< T > | make_shared_span (const std::shared_ptr< Y > &r, T *element_ptr, size_t size) |
Created a SharedSpan object around an internal buffer of a parent object. More... | |
LA_CORE_API std::vector< std::string > | string_split (const std::string &str, char delimiter) |
Split a std::string using a prescribed delimiter. More... | |
LA_CORE_API bool | starts_with (std::string_view str, std::string_view prefix) |
Checks if the string begins with the given prefix. More... | |
LA_CORE_API bool | ends_with (std::string_view str, std::string_view suffix) |
Checks if the string ends with the given suffix. More... | |
LA_CORE_API std::string | to_lower (std::string str) |
Convert a string to lowercase. More... | |
LA_CORE_API std::string | to_upper (std::string str) |
Convert a string to uppercase. More... | |
template<typename... Args> | |
std::string | string_format (fmt::format_string< Args... > format, Args &&... args) |
Format args according to the format string fmt, and return the result as a string. More... | |
template<class T , class... Args> | |
value_ptr< T > | make_value_ptr (Args &&... args) |
Helper function to create a value_ptr for a given type. More... | |
Useful functions that don't have their place anywhere else.
using span = ::nonstd::span<T, Extent> |
#include <lagrange/utils/span.h>
A bounds-safe view for sequences of objects.
void enable_fpe | ( | ) |
#include <lagrange/utils/fpe.h>
Enable floating-point exceptions (useful for debugging).
void disable_fpe | ( | ) |
#include <lagrange/utils/fpe.h>
Disable previously-enabled fpe.
void hash_combine | ( | size_t & | seed, |
const T & | v | ||
) |
#include <lagrange/utils/hash.h>
Hash an object v and combine it with an existing hash value seed.
NOT commutative.
Copied from https://www.boost.org/doc/libs/1_64_0/boost/functional/hash/hash.hpp. SPDX-License-Identifier: BSL-1.0
|
constexpr |
#include <lagrange/utils/invalid.h>
You can use invalid<T>() to get a value that can represent "invalid" values, such as invalid indices or invalid float data.
invalid<T>() is guaranteed to always be the same value for a given type T.
This is supported for arithmetic types, and returns:
std::numeric_limits<T>::max()
for integral types,std::numeric_limits<T>::infinity()
for floating point types.T | Type. |
internal::Range< Index > range | ( | Index | end | ) |
#include <lagrange/utils/range.h>
Returns an iterable object representing the range [0, end).
[in] | end | End of the range. This bound is exclusive. |
Index | Index type. |
internal::Range< Index > range | ( | Index | begin, |
Index | end | ||
) |
#include <lagrange/utils/range.h>
Returns an iterable object representing the range [begin, end).
[in] | begin | Start of the range. This bound is inclusive. |
[in] | end | End of the range. This bound is exclusive. |
Index | Index type. |
internal::SparseRange< Index > range_sparse | ( | Index | max, |
const std::vector< Index > & | active | ||
) |
#include <lagrange/utils/range.h>
Returns an iterable object representing a subset of the range [0, max).
If active is non-empty, it will iterate through the elements of active. Otherwise, it will iterate from 0 to max.
active
vector MUST exist while the range is being used. Do NOT write code such as: [in] | max | End of the range. This bound is exclusive. |
[in] | active | Active indices in the range. If empty, it will iterate through the whole range instead. |
Index | Index type. |
|
constexpr |
#include <lagrange/utils/safe_cast.h>
Perform safe cast from SourceType
to TargetType
, where "safe" means:
Example usage:
[in] | value | Value to cast. |
TargetType | Target scalar type. |
SourceType | Source scalar type. |
|
constexpr |
#include <lagrange/utils/safe_cast.h>
Safe cast specialization for TargetType == SourceType.
[in] | value | Value to cast. |
T | Scalar type. |
|
constexpr |
#include <lagrange/utils/safe_cast.h>
Safe cast specialization for bool.
[in] | value | Value to cast. |
TargetType | Target scalar type. |
|
constexpr |
#include <lagrange/utils/safe_cast.h>
Casting an enum to scalar and vice versa.
These are only to be used for assigning enums as (mesh) attributes, or to be used for reading back enums that were saved as mesh attributes.
[in] | u | Value to cast. |
T | Target scalar/enum type. |
U | Source scalar/enum type. |
|
noexcept |
#include <lagrange/utils/scope_guard.h>
Creates a scope guard around a callable object.
A scope guard is an object that employs RAII to execute a provided callback when leaving scope, be it through a fall-through, a return, or an exception. That callback can be a function, a function pointer, a functor, a lambda, a bind result, a std::function, a reference to any of these, or any other callable, as long as it respects a few preconditions – most of which are enforced during compilation, the rest being hopefully intuitive.
callback | Callable object to execute when leaving scope. |
Callback | Callable object type. |
SharedSpan< T > make_shared_span | ( | const std::shared_ptr< Y > & | r, |
T * | element_ptr, | ||
size_t | size | ||
) |
#include <lagrange/utils/SharedSpan.h>
Created a SharedSpan object around an internal buffer of a parent object.
T | The element_type of internal buffer. |
Y | The type of the parent object containing the buffer. |
[in] | r | A shared pointer of the parent object owning the buffer. |
[in] | element_ptr | A raw pointer to the internal buffer contained in the parent object. |
[in] | size | The size of the internal buffer. |
std::vector< std::string > string_split | ( | const std::string & | str, |
char | delimiter | ||
) |
#include <lagrange/utils/strings.h>
Split a std::string using a prescribed delimiter.
[in] | str | String to split. |
[in] | delimiter | Delimiter. |
bool starts_with | ( | std::string_view | str, |
std::string_view | prefix | ||
) |
#include <lagrange/utils/strings.h>
Checks if the string begins with the given prefix.
[in] | str | The string. |
[in] | prefix | The prefix. |
bool ends_with | ( | std::string_view | str, |
std::string_view | suffix | ||
) |
#include <lagrange/utils/strings.h>
Checks if the string ends with the given suffix.
[in] | str | The string. |
[in] | suffix | The suffix. |
std::string to_lower | ( | std::string | str | ) |
#include <lagrange/utils/strings.h>
Convert a string to lowercase.
[in] | str | The input string. |
std::string to_upper | ( | std::string | str | ) |
#include <lagrange/utils/strings.h>
Convert a string to uppercase.
[in] | str | The input string. |
std::string string_format | ( | fmt::format_string< Args... > | format, |
Args &&... | args | ||
) |
#include <lagrange/utils/strings.h>
Format args according to the format string fmt, and return the result as a string.
[in] | format | An object that represents the format string. |
[in] | args | Arguments to be formatted. |
Args | Types of the arguments to be formatted. |