PCL
ReferenceArray.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/ReferenceArray.h - Released 2024-06-18T15:48:54Z
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-2024 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 (https://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/StandardAllocator.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 
106 
110 
114 
118 
123  class iterator : public Iterator<RandomAccessIterator, T>
124  {
125  public:
126 
128  using iterator_class = typename iterator_base::iterator_class;
129  using item_type = typename iterator_base::item_type;
130 
134  iterator() = default;
135 
139  iterator( const iterator& ) = default;
140 
144  iterator( std::nullptr_t ) : it( nullptr )
145  {
146  }
147 
151  iterator& operator =( const iterator& ) = default;
152 
156  T* Pointer() const
157  {
158  return *it;
159  }
160 
165  operator T*() const
166  {
167  return *it;
168  }
169 
174  T& operator *() const
175  {
176  return **it;
177  }
178 
183  T* operator ->() const
184  {
185  return *it;
186  }
187 
193  iterator& operator ++()
194  {
195  ++it;
196  return *this;
197  }
198 
204  iterator operator ++( int )
205  {
206  indirect_iterator it0 = it;
207  ++it;
208  return it0;
209  }
210 
216  iterator& operator --()
217  {
218  --it;
219  return *this;
220  }
221 
227  iterator operator --( int )
228  {
229  indirect_iterator it0 = it;
230  --it;
231  return it0;
232  }
233 
241  iterator& operator +=( distance_type d )
242  {
243  it += d;
244  return *this;
245  }
246 
254  iterator& operator -=( distance_type d )
255  {
256  it -= d;
257  return *this;
258  }
259 
265  {
266  return iterator( it + d );
267  }
268 
274  {
275  return iterator( it - d );
276  }
277 
283  {
284  return it - i.it;
285  }
286 
291  bool operator ==( const iterator& i ) const
292  {
293  return it == i.it;
294  }
295 
300  bool operator <( const iterator& i ) const
301  {
302  return it < i.it;
303  }
304 
305  private:
306 
307  indirect_iterator it = nullptr;
308 
313  explicit
314  iterator( indirect_iterator i ) : it( i )
315  {
316  }
317 
318  friend class ReferenceArray<T,A>;
319  friend class ReferenceArray<T,A>::const_iterator;
320  };
321 
326  class const_iterator : public Iterator<RandomAccessIterator, T>
327  {
328  public:
329 
331  using iterator_class = typename iterator_base::iterator_class;
332  using item_type = typename iterator_base::item_type;
333 
337  const_iterator() = default;
338 
342  const_iterator( const iterator& i ) : it( i.it )
343  {
344  }
345 
349  const_iterator( std::nullptr_t ) : it( nullptr )
350  {
351  }
352 
356  const_iterator( const const_iterator& ) = default;
357 
362  const_iterator& operator =( const const_iterator& ) = default;
363 
368  const_iterator& operator =( const iterator& i )
369  {
370  it = i.it;
371  return *this;
372  }
373 
377  const T* Pointer() const
378  {
379  return *it;
380  }
381 
386  operator const T*() const
387  {
388  return *it;
389  }
390 
395  const T& operator *() const
396  {
397  return **it;
398  }
399 
404  const T* operator ->() const
405  {
406  return *it;
407  }
408 
414  const_iterator& operator ++()
415  {
416  ++it;
417  return *this;
418  }
419 
425  const_iterator operator ++( int )
426  {
427  const_indirect_iterator it0 = it;
428  ++it;
429  return it0;
430  }
431 
437  const_iterator& operator --()
438  {
439  --it;
440  return *this;
441  }
442 
448  const_iterator operator --( int )
449  {
450  const_indirect_iterator it0 = it;
451  --it;
452  return it0;
453  }
454 
462  const_iterator& operator +=( distance_type d )
463  {
464  it += d;
465  return *this;
466  }
467 
475  const_iterator& operator -=( distance_type d )
476  {
477  it -= d;
478  return *this;
479  }
480 
486  {
487  return const_iterator( it + d );
488  }
489 
495  {
496  return const_iterator( it - d );
497  }
498 
504  {
505  return it - i.it;
506  }
507 
513  {
514  return it - i.it;
515  }
516 
521  bool operator ==( const const_iterator& i ) const
522  {
523  return it == i.it;
524  }
525 
530  bool operator ==( const iterator& i ) const
531  {
532  return it == i.it;
533  }
534 
539  bool operator <( const const_iterator& i ) const
540  {
541  return it < i.it;
542  }
543 
548  bool operator <( const iterator& i ) const
549  {
550  return it < i.it;
551  }
552 
553  private:
554 
555  const_indirect_iterator it = nullptr;
556 
561  explicit
563  {
564  }
565 
566  friend class ReferenceArray<T,A>;
567  };
568 
573  using reverse_iterator = ReverseRandomAccessIterator<iterator, T>;
574 
579  using const_reverse_iterator = ReverseRandomAccessIterator<const_iterator, const T>;
580 
581  // -------------------------------------------------------------------------
582 
586  ReferenceArray() = default;
587 
594  ReferenceArray( size_type n, const T* p )
595  {
596  PCL_PRECONDITION( p != nullptr )
597  if ( p != nullptr )
598  m_array = array_implementation( n, p );
599  }
600 
608  template <class FI>
609  ReferenceArray( FI i, FI j )
610  {
611  for ( ; i != j; ++i )
612  if ( *i != nullptr )
613  m_array.Append( *i );
614  }
615 
619  ReferenceArray( const ReferenceArray& ) = default;
620 
625 
634  {
635  }
636 
641  bool IsUnique() const
642  {
643  return m_array.IsUnique();
644  }
645 
652  bool IsAliasOf( const ReferenceArray& x ) const
653  {
654  return m_array.IsAliasOf( x.m_array );
655  }
656 
666  {
667  m_array.EnsureUnique();
668  }
669 
674  size_type Size() const
675  {
676  return m_array.Size();
677  }
678 
683  {
684  return m_array.Length();
685  }
686 
693  {
694  return m_array.Capacity();
695  }
696 
705  {
706  return m_array.Available();
707  }
708 
724  bool IsValid() const
725  {
726  return m_array.IsValid();
727  }
728 
732  bool IsEmpty() const
733  {
734  return m_array.IsEmpty();
735  }
736 
742  {
743  return m_array.LowerBound();
744  }
745 
751  {
752  return m_array.UpperBound();
753  }
754 
758  const allocator& Allocator() const
759  {
760  return m_array.Allocator();
761  }
762 
766  void SetAllocator( const allocator& a )
767  {
768  m_array.SetAllocator( a );
769  }
770 
776  {
777  return iterator( m_array.At( i ) );
778  }
779 
785  {
786  return const_iterator( m_array.At( i ) );
787  }
788 
800  {
801  return iterator( m_array.MutableIterator( i.it ) );
802  }
803 
808  T& operator []( size_type i )
809  {
810  return *m_array[i];
811  }
812 
817  const T& operator []( size_type i ) const
818  {
819  return *m_array[i];
820  }
821 
826  {
827  return **m_array.Begin();
828  }
829 
834  const T& operator *() const
835  {
836  return **m_array.Begin();
837  }
838 
843  {
844  return iterator( m_array.Begin() );
845  }
846 
851  {
852  return const_iterator( m_array.Begin() );
853  }
854 
859  {
860  return const_iterator( m_array.ConstBegin() );
861  }
862 
867  {
868  return iterator( m_array.End() );
869  }
870 
875  {
876  return const_iterator( m_array.End() );
877  }
878 
883  {
884  return const_iterator( m_array.ConstEnd() );
885  }
886 
894  {
895  return iterator( m_array.End()-1 );
896  }
897 
905  {
906  return const_iterator( m_array.End()-1 );
907  }
908 
916  {
917  PCL_PRECONDITION( !IsEmpty() )
918  return const_iterator( m_array.End()-1 );
919  }
920 
929  {
930  PCL_PRECONDITION( !IsEmpty() )
931  return iterator( m_array.Begin()-1 );
932  }
933 
942  {
943  PCL_PRECONDITION( !IsEmpty() )
944  return const_iterator( m_array.Begin()-1 );
945  }
946 
955  {
956  PCL_PRECONDITION( !IsEmpty() )
957  return const_iterator( m_array.Begin()-1 );
958  }
959 
964  T& First()
965  {
966  return **m_array.Begin();
967  }
968 
973  const T& First() const
974  {
975  return **m_array.Begin();
976  }
977 
982  T& Last()
983  {
984  return **m_array.ReverseBegin();
985  }
986 
991  const T& Last() const
992  {
993  return **m_array.ReverseBegin();
994  }
995 
1006  {
1007  m_array.UniquifyIterator( i.it );
1008  }
1009 
1021  {
1022  m_array.UniquifyIterators( i.it, j.it );
1023  }
1024 
1025 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1030  {
1031  return Begin();
1032  }
1033 
1038  {
1039  return Begin();
1040  }
1041 
1046  {
1047  return End();
1048  }
1049 
1054  {
1055  return End();
1056  }
1057 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1058 
1065  ReferenceArray& operator =( const ReferenceArray& x )
1066  {
1067  Assign( x );
1068  return *this;
1069  }
1070 
1080  void Assign( const ReferenceArray& x )
1081  {
1082  m_array.Assign( x.m_array );
1083  }
1084 
1088  ReferenceArray& operator =( ReferenceArray&& x )
1089  {
1090  Transfer( x );
1091  return *this;
1092  }
1093 
1104  {
1105  m_array.Transfer( x.m_array );
1106  }
1107 
1118  {
1119  m_array.Transfer( std::move( x.m_array ) );
1120  }
1121 
1128  void Assign( const T* p, size_type n = 1 )
1129  {
1130  if ( p != nullptr )
1131  m_array.Assign( p, n );
1132  else
1133  m_array.Clear();
1134  }
1135 
1145  template <class FI>
1146  void Assign( FI i, FI j )
1147  {
1148  m_array.Clear();
1149  for ( ; i != j; ++i )
1150  if ( *i != nullptr )
1151  m_array.Append( *i );
1152  }
1153 
1164  template <class C>
1165  void CloneAssign( const C& x )
1166  {
1167  PCL_ASSERT_CONTAINER( C, T );
1168  CloneObjects( x, (C*)nullptr );
1169  }
1170 
1176  void Import( iterator i, iterator j )
1177  {
1178  m_array.Import( i.it, j.it );
1179  }
1180 
1193  {
1194  return m_array.Release();
1195  }
1196 
1209  {
1210  return iterator( m_array.Insert( i.it, x.m_array ) );
1211  }
1212 
1224  iterator Insert( const_iterator i, const T* p, size_type n = 1 )
1225  {
1226  return (p != nullptr) ? iterator( m_array.Insert( i.it, p, n ) ) :
1227  iterator( const_cast<indirect_iterator>( i.it ) );
1228  }
1229 
1244  template <class FI>
1245  iterator Insert( const_iterator i, FI p, FI q )
1246  {
1247  const_indirect_iterator it = i.it;
1248  for ( ; p != q; ++p )
1249  if ( *p != nullptr )
1250  it = m_array.Insert( it, *p );
1251  return iterator( const_cast<indirect_iterator>( it ) );
1252  }
1253 
1258  void Append( const ReferenceArray& x )
1259  {
1260  m_array.Append( x.m_array );
1261  }
1262 
1269  void Append( const T* p, size_type n = 1 )
1270  {
1271  if ( p != nullptr )
1272  m_array.Append( p, n );
1273  }
1274 
1284  template <class FI>
1285  void Append( FI p, FI q )
1286  {
1287  for ( ; p != q; ++p )
1288  if ( *p != nullptr )
1289  m_array.Append( *p );
1290  }
1291 
1296  void Prepend( const ReferenceArray& x )
1297  {
1298  m_array.Prepend( x.m_array );
1299  }
1300 
1307  void Prepend( const T* p, size_type n = 1 )
1308  {
1309  if ( p != nullptr )
1310  m_array.Prepend( p, n );
1311  }
1312 
1322  template <class FI>
1323  void Prepend( FI p, FI q )
1324  {
1325  for ( ; p != q; ++p )
1326  if ( *p != nullptr )
1327  m_array.Prepend( *p );
1328  }
1329 
1333  void Add( const ReferenceArray& x )
1334  {
1335  Append( x );
1336  }
1337 
1341  void Add( const T* p, size_type n = 1 )
1342  {
1343  Append( p, n );
1344  }
1345 
1349  template <class FI>
1350  void Add( FI i, FI j )
1351  {
1352  Append( i, j );
1353  }
1354 
1363  {
1364  m_array.Remove( i.it, n );
1365  }
1366 
1375  {
1376  m_array.Remove( i.it, j.it );
1377  }
1378 
1391  void RemoveFirst( size_type n = 1 )
1392  {
1393  m_array.RemoveFirst( n );
1394  }
1395 
1408  void RemoveLast( size_type n = 1 )
1409  {
1410  m_array.RemoveLast( n );
1411  }
1412 
1427  {
1428  m_array.Truncate( i.it );
1429  }
1430 
1435  void Shrink( size_type n = 1 )
1436  {
1437  m_array.Shrink( n );
1438  }
1439 
1447  void Remove( const T& v )
1448  {
1449  m_array.Remove( v );
1450  }
1451 
1459  template <class BP>
1460  void Remove( const T& v, BP p )
1461  {
1462  m_array.Remove( v, p );
1463  }
1464 
1471  void RemovePointer( const T* p )
1472  {
1473  m_array.Remove( p );
1474  }
1475 
1490  void Clear()
1491  {
1492  m_array.Clear();
1493  }
1494 
1506  void Destroy( iterator i, size_type n = 1 )
1507  {
1508  m_array.Destroy( i.it, n );
1509  }
1510 
1530  {
1531  m_array.Destroy( i.it, j.it );
1532  }
1533 
1544  void Destroy( const T& v )
1545  {
1546  m_array.Destroy( v );
1547  }
1548 
1560  template <class BP>
1561  void Destroy( const T& v, BP p )
1562  {
1563  m_array.Destroy( v, p );
1564  }
1565 
1573  void Destroy()
1574  {
1575  m_array.Destroy();
1576  }
1577 
1592  {
1593  return iterator( m_array.Replace( i.it, j.it, x.m_array ) );
1594  }
1595 
1605  {
1606  return iterator( m_array.Replace( i.it, j.it, p, (p != nullptr) ? n : size_type( 0 ) ) );
1607  }
1608 
1626  template <class FI>
1628  {
1630  for ( ; p != q; ++p )
1631  if ( *p != nullptr )
1632  m.Append( *p );
1633  return iterator( m_array.Replace( i.it, j.it, m ) );
1634  }
1635 
1643  void Reserve( size_type n )
1644  {
1645  m_array.Reserve( n );
1646  }
1647 
1660  void Squeeze()
1661  {
1662  m_array.Squeeze();
1663  }
1664 
1668  void Fill( const T& v )
1669  {
1670  pcl::Fill( Begin(), End(), v );
1671  }
1672 
1677  template <class F>
1678  void Apply( F f )
1679  {
1680  pcl::Apply( Begin(), End(), f );
1681  }
1682 
1687  template <class F>
1688  void Apply( F f ) const
1689  {
1690  pcl::Apply( Begin(), End(), f );
1691  }
1692 
1698  template <class F>
1700  {
1701  return const_iterator( pcl::FirstThat( Begin(), End(), f ).it );
1702  }
1703 
1709  template <class F>
1711  {
1712  return iterator( pcl::FirstThat( Begin(), End(), f ).it );
1713  }
1714 
1720  template <class F>
1722  {
1723  return const_iterator( pcl::LastThat( Begin(), End(), f ).it );
1724  }
1725 
1731  template <class F>
1733  {
1734  return iterator( pcl::LastThat( Begin(), End(), f ).it );
1735  }
1736 
1740  size_type Count( const T& v ) const
1741  {
1742  return pcl::Count( Begin(), End(), v );
1743  }
1744 
1752  size_type Count( const T* p ) const
1753  {
1754  return m_array.Count( p );
1755  }
1756 
1761  template <class BP>
1762  size_type Count( const T& v, BP p ) const
1763  {
1764  return pcl::Count( Begin(), End(), v, p );
1765  }
1766 
1771  template <class UP>
1772  size_type CountIf( UP p ) const
1773  {
1774  return pcl::CountIf( Begin(), End(), p );
1775  }
1776 
1780  {
1781  return const_iterator( pcl::MinItem( Begin(), End() ).it );
1782  }
1783 
1787  {
1788  return iterator( pcl::MinItem( Begin(), End() ).it );
1789  }
1790 
1793  template <class BP>
1794  const_iterator MinItem( BP p ) const
1795  {
1796  return const_iterator( pcl::MinItem( Begin(), End(), p ).it );
1797  }
1798 
1801  template <class BP>
1803  {
1804  return iterator( pcl::MinItem( Begin(), End(), p ).it );
1805  }
1806 
1810  {
1811  return const_iterator( pcl::MaxItem( Begin(), End() ).it );
1812  }
1813 
1817  {
1818  return iterator( pcl::MaxItem( Begin(), End() ).it );
1819  }
1820 
1823  template <class BP>
1824  const_iterator MaxItem( BP p ) const
1825  {
1826  return const_iterator( pcl::MaxItem( Begin(), End(), p ).it );
1827  }
1828 
1831  template <class BP>
1833  {
1834  return iterator( pcl::MaxItem( Begin(), End(), p ).it );
1835  }
1836 
1839  void Reverse()
1840  {
1841  m_array.Reverse();
1842  }
1843 
1847  {
1848  m_array.Rotate( n );
1849  }
1850 
1853  void ShiftLeft( const T* p, size_type n = 1 )
1854  {
1855  m_array.ShiftLeft( p, n );
1856  }
1857 
1860  void ShiftRight( const T* p, size_type n = 1 )
1861  {
1862  m_array.ShiftRight( p, n );
1863  }
1864 
1867  const_iterator Search( const T& v ) const
1868  {
1869  return const_iterator( pcl::LinearSearch( Begin(), End(), v ).it );
1870  }
1871 
1874  iterator Search( const T& v )
1875  {
1876  return iterator( pcl::LinearSearch( Begin(), End(), v ).it );
1877  }
1878 
1881  const_iterator Search( const T* p ) const
1882  {
1883  return const_iterator( m_array.Search( p ) );
1884  }
1885 
1888  iterator Search( const T* p )
1889  {
1890  return iterator( m_array.Search( p ) );
1891  }
1892 
1895  template <class BP>
1896  const_iterator Search( const T& v, BP p ) const
1897  {
1898  return const_iterator( pcl::LinearSearch( Begin(), End(), v, p ).it );
1899  }
1900 
1903  template <class BP>
1904  iterator Search( const T& v, BP p )
1905  {
1906  return iterator( pcl::LinearSearch( Begin(), End(), v, p ).it );
1907  }
1908 
1911  const_iterator SearchLast( const T& v ) const
1912  {
1913  return const_iterator( pcl::LinearSearchLast( Begin(), End(), v ).it );
1914  }
1915 
1918  iterator SearchLast( const T& v )
1919  {
1920  return iterator( pcl::LinearSearchLast( Begin(), End(), v ).it );
1921  }
1922 
1925  const_iterator SearchLast( const T* p ) const
1926  {
1927  return const_iterator( m_array.SearchLast( p ) );
1928  }
1929 
1932  iterator SearchLast( const T* p )
1933  {
1934  return iterator( m_array.SearchLast( p ) );
1935  }
1936 
1939  template <class BP>
1940  const_iterator SearchLast( const T& v, BP p ) const
1941  {
1942  return const_iterator( pcl::LinearSearchLast( Begin(), End(), v, p ).it );
1943  }
1944 
1947  template <class BP>
1948  iterator SearchLast( const T& v, BP p )
1949  {
1950  return iterator( pcl::LinearSearchLast( Begin(), End(), v, p ).it );
1951  }
1952 
1955  template <class FI>
1956  const_iterator SearchSubset( FI i, FI j ) const
1957  {
1958  return const_iterator( pcl::Search( Begin(), End(), i, j ).it );
1959  }
1960 
1963  template <class FI>
1964  iterator SearchSubset( FI i, FI j )
1965  {
1966  return iterator( pcl::Search( Begin(), End(), i, j ).it );
1967  }
1968 
1971  template <class FI, class BP>
1972  const_iterator SearchSubset( FI i, FI j, BP p ) const
1973  {
1974  return const_iterator( pcl::Search( Begin(), End(), i, j, p ).it );
1975  }
1976 
1979  template <class FI, class BP>
1980  iterator SearchSubset( FI i, FI j, BP p )
1981  {
1982  return iterator( pcl::Search( Begin(), End(), i, j, p ).it );
1983  }
1984 
1987  template <class C>
1988  const_iterator SearchSubset( const C& c ) const
1989  {
1990  return const_iterator( pcl::Search( Begin(), End(), c.Begin(), c.End() ).it );
1991  }
1992 
1995  template <class C>
1996  iterator SearchSubset( const C& c )
1997  {
1998  return iterator( pcl::Search( Begin(), End(), c.Begin(), c.End() ).it );
1999  }
2000 
2003  template <class C, class BP>
2004  const_iterator SearchSubset( const C& c, BP p ) const
2005  {
2006  return const_iterator( pcl::Search( Begin(), End(), c.Begin(), c.End(), p ).it );
2007  }
2008 
2011  template <class C, class BP>
2012  iterator SearchSubset( const C& c, BP p )
2013  {
2014  return iterator( pcl::Search( Begin(), End(), c.Begin(), c.End(), p ).it );
2015  }
2016 
2019  template <class BI>
2020  const_iterator SearchLastSubset( BI i, BI j ) const
2021  {
2022  return const_iterator( pcl::SearchLast( Begin(), End(), i, j ).it );
2023  }
2024 
2027  template <class BI>
2029  {
2030  return iterator( pcl::SearchLast( Begin(), End(), i, j ).it );
2031  }
2032 
2035  template <class BI, class BP>
2036  const_iterator SearchLastSubset( BI i, BI j, BP p ) const
2037  {
2038  return const_iterator( pcl::SearchLast( Begin(), End(), i, j, p ).it );
2039  }
2040 
2043  template <class BI, class BP>
2044  iterator SearchLastSubset( BI i, BI j, BP p )
2045  {
2046  return iterator( pcl::SearchLast( Begin(), End(), i, j, p ).it );
2047  }
2048 
2051  template <class C>
2052  const_iterator SearchLastSubset( const C& c ) const
2053  {
2054  return const_iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End() ).it );
2055  }
2056 
2059  template <class C>
2061  {
2062  return iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End() ).it );
2063  }
2064 
2067  template <class C, class BP>
2068  const_iterator SearchLastSubset( const C& c, BP p ) const
2069  {
2070  return const_iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), p ).it );
2071  }
2072 
2075  template <class C, class BP>
2076  iterator SearchLastSubset( const C& c, BP p )
2077  {
2078  return iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), p ).it );
2079  }
2080 
2083  bool Contains( const T& v ) const
2084  {
2085  return Search( v ) != End();
2086  }
2087 
2090  bool Contains( const T* p ) const
2091  {
2092  return m_array.Contains( p );
2093  }
2094 
2097  template <class BP>
2098  bool Contains( const T& v, BP p ) const
2099  {
2100  return Search( v, p ) != End();
2101  }
2102 
2105  template <class FI>
2106  iterator ContainsSubset( FI i, FI j ) const
2107  {
2108  return SearchSubset( i, j ) != End();
2109  }
2110 
2113  template <class FI, class BP>
2114  iterator ContainsSubset( FI i, FI j, BP p ) const
2115  {
2116  return SearchSubset( i, j, p ) != End();
2117  }
2118 
2121  template <class C>
2122  iterator ContainsSubset( const C& c ) const
2123  {
2124  return m_array.ContainsSubset( c );
2125  }
2126 
2129  template <class C, class BP>
2130  iterator ContainsSubset( const C& c, BP p ) const
2131  {
2132  return SearchSubset( c ) != End();
2133  }
2134 
2137  void Sort()
2138  {
2139  pcl::QuickSort( m_array.Begin(), m_array.End(),
2140  []( const T* a, const T* b ){ return *a < *b; } );
2141  }
2142 
2145  template <class BP>
2146  void Sort( BP p )
2147  {
2148  pcl::QuickSort( m_array.Begin(), m_array.End(),
2149  [p]( const T* a, const T* b ){ return p( *a, *b ); } );
2150  }
2151 
2155  friend void Swap( ReferenceArray& x1, ReferenceArray& x2 )
2156  {
2157  pcl::Swap( x1.m_array, x2.m_array );
2158  }
2159 
2176  template <class S, typename SP>
2177  S& ToSeparated( S& s, SP separator ) const
2178  {
2179  const_iterator i = Begin();
2180  if ( i < End() )
2181  {
2182  s.Append( S( *i ) );
2183  if ( ++i < End() )
2184  do
2185  {
2186  s.Append( separator );
2187  s.Append( S( *i ) );
2188  }
2189  while ( ++i < End() );
2190  }
2191  return s;
2192  }
2193 
2216  template <class S, typename SP, class AF>
2217  S& ToSeparated( S& s, SP separator, AF append ) const
2218  {
2219  const_iterator i = Begin();
2220  if ( i < End() )
2221  {
2222  append( s, S( *i ) );
2223  if ( ++i < End() )
2224  {
2225  S p( separator );
2226  do
2227  {
2228  append( s, p );
2229  append( s, S( *i ) );
2230  }
2231  while ( ++i < End() );
2232  }
2233  }
2234  return s;
2235  }
2236 
2245  template <class S>
2246  S& ToCommaSeparated( S& s ) const
2247  {
2248  return ToSeparated( s, ',' );
2249  }
2250 
2259  template <class S>
2260  S& ToSpaceSeparated( S& s ) const
2261  {
2262  return ToSeparated( s, ' ' );
2263  }
2264 
2273  template <class S>
2274  S& ToTabSeparated( S& s ) const
2275  {
2276  return ToSeparated( s, '\t' );
2277  }
2278 
2287  template <class S>
2288  S& ToNewLineSeparated( S& s ) const
2289  {
2290  return ToSeparated( s, '\n' );
2291  }
2292 
2303  uint64 Hash64( uint64 seed = 0 ) const
2304  {
2305  return m_array.Hash64( seed );
2306  }
2307 
2318  uint32 Hash32( uint32 seed = 0 ) const
2319  {
2320  return m_array.Hash32( seed );
2321  }
2322 
2327  uint64 Hash( uint64 seed = 0 ) const
2328  {
2329  return Hash64( seed );
2330  }
2331 
2332 private:
2333 
2334  array_implementation m_array;
2335 
2336  template <class C>
2337  void CloneObjects( const C& x, DirectContainer<T>* )
2338  {
2339  m_array.CloneAssign( x );
2340  }
2341 
2342  template <class C>
2343  void CloneObjects( const C& x, IndirectContainer<T>* )
2344  {
2345  m_array.Clear();
2346  m_array.Reserve( x.Length() );
2347  allocator a;
2348  for ( typename C::const_iterator p = x.Begin(); p != x.End(); ++p )
2349  if ( *p != nullptr )
2350  {
2351  T* o = a.Allocate( 1 );
2352  pcl::Construct( o, **p, a );
2353  m_array.Append( o );
2354  }
2355  }
2356 };
2357 
2358 // ----------------------------------------------------------------------------
2359 
2366 template <class T, class A> inline
2368 {
2369  return x1.Length() == x2.Length() && pcl::Equal( x1.Begin(), x2.Begin(), x2.End() );
2370 }
2371 
2378 template <class T, class A> inline
2380 {
2381  return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End() ) < 0;
2382 }
2383 
2391 template <class T, class A, class V> inline
2392 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>& x, const V* p )
2393 {
2394  x.Append( static_cast<const T*>( p ) );
2395  return x;
2396 }
2397 
2405 template <class T, class A, class V> inline
2406 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>&& x, const V* p )
2407 {
2408  x.Append( static_cast<const T*>( p ) );
2409  return x;
2410 }
2411 
2417 template <class T, class A> inline
2418 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>& x1, const ReferenceArray<T,A>& x2 )
2419 {
2420  x1.Append( x2 );
2421  return x1;
2422 }
2423 
2429 template <class T, class A> inline
2430 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>&& x1, const ReferenceArray<T,A>& x2 )
2431 {
2432  x1.Append( x2 );
2433  return x1;
2434 }
2435 
2436 // ----------------------------------------------------------------------------
2437 
2438 } // pcl
2439 
2440 #endif // __PCL_ReferenceArray_h
2441 
2442 // ----------------------------------------------------------------------------
2443 // EOF pcl/ReferenceArray.h - Released 2024-06-18T15:48:54Z
Provides memory allocation for PCL containers.
Definition: Allocator.h:132
Root base class of all PCL containers of objects.
Definition: Container.h:78
Generic dynamic array of pointers to objects.
Definition: IndirectArray.h:92
T *const * const_iterator
void Append(const IndirectArray &x)
Random access iterator class.
Definition: Iterator.h:94
Immutable ReferenceArray iterator.
const_iterator(const const_iterator &)=default
Immutable ReferenceArray reverse iterator.
Mutable ReferenceArray iterator.
iterator(const iterator &)=default
Mutable ReferenceArray reverse iterator.
Dynamic array of pointers to objects providing direct iteration and element access by reference.
iterator SearchLast(const T *p)
void CloneAssign(const C &x)
void Apply(F f) const
iterator Search(const T &v, BP p)
size_type Length() const
iterator Insert(const_iterator i, FI p, FI q)
const_iterator SearchSubset(const C &c) const
iterator ContainsSubset(FI i, FI j, BP p) const
iterator Insert(const_iterator i, const T *p, size_type n=1)
iterator At(size_type i)
reverse_iterator ReverseBegin()
void RemovePointer(const T *p)
void Remove(const T &v, BP p)
void Destroy(const T &v)
void Assign(const ReferenceArray &x)
void ShiftLeft(const T *p, size_type n=1)
const_iterator MaxItem() const
const_reverse_iterator ConstReverseBegin() const
ReferenceArray(FI i, FI j)
const_iterator ConstBegin() const
iterator Replace(const_iterator i, const_iterator j, const T *p, size_type n=1)
const_iterator SearchLastSubset(const C &c) const
iterator ContainsSubset(FI i, FI j) const
const_reverse_iterator ReverseEnd() const
const_iterator SearchSubset(FI i, FI j) const
void Transfer(ReferenceArray &&x)
size_type Size() const
const_reverse_iterator ConstReverseEnd() const
size_type Count(const T *p) const
void Destroy(iterator i, iterator j)
size_type Capacity() const
iterator MutableIterator(const_iterator i)
void Append(const T *p, size_type n=1)
void Destroy(iterator i, size_type n=1)
void Append(const ReferenceArray &x)
bool IsValid() const
void Assign(const T *p, size_type n=1)
iterator LastThat(F f)
iterator SearchSubset(const C &c, BP p)
const_iterator MinItem(BP p) const
const_iterator ConstEnd() const
typename array_implementation::iterator indirect_iterator
iterator Search(const T *p)
const_iterator Search(const T &v) const
const_iterator SearchLastSubset(const C &c, BP p) const
void UniquifyIterators(iterator &i, iterator &j)
void Prepend(const T *p, size_type n=1)
const_iterator MaxItem(BP p) const
void Add(FI i, FI j)
void Fill(const T &v)
uint32 Hash32(uint32 seed=0) const
size_type Count(const T &v) const
friend void Swap(ReferenceArray &x1, ReferenceArray &x2)
size_type CountIf(UP p) const
const_iterator Search(const T &v, BP p) const
void Destroy(const T &v, BP p)
bool Contains(const T *p) const
const_reverse_iterator ReverseBegin() const
const_iterator FirstThat(F f) const
const allocator & Allocator() const
iterator SearchLastSubset(BI i, BI j, BP p)
iterator SearchSubset(FI i, FI j, BP p)
const_iterator begin() const
void Assign(FI i, FI j)
size_type Available() const
reverse_iterator ReverseEnd()
iterator SearchLastSubset(BI i, BI j)
size_type Count(const T &v, BP p) const
iterator SearchLastSubset(const C &c, BP p)
const_iterator SearchLast(const T &v, BP p) const
iterator SearchLast(const T &v, BP p)
void RemoveFirst(size_type n=1)
void Reserve(size_type n)
bool Contains(const T &v) const
void Remove(const T &v)
const_iterator SearchLastSubset(BI i, BI j, BP p) const
uint64 Hash64(uint64 seed=0) const
void Remove(const_iterator i, const_iterator j)
const_iterator Begin() const
void ShiftRight(const T *p, size_type n=1)
const_iterator Search(const T *p) const
const_iterator MinItem() const
iterator ContainsSubset(const C &c, BP p) const
iterator FirstThat(F f)
bool IsEmpty() const
const_iterator SearchLastSubset(BI i, BI j) const
const_iterator End() const
bool Contains(const T &v, BP p) const
indirect_iterator Release()
void Add(const ReferenceArray &x)
const_iterator LastThat(F f) const
void Remove(const_iterator i, size_type n=1)
typename array_implementation::const_iterator const_indirect_iterator
void Add(const T *p, size_type n=1)
iterator MaxItem(BP p)
typename array_implementation::allocator allocator
const_iterator SearchLast(const T *p) const
iterator Replace(const_iterator i, const_iterator j, const ReferenceArray &x)
const_iterator SearchSubset(const C &c, BP p) const
ReferenceArray(size_type n, const T *p)
void UniquifyIterator(iterator &i)
ReferenceArray(ReferenceArray &&)=default
bool IsAliasOf(const ReferenceArray &x) const
const_iterator SearchLast(const T &v) const
size_type LowerBound() const
ReferenceArray()=default
void SetAllocator(const allocator &a)
const_iterator SearchSubset(FI i, FI j, BP p) const
void Prepend(const ReferenceArray &x)
iterator Insert(const_iterator i, const ReferenceArray &x)
void RemoveLast(size_type n=1)
void Shrink(size_type n=1)
bool IsUnique() const
const_iterator At(size_type i) const
uint64 Hash(uint64 seed=0) const
size_type UpperBound() const
void Prepend(FI p, FI q)
void Transfer(ReferenceArray &x)
void Append(FI p, FI q)
iterator Replace(const_iterator i, const_iterator j, FI p, FI q)
void Rotate(distance_type n)
iterator Search(const T &v)
typename array_implementation::block_allocator block_allocator
iterator SearchSubset(const C &c)
iterator MinItem(BP p)
iterator ContainsSubset(const C &c) const
const_iterator end() const
void Truncate(const_iterator i)
iterator SearchLastSubset(const C &c)
void Import(iterator i, iterator j)
iterator SearchSubset(FI i, FI j)
ReferenceArray(const ReferenceArray &)=default
iterator SearchLast(const T &v)
Reverse random access iterator.
Definition: Iterator.h:420
Array< T, A > & operator<<(Array< T, A > &x, const V &v)
Definition: Array.h:2295
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2267
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2278
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:504
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:548
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:464
uint64 Hash64(const void *data, size_type size, uint64 seed=0) noexcept
Definition: Math.h:4750
void Construct(T *p, A &a)
Definition: Allocator.h:247
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2) noexcept
Definition: Point.h:1459
unsigned long long uint64
Definition: Defs.h:682
unsigned int uint32
Definition: Defs.h:666
FI LinearSearch(FI i, FI j, const T &v) noexcept
Definition: Search.h:91
BI1 SearchLast(BI1 i1, BI1 j1, FI2 i2, FI2 j2) noexcept
Definition: Search.h:449
BI LinearSearchLast(BI i, BI j, const T &v) noexcept
Definition: Search.h:129
FI1 Search(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
Definition: Search.h:397
ptrdiff_t distance_type
Definition: Defs.h:615
size_t size_type
Definition: Defs.h:609
void QuickSort(RI i, RI j)
Definition: Sort.h:236
size_type CountIf(FI i, FI j, UP p) noexcept(noexcept(p))
Definition: Utility.h:423
BI LastThat(BI i, BI j, UP p) noexcept(noexcept(p))
Definition: Utility.h:350
size_type Count(FI i, FI j, const T &v) noexcept
Definition: Utility.h:384
FI MinItem(FI i, FI j) noexcept
Definition: Utility.h:441
bool Equal(FI1 i1, FI2 i2, FI2 j2) noexcept
Definition: Utility.h:592
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2) noexcept
Definition: Utility.h:639
FI MaxItem(FI i, FI j) noexcept
Definition: Utility.h:479
void Apply(FI i, FI j, F f) noexcept(noexcept(f))
Definition: Utility.h:249
FI FirstThat(FI i, FI j, UP p) noexcept(noexcept(p))
Definition: Utility.h:316
PCL root namespace.
Definition: AbstractImage.h:77
Generic container iterator.
Definition: Iterator.h:105
T item_type
Represents the item type.
Definition: Iterator.h:107