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 itkImageContainerInterface_h 19 #define itkImageContainerInterface_h 20 21 #include "itkObject.h" 22 23 namespace itk 24 { 25 /** \class ImageContainerInterface 26 * \brief Used for reference when writing containers conforming to 27 * this interface. 28 * 29 * This should only be used for reference when writing containers 30 * conforming to this interface. ITK uses generic programming to 31 * allow container type substitution, so polymorphism is not needed to 32 * use containers through this interface. This means that a container 33 * conforming to this interface need not be derived from it, and that 34 * their methods should not be virtual. However, the container must 35 * derive from Object in order to support the reference counting, 36 * modification time, and debug information required by this 37 * interface. 38 * 39 * Note that many comments refer to a "default element" or "default element 40 * value". This value is equal to the default constructor of the 41 * Element type. Also note that all non-const methods assume that the 42 * container was modified, and update the modification time. 43 * 44 * \tparam TElementIdentifier A type that shall be used to index the 45 * container. It must have a < operator defined for ordering. 46 * 47 * \tparam TElement The element type stored in the container. 48 * 49 * \ingroup ImageObjects 50 * \ingroup ITKCommon 51 */ 52 template< typename TElementIdentifier, typename TElement > 53 class ImageContainerInterface:public Object 54 { 55 public: 56 /** Standard class type aliases. */ 57 using Self = ImageContainerInterface; 58 using Superclass = Object; 59 using Pointer = SmartPointer< Self >; 60 using ConstPointer = SmartPointer< const Self >; 61 62 /** Standard part of every itk Object. */ 63 itkTypeMacro(ImageContainerInterface, Object); 64 65 /** Save the template parameters. */ 66 using ElementIdentifier = TElementIdentifier; 67 using Element = TElement; 68 69 /** Index operator. This version can be an lvalue. */ 70 virtual TElement & operator[](const ElementIdentifier) = 0; 71 72 /** Index operator. This version can only be an rvalue */ 73 virtual const TElement & operator[](const ElementIdentifier) const = 0; 74 75 /** Return a pointer to the beginning of the buffer. This is used by 76 * the image iterator class. */ 77 virtual TElement * GetBufferPointer() = 0; 78 79 /** Get the number of elements currently stored in the container. */ 80 virtual ElementIdentifier Size() const = 0; 81 82 /** Tell the container to allocate enough memory to allow at least 83 * as many elements as the size given to be stored. This is NOT 84 * guaranteed to actually allocate any memory, but is useful if the 85 * implementation of the container allocates contiguous storage. */ 86 virtual void Reserve(ElementIdentifier) = 0; 87 88 /** Tell the container to try to minimize its memory usage for storage of 89 * the current number of elements. This is NOT guaranteed to decrease 90 * memory usage. */ 91 virtual void Squeeze() = 0; 92 }; 93 } // end namespace itk 94 95 #endif 96