1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
/*=========================================================================
Program: Visualization Toolkit
Module: ObjectFactory.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 "vtkDebugLeaks.h"
#include "vtkObjectFactory.h"
#include "vtkObjectFactoryCollection.h"
#include "vtkOutputWindow.h"
#include "vtkOverrideInformation.h"
#include "vtkOverrideInformationCollection.h"
#include "vtkVersion.h"
#include "vtkPoints.h"
static int failed = 0;
class vtkTestPoints : public vtkPoints
{
public:
// Methods from vtkObject
~vtkTestPoints() VTK_OVERRIDE
{
}
vtkTypeMacro(vtkTestPoints,vtkPoints);
static vtkTestPoints* New() { VTK_STANDARD_NEW_BODY(vtkTestPoints) }
vtkTestPoints() { }
private:
vtkTestPoints(const vtkTestPoints&);
void operator=(const vtkTestPoints&);
};
class vtkTestPoints2 : public vtkPoints
{
public:
~vtkTestPoints2() VTK_OVERRIDE
{
}
// Methods from vtkObject
vtkTypeMacro(vtkTestPoints2,vtkPoints);
static vtkTestPoints2* New() { VTK_STANDARD_NEW_BODY(vtkTestPoints2) }
vtkTestPoints2() { }
private:
vtkTestPoints2(const vtkTestPoints2&);
void operator=(const vtkTestPoints2&);
};
VTK_CREATE_CREATE_FUNCTION(vtkTestPoints);
VTK_CREATE_CREATE_FUNCTION(vtkTestPoints2);
class VTK_EXPORT TestFactory : public vtkObjectFactory
{
public:
TestFactory();
static TestFactory* New()
{
TestFactory *f = new TestFactory;
f->InitializeObjectBase();
return f;
}
const char* GetVTKSourceVersion() VTK_OVERRIDE { return VTK_SOURCE_VERSION; }
const char* GetDescription() VTK_OVERRIDE { return "A fine Test Factory"; }
protected:
TestFactory(const TestFactory&);
void operator=(const TestFactory&);
};
TestFactory::TestFactory()
{
this->RegisterOverride("vtkPoints",
"vtkTestPoints",
"test vertex factory override",
1,
vtkObjectFactoryCreatevtkTestPoints);
this->RegisterOverride("vtkPoints", "vtkTestPoints2",
"test vertex factory override 2",
0,
vtkObjectFactoryCreatevtkTestPoints2);
}
void TestNewPoints(vtkPoints* v, const char* expectedClassName)
{
if(strcmp(v->GetClassName(), expectedClassName) != 0)
{
failed = 1;
cout << "Test Failed:\nExpected classname: " << expectedClassName
<< "\nCreated classname: " << v->GetClassName() << endl;
}
}
int TestObjectFactory(int, char *[])
{
vtkOutputWindow::GetInstance()->PromptUserOff();
vtkGenericWarningMacro("Test Generic Warning");
TestFactory* factory = TestFactory::New();
vtkObjectFactory::RegisterFactory(factory);
factory->Delete();
vtkPoints* v = vtkPoints::New();
TestNewPoints(v, "vtkTestPoints");
v->Delete();
// disable all vtkPoints creation with the
factory->Disable("vtkPoints");
v = vtkPoints::New();
TestNewPoints(v, "vtkPoints");
factory->SetEnableFlag(1, "vtkPoints", "vtkTestPoints2");
v->Delete();
v = vtkPoints::New();
TestNewPoints(v, "vtkTestPoints2");
factory->SetEnableFlag(0, "vtkPoints", "vtkTestPoints2");
factory->SetEnableFlag(1, "vtkPoints", "vtkTestPoints");
v->Delete();
v = vtkPoints::New();
TestNewPoints(v, "vtkTestPoints");
v->Delete();
vtkOverrideInformationCollection* oic =
vtkOverrideInformationCollection::New();
vtkObjectFactory::GetOverrideInformation("vtkPoints", oic);
vtkOverrideInformation* oi;
if(oic->GetNumberOfItems() != 2)
{
cout << "Incorrect number of overrides for vtkPoints, expected 2, got: "
<< oic->GetNumberOfItems() << "\n";
failed = 1;
if(oic->GetNumberOfItems() < 2)
{
return 1;
}
}
vtkCollectionSimpleIterator oicit;
oic->InitTraversal(oicit);
oi = oic->GetNextOverrideInformation(oicit);
oi->GetObjectFactory();
if(strcmp(oi->GetClassOverrideName(), "vtkPoints"))
{
cout << "failed: GetClassOverrideName should be vtkPoints, is: "
<< oi->GetClassOverrideName() << "\n";
failed = 1;
}
if(strcmp(oi->GetClassOverrideWithName(), "vtkTestPoints"))
{
cout << "failed: GetClassOverrideWithName should be vtkTestPoints, is: "
<< oi->GetClassOverrideWithName() << "\n";
failed = 1;
}
if(strcmp(oi->GetDescription(), "test vertex factory override"))
{
cout << "failed: GetClassOverrideWithName should be test vertex factory override, is: "
<< oi->GetDescription() << "\n";
failed = 1;
}
oi = oic->GetNextOverrideInformation(oicit);
if(strcmp(oi->GetClassOverrideName(), "vtkPoints"))
{
cout << "failed: GetClassOverrideName should be vtkPoints, is: "
<< oi->GetClassOverrideName() << "\n";
failed = 1;
}
if(strcmp(oi->GetClassOverrideWithName(), "vtkTestPoints2"))
{
cout << "failed: GetClassOverrideWithName should be vtkTestPoints2, is: "
<< oi->GetClassOverrideWithName() << "\n";
failed = 1;
}
if(strcmp(oi->GetDescription(), "test vertex factory override 2"))
{
cout << "failed: GetClassOverrideWithName should be test vertex factory override 2, is: "
<< oi->GetDescription() << "\n";
failed = 1;
}
oic->Delete();
vtkObjectFactory::UnRegisterAllFactories();
return failed;
}
|