File: otbObjectList.hxx

package info (click to toggle)
otb 7.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,005,476 kB
  • sloc: cpp: 270,143; xml: 128,722; ansic: 4,367; sh: 1,768; python: 1,084; perl: 92; makefile: 72
file content (338 lines) | stat: -rw-r--r-- 9,612 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
 * Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef otbObjectList_hxx
#define otbObjectList_hxx

#include "otbObjectList.h"
#include "itkMacro.h"

namespace otb
{
/**
 * Constructor
 */
template <class TObject>
ObjectList<TObject>::ObjectList()
{
}
/**
 * Set the minimum capacity of the vector.
 * \param size Size of the vector to reserve.
 */
template <class TObject>
void ObjectList<TObject>::Reserve(InternalContainerSizeType size)
{
  m_InternalContainer.reserve(size);
}
/**
 * Get the capacity of the vector.
 * \return The capacity of the vector.
 */
template <class TObject>
typename ObjectList<TObject>::InternalContainerSizeType ObjectList<TObject>::Capacity(void) const
{
  return m_InternalContainer.capacity();
}
/**
 * Get the number of elements in the vector.
 * \return The number of elements in the vector.
 */
template <class TObject>
typename ObjectList<TObject>::InternalContainerSizeType ObjectList<TObject>::Size(void) const
{
  return m_InternalContainer.size();
}
/**
 * Resize the maximal list capacity.
 * \param size The new maximal size of the list.
 */
template <class TObject>
void ObjectList<TObject>::Resize(InternalContainerSizeType size)
{
  m_InternalContainer.resize(size);
}
/**
 * Append an element to the list.
 * \param element Pointer to the element to append.
 */
template <class TObject>
void ObjectList<TObject>::PushBack(ObjectType* element)
{
  m_InternalContainer.push_back(element);
  this->Modified();
}

/**
 * Delete the last element to the list.
 */
template <class TObject>
void ObjectList<TObject>::PopBack(void)
{
  if (m_InternalContainer.size() > 0)
  {
    m_InternalContainer.pop_back();
    this->Modified();
  }
}

/**
 * Set the nth element of the list.
 * \param index The index where to put the element.
 * \param element Pointer to the element to set.
 */
template <class TObject>
void ObjectList<TObject>::SetNthElement(unsigned int index, ObjectPointerType element)
{
  if (index >= m_InternalContainer.size())
  {
    itkExceptionMacro(<< "Impossible to SetNthElement with the index element " << index << "; this element don't exist, the size of the list is "
                      << m_InternalContainer.size() << ".");
  }
  m_InternalContainer[index] = element;
  this->Modified();
}
/**
 * Set the nth element of the list.
 * \param index The index where to put the element.
 * \param element Pointer to the element to set.
 */
template <class TObject>
void ObjectList<TObject>::SetNthElement(unsigned int index, const ObjectType* element)
{
  if (index >= m_InternalContainer.size())
  {
    itkExceptionMacro(<< "Impossible to SetNthElement with the index element " << index << "; this element don't exist, the size of the list is "
                      << m_InternalContainer.size() << ".");
  }
  m_InternalContainer[index] = const_cast<ObjectType*>(element);
  this->Modified();
}

/**
 * Get the nth element of the list.
 * \param index The index of the object to get.
 * \return The pointer to the nth element of the list.
 */
template <class TObject>
typename ObjectList<TObject>::ObjectPointerType ObjectList<TObject>::GetNthElement(unsigned int index) const
{
  if (index >= m_InternalContainer.size())
  {
    itkExceptionMacro(<< "Impossible to GetNthElement with the index element " << index << "; this element don't exist, the size of the list is "
                      << m_InternalContainer.size() << ".");
  }
  return m_InternalContainer[index];
}

template <class TObject>
typename ObjectList<TObject>::Superclass* ObjectList<TObject>::GetNthDataObject(unsigned int index) const
{

  return dynamic_cast<itk::DataObject*>(GetNthElement(index).GetPointer());
}

/**
   * Return the first element of the list.
   * \return The first element of the list.
   */

template <class TObject>
typename ObjectList<TObject>::ObjectPointerType ObjectList<TObject>::Front(void)
{
  return m_InternalContainer.front();
}
/**
 * Return the last element of the list.
 * \return The last element of the list.
 */
template <class TObject>
typename ObjectList<TObject>::ObjectPointerType ObjectList<TObject>::Back(void)
{
  return m_InternalContainer.back();
}
/**
 * Erase the nth element in the list.
 * \param index The index of the element to erase.
 */
template <class TObject>
void ObjectList<TObject>::Erase(unsigned int index)
{
  if (index >= m_InternalContainer.size())
  {
    itkExceptionMacro(<< "Impossible to erase the index element " << index << "; the size of the list is " << m_InternalContainer.size() << ".");
  }
  m_InternalContainer.erase(m_InternalContainer.begin() + index);
  this->Modified();
}
/**
 * Clear the object list.
 */
template <class TObject>
void ObjectList<TObject>::Clear(void)
{
  m_InternalContainer.clear();
  this->Modified();
}

/**
 * Insert an element
 */
template <class TObject>
typename ObjectList<TObject>::Iterator ObjectList<TObject>::Insert(Iterator position, ObjectPointerType element)
{
  Iterator iter(m_InternalContainer.insert(position.GetIter(), element));
  this->Modified();
  return iter;
}

/**
 * Insert an element
 */
template <class TObject>
typename ObjectList<TObject>::ReverseIterator ObjectList<TObject>::Insert(ReverseIterator position, ObjectPointerType element)
{
  ReverseIterator iter((typename InternalContainerType::reverse_iterator)(m_InternalContainer.insert(position.GetIter().base(), element)));
  this->Modified();
  return iter;
}

/**
 * Get an Iterator that points to the beginning of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::Iterator ObjectList<TObject>::Begin(void)
{
  Iterator iter(m_InternalContainer.begin());
  return iter;
}
/**
 * Get a ConstIterator that points to the beginning of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::ConstIterator ObjectList<TObject>::Begin(void) const
{
  ConstIterator iter(m_InternalContainer.begin());
  return iter;
}
/**
 * Get a ReverseIterator that points to the reverse beginning of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::ReverseIterator ObjectList<TObject>::ReverseBegin(void)
{
  ReverseIterator iter(m_InternalContainer.rbegin());
  return iter;
}
/**
 * Get a ReverseConstIterator that points to the reverse beginning of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::ReverseConstIterator ObjectList<TObject>::ReverseBegin(void) const
{
  ReverseConstIterator iter(m_InternalContainer.rbegin());
  return iter;
}
/**
 * Get an Iterator that points past-the-end of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::Iterator ObjectList<TObject>::End(void)
{
  Iterator iter(m_InternalContainer.end());
  return iter;
}
/**
 * Get a ConstIterator that points past-the-end of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::ConstIterator ObjectList<TObject>::End(void) const
{
  ConstIterator iter(m_InternalContainer.end());
  return iter;
}
/**
 * Get a ReverseIterator that points to the reverse past-the-end of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::ReverseIterator ObjectList<TObject>::ReverseEnd(void)
{
  ReverseIterator iter(m_InternalContainer.rend());
  return iter;
}
/**
 * Get a ReverseConstIterator that points to the reverse past-the-end of the container.
 * \return The iterator.
 */
template <class TObject>
typename ObjectList<TObject>::ReverseConstIterator ObjectList<TObject>::ReverseEnd(void) const
{
  ReverseConstIterator iter(m_InternalContainer.rend());
  return iter;
}
/**
 * Erase elements from begin to last.
 * \param begin Iterator pointing on first object to erase.
 * \param end Iterator pointing past the last object to erase.
 */
template <class TObject>
void ObjectList<TObject>::Erase(Iterator begin, Iterator end)
{
  m_InternalContainer.erase(begin.GetIter(), end.GetIter());
  this->Modified();
}
/**
 * Erase loc element.
 * \param loc Iterator pointing on object to erase.
 */
template <class TObject>
void ObjectList<TObject>::Erase(Iterator loc)
{
  m_InternalContainer.erase(loc.GetIter());
  this->Modified();
}

/**PrintSelf method */
template <class TObject>
void ObjectList<TObject>::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  Superclass::PrintSelf(os, indent);
  os << indent << "Size: " << m_InternalContainer.size() << std::endl;
  os << indent << "List contains : " << std::endl;
  ConstIterator iter = this->Begin();
  while (iter != this->End())
  {
    os << indent.GetNextIndent() << iter.Get().GetPointer() << std::endl;
    os << indent.GetNextIndent() << iter.Get() << std::endl;
    //                iter.Get()->PrintSelf(os, indent.GetNextIndent());
    //                iter.Get()->Print(os, indent.GetNextIndent());
    ++iter;
  }
}
} // end namespace otb

#endif