1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 /*=========================================================================
19 *
20 * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21 *
22 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23 *
24 * For complete copyright, license and disclaimer of warranty information
25 * please refer to the NOTICE file at the top of the ITK source tree.
26 *
27 *=========================================================================*/
28 #ifndef itkDataObjectDecorator_hxx
29 #define itkDataObjectDecorator_hxx
30
31 #include "itkDataObjectDecorator.h"
32 #include <algorithm>
33
34 namespace itk
35 {
36 /**
37 *
38 */
39 template< typename T >
40 void
41 DataObjectDecorator< T >
Set(const ComponentType * val)42 ::Set( const ComponentType *val)
43 {
44 if ( m_Component != val )
45 {
46 m_Component = const_cast<ComponentType*>(val);
47 this->Modified();
48 }
49 }
50
51 /**
52 *
53 */
54 template< typename T >
55 const T *
56 DataObjectDecorator< T >
Get() const57 ::Get() const
58 {
59 return m_Component.GetPointer();
60 }
61
62 /**
63 *
64 */
65 template< typename T >
66 T *
67 DataObjectDecorator< T >
GetModifiable()68 ::GetModifiable()
69 {
70 return m_Component.GetPointer();
71 }
72
73 /**
74 *
75 */
76 template< typename T >
77 ModifiedTimeType
78 DataObjectDecorator< T >
GetMTime() const79 ::GetMTime() const
80 {
81 const ModifiedTimeType t = Superclass::GetMTime();
82 if (m_Component.IsNotNull())
83 {
84 return std::max(t, m_Component->GetMTime());
85 }
86 return t;
87 }
88
89 /**
90 *
91 */
92 template< typename T >
93 void
94 DataObjectDecorator< T >
Initialize()95 ::Initialize()
96 {
97 Superclass::Initialize();
98
99 // make sure the MTime does not change
100 if ( m_Component.IsNull())
101 {
102 return;
103 }
104 if ( m_Component->GetMTime() > Superclass::GetMTime() )
105 {
106 this->SetTimeStamp(m_Component->GetTimeStamp());
107 }
108 m_Component = nullptr;
109 }
110
111 /**
112 *
113 */
114 template< typename T >
115 void
116 DataObjectDecorator< T >
Graft(const DataObject * data)117 ::Graft( const DataObject *data )
118 {
119 const auto * decorator = dynamic_cast< const Self * >( data );
120 this->Graft(decorator);
121 }
122
123 /**
124 *
125 */
126 template< typename T >
127 void
128 DataObjectDecorator< T >
Graft(const Self * data)129 ::Graft( const Self *data )
130 {
131 if ( !data )
132 {
133 return;
134 }
135
136 this->Set(data->m_Component);
137 }
138
139 /**
140 *
141 */
142 template< typename T >
143 void
144 DataObjectDecorator< T >
PrintSelf(std::ostream & os,Indent indent) const145 ::PrintSelf(std::ostream & os, Indent indent) const
146 {
147 Superclass::PrintSelf(os, indent);
148
149 os << indent << "Component: " << m_Component << std::endl;
150 }
151 } // end namespace itk
152
153 #endif
154