Class SharedLib

Synopsis

#include <src/uvw/lib.h>

class SharedLib final: public UnderlyingType<SharedLib, uv_lib_t>

Description

The SharedLib class.

uvw provides cross platform utilities for loading shared libraries and retrieving symbols from them, by means of the API offered by libuv.

Inheritance

Ancestors: UnderlyingType

Methods

SharedLib
~SharedLib
errorReturns the last error message, if any.
operator boolChecks if the library has been correctly opened.
symRetrieves a data pointer from a dynamic library.

Source

Lines 22-60 in src/uvw/lib.h.

class SharedLib final: public UnderlyingType<SharedLib, uv_lib_t> {
public:
    explicit SharedLib(ConstructorAccess ca, std::shared_ptr<Loop> ref, const std::string &filename) noexcept;

    ~SharedLib() noexcept;

    /**
     * @brief Checks if the library has been correctly opened.
     * @return True if the library is opened, false otherwise.
     */
    explicit operator bool() const noexcept;

    /**
     * @brief Retrieves a data pointer from a dynamic library.
     *
     * `F` shall be a valid function type (as an example, `void(int)`).<br/>
     * It is legal for a symbol to map to `nullptr`.
     *
     * @param name The symbol to be retrieved.
     * @return A valid function pointer in case of success, `nullptr` otherwise.
     */
    template<typename F>
    F * sym(const std::string &name) {
        static_assert(std::is_function_v<F>);
        F *func;
        auto err = uv_dlsym(get(), name.data(), reinterpret_cast<void**>(&func));
        if(err) { func = nullptr; }
        return func;
    }

    /**
     * @brief Returns the last error message, if any.
     * @return The last error message, if any.
     */
    const char * error() const noexcept;

private:
    bool opened;
};





Add Discussion as Guest

Log in