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 itkSimpleDataObjectDecorator_h
29 #define itkSimpleDataObjectDecorator_h
30 
31 #include "itkDataObject.h"
32 #include "itkObjectFactory.h"
33 
34 namespace itk
35 {
36 /** \class SimpleDataObjectDecorator
37  * \brief Decorates any "simple" data type (data types without smart pointers) with a DataObject API
38  *
39  * SimpleDataObjectDecorator decorates an object with a DataObject
40  * API. This allows simple objects to be encapsulated into objects
41  * that can be passed as down the pipeline. This decorator is intended
42  * to be used on native types (float, int, etc.) or any objects not
43  * derived from itkObject.  To decorate a subclass of itkObject, see
44  * DataObjectDecorator.
45  *
46  * The decorator provides two methods Set() and Get() to access the
47  * decorated object (referred internally as the component).
48  *
49  * Note that when an instance of SimpleDataObjectDecorator is created,
50  * the component is initialized with its default constructor.
51  *
52  * SimpleDataObjectDecorator can decorate any simple data type. Two
53  * other decorators are provided for decorating pointers.
54  * DataObjectDecorator will decorate pointers to subclasses of
55  * itkObject (internally storing the pointer in a
56  * SmartPointer). AutoPointerDataObjectDecorator will decorate any
57  * other pointer and manage the memory deallocationg of the component.
58  *
59  * \sa DataObjectDecorator
60  * \sa AutoPointerDataObjectDecorator
61  * \ingroup ITKSystemObjects
62  *
63  * \ingroup ITKCommon
64  */
65 template< typename T >
66 class ITK_TEMPLATE_EXPORT SimpleDataObjectDecorator:public DataObject
67 {
68 public:
69   ITK_DISALLOW_COPY_AND_ASSIGN(SimpleDataObjectDecorator);
70 
71   /** Standard type alias. */
72   using Self = SimpleDataObjectDecorator;
73   using Superclass = DataObject;
74   using Pointer = SmartPointer< Self >;
75   using ConstPointer = SmartPointer< const Self >;
76 
77   /** Typedef for the component type (object being decorated) */
78   using ComponentType = T;
79 
80   /** Method for creation through the object factory. */
81   itkNewMacro(Self);
82 
83   /** Run-time type information (and related methods). */
84   itkTypeMacro(SimpleDataObjectDecorator, DataObject);
85 
86   /** Set the contained object */
87   virtual void Set(const T & val);
88 
89   /** Get the contained object */
Get()90   virtual T &       Get() { return m_Component; }
Get()91   virtual const T & Get() const { return m_Component; }
92 
93 protected:
94   SimpleDataObjectDecorator();
95   ~SimpleDataObjectDecorator() override = default;
96   void PrintSelf(std::ostream & os, Indent indent) const override;
97 
98 protected:
99 
100 private:
101   ComponentType m_Component;
102   bool          m_Initialized;
103 };
104 } // end namespace itk
105 
106 #ifndef ITK_MANUAL_INSTANTIATION
107 #include "itkSimpleDataObjectDecorator.hxx"
108 #endif
109 
110 #endif
111