4In VTK, certain classes can have what are called
"implementations". When the
5base
class is requested, it instead looks into a list of available
6implementations. One of the implementations is then constructed and returned
10constructed, it instead actually returns a window for the X window system,
11Cocoa, or Win32 depending
on what is available.
13VTK's implementation utilizes the [autoinit](@ref module-autoinit) logic of the
14module system. A module which contains an object factory must declare itself as
15`IMPLEMENTABLE` and modules which contain an implementation of an object
16factory must claim that they `IMPLEMENTS` modules containing those base object
17factories (a module may contain the object factory and an implementation; it
18then says that it `IMPLEMENTS` itself).
21set(_vtkObjectFactory_source_dir
"${CMAKE_CURRENT_LIST_DIR}")
24@brief Declare a factory
override
26Declare that a
class in this module (the implementation) is an `OVERRIDE` for a
32 OVERRIDE <implementation>)
36 cmake_parse_arguments(PARSE_ARGV 0 _vtk_object_factory_declare
41 if (_vtk_object_factory_declare_UNPARSED_ARGUMENTS)
43 "Unparsed arguments for vtk_object_factory_declare: "
44 "${_vtk_object_factory_declare_UNPARSED_ARGUMENTS}")
47 if (NOT DEFINED _vtk_object_factory_declare_BASE)
49 "The `BASE` argument is required.")
52 if (NOT DEFINED _vtk_object_factory_declare_OVERRIDE)
54 "The `OVERRIDE` argument is required.")
57 set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}
" APPEND
59 _vtk_object_factory_overrides "${_vtk_object_factory_declare_OVERRIDE}
")
60 set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}
" APPEND
62 "_vtk_object_factory_override_${_vtk_object_factory_declare_OVERRIDE}
" "${_vtk_object_factory_declare_BASE}
")
66@brief Generate source for overrides in a module
68A module may only have a single declaration of all its object factory
69implementations. This function generates the source for all of the overrides
70declared using @ref vtk_object_factory_declare.
73vtk_object_factory_configure(
74 SOURCE_FILE <variable>
75 [HEADER_FILE <variable>]
76 [EXPORT_MACRO <macro>]
78 [EXTRA_INCLUDES <include>...])
81 - `SOURCE_FILE`: (Required) A variable to set to the path to generated source
83 - `HEADER_FILE`: (Recommended) A variable to set to the path to generated
84 header file. This should not be treated as a public header.
85 - `EXPORT_MACRO`: (Recommended) The export macro to add to the generated
87 - `INITIAL_CODE`: C++ code to run when the object factory is initialized.
88 - `EXTRA_INCLUDES`: A list of headers to include. The header names need to
89 include the `<>` or `""` quoting.
91function (vtk_object_factory_configure)
92 if (NOT DEFINED _vtk_build_module)
97 cmake_parse_arguments(PARSE_ARGV 0 _vtk_object_factory_configure
99 "SOURCE_FILE;HEADER_FILE;INITIAL_CODE;EXPORT_MACRO
"
102 if (_vtk_object_factory_configure_UNPARSED_ARGUMENTS)
105 "${_vtk_object_factory_configure_UNPARSED_ARGUMENTS}
")
108 get_property(_vtk_object_factory_done
110 PROPERTY "_vtk_object_factory_${_vtk_build_module}
"
112 if (_vtk_object_factory_done)
114 "An
object factory has already been created
for ${_vtk_build_module}.
")
118 "_vtk_object_factory_${_vtk_build_module}
" 1)
121 get_property(_vtk_object_factory_overrides
123 PROPERTY _vtk_object_factory_overrides)
125 if (NOT _vtk_object_factory_overrides)
127 "The ${_vtk_build_module} is generating an
object factory, but does not have any declared overrides.
")
130 set(_vtk_object_factory_doc
131 "Override
for ${_vtk_build_module} module
")
133 set(_vtk_object_factory_includes "")
134 set(_vtk_object_factory_functions "")
135 set(_vtk_object_factory_calls "")
137 foreach (_vtk_object_factory_extra_include IN LISTS _vtk_object_factory_configure_EXTRA_INCLUDES)
138 string(APPEND _vtk_object_factory_includes
139 "#include ${_vtk_object_factory_extra_include}\n
")
142 foreach (_vtk_object_factory_override IN LISTS _vtk_object_factory_overrides)
143 get_property(_vtk_object_factory_base
145 PROPERTY "_vtk_object_factory_override_${_vtk_object_factory_override}
")
146 string(APPEND _vtk_object_factory_includes
147 "#include \
"${_vtk_object_factory_override}.h\"\n")
148 string(APPEND _vtk_object_factory_functions
149 "VTK_CREATE_CREATE_FUNCTION(${_vtk_object_factory_override})\n")
150 string(APPEND _vtk_object_factory_calls
151 "this->RegisterOverride(\"${_vtk_object_factory_base}\", \"${_vtk_object_factory_override}\", \"${_vtk_object_factory_doc}\", 1, vtkObjectFactoryCreate${_vtk_object_factory_override});\n")
154 get_property(_vtk_object_factory_library_name GLOBAL
155 PROPERTY "_vtk_module_${_vtk_build_module}_library_name
")
157 set(_vtk_object_factory_overrides_header
158 "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_object_factory_library_name}ObjectFactory.h
")
159 set(_vtk_object_factory_overrides_source
160 "${CMAKE_CURRENT_BINARY_DIR}/${_vtk_object_factory_library_name}ObjectFactory.cxx
")
164 "${_vtk_object_factory_overrides_header}
"
168 "${_vtk_object_factory_overrides_source}
"
171 if (_vtk_object_factory_configure_HEADER_FILE)
172 set("${_vtk_object_factory_configure_HEADER_FILE}
"
173 "${_vtk_object_factory_overrides_header}
"
177 set("${_vtk_object_factory_configure_SOURCE_FILE}
"
178 "${_vtk_object_factory_overrides_source}
"
abstract base class for vtkObjectFactories
create a window for renderers to draw into
function vtk_object_factory_configure()
Generate source for overrides in a module.
function vtk_object_factory_declare()
Declare a factory override.