[mrpt-core]

Core functions for MRPT.

Library mrpt-core

[New in MRPT 2.0.0]

This library is part of MRPT and can be installed in Debian-based systems with:

sudo apt install libmrpt-core-dev

Read also how to import MRPT into your CMake scripts.

Library contents

// typedefs

typedef std::optional<std::reference_wrapper<T>> mrpt::optional_ref;

// enums

enum mrpt::cpu::feature;

// structs

template <class T>
struct mrpt::copiable_NULL_ptr;

template <class T>
struct mrpt::copiable_NULL_ptr_basic;

template <class T>
struct mrpt::ignored_copy_ptr;

template <class T>
struct mrpt::non_copiable_ptr;

template <class T>
struct mrpt::non_copiable_ptr_basic;

template <class T>
struct mrpt::safe_ptr;

template <class T>
struct mrpt::safe_ptr_basic;

// classes

class mrpt::cpu::internal::CPU_analyzer;
class mrpt::Clock;

template <class T>
class mrpt::LockHelper;

class mrpt::WorkerThreadsPool;

// global functions

template <class VECTOR_T>
void mrpt::vector_strong_clear(VECTOR_T& v);

template <std::size_t N, typename F>
void mrpt::for_(F func);

std::string mrpt::demangle(const std::string& symbolName);
std::string mrpt::exception_to_str(const std::exception& e);
std::string mrpt::format_impl(const char* fmt, ...);

template <typename T>
std::string mrpt::to_string(T v);

template <typename T>
T mrpt::from_string(
    const std::string& s,
    const T& defValue = T{},
    bool throw_on_error = true
    );

template <class T>
T mrpt::get_env(const std::string& varname, const T& defValue = T());

template <class T>
LockHelper<T> mrpt::lockHelper(T& t);

void mrpt::reverseBytesInPlace(bool& v_in_out);
void mrpt::reverseBytesInPlace(uint8_t& v_in_out);
void mrpt::reverseBytesInPlace(int8_t& v_in_out);
void mrpt::reverseBytesInPlace(uint16_t& v_in_out);
void mrpt::reverseBytesInPlace(int16_t& v_in_out);
void mrpt::reverseBytesInPlace(uint32_t& v_in_out);
void mrpt::reverseBytesInPlace(int32_t& v_in_out);
void mrpt::reverseBytesInPlace(uint64_t& v_in_out);
void mrpt::reverseBytesInPlace(int64_t& v_in_out);
void mrpt::reverseBytesInPlace(float& v_in_out);
void mrpt::reverseBytesInPlace(double& v_in_out);
void mrpt::reverseBytesInPlace(long double& v_in_out);
void mrpt::reverseBytesInPlace(std::chrono::time_point<mrpt::Clock>& v_in_out);

template <class T>
void mrpt::reverseBytes(const T& v_in, T& v_out);

template <class T>
T mrpt::reverseBytes(const T& v_in);

template <class T>
T mrpt::toNativeEndianness(const T& v_in);

template <
    typename enum_t,
    typename underlying_t = typename std::underlying_type<enum_t>::type
    >
void mrpt::reverseBytesInPlace_enum(enum_t& v);

bool mrpt::cpu::supports(feature f);
void mrpt::cpu::overrideDetectedFeature(feature f, bool newValue);
std::string mrpt::cpu::features_as_string();

Typedefs

typedef std::optional<std::reference_wrapper<T>> mrpt::optional_ref

Shorter name for std::optional<std::reference_wrapper<T>>

Global Functions

template <class VECTOR_T>
void mrpt::vector_strong_clear(VECTOR_T& v)

Like calling a std::vector<>’s clear() method, but really forcing deallocating the memory.

template <std::size_t N, typename F>
void mrpt::for_(F func)

constexpr for loop.

Example:

mrpt::for_<10>( [&](auto i) { std::cout << i.value << " "; } );

(New in MRPT 2.1.0)

Credits to SO.

std::string mrpt::demangle(const std::string& symbolName)

Demangle a C++ symbol name (works on both Windows and Unices)

std::string mrpt::exception_to_str(const std::exception& e)

Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THROW_EXCEPTION,…) in between MRPT_START/MRPT_END macros, will contain function names and line numbers across the call stack at the original throw point.

See example of use in [mrpt-core] Uses C++11 throw_with_nested(), rethrow_if_nested().

std::string mrpt::format_impl(const char* fmt, ...)

A std::string version of C sprintf.

You can call this to obtain a std::string using printf-like syntax.

template <typename T>
std::string mrpt::to_string(T v)

Just like std::to_string(), but with an overloaded version for std::string arguments.

template <typename T>
T mrpt::from_string(
    const std::string& s,
    const T& defValue = T{},
    bool throw_on_error = true
    )

Converts from string to any data type that supports reading (>>) from a text stream.

In case of error, the given default value is returned, or an exception raised.

template <class T>
T mrpt::get_env(
    const std::string& varname,
    const T& defValue = T()
    )

Reads an environment variable, with a default value if not present.

template <class T>
LockHelper<T> mrpt::lockHelper(T& t)

Syntactic sugar to easily create a locker to any kind of std::mutex.

void mrpt::reverseBytesInPlace(bool& v_in_out)

Reverse the order of the bytes of a given type (useful for transforming btw little/big endian)

template <class T>
void mrpt::reverseBytes(const T& v_in, T& v_out)

Reverse the order of the bytes of a given type (useful for transforming btw little/big endian)

bool mrpt::cpu::supports(feature f)

Returns true if the current CPU (and OS) supports the given CPU feature.

void mrpt::cpu::overrideDetectedFeature(feature f, bool newValue)

Blindly enables/disables a CPU feature flag in the list of detected features to be reported in subsequent calls to mrpt::cpu::supports().

Could be used to disable a given CPU feature for benchmarking dynamically-dispatched functions.

Enabling a feature that is not actually supported by the current CPU would probably lead to program crashes.

std::string mrpt::cpu::features_as_string()

Returns a string with detected features: “MMX:1 SSE2:0 etc.”.