Registry 用法

内容表

关于

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);

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); }

延伸阅读

maxon::Class
定义: objectbase.h:681
maxon::String
定义: string.h:1197
maxon::Id
定义: apibaseid.h:250
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::Col3
A color consisting of three components R, G and B.
定义: col.h:14

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1