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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
|
/*
* Copyright (C) 2005-2017 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_h
#define otbObjectList_h
#include <vector>
#include "itkDataObject.h"
#include "otbDataObjectListInterface.h"
#include "itkObjectFactory.h"
namespace otb
{
/** \class ObjectList
* \brief This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >.
*
* ObjectList stores SmartPointer to ObjectType in a std::vector data structure. It provides the same
* methods and iterators interfaces.
*
* \ingroup OTBObjectList
*/
template <class TObject>
class ITK_EXPORT ObjectList : public itk::DataObject , public DataObjectListInterface
{
public:
/** Standard typedefs */
typedef ObjectList Self;
typedef itk::DataObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkTypeMacro(ObjectList, DataObject);
/** Creation through object factory macro */
itkNewMacro(Self);
/** Template parameter typedefs */
typedef TObject ObjectType;
typedef itk::SmartPointer<ObjectType> ObjectPointerType;
typedef std::vector<ObjectPointerType> InternalContainerType;
typedef typename InternalContainerType::size_type InternalContainerSizeType;
/**
* Set the minimum capacity of the vector.
* \param size Size of the vector to reserve.
*/
void Reserve(InternalContainerSizeType size);
/**
* Get the capacity of the vector.
* \return The capacity of the vector.
*/
InternalContainerSizeType Capacity(void) const;
/**
* Get the number of elements in the vector.
* \return The number of elements in the vector.
*/
InternalContainerSizeType Size(void) const override;
/**
* Resize the maximal list capacity.
* \param size The new maximal size of the list.
*/
void Resize(InternalContainerSizeType size);
/**
* Append an element to the list.
* \param element Pointer to the element to append.
*/
void PushBack(ObjectType* element);
/**
* Delete the last element to the list.
*/
void PopBack(void);
/**
* Set the nth element of the list.
* \param index The index where to put the element.
* \param element Pointer to the element to set.
*/
void SetNthElement(unsigned int index, ObjectPointerType element);
void SetNthElement(unsigned int index, const ObjectType * element);
/**
* 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.
*/
ObjectPointerType GetNthElement(unsigned int index) const;
/**
* Get the nth element of the list as a DataObject *.
* \param index The index of the object to get.
*/
Superclass * GetNthDataObject(unsigned int index) const override;
/**
* Return the first element of the list.
* \return The first element of the list.
*/
ObjectPointerType Front(void);
/**
* Return the last element of the list.
* \return The last element of the list.
*/
ObjectPointerType Back(void);
/**
* Erase the nth element of the list.
* \param index The index of the element to erase.
*/
void Erase(unsigned int index);
/**
* Clear the object list.
*/
void Clear(void);
class ConstIterator;
class ReverseIterator;
class ReverseConstIterator;
class Iterator;
friend class Iterator;
friend class ConstIterator;
friend class ReverseIterator;
friend class ReverseConstIterator;
/**
* Insert an element at a given position
* \param position A random access iterator
* \return An iterator that points to the newly insereted element.
*/
Iterator Insert(Iterator position, ObjectPointerType element);
/**
* Insert an element at a given position
* \param position A reverse iterator
* \return A reverse iterator that points to the newly insereted element.
*/
ReverseIterator Insert(ReverseIterator position, ObjectPointerType element);
/** \class Iterator
* \brief Iterator of the object list.
*
* \ingroup OTBObjectList
*/
class ITK_EXPORT Iterator
{
public:
friend class ObjectList;
friend class ConstIterator;
/** typedef of the internal iterator */
typedef typename InternalContainerType::iterator InternalIteratorType;
/** Constructor */
Iterator() {};
/** Constructor with iternal iterator parameter */
Iterator(InternalIteratorType iter)
{
m_Iter = iter;
};
/**
* Get the current object.
* \return The current object pointed by the iterator.
*/
ObjectPointerType Get(void)
{
return (*m_Iter);
}
/**
* Set the current object
*/
void Set(ObjectPointerType element)
{
(*m_Iter) = element;
this->Modified();
}
/**
* Increment.
*/
Iterator & operator ++()
{
++m_Iter;
return *this;
}
/**
* Decrement.
*/
Iterator & operator --()
{
--m_Iter;
return *this;
}
/**
* Add
*/
Iterator operator +(int i)
{
Iterator lIter(m_Iter + i);
return lIter;
}
/**
* Remove
*/
Iterator operator -(int i)
{
Iterator lIter(m_Iter - i);
return lIter;
}
/**
*/
Iterator
operator += ( int i )
{
return m_Iter + i;
}
/**
*/
Iterator
operator -= ( int i )
{
return m_Iter - i;
}
/**
* Difference comparison operator.
*/
bool operator !=(const Iterator& it)
{
return (m_Iter != it.m_Iter);
}
/**
* Equality comparison operator.
*/
bool operator ==(const Iterator& it)
{
return (m_Iter == it.m_Iter);
}
/**
* Instantiation operator.
*/
Iterator & operator =(const Iterator& it)
{
m_Iter = it.m_Iter;
return *this;
}
/**
* Copy operator.
*/
Iterator(const Iterator &it)
{
m_Iter = it.m_Iter;
};
/**
* Get the current internal iterator
*/
InternalIteratorType& GetIter(void)
{
return (m_Iter);
}
private:
// Internal iterator.
InternalIteratorType m_Iter;
};
/** \class ConstIterator
* \brief ConstIterator of the object list.
*
* \ingroup OTBObjectList
*/
class ITK_EXPORT ConstIterator
{
public:
friend class ObjectList;
friend class Iterator;
/** typedef of the internal iterator */
typedef typename InternalContainerType::const_iterator InternalConstIteratorType;
/** Constructor */
ConstIterator() {};
/** Constructor with iternal iterator parameter */
ConstIterator(InternalConstIteratorType iter)
{
m_Iter = iter;
};
/**
* Get the current object.
* \return The current object pointed by the iterator.
*/
ObjectPointerType Get(void)
{
return (*m_Iter);
}
/**
* Increment.
*/
ConstIterator & operator ++()
{
++m_Iter;
return *this;
}
/**
* Decrement.
*/
ConstIterator & operator --()
{
--m_Iter;
return *this;
}
/**
* Difference comparison operator.
*/
bool operator !=(const ConstIterator& it)
{
return (m_Iter != it.m_Iter);
}
/**
* Equality comparison operator.
*/
bool operator ==(const ConstIterator& it)
{
return (m_Iter == it.m_Iter);
}
/**
* Instantiation operator.
*/
ConstIterator & operator =(const ConstIterator& it)
{
m_Iter = it.m_Iter;
return *this;
}
/**
* Instantiation operator.
*/
ConstIterator & operator =(const Iterator& it)
{
m_Iter = it.m_Iter;
return *this;
}
/**
* Copy operator.
*/
ConstIterator(const ConstIterator &it)
{
m_Iter = it.m_Iter;
};
/**
* Copy operator.
*/
ConstIterator(const Iterator &it)
{
m_Iter = it.m_Iter;
};
private:
// Internal iterator.
InternalConstIteratorType m_Iter;
};
/** \class ReverseIterator
* \brief ReverseIterator of the object list.
*
* \ingroup OTBObjectList
*/
class ITK_EXPORT ReverseIterator
{
public:
friend class ObjectList;
friend class Iterator;
friend class ReverseConstIterator;
/** typedef of the internal iterator */
typedef typename InternalContainerType::reverse_iterator InternalReverseIteratorType;
/** Constructor */
ReverseIterator() {};
/** Constructor with iternal iterator parameter */
ReverseIterator(InternalReverseIteratorType iter)
{
m_Iter = iter;
};
/**
* Get the current object.
* \return The current object pointed by the iterator.
*/
ObjectPointerType Get(void)
{
return (*m_Iter);
}
/**
* Set the current object
*/
void Set(ObjectPointerType element)
{
(*m_Iter) = element;
}
/**
* Increment.
*/
ReverseIterator & operator ++()
{
++m_Iter;
return *this;
}
/**
* Decrement.
*/
ReverseIterator & operator --()
{
--m_Iter;
return *this;
}
/**
* Difference comparison operator.
*/
bool operator !=(const ReverseIterator& it)
{
return (m_Iter != it.m_Iter);
}
/**
* Equality comparison operator.
*/
bool operator ==(const ReverseIterator& it)
{
return (m_Iter == it.m_Iter);
}
/**
* Instantiation operator.
*/
ReverseIterator & operator =(const ReverseIterator& it)
{
m_Iter = it.m_Iter;
return *this;
}
/**
* Copy operator.
*/
ReverseIterator(const ReverseIterator &it)
{
m_Iter = it.m_Iter;
};
/**
* Get the current internal iterator
*/
InternalReverseIteratorType& GetIter(void)
{
return (m_Iter);
}
private:
// Internal iterator.
InternalReverseIteratorType m_Iter;
};
/** \class ReverseConstIterator
* \brief ReverseConstIterator of the object list.
*
* \ingroup OTBObjectList
*/
class ITK_EXPORT ReverseConstIterator
{
public:
friend class ObjectList;
friend class Iterator;
friend class ConstIterator;
friend class ReverseIterator;
/** typedef of the internal iterator */
typedef typename InternalContainerType::const_reverse_iterator InternalReverseConstIteratorType;
/** Constructor */
ReverseConstIterator() {};
/** Constructor with iternal iterator parameter */
ReverseConstIterator(InternalReverseConstIteratorType iter)
{
m_Iter = iter;
};
/**
* Get the current object.
* \return The current object pointed by the iterator.
*/
ObjectPointerType Get(void)
{
return (*m_Iter);
}
/**
* Increment.
*/
ReverseConstIterator & operator ++()
{
++m_Iter;
return *this;
}
/**
* Decrement.
*/
ReverseConstIterator & operator --()
{
--m_Iter;
return *this;
}
/**
* Difference comparison operator.
*/
bool operator !=(const ReverseConstIterator& it)
{
return (m_Iter != it.m_Iter);
}
/**
* Equality comparison operator.
*/
bool operator ==(const ReverseConstIterator& it)
{
return (m_Iter == it.m_Iter);
}
/**
* Instantiation operator.
*/
ReverseConstIterator & operator =(const ReverseConstIterator& it)
{
m_Iter = it.m_Iter;
return *this;
}
/**
* Instantiation operator.
*/
ReverseConstIterator & operator =(const ReverseIterator& it)
{
m_Iter = it.m_Iter;
return *this;
}
/**
* Copy operator.
*/
ReverseConstIterator(const ReverseConstIterator &it)
{
m_Iter = it.m_Iter;
};
/**
* Copy operator.
*/
ReverseConstIterator(const ReverseIterator &it)
{
m_Iter = it.m_Iter;
};
private:
// Internal iterator.
InternalReverseConstIteratorType m_Iter;
};
/**
* Get an Iterator that points to the beginning of the container.
* \return The iterator.
*/
Iterator Begin(void);
/**
* Get a ConstIterator that points to the beginning of the container.
* \return The iterator.
*/
ConstIterator Begin(void) const;
/**
* Get a ReverseIterator that points to the reverse beginning of the container.
* \return The iterator.
*/
ReverseIterator ReverseBegin(void);
/**
* Get a ReverseConstIterator that points to the reverse beginning of the container.
* \return The iterator.
*/
ReverseConstIterator ReverseBegin(void) const;
/**
* Get an Iterator that points past-the-end of the container.
* \return The iterator.
*/
Iterator End(void);
/**
* Get a ConstIterator that points past-the-end of the container.
* \return The iterator.
*/
ConstIterator End(void) const;
/**
* Get a ReverseIterator that points to the reverse past-the-end of the container.
* \return The iterator.
*/
ReverseIterator ReverseEnd(void);
/**
* Get a ReverseConstIterator that points to the reverse past-the-end of the container.
* \return The iterator.
*/
ReverseConstIterator ReverseEnd(void) const;
/**
* 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.
*/
void Erase(Iterator begin, Iterator end);
/**
* Erase loc element.
* \param loc Iterator pointing on object to erase.
*/
void Erase(Iterator loc);
protected:
/** Constructor */
ObjectList();
/** Destructor */
~ObjectList() override {}
/**PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const override;
private:
ObjectList(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
/** The internal std::vector object container */
InternalContainerType m_InternalContainer;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbObjectList.txx"
#endif
#endif
|