shiva
last version
last version
  • Shiva Documentation
  • Shiva
    • Changelog
    • FAQ
    • Gallery
    • Installation
    • Modules
      • shiva::box2d
      • shiva::dll
      • shiva::ecs
      • shiva::entt
      • shiva::enums
      • shiva::error
      • shiva::event
      • shiva::filesystem
      • shiva::input
      • shiva::json
      • shiva::lua
      • shiva::meta
      • shiva::pp
      • shiva::pyscripting
      • shiva::range
      • shiva::reflection
      • shiva::scenes
      • shiva::sfml
        • shiva::system-sfml-animation
        • shiva::system-sfml-graphics
        • shiva::system-sfml-inputs
        • shiva::system-sfml-resources
      • shiva::spdlog
      • shiva::stacktrace
      • shiva::timer
      • shiva::world
    • Roadmap
    • Scripting
      • Lua
      • Python
    • Tutorial
      • Quick'start
      • How to create/build/install a system plugin
      • How to create a scripted system
      • How to create a project through the CLI tools and build it
Powered by GitBook
On this page
  • plugins_registry:
  • Description
  • Diagram
  • plugins_registry API
  • helpers
  1. Shiva
  2. Modules

shiva::dll

Previousshiva::box2dNextshiva::ecs

Last updated 6 years ago

plugins_registry:

Description

This class allows you to store plugin creation symbols through its template CreatorSignature parameter. Through this class you are able to retrieve the number of plugins, apply a functor on each of the symbols (as creates the plugin for example).

Diagram

plugins_registry API

template <typename CreatorSignature>
class plugins_registry;
explicit plugins_registry(shiva::fs::path &&plugins_directory, const std::string library_pattern_matching) noexcept;

plugins_registry

Parameters

  • plugins_directory represents the path to the directory containing the plugins

  • library_pattern_matching represents a basic pattern to respect for libraries to load

For example if the pattern is [shiva-system] then only libraries that have [shiva-system] in their names will be loaded. [libshiva-system-plugin.so] will be loaded [libother-things.so] will not be loaded.

Functions Name

Description

load all symbols for plugins creation from the plugins_directory

return the number of plugins

apply a functor on each symbols

load_all_symbols

bool load_all_symbols() noexcept;

Return value

Possible name

Description

success

boolean

  • true if all the symbols of all the libraries have been correctly loaded

  • false if a symbol from one of the libraries was not loaded

  • false if the plugins_directory doesn't exist

Example

bool success = plugins_registry.load_all_symbols();
if (!success) {
   /* The loading of symbols failed */
}

Notes

This function allows you to load symbols from the template to create the object. The symbols are loaded recursively from the folder you specified in the object's constructor.

If one of the symbols could not be correctly loaded the function does not stop and proceeds to load the next plugin. If when browsing folders a corrupted file is spotted the function switch to loading the next plugin.

nb_plugins

size_t nb_plugins() const noexcept;

Return value

Possible name

Description

nb_plugins

size_t

  • numbers of plugins

Example

size_t nb_plugins = plugins_registry.nb_plugins();
if (nb_plugins < 4) {
    //! Oh no, i was exepcting at least 4 plugins
}

apply_on_each_symbols

template <typename TFunctor>
void apply_on_each_symbols(TFunctor &&functor);

Template parameters

Name

Description

functor

TFunctor

  • represents the functor to apply on each of the loaded symbols.

Example

auto functor = [this](auto &&symbol) {
                auto res = symbol(/* parmeters for the creation of the object */);
                // res -> object created by the symbol creator
                // manipulate res or put it in a container for example.
                this->container_object.push_back(std::move(res));
            };

plugins_registry_.apply_on_each_symbols(functor);

Notes

helpers

Functions Name

Description

check if a specific path is a shared library

is_shared_library

static inline bool is_shared_library(const fs::path &path) noexcept;

Parameters

Name

Description

path

fs::path

  • the path to be tested

Return value

Possible name

Description

result

boolean

  • true if the path is a shared_library

  • false otherwise

Example

// result is true
bool result = shiva::helpers::is_shared_library(shiva::fs::path("path/libfoo.so"));

// result is false
result = shiva::helpers::is_shared_library(shiva::fs::path("path/libbar"));

if (!result) {
   /* The path given as parameter doesn't seem's to be a shared_library */
}

Notes

  • check if the path passed in parameter is a shared library

This function applies the functor as a parameter to each of the symbols that were previously loaded by the function.

load_all_symbols
load_all_symbols
nb_plugins
apply_on_each_symbols
is_shared_library