ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkImportImageContainer.h
Go to the documentation of this file.
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 #ifndef __itkImportImageContainer_h
19 #define __itkImportImageContainer_h
20 
21 #include "itkObject.h"
22 #include "itkObjectFactory.h"
23 #include <utility>
24 
25 namespace itk
26 {
44 template< typename TElementIdentifier, typename TElement >
46 {
47 public:
50  typedef Object Superclass;
53 
55  typedef TElementIdentifier ElementIdentifier;
56  typedef TElement Element;
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(ImportImageContainer, Object);
63 
65  TElement * GetImportPointer() { return m_ImportPointer; }
66 
73  void SetImportPointer(TElement *ptr, TElementIdentifier num,
74  bool LetContainerManageMemory = false);
75 
77  TElement & operator[](const ElementIdentifier id)
78  { return m_ImportPointer[id]; }
79 
81  const TElement & operator[](const ElementIdentifier id) const
82  { return m_ImportPointer[id]; }
83 
86  TElement * GetBufferPointer()
87  { return m_ImportPointer; }
88 
91  { return m_Capacity; }
92 
94  ElementIdentifier Size(void) const
95  { return m_Size; }
96 
109  void Reserve(ElementIdentifier num);
110 
117  void Squeeze(void);
118 
120  void Initialize(void);
121 
131  itkSetMacro(ContainerManageMemory, bool);
132  itkGetConstMacro(ContainerManageMemory, bool);
133  itkBooleanMacro(ContainerManageMemory);
134 protected:
136  virtual ~ImportImageContainer();
138 
142  void PrintSelf(std::ostream & os, Indent indent) const;
143 
144  virtual TElement * AllocateElements(ElementIdentifier size) const;
145 
146  virtual void DeallocateManagedMemory();
147 
148  /* Set the m_Size member that represents the number of elements
149  * currently stored in the container. Use this function with great
150  * care since it only changes the m_Size member and not the actual size
151  * of the import pointer m_ImportPointer. It should typically
152  * be used only to override AllocateElements and
153  * DeallocateManagedMemory. */
154  itkSetMacro(Size, TElementIdentifier);
155 
156  /* Set the m_Capacity member that represents the capacity of
157  * the current container. Use this function with great care
158  * since it only changes the m_Capacity member and not the actual
159  * capacity of the import pointer m_ImportPointer. It should typically
160  * be used only to override AllocateElements and
161  * DeallocateManagedMemory. */
162  itkSetMacro(Capacity, TElementIdentifier);
163 
164  /* Set the m_ImportPointer member. Use this function with great care
165  * since it only changes the m_ImportPointer member but not the m_Size
166  * and m_Capacity members. It should typically be used only to override
167  * AllocateElements and DeallocateManagedMemory. */
168  void SetImportPointer(TElement *ptr){ m_ImportPointer = ptr; }
169 private:
170  ImportImageContainer(const Self &); //purposely not implemented
171  void operator=(const Self &); //purposely not implemented
172 
173  TElement * m_ImportPointer;
174  TElementIdentifier m_Size;
175  TElementIdentifier m_Capacity;
177 };
178 } // end namespace itk
179 
180 // Define instantiation macro for this template.
181 #define ITK_TEMPLATE_ImportImageContainer(_, EXPORT, TypeX, TypeY) \
182  namespace itk \
183  { \
184  _( 2 ( class EXPORT ImportImageContainer< ITK_TEMPLATE_2 TypeX > ) ) \
185  namespace Templates \
186  { \
187  typedef ImportImageContainer< ITK_TEMPLATE_2 TypeX > ImportImageContainer##TypeY; \
188  } \
189  }
190 
191 #if ITK_TEMPLATE_EXPLICIT
192 #include "Templates/itkImportImageContainer+-.h"
193 #endif
194 
195 #if ITK_TEMPLATE_TXX
196 #include "itkImportImageContainer.hxx"
197 #endif
198 
199 #endif
200