ITK  4.4.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);
135 
136 protected:
138  virtual ~ImportImageContainer();
139 
143  void PrintSelf(std::ostream & os, Indent indent) const;
144 
145  virtual TElement * AllocateElements(ElementIdentifier size) const;
146 
147  virtual void DeallocateManagedMemory();
148 
149  /* Set the m_Size member that represents the number of elements
150  * currently stored in the container. Use this function with great
151  * care since it only changes the m_Size member and not the actual size
152  * of the import pointer m_ImportPointer. It should typically
153  * be used only to override AllocateElements and
154  * DeallocateManagedMemory. */
155  itkSetMacro(Size, TElementIdentifier);
156 
157  /* Set the m_Capacity member that represents the capacity of
158  * the current container. Use this function with great care
159  * since it only changes the m_Capacity member and not the actual
160  * capacity of the import pointer m_ImportPointer. It should typically
161  * be used only to override AllocateElements and
162  * DeallocateManagedMemory. */
163  itkSetMacro(Capacity, TElementIdentifier);
164 
165  /* Set the m_ImportPointer member. Use this function with great care
166  * since it only changes the m_ImportPointer member but not the m_Size
167  * and m_Capacity members. It should typically be used only to override
168  * AllocateElements and DeallocateManagedMemory. */
169  void SetImportPointer(TElement *ptr){ m_ImportPointer = ptr; }
170 
171 private:
172  ImportImageContainer(const Self &); //purposely not implemented
173  void operator=(const Self &); //purposely not implemented
174 
175  TElement * m_ImportPointer;
176  TElementIdentifier m_Size;
177  TElementIdentifier m_Capacity;
179 };
180 } // end namespace itk
181 
182 #ifndef ITK_MANUAL_INSTANTIATION
183 #include "itkImportImageContainer.hxx"
184 #endif
185 
186 #endif
187