Commit 2ad5045b authored by Ben Boeckel's avatar Ben Boeckel
Browse files

vtkMakeInstantiator: remove support

This has been deprecated in 8.1.
parent 884acc14
#
# a cmake implementation of the Wrap Tcl command
#
# VTK_MAKE_INSTANTIATOR(className
# outSourceList
# src-list1
# EXPORT_MACRO
# HEADER_LOCATION
# INCLUDES)
#
# Generates a new class with the given name and adds its files to the
# given outSourceList. It registers the classes from the other given
# source lists with vtkInstantiator when it is loaded. The output
# source list should be added to the library with the classes it
# registers.
# The EXPORT_MACRO argument must be given and followed by the export
# macro to use when generating the class (ex. VTK_COMMON_EXPORT).
# The HEADER_LOCATION option must be followed by a path. It specifies
# the directory in which to place the generated class's header file.
# The generated class implementation files always go in the build
# directory corresponding to the CMakeLists.txt file containing
# the command. This is the default location for the header.
# The INCLUDES option can be followed by a list of zero or more files.
# These files will be #included by the generated instantiator header,
# and can be used to gain access to the specified exportMacro in the
# C++ code.
MACRO(VTK_MAKE_INSTANTIATOR2 className outSourceList)
# convert to the WRAP3 signature
SET (SOURCES)
SET (INCLUDES)
SET (MODE SOURCES_MODE)
FOREACH(ARG ${ARGN})
SET (MODE_CHANGED 0)
IF (ARG MATCHES INCLUDES)
SET (MODE INCLUDES_MODE)
SET (MODE_CHANGED 1)
ENDIF ()
IF (ARG MATCHES EXPORT_MACRO)
SET (MODE EXPORT_MODE)
SET (MODE_CHANGED 1)
ENDIF ()
IF (ARG MATCHES HEADER_LOCATION)
SET (MODE HEADER_LOCATION_MODE)
SET (MODE_CHANGED 1)
ENDIF ()
IF (ARG MATCHES INCLUDES)
SET (MODE INCLUDES_MODE)
SET (MODE_CHANGED 1)
ENDIF ()
IF (NOT MODE_CHANGED)
IF (MODE MATCHES SOURCES_MODE)
SET(SOURCES ${SOURCES} ${ARG})
ENDIF ()
IF (MODE MATCHES INCLUDES_MODE)
SET(INCLUDES ${INCLUDES} ${ARG})
ENDIF ()
IF (MODE MATCHES EXPORT_MODE)
SET(EXPORT_MACRO "${ARG}")
ENDIF ()
IF (MODE MATCHES HEADER_LOCATION_MODE)
SET(HEADER_LOCATION "${ARG}")
ENDIF ()
ENDIF ()
ENDFOREACH()
VTK_MAKE_INSTANTIATOR3(${className} ${outSourceList} "${SOURCES}" "${EXPORT_MACRO}" "${HEADER_LOCATION}" "${INCLUDES}")
ENDMACRO()
MACRO(VTK_MAKE_INSTANTIATOR3 className outSourceList SOURCES EXPORT_MACRO HEADER_LOCATION INCLUDES)
# Initialize local variables
SET(HEADER_CONTENTS)
SET(CXX_CONTENTS_INCLUDE)
SET(CXX_CONTENTS)
SET(CXX_CONTENTS2)
SET(CXX_CONTENTS3)
# make the arguments available to the configured files
SET (VTK_MAKE_INSTANTIATOR_CLASS_NAME ${className})
SET (VTK_MAKE_INSTANTIATOR_EXPORT_MACRO ${EXPORT_MACRO})
# For each include
FOREACH(FILE ${INCLUDES})
# generate the header
SET (HEADER_CONTENTS
"${HEADER_CONTENTS}#include \"${FILE}\"\n")
ENDFOREACH()
# For each class
FOREACH(FILE ${SOURCES})
# should we wrap the file?
SET (WRAP_THIS_CLASS 1)
GET_SOURCE_FILE_PROPERTY(TMP_WRAP_EXCLUDE ${FILE} WRAP_EXCLUDE)
GET_SOURCE_FILE_PROPERTY(TMP_ABSTRACT ${FILE} ABSTRACT)
# if it is abstract or wrap exclude then don't wrap it
IF (TMP_WRAP_EXCLUDE OR TMP_ABSTRACT)
SET (WRAP_THIS_CLASS 0)
ENDIF ()
# don't wrap vtkIndent or vtkTimeStamp
IF (${FILE} STREQUAL "vtkIndent")
SET (WRAP_THIS_CLASS 0)
ENDIF ()
IF (${FILE} STREQUAL "vtkTimeStamp")
SET (WRAP_THIS_CLASS 0)
ENDIF ()
IF (${FILE} STREQUAL "vtkVariant")
SET (WRAP_THIS_CLASS 0)
ENDIF ()
IF (${FILE} STREQUAL "vtkObjectBase")
SET (WRAP_THIS_CLASS 0)
ENDIF ()
IF (${FILE} MATCHES "vtkInformation.*Key")
SET (WRAP_THIS_CLASS 0)
ENDIF ()
# finally if we should wrap it, then ...
IF (WRAP_THIS_CLASS)
# what is the filename without the extension
GET_FILENAME_COMPONENT(TMP_FILENAME ${FILE} NAME_WE)
SET (CXX_CONTENTS_INCLUDE
"${CXX_CONTENTS_INCLUDE}#include \"${TMP_FILENAME}.h\"\n")
# generate the implementation
SET (CXX_CONTENTS
"${CXX_CONTENTS}vtkInstantiatorNewMacro(${TMP_FILENAME})\n")
SET (CXX_CONTENTS2
"${CXX_CONTENTS2} vtkInstantiator::RegisterInstantiator(\"${TMP_FILENAME}\", vtkInstantiator${TMP_FILENAME}New);\n")
SET (CXX_CONTENTS3
"${CXX_CONTENTS3} vtkInstantiator::UnRegisterInstantiator(\"${TMP_FILENAME}\", vtkInstantiator${TMP_FILENAME}New);\n")
ENDIF ()
ENDFOREACH()
# add the source file to the source list
SET(${outSourceList} ${${outSourceList}}
${CMAKE_CURRENT_BINARY_DIR}/${className}.cxx)
SET_SOURCE_FILES_PROPERTIES(
${CMAKE_CURRENT_BINARY_DIR}/${className}.cxx
PROPERTIES GENERATED 1 WRAP_EXCLUDE 1 ABSTRACT 0
)
CONFIGURE_FILE(
${VTK_CMAKE_DIR}/vtkMakeInstantiator.h.in
${HEADER_LOCATION}/${className}.h
@ONLY
)
CONFIGURE_FILE(
${VTK_CMAKE_DIR}/vtkMakeInstantiator.cxx.in
${CMAKE_CURRENT_BINARY_DIR}/${className}.cxx
@ONLY
)
ENDMACRO()
#include "@VTK_MAKE_INSTANTIATOR_CLASS_NAME@.h"
@CXX_CONTENTS_INCLUDE@
#include "vtkSetGet.h"
@CXX_CONTENTS@
void @VTK_MAKE_INSTANTIATOR_CLASS_NAME@::ClassInitialize()
{
@CXX_CONTENTS2@
}
void @VTK_MAKE_INSTANTIATOR_CLASS_NAME@::ClassFinalize()
{
@CXX_CONTENTS3@
}
@VTK_MAKE_INSTANTIATOR_CLASS_NAME@::@VTK_MAKE_INSTANTIATOR_CLASS_NAME@()
{
if(++@VTK_MAKE_INSTANTIATOR_CLASS_NAME@::Count == 1)
{
@VTK_MAKE_INSTANTIATOR_CLASS_NAME@::ClassInitialize();
}
}
@VTK_MAKE_INSTANTIATOR_CLASS_NAME@::~@VTK_MAKE_INSTANTIATOR_CLASS_NAME@()
{
if(--@VTK_MAKE_INSTANTIATOR_CLASS_NAME@::Count == 0)
{
@VTK_MAKE_INSTANTIATOR_CLASS_NAME@::ClassFinalize();
}
}
// Number of translation units that include this class's header.
// Purposely not initialized. Default is static initialization to 0.
unsigned int @VTK_MAKE_INSTANTIATOR_CLASS_NAME@::Count;
#ifndef @VTK_MAKE_INSTANTIATOR_CLASS_NAME@_h
#define @VTK_MAKE_INSTANTIATOR_CLASS_NAME@_h
#include "vtkInstantiator.h"
@HEADER_CONTENTS@
class @VTK_MAKE_INSTANTIATOR_EXPORT_MACRO@ @VTK_MAKE_INSTANTIATOR_CLASS_NAME@
{
public:
@VTK_MAKE_INSTANTIATOR_CLASS_NAME@();
~@VTK_MAKE_INSTANTIATOR_CLASS_NAME@();
private:
static void ClassInitialize();
static void ClassFinalize();
static unsigned int Count;
};
static @VTK_MAKE_INSTANTIATOR_CLASS_NAME@ @VTK_MAKE_INSTANTIATOR_CLASS_NAME@Initializer;
#endif
......@@ -6,9 +6,6 @@ include(${_VTKModuleMacros_DIR}/vtkModuleAPI.cmake)
include(VTKGenerateExportHeader)
include(vtkWrapping)
include(vtkTargetLinkLibrariesWithDynamicLookup)
if(VTK_MAKE_INSTANTIATORS)
include(vtkMakeInstantiator)
endif()
if(UNIX AND VTK_BUILD_FORWARDING_EXECUTABLES)
include(vtkForwardingExecutable)
endif()
......@@ -678,15 +675,6 @@ function(vtk_module_library name)
list(APPEND _hdrs "${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}Module.h")
list(REMOVE_DUPLICATES _hdrs)
# The instantiators are off by default, and only work on wrapped modules.
if(VTK_MAKE_INSTANTIATORS AND NOT ${vtk-module}_EXCLUDE_FROM_WRAPPING)
string(TOUPPER "${vtk-module}_EXPORT" _export_macro)
vtk_make_instantiator3(${vtk-module}Instantiator _instantiator_SRCS
"${ARGN}" ${_export_macro} ${CMAKE_CURRENT_BINARY_DIR}
${vtk-module}Module.h)
list(APPEND _hdrs "${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}Instantiator.h")
endif()
# Add the vtkWrapHierarchy custom command output to the target, if any.
# TODO: Re-order things so we do not need to duplicate this condition.
if(NOT ${vtk-module}_EXCLUDE_FROM_WRAPPING AND
......@@ -709,7 +697,7 @@ function(vtk_module_library name)
# OBJECT libraries don't like this variable being set; clear it.
unset(${vtk-module}_LIB_DEPENDS CACHE)
endif()
vtk_add_library(${vtk-module}${force_object} ${ARGN} ${_hdrs} ${_instantiator_SRCS} ${_hierarchy})
vtk_add_library(${vtk-module}${force_object} ${ARGN} ${_hdrs} ${_hierarchy})
if(_vtk_build_as_kit)
# Make an interface library to link with for libraries.
add_library(${vtk-module} INTERFACE)
......
......@@ -513,9 +513,6 @@ if (NOT VTK_INSTALL_NO_DEVELOPMENT)
CMake/vtkGroups.cmake
CMake/vtkForwardingExecutable.cmake
CMake/vtkJavaWrapping.cmake
CMake/vtkMakeInstantiator.cmake
CMake/vtkMakeInstantiator.cxx.in
CMake/vtkMakeInstantiator.h.in
CMake/vtkModuleAPI.cmake
CMake/vtkModuleHeaders.cmake.in
CMake/vtkModuleInfo.cmake.in
......
......@@ -485,10 +485,6 @@ if(VTK_WRAP_PYTHON OR VTK_WRAP_TCL OR VTK_WRAP_JAVA)
set(VTK_WRAP_HIERARCHY_EXE vtkWrapHierarchy)
endif()
# This is not normally necessary, but could be desirable in some circumstances.
option(VTK_MAKE_INSTANTIATORS "Should all modules build instantiators" OFF)
mark_as_advanced(VTK_MAKE_INSTANTIATORS)
# Kits bundle multiple modules together into a single library, this
# is used to dramatically reduce the number of generated libraries.
option(VTK_ENABLE_KITS "Build VTK using kits instead of modules." OFF)
......
......@@ -288,11 +288,6 @@ SET(Module_SRCS
${CMAKE_CURRENT_BINARY_DIR}/vtkVersionMacros.h
)
if (NOT VTK_LEGACY_REMOVE)
list(APPEND Module_SRCS
vtkInstantiator.cxx)
endif ()
set(${vtk-module}_HDRS
vtkABI.h
vtkAngularPeriodicDataArray.h
......
......@@ -107,7 +107,6 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestGarbageCollector.cxx
TestGenericDataArrayAPI.cxx
TestInformationKeyLookup.cxx
# TestInstantiator.cxx # Have not enabled instantiators.
TestLookupTable.cxx
TestLookupTableThreaded.cxx
TestMath.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestInstantiator.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME Test of vtkCommonInstantiator
// .SECTION Description
// Make sure common registers its classes with vtkInstantiator.
#include "vtkCommonInstantiator.h"
int main()
{
int result = 0;
vtkObject* object = vtkInstantiator::CreateInstance("vtkDoubleArray");
if(object)
{
if(object->IsA("vtkDoubleArray"))
{
cout << "Successfully created an instance of vtkDoubleArray." << endl;
}
else
{
cerr << "Created an instance of " << object->GetClassName()
<< "instead of vtkDoubleArray." << endl;
result = 1;
}
object->Delete();
}
else
{
cerr << "Failed to create an instance of vtkDoubleArray." << endl;
result = 1;
}
return result;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkInstantiator.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkInstantiator.h"
#include "vtkObjectFactory.h"
vtkStandardNewMacro(vtkInstantiator);
// Node in hash table.
class vtkInstantiatorHashNode
{
public:
typedef vtkInstantiator::CreateFunction CreateFunction;
vtkInstantiatorHashNode() { this->ClassName = nullptr; this->Function = nullptr; }
void SetClassName(const char* className) { this->ClassName = className; }
const char* GetClassName() { return this->ClassName; }
void SetFunction(CreateFunction function) { this->Function = function; }
CreateFunction GetFunction() { return this->Function; }
private:
const char* ClassName;
CreateFunction Function;
};
// Hash table used by vtkInstantiator. Must not be a vtkObject.
class vtkInstantiatorHashTable
{
public:
vtkInstantiatorHashTable();
~vtkInstantiatorHashTable();
void PrintSelf(ostream& os, vtkIndent indent);
typedef vtkInstantiator::CreateFunction CreateFunction;
void Insert(const char* className, CreateFunction function);
void Erase(const char* className, CreateFunction function);
CreateFunction Find(const char* className);
protected:
unsigned long Hash(const char* s);
void ExtendBucket(unsigned long bucket);
const char* AddClassName(const char* className);
vtkInstantiatorHashNode** Buckets;
unsigned int* BucketCounts;
unsigned int* BucketSizes;
unsigned long NumberOfBuckets;
char** ClassNames;
unsigned long NumberOfClassNames;
unsigned long ClassNamesSize;
private:
vtkInstantiatorHashTable(const vtkInstantiatorHashTable&) = delete;
void operator=(const vtkInstantiatorHashTable&) = delete;
};
//----------------------------------------------------------------------------
vtkInstantiatorHashTable::vtkInstantiatorHashTable()
{
this->NumberOfBuckets = 101;
this->Buckets = new vtkInstantiatorHashNode*[this->NumberOfBuckets];
this->BucketCounts = new unsigned int[this->NumberOfBuckets];
this->BucketSizes = new unsigned int[this->NumberOfBuckets];
unsigned int i;
for(i=0;i < this->NumberOfBuckets;++i)
{
this->BucketCounts[i] = 0;
this->BucketSizes[i] = 16;
this->Buckets[i] = new vtkInstantiatorHashNode[this->BucketSizes[i]];
}
this->NumberOfClassNames = 0;
this->ClassNamesSize = 256;
this->ClassNames = new char*[this->ClassNamesSize];
}
//----------------------------------------------------------------------------
vtkInstantiatorHashTable::~vtkInstantiatorHashTable()
{
unsigned long i;
for(i=0; i < this->NumberOfBuckets;++i)
{
delete [] this->Buckets[i];
}
delete [] this->BucketSizes;
delete [] this->BucketCounts;
delete [] this->Buckets;
for(i=0;i < this->NumberOfClassNames;++i)
{
delete [] this->ClassNames[i];
}
delete [] this->ClassNames;
}
//----------------------------------------------------------------------------
void vtkInstantiatorHashTable::PrintSelf(ostream& os, vtkIndent indent)
{
os << indent << "NumberOfBuckets: " << this->NumberOfBuckets << "\n";
double avgBucketSize = 0;
unsigned long maxBucketSize = 0;
unsigned long minBucketSize = this->NumberOfClassNames;
for(unsigned long i=0;i < this->NumberOfBuckets;++i)
{
avgBucketSize += this->BucketCounts[i];
if(this->BucketCounts[i] > maxBucketSize)
{ maxBucketSize = this->BucketCounts[i]; }
if(this->BucketCounts[i] < minBucketSize)
{ minBucketSize = this->BucketCounts[i]; }
}
avgBucketSize /= double(this->NumberOfBuckets);
os << indent << "Average Bucket Size: " << avgBucketSize << "\n";
os << indent << "Minimum Bucket Size: " << minBucketSize << "\n";
os << indent << "Maximum Bucket Size: " << maxBucketSize << "\n";
}
//----------------------------------------------------------------------------
void vtkInstantiatorHashTable::Insert(const char* className,
CreateFunction function)
{
unsigned long bucket = this->Hash(className);
if(this->BucketCounts[bucket] == this->BucketSizes[bucket])
{ this->ExtendBucket(bucket); }
// Do not check if the class is already registered. It is possible
// that more than one create function will be registered for the
// same class, and even that the same function is registered more
// than once. Each register should have a corresponding unregister.
// As long as any register has not had its corresponding unregister,
// we want to allow the class to be created.
unsigned int pos = this->BucketCounts[bucket]++;
this->Buckets[bucket][pos].SetClassName(this->AddClassName(className));
this->Buckets[bucket][pos].SetFunction(function);
}
//----------------------------------------------------------------------------
void vtkInstantiatorHashTable::Erase(const char* className,
CreateFunction function)
{
unsigned long bucket = this->Hash(className);
// Find the exact registration function we have been given, and
// remove it only once. If more than one funcion has been
// registered for this class, or the same function more than once,
// each register should have its corresponding unregister.
unsigned int i;
for(i=0; i < this->BucketCounts[bucket];++i)
{
if(((this->Buckets[bucket][i].GetFunction() == function)
&& (strcmp(this->Buckets[bucket][i].GetClassName(), className) == 0)))
{
unsigned int j;
--this->BucketCounts[bucket];
for(j=i;j < this->BucketCounts[bucket];++j)
{
this->Buckets[bucket][j] = this->Buckets[bucket][j+1];
}
return;
}
}
}
//----------------------------------------------------------------------------
vtkInstantiatorHashTable::CreateFunction
vtkInstantiatorHashTable::Find(const char* className)
{
unsigned long bucket = this->Hash(className);
unsigned int i;
for(i=0; i < this->BucketCounts[bucket];++i)
{
if(strcmp(this->Buckets[bucket][i].GetClassName(), className) == 0)
{ return this->Buckets[bucket][i].GetFunction(); }
}
return nullptr;
}
//----------------------------------------------------------------------------
unsigned long vtkInstantiatorHashTable::Hash(const char* s)
{
unsigned long h = 0;
for(;*s;++s) { h = 5*h + *s; }
return h % this->NumberOfBuckets;
}
//----------------------------------------------------------------------------
void vtkInstantiatorHashTable::ExtendBucket(unsigned long bucket)
{
unsigned int newSize = this->BucketSizes[bucket] * 2;
vtkInstantiatorHashNode* newBucket =
new vtkInstantiatorHashNode[newSize];
unsigned int i;
for(i=0; i < this->BucketCounts[bucket];++i)
{ newBucket[i] = this->Buckets[bucket][i]; }
delete [] this->Buckets[bucket];
this->Buckets[bucket] = newBucket;
this->BucketSizes[bucket] = newSize;
}
//----------------------------------------------------------------------------
const char* vtkInstantiatorHashTable::AddClassName(const char* className)
{
if(this->NumberOfClassNames == this->ClassNamesSize)
{
unsigned long newSize = this->ClassNamesSize * 2;
char** newNames = new char*[newSize];
unsigned long i;
for(i=0;i < this->NumberOfClassNames;++i)
{ newNames[i] = this->ClassNames[i]; }
delete [] this->ClassNames;
this->ClassNames = newNames;
this->ClassNamesSize = newSize;
}
char* newName = new char[strlen(className)+1];
strcpy(newName, className);
this->ClassNames[this->NumberOfClassNames++] = newName;
return newName;
}
//----------------------------------------------------------------------------
// Implementation of actual vtkInstantiator class.
//----------------------------------------------------------------------------
vtkInstantiator::vtkInstantiator()
{
}
//----------------------------------------------------------------------------
vtkInstantiator::~vtkInstantiator()
{
}
//----------------------------------------------------------------------------
void vtkInstantiator::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
vtkInstantiator::CreatorTable->PrintSelf(os, indent);
}
//----------------------------------------------------------------------------