PCL
ReferenceArray.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/ReferenceArray.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_ReferenceArray_h
53 #define __PCL_ReferenceArray_h
54 
56 
57 #include <pcl/Diagnostics.h>
58 
59 #include <pcl/Allocator.h>
60 #include <pcl/Container.h>
61 #include <pcl/IndirectArray.h>
62 #include <pcl/Iterator.h>
63 #include <pcl/StdAlloc.h>
64 
65 namespace pcl
66 {
67 
68 // ----------------------------------------------------------------------------
69 
94 template <typename T, class A = StandardAllocator>
95 class PCL_CLASS ReferenceArray : public DirectContainer<T>
96 {
97 public:
98 
102 
107 
110  typedef typename array_implementation::allocator
112 
115  typedef typename array_implementation::iterator
117 
120  typedef typename array_implementation::const_iterator
122 
127  class iterator : public Iterator<RandomAccessIterator, T>
128  {
129  public:
130 
132 
133  typedef typename iterator_base::iterator_class
135 
136  typedef typename iterator_base::item_type item_type;
137 
141  iterator() : iterator_base(), it()
142  {
143  }
144 
148  iterator( const iterator& ) = default;
149 
153  iterator( std::nullptr_t ) : iterator_base(), it( nullptr )
154  {
155  }
156 
160  iterator& operator =( const iterator& ) = default;
161 
166  operator T*() const
167  {
168  return *it;
169  }
170 
175  T& operator *() const
176  {
177  return **it;
178  }
179 
184  T* operator ->() const
185  {
186  return *it;
187  }
188 
194  iterator& operator ++()
195  {
196  ++it;
197  return *this;
198  }
199 
205  iterator operator ++( int )
206  {
207  indirect_iterator it0 = it;
208  ++it;
209  return it0;
210  }
211 
217  iterator& operator --()
218  {
219  --it;
220  return *this;
221  }
222 
228  iterator operator --( int )
229  {
230  indirect_iterator it0 = it;
231  --it;
232  return it0;
233  }
234 
242  iterator& operator +=( distance_type d )
243  {
244  it += d;
245  return *this;
246  }
247 
255  iterator& operator -=( distance_type d )
256  {
257  it -= d;
258  return *this;
259  }
260 
266  {
267  return iterator( it + d );
268  }
269 
275  {
276  return iterator( it - d );
277  }
278 
284  {
285  return it - i.it;
286  }
287 
292  bool operator ==( const iterator& i ) const
293  {
294  return it == i.it;
295  }
296 
301  bool operator <( const iterator& i ) const
302  {
303  return it < i.it;
304  }
305 
306  private:
307 
309 
314  explicit
315  iterator( indirect_iterator i ) : iterator_base(), it( i )
316  {
317  }
318 
319  friend class ReferenceArray<T,A>;
320  friend class ReferenceArray<T,A>::const_iterator;
321  };
322 
327  class const_iterator : public Iterator<RandomAccessIterator, T>
328  {
329  public:
330 
331  typedef Iterator<RandomAccessIterator, T> iterator_base;
332 
333  typedef typename iterator_base::iterator_class
334  iterator_class;
335 
336  typedef typename iterator_base::item_type item_type;
337 
341  const_iterator() : iterator_base(), it()
342  {
343  }
344 
348  const_iterator( const iterator& i ) : iterator_base(), it( i.it )
349  {
350  }
351 
355  const_iterator( std::nullptr_t ) : iterator_base(), it( nullptr )
356  {
357  }
358 
362  const_iterator( const const_iterator& ) = default;
363 
368  const_iterator& operator =( const const_iterator& ) = default;
369 
374  const_iterator& operator =( const iterator& i )
375  {
376  it = i.it;
377  return *this;
378  }
379 
384  operator const T*() const
385  {
386  return *it;
387  }
388 
393  const T& operator *() const
394  {
395  return **it;
396  }
397 
402  const T* operator ->() const
403  {
404  return *it;
405  }
406 
412  const_iterator& operator ++()
413  {
414  ++it;
415  return *this;
416  }
417 
423  const_iterator operator ++( int )
424  {
425  const_indirect_iterator it0 = it;
426  ++it;
427  return it0;
428  }
429 
435  const_iterator& operator --()
436  {
437  --it;
438  return *this;
439  }
440 
446  const_iterator operator --( int )
447  {
448  const_indirect_iterator it0 = it;
449  --it;
450  return it0;
451  }
452 
460  const_iterator& operator +=( distance_type d )
461  {
462  it += d;
463  return *this;
464  }
465 
473  const_iterator& operator -=( distance_type d )
474  {
475  it -= d;
476  return *this;
477  }
478 
484  {
485  return const_iterator( it + d );
486  }
487 
493  {
494  return const_iterator( it - d );
495  }
496 
502  {
503  return it - i.it;
504  }
505 
511  {
512  return it - i.it;
513  }
514 
519  bool operator ==( const const_iterator& i ) const
520  {
521  return it == i.it;
522  }
523 
528  bool operator ==( const iterator& i ) const
529  {
530  return it == i.it;
531  }
532 
537  bool operator <( const const_iterator& i ) const
538  {
539  return it < i.it;
540  }
541 
546  bool operator <( const iterator& i ) const
547  {
548  return it < i.it;
549  }
550 
551  private:
552 
554 
559  explicit
560  const_iterator( const_indirect_iterator i ) : iterator_base(), it( i )
561  {
562  }
563 
564  friend class ReferenceArray<T,A>;
565  };
566 
573 
580 
581  // -------------------------------------------------------------------------
582 
586  ReferenceArray() : m_array()
587  {
588  }
589 
596  ReferenceArray( size_type n, const T* p ) : m_array()
597  {
598  PCL_PRECONDITION( p != nullptr )
599  if ( p != nullptr )
600  m_array = array_implementation( n, p );
601  }
602 
610  template <class FI>
611  ReferenceArray( FI i, FI j ) : m_array()
612  {
613  for ( ; i != j; ++i )
614  if ( *i != nullptr )
615  m_array.Append( *i );
616  }
617 
621  ReferenceArray( const ReferenceArray& x ) : m_array( x.m_array )
622  {
623  }
624 
628  ReferenceArray( ReferenceArray&& x ) : m_array( std::move( x.m_array ) )
629  {
630  }
631 
640  {
641  }
642 
647  bool IsUnique() const
648  {
649  return m_array.IsUnique();
650  }
651 
658  bool IsAliasOf( const ReferenceArray& x ) const
659  {
660  return m_array.IsAliasOf( x.m_array );
661  }
662 
672  {
673  m_array.EnsureUnique();
674  }
675 
680  size_type Size() const
681  {
682  return m_array.Size();
683  }
684 
689  {
690  return m_array.Length();
691  }
692 
699  {
700  return m_array.Capacity();
701  }
702 
711  {
712  return m_array.Available();
713  }
714 
730  bool IsValid() const
731  {
732  return m_array.IsValid();
733  }
734 
738  bool IsEmpty() const
739  {
740  return m_array.IsEmpty();
741  }
742 
748  {
749  return m_array.LowerBound();
750  }
751 
757  {
758  return m_array.UpperBound();
759  }
760 
764  const allocator& GetAllocator() const
765  {
766  return m_array.GetAllocator();
767  }
768 
772  void SetAllocator( const allocator& a )
773  {
774  m_array.SetAllocator( a );
775  }
776 
781  iterator At( size_type i )
782  {
783  return iterator( m_array.At( i ) );
784  }
785 
790  const_iterator At( size_type i ) const
791  {
792  return const_iterator( m_array.At( i ) );
793  }
794 
805  iterator MutableIterator( const_iterator i )
806  {
807  return iterator( m_array.MutableIterator( i.it ) );
808  }
809 
814  T& operator []( size_type i )
815  {
816  return *m_array[i];
817  }
818 
823  const T& operator []( size_type i ) const
824  {
825  return *m_array[i];
826  }
827 
832  {
833  return **m_array.Begin();
834  }
835 
840  const T& operator *() const
841  {
842  return **m_array.Begin();
843  }
844 
848  iterator Begin()
849  {
850  return iterator( m_array.Begin() );
851  }
852 
856  const_iterator Begin() const
857  {
858  return const_iterator( m_array.Begin() );
859  }
860 
864  const_iterator ConstBegin() const
865  {
866  return const_iterator( m_array.ConstBegin() );
867  }
868 
872  iterator End()
873  {
874  return iterator( m_array.End() );
875  }
876 
880  const_iterator End() const
881  {
882  return const_iterator( m_array.End() );
883  }
884 
888  const_iterator ConstEnd() const
889  {
890  return const_iterator( m_array.ConstEnd() );
891  }
892 
899  reverse_iterator ReverseBegin()
900  {
901  return iterator( m_array.End()-1 );
902  }
903 
910  const_reverse_iterator ReverseBegin() const
911  {
912  return const_iterator( m_array.End()-1 );
913  }
914 
921  const_reverse_iterator ConstReverseBegin() const
922  {
923  PCL_PRECONDITION( !IsEmpty() )
924  return const_iterator( m_array.End()-1 );
925  }
926 
934  reverse_iterator ReverseEnd()
935  {
936  PCL_PRECONDITION( !IsEmpty() )
937  return iterator( m_array.Begin()-1 );
938  }
939 
947  const_reverse_iterator ReverseEnd() const
948  {
949  PCL_PRECONDITION( !IsEmpty() )
950  return const_iterator( m_array.Begin()-1 );
951  }
952 
960  const_reverse_iterator ConstReverseEnd() const
961  {
962  PCL_PRECONDITION( !IsEmpty() )
963  return const_iterator( m_array.Begin()-1 );
964  }
965 
970  T& First()
971  {
972  return **m_array.Begin();
973  }
974 
979  const T& First() const
980  {
981  return **m_array.Begin();
982  }
983 
988  T& Last()
989  {
990  return **m_array.ReverseBegin();
991  }
992 
997  const T& Last() const
998  {
999  return **m_array.ReverseBegin();
1000  }
1001 
1011  void UniquifyIterator( iterator& i )
1012  {
1013  m_array.UniquifyIterator( i.it );
1014  }
1015 
1026  void UniquifyIterators( iterator& i, iterator& j )
1027  {
1028  m_array.UniquifyIterators( i.it, j.it );
1029  }
1030 
1031 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1032 
1035  iterator begin()
1036  {
1037  return Begin();
1038  }
1039 
1043  const_iterator begin() const
1044  {
1045  return Begin();
1046  }
1047 
1051  iterator end()
1052  {
1053  return End();
1054  }
1055 
1059  const_iterator end() const
1060  {
1061  return End();
1062  }
1063 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1064 
1071  ReferenceArray& operator =( const ReferenceArray& x )
1072  {
1073  Assign( x );
1074  return *this;
1075  }
1076 
1086  void Assign( const ReferenceArray& x )
1087  {
1088  m_array.Assign( x.m_array );
1089  }
1090 
1094  ReferenceArray& operator =( ReferenceArray&& x )
1095  {
1096  Transfer( x );
1097  return *this;
1098  }
1099 
1110  {
1111  m_array.Transfer( x.m_array );
1112  }
1113 
1124  {
1125  m_array.Transfer( std::move( x.m_array ) );
1126  }
1127 
1134  void Assign( const T* p, size_type n = 1 )
1135  {
1136  if ( p != nullptr )
1137  m_array.Assign( p, n );
1138  else
1139  m_array.Clear();
1140  }
1141 
1151  template <class FI>
1152  void Assign( FI i, FI j )
1153  {
1154  m_array.Clear();
1155  for ( ; i != j; ++i )
1156  if ( *i != nullptr )
1157  m_array.Append( *i );
1158  }
1159 
1170  template <class C>
1171  void CloneAssign( const C& x )
1172  {
1173  PCL_ASSERT_CONTAINER( C, T );
1174  CloneObjects( x, (C*)nullptr );
1175  }
1176 
1182  void Import( iterator i, iterator j )
1183  {
1184  m_array.Import( i.it, j.it );
1185  }
1186 
1199  {
1200  return m_array.Release();
1201  }
1202 
1214  iterator Insert( const_iterator i, const ReferenceArray& x )
1215  {
1216  return iterator( m_array.Insert( i.it, x.m_array ) );
1217  }
1218 
1230  iterator Insert( const_iterator i, const T* p, size_type n = 1 )
1231  {
1232  return (p != nullptr) ? iterator( m_array.Insert( i.it, p, n ) ) :
1233  iterator( const_cast<indirect_iterator>( i.it ) );
1234  }
1235 
1250  template <class FI>
1251  iterator Insert( const_iterator i, FI p, FI q )
1252  {
1253  const_indirect_iterator it = i.it;
1254  for ( ; p != q; ++p )
1255  if ( *p != nullptr )
1256  it = m_array.Insert( it, *p );
1257  return iterator( const_cast<indirect_iterator>( it ) );
1258  }
1259 
1264  void Append( const ReferenceArray& x )
1265  {
1266  m_array.Append( x.m_array );
1267  }
1268 
1275  void Append( const T* p, size_type n = 1 )
1276  {
1277  if ( p != nullptr )
1278  m_array.Append( p, n );
1279  }
1280 
1290  template <class FI>
1291  void Append( FI p, FI q )
1292  {
1293  for ( ; p != q; ++p )
1294  if ( *p != nullptr )
1295  m_array.Append( *p );
1296  }
1297 
1302  void Prepend( const ReferenceArray& x )
1303  {
1304  m_array.Prepend( x.m_array );
1305  }
1306 
1313  void Prepend( const T* p, size_type n = 1 )
1314  {
1315  if ( p != nullptr )
1316  m_array.Prepend( p, n );
1317  }
1318 
1328  template <class FI>
1329  void Prepend( FI p, FI q )
1330  {
1331  for ( ; p != q; ++p )
1332  if ( *p != nullptr )
1333  m_array.Prepend( *p );
1334  }
1335 
1339  void Add( const ReferenceArray& x )
1340  {
1341  Append( x );
1342  }
1343 
1347  void Add( const T* p, size_type n = 1 )
1348  {
1349  Append( p, n );
1350  }
1351 
1355  template <class FI>
1356  void Add( FI i, FI j )
1357  {
1358  Append( i, j );
1359  }
1360 
1368  void Remove( const_iterator i, size_type n = 1 )
1369  {
1370  m_array.Remove( i.it, n );
1371  }
1372 
1380  void Remove( const_iterator i, const_iterator j )
1381  {
1382  m_array.Remove( i.it, j.it );
1383  }
1384 
1398  void Truncate( const_iterator i )
1399  {
1400  m_array.Truncate( i.it );
1401  }
1402 
1415  void Shrink( size_type n = 1 )
1416  {
1417  m_array.Shrink( n );
1418  }
1419 
1427  void Remove( const T& v )
1428  {
1429  m_array.Remove( v );
1430  }
1431 
1439  template <class BP>
1440  void Remove( const T& v, BP p )
1441  {
1442  m_array.Remove( v, p );
1443  }
1444 
1451  void RemovePointer( const T* p )
1452  {
1453  m_array.Remove( p );
1454  }
1455 
1470  void Clear()
1471  {
1472  m_array.Clear();
1473  }
1474 
1486  void Destroy( iterator i, size_type n = 1 )
1487  {
1488  m_array.Destroy( i.it, n );
1489  }
1490 
1509  void Destroy( iterator i, iterator j )
1510  {
1511  m_array.Destroy( i.it, j.it );
1512  }
1513 
1524  void Destroy( const T& v )
1525  {
1526  m_array.Destroy( v );
1527  }
1528 
1540  template <class BP>
1541  void Destroy( const T& v, BP p )
1542  {
1543  m_array.Destroy( v, p );
1544  }
1545 
1553  void Destroy()
1554  {
1555  m_array.Destroy();
1556  }
1557 
1571  iterator Replace( const_iterator i, const_iterator j, const ReferenceArray& x )
1572  {
1573  return iterator( m_array.Replace( i.it, j.it, x.m_array ) );
1574  }
1575 
1584  iterator Replace( const_iterator i, const_iterator j, const T* p, size_type n = 1 )
1585  {
1586  return iterator( m_array.Replace( i.it, j.it, p, (p != nullptr) ? n : size_type( 0 ) ) );
1587  }
1588 
1606  template <class FI>
1607  iterator Replace( const_iterator i, const_iterator j, FI p, FI q )
1608  {
1609  array_implementation m;
1610  for ( ; p != q; ++p )
1611  if ( *p != nullptr )
1612  m.Append( *p );
1613  return iterator( m_array.Replace( i.it, j.it, m ) );
1614  }
1615 
1623  void Reserve( size_type n )
1624  {
1625  m_array.Reserve( n );
1626  }
1627 
1640  void Squeeze()
1641  {
1642  m_array.Squeeze();
1643  }
1644 
1648  void Fill( const T& v )
1649  {
1650  pcl::Fill( Begin(), End(), v );
1651  }
1652 
1657  template <class F>
1658  void Apply( F f )
1659  {
1660  pcl::Apply( Begin(), End(), f );
1661  }
1662 
1667  template <class F>
1668  void Apply( F f ) const
1669  {
1670  pcl::Apply( Begin(), End(), f );
1671  }
1672 
1678  template <class F>
1679  iterator FirstThat( F f ) const
1680  {
1681  return iterator( const_cast<indirect_iterator>( pcl::FirstThat( Begin(), End(), f ).it ) );
1682  }
1683 
1689  template <class F>
1690  iterator LastThat( F f ) const
1691  {
1692  return iterator( const_cast<indirect_iterator>( pcl::LastThat( Begin(), End(), f ).it ) );
1693  }
1694 
1698  size_type Count( const T& v ) const
1699  {
1700  return pcl::Count( Begin(), End(), v );
1701  }
1702 
1710  size_type Count( const T* p ) const
1711  {
1712  return m_array.Count( p );
1713  }
1714 
1719  template <class BP>
1720  size_type Count( const T& v, BP p ) const
1721  {
1722  return pcl::Count( Begin(), End(), v, p );
1723  }
1724 
1729  template <class UP>
1730  size_type CountIf( UP p ) const
1731  {
1732  return pcl::CountIf( Begin(), End(), p );
1733  }
1734 
1737  iterator MinItem() const
1738  {
1739  return iterator( const_cast<indirect_iterator>( pcl::MinItem( Begin(), End() ).it ) );
1740  }
1741 
1744  template <class BP>
1745  iterator MinItem( BP p ) const
1746  {
1747  return iterator( const_cast<indirect_iterator>( pcl::MinItem( Begin(), End(), p ).it ) );
1748  }
1749 
1752  iterator MaxItem() const
1753  {
1754  return iterator( const_cast<indirect_iterator>( pcl::MaxItem( Begin(), End() ).it ) );
1755  }
1756 
1759  template <class BP>
1760  iterator MaxItem( BP p ) const
1761  {
1762  return iterator( const_cast<indirect_iterator>( pcl::MaxItem( Begin(), End(), p ).it ) );
1763  }
1764 
1767  void Reverse()
1768  {
1769  m_array.Reverse();
1770  }
1771 
1775  {
1776  m_array.Rotate( n );
1777  }
1778 
1781  void ShiftLeft( const T* p, size_type n = 1 )
1782  {
1783  m_array.ShiftLeft( p, n );
1784  }
1785 
1788  void ShiftRight( const T* p, size_type n = 1 )
1789  {
1790  m_array.ShiftRight( p, n );
1791  }
1792 
1795  iterator Search( const T& v ) const
1796  {
1797  return iterator( const_cast<indirect_iterator>( pcl::LinearSearch( Begin(), End(), v ).it ) );
1798  }
1799 
1802  iterator Search( const T* p ) const
1803  {
1804  return iterator( m_array.Search( p ) );
1805  }
1806 
1809  template <class BP>
1810  iterator Search( const T& v, BP p ) const
1811  {
1812  return iterator( const_cast<indirect_iterator>( pcl::LinearSearch( Begin(), End(), v, p ).it ) );
1813  }
1814 
1817  iterator SearchLast( const T& v ) const
1818  {
1819  return iterator( const_cast<indirect_iterator>( pcl::LinearSearchLast( Begin(), End(), v ).it ) );
1820  }
1821 
1824  iterator SearchLast( const T* p ) const
1825  {
1826  return iterator( m_array.SearchLast( p ) );
1827  }
1828 
1831  template <class BP>
1832  iterator SearchLast( const T& v, BP p ) const
1833  {
1834  return iterator( const_cast<indirect_iterator>( pcl::LinearSearchLast( Begin(), End(), v, p ).it ) );
1835  }
1836 
1839  template <class FI>
1840  iterator SearchSubset( FI i, FI j ) const
1841  {
1842  return iterator( const_cast<indirect_iterator>( pcl::Search( Begin(), End(), i, j ).it ) );
1843  }
1844 
1847  template <class FI, class BP>
1848  iterator SearchSubset( FI i, FI j, BP p ) const
1849  {
1850  return iterator( const_cast<indirect_iterator>( pcl::Search( Begin(), End(), i, j, p ).it ) );
1851  }
1852 
1855  template <class C>
1856  iterator SearchSubset( const C& c ) const
1857  {
1858  return iterator( const_cast<indirect_iterator>( pcl::Search( Begin(), End(), c.Begin(), c.End() ).it ) );
1859  }
1860 
1863  template <class C, class BP>
1864  iterator SearchSubset( const C& c, BP p ) const
1865  {
1866  return iterator( const_cast<indirect_iterator>( pcl::Search( Begin(), End(), c.Begin(), c.End(), p ).it ) );
1867  }
1868 
1871  template <class BI>
1872  iterator SearchLastSubset( BI i, BI j ) const
1873  {
1874  return iterator( const_cast<indirect_iterator>( pcl::SearchLast( Begin(), End(), i, j ).it ) );
1875  }
1876 
1879  template <class BI, class BP>
1880  iterator SearchLastSubset( BI i, BI j, BP p ) const
1881  {
1882  return iterator( const_cast<indirect_iterator>( pcl::SearchLast( Begin(), End(), i, j, p ).it ) );
1883  }
1884 
1887  template <class C>
1888  iterator SearchLastSubset( const C& c ) const
1889  {
1890  return iterator( const_cast<indirect_iterator>( pcl::SearchLast( Begin(), End(), c.Begin(), c.End() ).it ) );
1891  }
1892 
1895  template <class C, class BP>
1896  iterator SearchLastSubset( const C& c, BP p ) const
1897  {
1898  return iterator( const_cast<indirect_iterator>( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), p ).it ) );
1899  }
1900 
1903  bool Contains( const T& v ) const
1904  {
1905  return Search( v ) != End();
1906  }
1907 
1910  bool Contains( const T* p ) const
1911  {
1912  return m_array.Contains( p );
1913  }
1914 
1917  template <class BP>
1918  bool Contains( const T& v, BP p ) const
1919  {
1920  return Search( v, p ) != End();
1921  }
1922 
1925  template <class FI>
1926  iterator ContainsSubset( FI i, FI j ) const
1927  {
1928  return SearchSubset( i, j ) != End();
1929  }
1930 
1933  template <class FI, class BP>
1934  iterator ContainsSubset( FI i, FI j, BP p ) const
1935  {
1936  return SearchSubset( i, j, p ) != End();
1937  }
1938 
1941  template <class C>
1942  iterator ContainsSubset( const C& c ) const
1943  {
1944  return m_array.ContainsSubset( c );
1945  }
1946 
1949  template <class C, class BP>
1950  iterator ContainsSubset( const C& c, BP p ) const
1951  {
1952  return SearchSubset( c ) != End();
1953  }
1954 
1957  void Sort()
1958  {
1959  pcl::QuickSort( m_array.Begin(), m_array.End(),
1960  []( const T* a, const T* b ){ return *a < *b; } );
1961  }
1962 
1965  template <class BP>
1966  void Sort( BP p )
1967  {
1968  pcl::QuickSort( m_array.Begin(), m_array.End(),
1969  [p]( const T* a, const T* b ){ return p( *a, *b ); } );
1970  }
1971 
1975  friend void Swap( ReferenceArray& x1, ReferenceArray& x2 )
1976  {
1977  pcl::Swap( x1.m_array, x2.m_array );
1978  }
1979 
1996  template <class S, typename SP>
1997  S& ToSeparated( S& s, SP separator ) const
1998  {
1999  const_iterator i = Begin();
2000  if ( i < End() )
2001  {
2002  s.Append( S( *i ) );
2003  if ( ++i < End() )
2004  do
2005  {
2006  s.Append( separator );
2007  s.Append( S( *i ) );
2008  }
2009  while ( ++i < End() );
2010  }
2011  return s;
2012  }
2013 
2036  template <class S, typename SP, class AF>
2037  S& ToSeparated( S& s, SP separator, AF append ) const
2038  {
2039  const_iterator i = Begin();
2040  if ( i < End() )
2041  {
2042  append( s, S( *i ) );
2043  if ( ++i < End() )
2044  {
2045  S p( separator );
2046  do
2047  {
2048  append( s, p );
2049  append( s, S( *i ) );
2050  }
2051  while ( ++i < End() );
2052  }
2053  }
2054  return s;
2055  }
2056 
2065  template <class S>
2066  S& ToCommaSeparated( S& s ) const
2067  {
2068  return ToSeparated( s, ',' );
2069  }
2070 
2079  template <class S>
2080  S& ToSpaceSeparated( S& s ) const
2081  {
2082  return ToSeparated( s, ' ' );
2083  }
2084 
2093  template <class S>
2094  S& ToTabSeparated( S& s ) const
2095  {
2096  return ToSeparated( s, '\t' );
2097  }
2098 
2109  uint64 Hash64( uint64 seed = 0 ) const
2110  {
2111  return m_array.Hash64( seed );
2112  }
2113 
2124  uint32 Hash32( uint32 seed = 0 ) const
2125  {
2126  return m_array.Hash32( seed );
2127  }
2128 
2133  uint64 Hash( uint64 seed = 0 ) const
2134  {
2135  return Hash64( seed );
2136  }
2137 
2138 private:
2139 
2140  array_implementation m_array;
2141 
2142  template <class C>
2143  void CloneObjects( const C& x, DirectContainer<T>* )
2144  {
2145  m_array.CloneAssign( x );
2146  }
2147 
2148  template <class C>
2149  void CloneObjects( const C& x, IndirectContainer<T>* )
2150  {
2151  m_array.Clear();
2152  m_array.Reserve( x.Length() );
2153  allocator a;
2154  for ( typename C::const_iterator p = x.Begin(); p != x.End(); ++p )
2155  if ( *p != nullptr )
2156  {
2157  T* o = a.Allocate( 1 );
2158  pcl::Construct( o, **p, a );
2159  m_array.Append( o );
2160  }
2161  }
2162 };
2163 
2164 // ----------------------------------------------------------------------------
2165 
2172 template <class T, class A> inline
2174 {
2175  return x1.Length() == x2.Length() && pcl::Equal( x1.Begin(), x2.Begin(), x2.End() );
2176 }
2177 
2184 template <class T, class A> inline
2185 bool operator <( const ReferenceArray<T,A>& x1, const ReferenceArray<T,A>& x2 )
2186 {
2187  return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End() ) < 0;
2188 }
2189 
2197 template <class T, class A, class V> inline
2198 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>& x, const V* p )
2199 {
2200  x.Append( static_cast<const T*>( p ) );
2201  return x;
2202 }
2203 
2211 template <class T, class A, class V> inline
2212 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>&& x, const V* p )
2213 {
2214  x.Append( static_cast<const T*>( p ) );
2215  return x;
2216 }
2217 
2223 template <class T, class A> inline
2224 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>& x1, const ReferenceArray<T,A>& x2 )
2225 {
2226  x1.Append( x2 );
2227  return x1;
2228 }
2229 
2235 template <class T, class A> inline
2236 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>&& x1, const ReferenceArray<T,A>& x2 )
2237 {
2238  x1.Append( x2 );
2239  return x1;
2240 }
2241 
2242 // ----------------------------------------------------------------------------
2243 
2244 } // pcl
2245 
2246 #endif // __PCL_ReferenceArray_h
2247 
2248 // ----------------------------------------------------------------------------
2249 // EOF pcl/ReferenceArray.h - Released 2019-11-07T10:59:34Z
const_reverse_iterator ConstReverseEnd() const
T item_type
Represents the item type.
Definition: Iterator.h:107
Random access iterator class.
Definition: Iterator.h:93
void Append(FI p, FI q)
iterator SearchLast(const T *p) const
uint64 Hash64(const void *data, size_type size, uint64 seed=0)
Definition: Math.h:3551
Abstract base class of all XML document node classes.
Definition: XML.h:498
bool Contains(const T *p) const
ReferenceArray(ReferenceArray &&x)
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:539
bool IsUnique() const
void Append(const IndirectArray &x)
BI LinearSearchLast(BI i, BI j, const T &v)
Definition: Search.h:129
Generic container iterator.
Definition: Iterator.h:104
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:455
iterator ContainsSubset(FI i, FI j) const
bool Contains(const T &v, BP p) const
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2)
Definition: Point.h:1402
Dynamic array of pointers to objects providing direct iteration and element access by reference...
void Assign(const T *p, size_type n=1)
size_type Count(FI i, FI j, const T &v)
Definition: Utility.h:384
const T & First() const
iterator MinItem() const
void UniquifyIterators(iterator &i, iterator &j)
friend void Swap(ReferenceArray &x1, ReferenceArray &x2)
iterator MaxItem() const
size_type Capacity() const
bool Contains(const T &v) const
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2)
Definition: Utility.h:639
iterator SearchLast(const T &v, BP p) const
PCL root namespace.
Definition: AbstractImage.h:76
bool IsAliasOf(const ReferenceArray &x) const
BI LastThat(BI i, BI j, UP p)
Definition: Utility.h:350
void Prepend(const ReferenceArray &x)
Mutable ReferenceArray iterator.
void Assign(const ReferenceArray &x)
reverse_iterator ReverseBegin()
FI LinearSearch(FI i, FI j, const T &v)
Definition: Search.h:91
ReferenceArray(const ReferenceArray &x)
array_implementation::allocator allocator
const_iterator begin() const
ReferenceArray(size_type n, const T *p)
FI MaxItem(FI i, FI j)
Definition: Utility.h:479
void Destroy(const T &v)
void Destroy(iterator i, iterator j)
size_type Count(const T *p) const
const_iterator ConstEnd() const
iterator Replace(const_iterator i, const_iterator j, FI p, FI q)
void Construct(T *p, A &a)
Definition: Allocator.h:246
void Transfer(ReferenceArray &x)
iterator Replace(const_iterator i, const_iterator j, const T *p, size_type n=1)
iterator At(size_type i)
bool Equal(FI1 i1, FI2 i2, FI2 j2)
Definition: Utility.h:592
Generic dynamic array of pointers to objects.
Definition: IndirectArray.h:91
void SetAllocator(const allocator &a)
iterator ContainsSubset(FI i, FI j, BP p) const
reverse_iterator ReverseEnd()
Mutable ReferenceArray reverse iterator.
size_type Size() const
void ShiftRight(const T *p, size_type n=1)
BI1 SearchLast(BI1 i1, BI1 j1, FI2 i2, FI2 j2)
Definition: Search.h:449
iterator MinItem(BP p) const
size_t size_type
Definition: Defs.h:543
iterator Insert(const_iterator i, const ReferenceArray &x)
Provides memory allocation for PCL containers.
Definition: Allocator.h:131
void ShiftLeft(const T *p, size_type n=1)
iterator Search(const T &v) const
void Transfer(ReferenceArray &&x)
void Add(FI i, FI j)
const_reverse_iterator ReverseEnd() const
iterator SearchLastSubset(const C &c, BP p) const
void Apply(FI i, FI j, F f)
Definition: Utility.h:249
Root base class of all PCL containers of pointers to objects.
Definition: Container.h:88
T * Allocate(size_type n, size_type extra=0)
Definition: Allocator.h:162
void Append(const T *p, size_type n=1)
unsigned long long uint64
Definition: Defs.h:616
void Prepend(FI p, FI q)
iterator Insert(const_iterator i, const T *p, size_type n=1)
const_iterator At(size_type i) const
void Fill(const T &v)
void Rotate(distance_type n)
void Append(const ReferenceArray &x)
iterator SearchLastSubset(const C &c) const
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:495
void UniquifyIterator(iterator &i)
void Import(iterator i, iterator j)
size_type CountIf(FI i, FI j, UP p)
Definition: Utility.h:423
array_implementation::block_allocator block_allocator
iterator SearchSubset(const C &c, BP p) const
const_iterator End() const
const_iterator Begin() const
Immutable ReferenceArray reverse iterator.
void Reserve(size_type n)
iterator MutableIterator(const_iterator i)
size_type UpperBound() const
uint32 Hash32(uint32 seed=0) const
const T & Last() const
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2)
Definition: Array.h:2086
void Remove(const T &v, BP p)
void Truncate(const_iterator i)
iterator Search(const T *p) const
const allocator & GetAllocator() const
iterator ContainsSubset(const C &c, BP p) const
size_type LowerBound() const
iterator SearchLastSubset(BI i, BI j) const
iterator MaxItem(BP p) const
iterator LastThat(F f) const
size_type CountIf(UP p) const
IndirectArray< T, A > array_implementation
void QuickSort(RI i, RI j)
Definition: Sort.h:250
iterator Replace(const_iterator i, const_iterator j, const ReferenceArray &x)
void Assign(FI i, FI j)
Root base class of all PCL containers of objects.
Definition: Container.h:77
void Prepend(const T *p, size_type n=1)
array_implementation::iterator indirect_iterator
void Add(const ReferenceArray &x)
void Shrink(size_type n=1)
iterator ContainsSubset(const C &c) const
array_implementation::const_iterator const_indirect_iterator
Reverse random access iterator.
Definition: Iterator.h:414
iterator SearchSubset(FI i, FI j) const
A block allocator class that uses the standard new and delete operators.
Definition: StdAlloc.h:81
FI MinItem(FI i, FI j)
Definition: Utility.h:441
void Apply(F f) const
FI1 Search(FI1 i1, FI1 j1, FI2 i2, FI2 j2)
Definition: Search.h:397
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2)
Definition: Array.h:2075
iterator FirstThat(F f) const
size_type Length() const
size_type Count(const T &v, BP p) const
iterator Insert(const_iterator i, FI p, FI q)
void Reserve(size_type n)
size_type Available() const
void Add(const T *p, size_type n=1)
void Remove(const_iterator i, const_iterator j)
bool IsValid() const
ptrdiff_t distance_type
Definition: Defs.h:549
void Remove(const_iterator i, size_type n=1)
uint64 Hash64(uint64 seed=0) const
uint64 Hash(uint64 seed=0) const
const_reverse_iterator ConstReverseBegin() const
size_type Count(const T &v) const
iterator SearchSubset(FI i, FI j, BP p) const
FI FirstThat(FI i, FI j, UP p)
Definition: Utility.h:316
void Remove(const T &v)
bool IsEmpty() const
void Destroy(const T &v, BP p)
iterator SearchLastSubset(BI i, BI j, BP p) const
unsigned int uint32
Definition: Defs.h:600
iterator SearchLast(const T &v) const
void CloneAssign(const C &x)
const_iterator end() const
const_iterator ConstBegin() const
iterator Search(const T &v, BP p) const
ReferenceArray(FI i, FI j)
Immutable ReferenceArray iterator.
const_reverse_iterator ReverseBegin() const
indirect_iterator Release()
iterator SearchSubset(const C &c) const
void RemovePointer(const T *p)
void Destroy(iterator i, size_type n=1)
void CloneAssign(const C &x)