| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkIndexedContainerInterface.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkIndexedContainerInterface_h |
| 18 |
|
#define __itkIndexedContainerInterface_h |
| 19 |
|
|
| 20 |
|
#include "itkObject.h" |
| 21 |
|
|
| 22 |
|
namespace itk |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
/** \class IndexedContainerInterface |
| 26 |
|
* This should only be used for reference when writing containers |
| 27 |
|
* conforming to this interface. ITK uses generic programming to |
| 28 |
|
* allow container type substitution, so polymorphism is not needed to |
| 29 |
|
* use containers through this interface. This means that a container |
| 30 |
|
* conforming to this interface need not be derived from it, and that |
| 31 |
|
* their methods should not be virtual. However, the container must |
| 32 |
|
* derive from Object in order to support the reference counting, |
| 33 |
|
* modification time, and debug information required by this |
| 34 |
|
* interface. |
| 35 |
|
* |
| 36 |
|
* Note that many comments refer to a "default element" or "default element |
| 37 |
|
* value". This value is equal to the default constructor of the |
| 38 |
|
* Element type. Also note that all non-const methods assume that the |
| 39 |
|
* container was modified, and update the modification time. |
| 40 |
|
* |
| 41 |
|
* Template parameters for IndexedContainerInterface: |
| 42 |
|
* |
| 43 |
|
* TElementIdentifier = |
| 44 |
|
* A type that shall be used to index the container. |
| 45 |
|
* It must have a < operator defined for ordering. |
| 46 |
|
* |
| 47 |
|
* TElement = |
| 48 |
|
* The element type stored in the container. |
| 49 |
|
* |
| 50 |
|
* \ingroup DataRepresentation |
| 51 |
|
*/ |
| 52 |
|
|
| 53 |
|
template <typename TElementIdentifier, typename TElement> |
| 54 |
|
class IndexedContainerInterface: public Object |
| 55 |
|
{ |
| 56 |
|
public: |
| 57 |
|
/** Standard class typedefs. */ |
| 58 |
|
typedef IndexedContainerInterface Self; |
| 59 |
TDA |
typedef Object Superclass; |
| 60 |
TDA |
typedef SmartPointer<Self> Pointer; |
| 61 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 62 |
|
|
| 63 |
|
/** Standard part of every itk Object. */ |
| 64 |
|
itkTypeMacro(IndexedContainerInterface, Object); |
| 65 |
|
|
| 66 |
|
/** Save the template parameters. */ |
| 67 |
|
typedef TElementIdentifier ElementIdentifier; |
| 68 |
|
typedef TElement Element; |
| 69 |
|
|
| 70 |
|
/** Get a reference to an existing element. |
| 71 |
|
* It is NOT guaranteed that the element will or will not be created if it |
| 72 |
|
* doesn't exist. This behavior is implementation-specific. |
| 73 |
|
* |
| 74 |
|
* It is assumed that the value of the element is modified through the |
| 75 |
|
* reference. */ |
| 76 |
|
Element& ElementAt(ElementIdentifier); |
| 77 |
|
|
| 78 |
|
/** Get a reference to an existing element. |
| 79 |
|
* It is guaranteed that the element will be inserted with a default |
| 80 |
|
* value if it does not exist. |
| 81 |
|
* |
| 82 |
|
* It is assumed that the value of the element is modified through the |
| 83 |
|
* reference. */ |
| 84 |
|
Element& CreateElementAt(ElementIdentifier); |
| 85 |
|
|
| 86 |
|
/** Get a copy of an element without range checking. */ |
| 87 |
SEM |
Element GetElement(ElementIdentifier) const ; |
| 88 |
|
|
| 89 |
|
/** Set the value of an element. |
| 90 |
|
* It is NOT guaranteed whether a spot for the element will be created |
| 91 |
|
* automatically. This is implementation-defined. */ |
| 92 |
|
void SetElement(ElementIdentifier, Element); |
| 93 |
|
|
| 94 |
|
/** Set the value of an element. |
| 95 |
|
* It is guaranteed that a spot for the element will be created if it |
| 96 |
|
* doesn't exist. */ |
| 97 |
|
void InsertElement(ElementIdentifier, Element); |
| 98 |
|
|
| 99 |
|
/** Test if there is an entry in the container corresponding to the given |
| 100 |
|
* index. */ |
| 101 |
SEM |
bool IndexExists(ElementIdentifier) const ; |
| 102 |
|
|
| 103 |
|
/** Combine the GetElement and IndexExists into one method. |
| 104 |
|
* If false is returned, then no element with the given identifier was found. |
| 105 |
|
* If true is returned, then the identifier was found. In this case, |
| 106 |
|
* if the element pointer given as input is not null, the element is filled |
| 107 |
|
* in with the value of the element found. */ |
| 108 |
SEM |
bool GetElementIfIndexExists(ElementIdentifier, Element*) const ; |
| 109 |
|
|
| 110 |
|
/** Create an entry in the container corresponding to the given index. |
| 111 |
|
* The entry will be initialized with the default element. |
| 112 |
|
* If an entry already exists, its value will be overwritten with the |
| 113 |
|
* default element. */ |
| 114 |
|
void CreateIndex(ElementIdentifier); |
| 115 |
|
|
| 116 |
|
/** Delete the entry in the container corresponding to the given identifier. |
| 117 |
|
* |
| 118 |
|
* It is NOT guaranteed that IndexExists(id) will return false if called |
| 119 |
|
* right after DeleteIndex(id). This behavior is implementation-defined. |
| 120 |
|
* If the identifier's location is left behind, though, it will have the |
| 121 |
|
* value of the default element. */ |
| 122 |
|
void DeleteIndex(ElementIdentifier); |
| 123 |
|
|
| 124 |
|
/** Support iteration operations through a container. |
| 125 |
|
* Dereferencing the iterator must provide an object with the following |
| 126 |
|
* methods: |
| 127 |
|
* ElementIdentifier Index(void) const; |
| 128 |
|
* Element& Value(void); */ |
| 129 |
MCM |
class Iterator {}; |
| 130 |
|
|
| 131 |
|
/** Support const iteration operations through a container. |
| 132 |
|
* Dereferencing the iterator must provide an object with the following |
| 133 |
|
* methods: |
| 134 |
|
* ElementIdentifier Index(void) const; |
| 135 |
|
* const Element& Value(void) const; */ |
| 136 |
MCM |
class ConstIterator {}; |
| 137 |
|
|
| 138 |
|
/** Get a begin iterator for the container. */ |
| 139 |
|
Iterator Begin(); |
| 140 |
|
|
| 141 |
|
/** Get an end iterator for the container. */ |
| 142 |
|
Iterator End(); |
| 143 |
|
|
| 144 |
|
/** Get a begin const iterator for the container. */ |
| 145 |
SEM |
ConstIterator Begin() const ; |
| 146 |
|
|
| 147 |
|
/** Get an end const iterator for the container. */ |
| 148 |
SEM |
ConstIterator End() const ; |
| 149 |
|
|
| 150 |
|
/** Get the number of elements currently stored in the container. */ |
| 151 |
SEM |
unsigned long Size(void) const ; |
| 152 |
|
|
| 153 |
|
/** Tell the container to allocate enough memory to allow at least |
| 154 |
|
* as many elements as the size given to be stored. This is NOT |
| 155 |
|
* guaranteed to actually allocate any memory, but is useful if the |
| 156 |
|
* implementation of the container allocates contiguous storage. */ |
| 157 |
|
void Reserve(ElementIdentifier); |
| 158 |
|
|
| 159 |
|
/** Tell the container to try to minimize its memory usage for storage of |
| 160 |
|
* the current number of elements. This is NOT guaranteed to decrease |
| 161 |
|
* memory usage. */ |
| 162 |
|
void Squeeze(void); |
| 163 |
|
|
| 164 |
|
/** Tell the container to release any memory it may have allocated and |
| 165 |
|
* return itself to its initial state. */ |
| 166 |
|
void Initialize(void); |
| 167 |
|
|
| 168 |
|
}; |
| 169 |
|
|
| 170 |
|
} // end namespace itk |
| 171 |
|
|
| 172 |
|
#endif |
| 173 |
|
|