|
Medical Imaging Interaction Toolkit
2026.06.00
Medical Imaging Interaction Toolkit
|
The CppMicroServices module provides a generic resources system to embed arbitrary files into a module's shared library (the size limitation per resource is 2GB, due to the used ZIP format).
The following features are supported:
The following conventions and limitations apply:
Resources are embedded into a module's shared or static library (or into an executable) by using the usResourceCompiler executable. It will create a ZIP archive of all input files and can append it to the module file.
If you are using CMake, consider using the provided usFunctionEmbedResources CMake macro which handles the invocation of the usResourceCompiler executable and sets up the correct file dependencies. Otherwise, you also need to make sure that the set of static modules linked into a shared module or executable is also in the input file list of your usResourceCompiler call for that shared module or executable.
Each module provides access to its embedded resources via the Module class which provides methods returning ModuleResource objects. The ModuleResourceStream class provides a std::istream compatible object to access the resource contents.
The following example shows how to retrieve a resource from each currently loaded module whose path is specified by a module property:
This example could be enhanced to dynamically react to modules being loaded and unloaded, making use of the popular "extender pattern" from OSGi.
The resources system has the following runtime characteristics:
Module or ModuleResource objects for resource information will not extract the embedded resource data and hence only has minimal runtime and memory overhead.ModuleResourceStream object will allocate memory for the uncompressed resource data and inflate it. The memory will be free'ed after the ModuleResourceStream object is destroyed.