KWStyle - itkMapContainer.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkMapContainer.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:41 $
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 DEF #ifndef _itkMapContainer_txx
18 DEF #define _itkMapContainer_txx
19 #include "itkMapContainer.h"
20
21 namespace itk
22 {
23   
24 /**
25  * Get a reference to the element at the given index.
26  * If the index does not exist, it is created automatically.
27  *
28  * It is assumed that the value of the element is modified through the
29  * reference.
30  */
31 template <typename TElementIdentifier, typename TElement>
32 typename MapContainer< TElementIdentifier , TElement >::Element&
33 MapContainer< TElementIdentifier , TElement >
34 ::ElementAt(ElementIdentifier id)
35 {
36   this->Modified();
37   return this->MapType::operator[](id);
38 }
39
40 /**
41  * Get a reference to the element at the given index.
42  *
43  */
44 template <typename TElementIdentifier, typename TElement>
45 const typename MapContainer< TElementIdentifier , TElement >::Element&
46 MapContainer< TElementIdentifier , TElement >
47 ::ElementAt(ElementIdentifier id) const
48 {
49   return this->MapType::find(id)->second;
50 }
51
52
53 EML
54 /**
55  * Get a reference to the element at the given index.
56  * If the index does not exist, it is created automatically.
57  *
58  * It is assumed that the value of the element is modified through the
59  * reference.
60  */
61 template <typename TElementIdentifier, typename TElement>
62 typename MapContainer< TElementIdentifier , TElement >::Element&
63 MapContainer< TElementIdentifier , TElement >
64 ::CreateElementAt(ElementIdentifier id)
65 {
66   this->Modified();
67   return this->MapType::operator[](id);
68 }
69
70
71 /**
72  * Get the element at the specified index.  There is no check for
73  * existence performed.
74  */
75 template <typename TElementIdentifier, typename TElement>
76 typename MapContainer< TElementIdentifier , TElement >::Element
77 MapContainer< TElementIdentifier , TElement >
78 ::GetElement(ElementIdentifier id) const
79 {
80   return this->MapType::find(id)->second;
81 }
82
83
84 /**
85  * Set the given index value to the given element.  If the index doesn't
86  * exist, it is automatically created.
87  */
88 template <typename TElementIdentifier, typename TElement>
89 void
90 MapContainer< TElementIdentifier , TElement >
91 ::SetElement(ElementIdentifier id, Element element)
92 {
93   MapType::operator[](id) = element;
94   this->Modified();
95 }
96
97
98 /**
99  * Set the given index value to the given element.  If the index doesn't
100  * exist, it is automatically created.
101  */
102 template <typename TElementIdentifier, typename TElement>
103 void
104 MapContainer< TElementIdentifier , TElement >
105 ::InsertElement(ElementIdentifier id, Element element)
106 {
107   this->MapType::operator[](id) = element;
108   this->Modified();
109 }
110
111
112 /**
113  * Check if the STL map has an entry corresponding to the given index.
114  * The count will be either 1 or 0.
115  */
116 template <typename TElementIdentifier, typename TElement>
117 bool
118 MapContainer< TElementIdentifier , TElement >
119 ::IndexExists(ElementIdentifier id) const
120 {
121   return (this->MapType::count(id) > 0);
122 }
123
124
125 /**
126  * If the given index doesn't exist in the map, return false.
127  * Otherwise, set the element through the pointer (if it isn't null), and
128  * return true.
129  */
130 template <typename TElementIdentifier, typename TElement>
131 bool
132 MapContainer< TElementIdentifier , TElement >
133 ::GetElementIfIndexExists(ElementIdentifier id, Element* element) const
134 {
135   if(this->MapType::count(id) > 0)
136     {
137     if( element )
138       {
139       *element = this->MapType::find(id)->second;
140       }
141     return true;
142     }
143   return false;
144 }
145
146
147 /**
148  * The STL map will create an entry for a given index through the indexing
149  * operator.  Whether or not it is created, it will be assigned to the
150  * default element.
151  */
152 template <typename TElementIdentifier, typename TElement>
153 void
154 MapContainer< TElementIdentifier , TElement >
155 ::CreateIndex(ElementIdentifier id)
156 {
157   this->MapType::operator[](id) = Element();
158   this->Modified();
159 }
160
161
162 /**
163  * Delete the entry in the STL map corresponding to the given identifier.
164  * If the entry does not exist, nothing happens.
165  */
166 template <typename TElementIdentifier, typename TElement>
167 void
168 MapContainer< TElementIdentifier , TElement >
169 ::DeleteIndex(ElementIdentifier id)
170 {
171   this->MapType::erase(id);
172   this->Modified();
173 }
174
175
176 /**
177  * Get a begin const iterator for the map.
178  */
179 template <typename TElementIdentifier, typename TElement>
180 typename MapContainer< TElementIdentifier , TElement >::ConstIterator
181 MapContainer< TElementIdentifier , TElement >
182 ::Begin(void) const
183 {
184   return ConstIterator(this->MapType::begin());
185 }
186
187
188 /**
189  * Get an end const iterator for the map.
190  */
191 template <typename TElementIdentifier, typename TElement>
192 typename MapContainer< TElementIdentifier , TElement >::ConstIterator
193 MapContainer< TElementIdentifier , TElement >
194 ::End(void) const
195 {
196   return ConstIterator(this->MapType::end());
197 }
198
199
200 /**
201  * Get a begin const iterator for the map.
202  */
203 template <typename TElementIdentifier, typename TElement>
204 typename MapContainer< TElementIdentifier , TElement >::Iterator
205 MapContainer< TElementIdentifier , TElement >
206 ::Begin(void) 
207 {
208   return Iterator(this->MapType::begin());
209 }
210
211
212 /**
213  * Get an end const iterator for the map.
214  */
215 template <typename TElementIdentifier, typename TElement>
216 typename MapContainer< TElementIdentifier , TElement >::Iterator
217 MapContainer< TElementIdentifier , TElement >
218 ::End(void) 
219 {
220   return Iterator(this->MapType::end());
221 }
222
223
224 /**
225  * Get the number of elements currently stored in the map.
226  */
227 template <typename TElementIdentifier, typename TElement>
228 unsigned long
229 MapContainer< TElementIdentifier , TElement >
230 ::Size(void) const
231 {
232   return static_cast<unsigned long>( this->MapType::size() );
233 }
234
235 /**
236  * Tell the container to allocate enough memory to allow at least
237  * as many elements as the size given to be stored.  This is NOT
238  * guaranteed to actually allocate any memory, but is useful if the
239  * implementation of the container allocates contiguous storage.
240  */
241 template <typename TElementIdentifier, typename TElement>
242 void
243 MapContainer< TElementIdentifier , TElement >
244 ::Reserve(ElementIdentifier size)
245 {
246   ElementIdentifier curSize = this->Size();
247   while ( curSize < size )
248     {
249     this->CreateIndex(curSize);
250     curSize = this->Size();
251     }
252 }
253
254 /**
255  * Tell the container to try to minimize its memory usage for storage of
256  * the current number of elements.  This is NOT guaranteed to decrease
257  * memory usage.
258  */
259 template <typename TElementIdentifier, typename TElement>
260 void
261 MapContainer< TElementIdentifier , TElement >
262 ::Squeeze(void)
263 {
264 }
265
266 /**
267  * Tell the container to release any memory it may have allocated and
268  * return itself to its initial state.
269  */
270 template <typename TElementIdentifier, typename TElement>
271 void
272 MapContainer< TElementIdentifier , TElement >
273 ::Initialize(void)
274 {
275   this->MapType::clear();
276 }
277
278
279 // end namespace itk
280
281 #endif
282

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:20PM
© Kitware Inc.