forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkInformationExecutivePortKey.cxx
146 lines (129 loc) · 4.61 KB
/
vtkInformationExecutivePortKey.cxx
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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkInformationExecutivePortKey.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 "vtkInformationExecutivePortKey.h"
#include "vtkExecutive.h"
#include "vtkInformation.h"
#include "vtkSmartPointer.h"
//------------------------------------------------------------------------------
vtkInformationExecutivePortKey::vtkInformationExecutivePortKey(
const char* name, const char* location)
: vtkInformationKey(name, location)
{
vtkFilteringInformationKeyManager::Register(this);
}
//------------------------------------------------------------------------------
vtkInformationExecutivePortKey::~vtkInformationExecutivePortKey() = default;
//------------------------------------------------------------------------------
void vtkInformationExecutivePortKey::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
class vtkInformationExecutivePortValue : public vtkObjectBase
{
public:
vtkBaseTypeMacro(vtkInformationExecutivePortValue, vtkObjectBase);
vtkSmartPointer<vtkExecutive> Executive;
int Port;
};
//------------------------------------------------------------------------------
void vtkInformationExecutivePortKey::Set(vtkInformation* info, vtkExecutive* executive, int port)
{
if (executive)
{
if (vtkInformationExecutivePortValue* oldv =
static_cast<vtkInformationExecutivePortValue*>(this->GetAsObjectBase(info)))
{
// Replace the existing value.
oldv->Executive = executive;
oldv->Port = port;
// Since this sets a value without call SetAsObjectBase(),
// the info has to be modified here (instead of
// vtkInformation::SetAsObjectBase()
info->Modified();
}
else
{
// Allocate a new value.
vtkInformationExecutivePortValue* v = new vtkInformationExecutivePortValue;
v->InitializeObjectBase();
v->Executive = executive;
v->Port = port;
this->SetAsObjectBase(info, v);
v->Delete();
}
}
else
{
this->SetAsObjectBase(info, nullptr);
}
}
void vtkInformationExecutivePortKey::Get(vtkInformation* info, vtkExecutive*& executive, int& port)
{
if (vtkInformationExecutivePortValue* v =
static_cast<vtkInformationExecutivePortValue*>(this->GetAsObjectBase(info)))
{
executive = v->Executive;
port = v->Port;
return;
}
executive = nullptr;
port = 0;
}
//------------------------------------------------------------------------------
vtkExecutive* vtkInformationExecutivePortKey::GetExecutive(vtkInformation* info)
{
if (vtkInformationExecutivePortValue* v =
static_cast<vtkInformationExecutivePortValue*>(this->GetAsObjectBase(info)))
{
return v->Executive;
}
return nullptr;
}
//------------------------------------------------------------------------------
int vtkInformationExecutivePortKey::GetPort(vtkInformation* info)
{
vtkInformationExecutivePortValue* v =
static_cast<vtkInformationExecutivePortValue*>(this->GetAsObjectBase(info));
return v ? v->Port : 0;
}
//------------------------------------------------------------------------------
void vtkInformationExecutivePortKey::ShallowCopy(vtkInformation* from, vtkInformation* to)
{
this->Set(to, this->GetExecutive(from), this->GetPort(from));
}
//------------------------------------------------------------------------------
void vtkInformationExecutivePortKey::Print(ostream& os, vtkInformation* info)
{
// Print the value.
if (this->Has(info))
{
vtkExecutive* executive = this->GetExecutive(info);
int port = this->GetPort(info);
if (executive)
{
os << executive->GetClassName() << "(" << executive << ") port " << port;
}
else
{
os << "(nullptr) port " << port;
}
}
}
//------------------------------------------------------------------------------
void vtkInformationExecutivePortKey::Report(vtkInformation* info, vtkGarbageCollector* collector)
{
if (vtkInformationExecutivePortValue* v =
static_cast<vtkInformationExecutivePortValue*>(this->GetAsObjectBase(info)))
{
v->Executive.Report(collector, this->GetName());
}
}