Support specifying object factory overrides in executables
The vtkObjectFactory
class should gain support for preferring certain overrides as given by the executable that is running. For example, one can create two versions of an application, one which is for desktop use and another that is for VR device use. Currently, vtkRenderingOpenVR
disables all other overrides of the classes that it overrides, effectively disabling support of the other overrides while it is loaded.
The proposed solution is to support "override attributes" on override classes. Executables could then register their preferences with vtkObjectFactory
and when a factory base class is requested, it would consult the preferences and the available attributes and construct the "best" option.
Implementation details:
-
vtkObjectFactory::RegisterOverride
would take an additional argument of a linked list of attributes for the override. - Overriding classes would indicate that they have overrides via the
<classname>_OVERRIDE_ATTRIBUTES
preprocessor definition. It would resolve to the pointer to the head of a linked list describing the attributes for the class (this would allow for intermediate base classes to provide attributes that may be referenced by subclasses). -
vtkObjectFactory.cmake
would use#ifdef
to specify this attribute to theRegisterOverride
call. -
vtkObjectFactory.cmake
would provide a function to create a source file which indicates preferences tovtkObjectFactory
as a static initialization function for use in executables.
One question is where the logic of choosing an override lives.
-
Embedded proposal We describe an algorithm in
vtkObjectFactory
which performs the selection based on its input data. One could be "strength of preference is from first attribute specified to last and within each attribute, first to last". So the selection between classJ
withAttrA=X,AttrB=N
and classK
withAttrA=Y,AttrB=M
with the preferencesAttrA=X,Y;AttrB=M,N
would be classJ
sinceAttrA
is a "stronger" preference. -
Callback proposal It can either live in a function that is passed to
vtkObjectFactory
which it then calls for override requests (where attributes are available) with the list of constructor functions paired with the attributes describing each. Here, thevtkObjectFactory.cmake
module should have the option to provide a default implementation of this callback, likely similar to whatever the Embedded proposal is.