Registry Usage

About

Interface implementations stored at a registry are used by accessing the component class with the given maxon::Id from the registry. Then it is possible to create a reference class instance to use the implementation.

Registry Access

Registries are based on the maxon::Registry class. A given element stored in a registry is identified with a maxon::Id.

// This example creates a reference object from the registry with the given ID.
// get the class with the given Id from the registry "ColorClasses"
const maxon::Id redID { "net.maxonexample.class.colors.red" };
const maxon::Class<ColorRef>* const componentClass = ColorClasses::Find(redID);
if (componentClass == nullptr)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION, "Could not get color."_s);
// create reference object
const ColorRef color = componentClass->Create() iferr_return;
// use reference object
const maxon::String colorName = color.GetName();
const maxon::Color32 colorRGB = color.GetRGB();
DiagnosticOutput("Color Name: @", colorName);
DiagnosticOutput("Color RGB: @", colorRGB);
Definition: objectbase.h:709
Definition: apibaseid.h:253
Definition: string.h:1235
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define iferr_return
Definition: resultbase.h:1519
A color consisting of three components R, G and B.
Definition: col.h:16

One can also simply loop through all elements with maxon::Registry::GetEntries():

// This example loops through all component classes known to the given registry.
for (const auto& it : ColorClasses::GetEntries())
{
// get class
const maxon::Class<ColorRef>& componentClass = it;
// create reference object
const ColorRef color = componentClass.Create() iferr_return;
// use reference object
const maxon::Id& eid = it.GetId();
const maxon::String colorName = color.GetName();
const maxon::Color32 colorRGB = color.GetRGB();
DiagnosticOutput("ID: @", eid);
DiagnosticOutput("Color Name: @", colorName);
DiagnosticOutput("Color RGB: @", colorRGB);
}

Further Reading