PCL
ReferenceArray.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.5
6 // ----------------------------------------------------------------------------
7 // pcl/ReferenceArray.h - Released 2024-12-28T16:53:48Z
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 
122 
126 
130 
135  class iterator : public Iterator<RandomAccessIterator, T>
136  {
137  public:
138 
140  using iterator_class = typename iterator_base::iterator_class;
141  using item_type = typename iterator_base::item_type;
142 
146  iterator() = default;
147 
151  iterator( const iterator& ) = default;
152 
156  iterator( std::nullptr_t ) : it( nullptr )
157  {
158  }
159 
163  iterator& operator =( const iterator& ) = default;
164 
168  T* Pointer() const
169  {
170  return *it;
171  }
172 
177  operator T*() const
178  {
179  return *it;
180  }
181 
186  T& operator *() const
187  {
188  return **it;
189  }
190 
195  T* operator ->() const
196  {
197  return *it;
198  }
199 
205  iterator& operator ++()
206  {
207  ++it;
208  return *this;
209  }
210 
216  iterator operator ++( int )
217  {
218  indirect_iterator it0 = it;
219  ++it;
220  return it0;
221  }
222 
228  iterator& operator --()
229  {
230  --it;
231  return *this;
232  }
233 
239  iterator operator --( int )
240  {
241  indirect_iterator it0 = it;
242  --it;
243  return it0;
244  }
245 
253  iterator& operator +=( distance_type d )
254  {
255  it += d;
256  return *this;
257  }
258 
266  iterator& operator -=( distance_type d )
267  {
268  it -= d;
269  return *this;
270  }
271 
277  {
278  return iterator( it + d );
279  }
280 
286  {
287  return iterator( it - d );
288  }
289 
295  {
296  return it - i.it;
297  }
298 
303  bool operator ==( const iterator& i ) const
304  {
305  return it == i.it;
306  }
307 
312  bool operator <( const iterator& i ) const
313  {
314  return it < i.it;
315  }
316 
317  private:
318 
319  indirect_iterator it = nullptr;
320 
325  explicit
326  iterator( indirect_iterator i ) : it( i )
327  {
328  }
329 
330  friend class ReferenceArray<T,A>;
331  friend class ReferenceArray<T,A>::const_iterator;
332  };
333 
338  class const_iterator : public Iterator<RandomAccessIterator, T>
339  {
340  public:
341 
343  using iterator_class = typename iterator_base::iterator_class;
344  using item_type = typename iterator_base::item_type;
345 
349  const_iterator() = default;
350 
354  const_iterator( const iterator& i ) : it( i.it )
355  {
356  }
357 
361  const_iterator( std::nullptr_t ) : it( nullptr )
362  {
363  }
364 
368  const_iterator( const const_iterator& ) = default;
369 
374  const_iterator& operator =( const const_iterator& ) = default;
375 
380  const_iterator& operator =( const iterator& i )
381  {
382  it = i.it;
383  return *this;
384  }
385 
389  const T* Pointer() const
390  {
391  return *it;
392  }
393 
398  operator const T*() const
399  {
400  return *it;
401  }
402 
407  const T& operator *() const
408  {
409  return **it;
410  }
411 
416  const T* operator ->() const
417  {
418  return *it;
419  }
420 
426  const_iterator& operator ++()
427  {
428  ++it;
429  return *this;
430  }
431 
437  const_iterator operator ++( int )
438  {
439  const_indirect_iterator it0 = it;
440  ++it;
441  return it0;
442  }
443 
449  const_iterator& operator --()
450  {
451  --it;
452  return *this;
453  }
454 
460  const_iterator operator --( int )
461  {
462  const_indirect_iterator it0 = it;
463  --it;
464  return it0;
465  }
466 
474  const_iterator& operator +=( distance_type d )
475  {
476  it += d;
477  return *this;
478  }
479 
487  const_iterator& operator -=( distance_type d )
488  {
489  it -= d;
490  return *this;
491  }
492 
498  {
499  return const_iterator( it + d );
500  }
501 
507  {
508  return const_iterator( it - d );
509  }
510 
516  {
517  return it - i.it;
518  }
519 
525  {
526  return it - i.it;
527  }
528 
533  bool operator ==( const const_iterator& i ) const
534  {
535  return it == i.it;
536  }
537 
542  bool operator ==( const iterator& i ) const
543  {
544  return it == i.it;
545  }
546 
551  bool operator <( const const_iterator& i ) const
552  {
553  return it < i.it;
554  }
555 
560  bool operator <( const iterator& i ) const
561  {
562  return it < i.it;
563  }
564 
565  private:
566 
567  const_indirect_iterator it = nullptr;
568 
573  explicit
575  {
576  }
577 
578  friend class ReferenceArray<T,A>;
579  };
580 
585  using reverse_iterator = ReverseRandomAccessIterator<iterator, T>;
586 
591  using const_reverse_iterator = ReverseRandomAccessIterator<const_iterator, const T>;
592 
593  // -------------------------------------------------------------------------
594 
598  ReferenceArray() = default;
599 
606  ReferenceArray( size_type n, const T* p )
607  {
608  PCL_PRECONDITION( p != nullptr )
609  if ( p != nullptr )
610  m_array = array_implementation( n, p );
611  }
612 
620  template <class FI>
621  ReferenceArray( FI i, FI j )
622  {
623  for ( ; i != j; ++i )
624  if ( *i != nullptr )
625  m_array.Append( *i );
626  }
627 
631  ReferenceArray( const ReferenceArray& ) = default;
632 
637 
646  {
647  }
648 
653  bool IsUnique() const
654  {
655  return m_array.IsUnique();
656  }
657 
664  bool IsAliasOf( const ReferenceArray& x ) const
665  {
666  return m_array.IsAliasOf( x.m_array );
667  }
668 
678  {
679  m_array.EnsureUnique();
680  }
681 
686  size_type Size() const
687  {
688  return m_array.Size();
689  }
690 
695  {
696  return m_array.Length();
697  }
698 
705  {
706  return m_array.Capacity();
707  }
708 
717  {
718  return m_array.Available();
719  }
720 
736  bool IsValid() const
737  {
738  return m_array.IsValid();
739  }
740 
744  bool IsEmpty() const
745  {
746  return m_array.IsEmpty();
747  }
748 
754  {
755  return m_array.LowerBound();
756  }
757 
763  {
764  return m_array.UpperBound();
765  }
766 
770  const allocator& Allocator() const
771  {
772  return m_array.Allocator();
773  }
774 
778  void SetAllocator( const allocator& a )
779  {
780  m_array.SetAllocator( a );
781  }
782 
788  {
789  return iterator( m_array.At( i ) );
790  }
791 
797  {
798  return const_iterator( m_array.At( i ) );
799  }
800 
812  {
813  return iterator( m_array.MutableIterator( i.it ) );
814  }
815 
820  T& operator []( size_type i )
821  {
822  return *m_array[i];
823  }
824 
829  const T& operator []( size_type i ) const
830  {
831  return *m_array[i];
832  }
833 
838  {
839  return **m_array.Begin();
840  }
841 
846  const T& operator *() const
847  {
848  return **m_array.Begin();
849  }
850 
855  {
856  return iterator( m_array.Begin() );
857  }
858 
863  {
864  return const_iterator( m_array.Begin() );
865  }
866 
871  {
872  return const_iterator( m_array.ConstBegin() );
873  }
874 
879  {
880  return iterator( m_array.End() );
881  }
882 
887  {
888  return const_iterator( m_array.End() );
889  }
890 
895  {
896  return const_iterator( m_array.ConstEnd() );
897  }
898 
906  {
907  return iterator( m_array.End()-1 );
908  }
909 
917  {
918  return const_iterator( m_array.End()-1 );
919  }
920 
928  {
929  PCL_PRECONDITION( !IsEmpty() )
930  return const_iterator( m_array.End()-1 );
931  }
932 
941  {
942  PCL_PRECONDITION( !IsEmpty() )
943  return iterator( m_array.Begin()-1 );
944  }
945 
954  {
955  PCL_PRECONDITION( !IsEmpty() )
956  return const_iterator( m_array.Begin()-1 );
957  }
958 
967  {
968  PCL_PRECONDITION( !IsEmpty() )
969  return const_iterator( m_array.Begin()-1 );
970  }
971 
976  T& First()
977  {
978  return **m_array.Begin();
979  }
980 
985  const T& First() const
986  {
987  return **m_array.Begin();
988  }
989 
994  T& Last()
995  {
996  return **m_array.ReverseBegin();
997  }
998 
1003  const T& Last() const
1004  {
1005  return **m_array.ReverseBegin();
1006  }
1007 
1018  {
1019  m_array.UniquifyIterator( i.it );
1020  }
1021 
1033  {
1034  m_array.UniquifyIterators( i.it, j.it );
1035  }
1036 
1037 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
1042  {
1043  return Begin();
1044  }
1045 
1050  {
1051  return Begin();
1052  }
1053 
1058  {
1059  return End();
1060  }
1061 
1066  {
1067  return End();
1068  }
1069 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
1070 
1077  ReferenceArray& operator =( const ReferenceArray& x )
1078  {
1079  Assign( x );
1080  return *this;
1081  }
1082 
1092  void Assign( const ReferenceArray& x )
1093  {
1094  m_array.Assign( x.m_array );
1095  }
1096 
1100  ReferenceArray& operator =( ReferenceArray&& x )
1101  {
1102  Transfer( x );
1103  return *this;
1104  }
1105 
1116  {
1117  m_array.Transfer( x.m_array );
1118  }
1119 
1130  {
1131  m_array.Transfer( std::move( x.m_array ) );
1132  }
1133 
1140  void Assign( const T* p, size_type n = 1 )
1141  {
1142  if ( p != nullptr )
1143  m_array.Assign( p, n );
1144  else
1145  m_array.Clear();
1146  }
1147 
1157  template <class FI>
1158  void Assign( FI i, FI j )
1159  {
1160  m_array.Clear();
1161  for ( ; i != j; ++i )
1162  if ( *i != nullptr )
1163  m_array.Append( *i );
1164  }
1165 
1176  template <class C>
1177  void CloneAssign( const C& x )
1178  {
1179  PCL_ASSERT_CONTAINER( C, T );
1180  CloneObjects( x, (C*)nullptr );
1181  }
1182 
1188  void Import( iterator i, iterator j )
1189  {
1190  m_array.Import( i.it, j.it );
1191  }
1192 
1205  {
1206  return m_array.Release();
1207  }
1208 
1221  {
1222  return iterator( m_array.Insert( i.it, x.m_array ) );
1223  }
1224 
1236  iterator Insert( const_iterator i, const T* p, size_type n = 1 )
1237  {
1238  return (p != nullptr) ? iterator( m_array.Insert( i.it, p, n ) ) :
1239  iterator( const_cast<indirect_iterator>( i.it ) );
1240  }
1241 
1256  template <class FI>
1257  iterator Insert( const_iterator i, FI p, FI q )
1258  {
1259  const_indirect_iterator it = i.it;
1260  for ( ; p != q; ++p )
1261  if ( *p != nullptr )
1262  it = m_array.Insert( it, *p );
1263  return iterator( const_cast<indirect_iterator>( it ) );
1264  }
1265 
1270  void Append( const ReferenceArray& x )
1271  {
1272  m_array.Append( x.m_array );
1273  }
1274 
1281  void Append( const T* p, size_type n = 1 )
1282  {
1283  if ( p != nullptr )
1284  m_array.Append( p, n );
1285  }
1286 
1296  template <class FI>
1297  void Append( FI p, FI q )
1298  {
1299  for ( ; p != q; ++p )
1300  if ( *p != nullptr )
1301  m_array.Append( *p );
1302  }
1303 
1308  void Prepend( const ReferenceArray& x )
1309  {
1310  m_array.Prepend( x.m_array );
1311  }
1312 
1319  void Prepend( const T* p, size_type n = 1 )
1320  {
1321  if ( p != nullptr )
1322  m_array.Prepend( p, n );
1323  }
1324 
1334  template <class FI>
1335  void Prepend( FI p, FI q )
1336  {
1337  for ( ; p != q; ++p )
1338  if ( *p != nullptr )
1339  m_array.Prepend( *p );
1340  }
1341 
1345  void Add( const ReferenceArray& x )
1346  {
1347  Append( x );
1348  }
1349 
1353  void Add( const T* p, size_type n = 1 )
1354  {
1355  Append( p, n );
1356  }
1357 
1361  template <class FI>
1362  void Add( FI i, FI j )
1363  {
1364  Append( i, j );
1365  }
1366 
1375  {
1376  m_array.Remove( i.it, n );
1377  }
1378 
1387  {
1388  m_array.Remove( i.it, j.it );
1389  }
1390 
1403  void RemoveFirst( size_type n = 1 )
1404  {
1405  m_array.RemoveFirst( n );
1406  }
1407 
1420  void RemoveLast( size_type n = 1 )
1421  {
1422  m_array.RemoveLast( n );
1423  }
1424 
1439  {
1440  m_array.Truncate( i.it );
1441  }
1442 
1447  void Shrink( size_type n = 1 )
1448  {
1449  m_array.Shrink( n );
1450  }
1451 
1459  void Remove( const T& v )
1460  {
1461  m_array.Remove( v );
1462  }
1463 
1471  template <class BP>
1472  void Remove( const T& v, BP p )
1473  {
1474  m_array.Remove( v, p );
1475  }
1476 
1483  void RemovePointer( const T* p )
1484  {
1485  m_array.Remove( p );
1486  }
1487 
1502  void Clear()
1503  {
1504  m_array.Clear();
1505  }
1506 
1518  void Destroy( iterator i, size_type n = 1 )
1519  {
1520  m_array.Destroy( i.it, n );
1521  }
1522 
1542  {
1543  m_array.Destroy( i.it, j.it );
1544  }
1545 
1556  void Destroy( const T& v )
1557  {
1558  m_array.Destroy( v );
1559  }
1560 
1572  template <class BP>
1573  void Destroy( const T& v, BP p )
1574  {
1575  m_array.Destroy( v, p );
1576  }
1577 
1585  void Destroy()
1586  {
1587  m_array.Destroy();
1588  }
1589 
1604  {
1605  return iterator( m_array.Replace( i.it, j.it, x.m_array ) );
1606  }
1607 
1617  {
1618  return iterator( m_array.Replace( i.it, j.it, p, (p != nullptr) ? n : size_type( 0 ) ) );
1619  }
1620 
1638  template <class FI>
1640  {
1642  for ( ; p != q; ++p )
1643  if ( *p != nullptr )
1644  m.Append( *p );
1645  return iterator( m_array.Replace( i.it, j.it, m ) );
1646  }
1647 
1655  void Reserve( size_type n )
1656  {
1657  m_array.Reserve( n );
1658  }
1659 
1672  void Squeeze()
1673  {
1674  m_array.Squeeze();
1675  }
1676 
1680  void Fill( const T& v )
1681  {
1682  pcl::Fill( Begin(), End(), v );
1683  }
1684 
1689  template <class F>
1690  void Apply( F f )
1691  {
1692  pcl::Apply( Begin(), End(), f );
1693  }
1694 
1699  template <class F>
1700  void Apply( F f ) const
1701  {
1702  pcl::Apply( Begin(), End(), f );
1703  }
1704 
1710  template <class F>
1712  {
1713  return const_iterator( pcl::FirstThat( Begin(), End(), f ).it );
1714  }
1715 
1721  template <class F>
1723  {
1724  return iterator( pcl::FirstThat( Begin(), End(), f ).it );
1725  }
1726 
1732  template <class F>
1734  {
1735  return const_iterator( pcl::LastThat( Begin(), End(), f ).it );
1736  }
1737 
1743  template <class F>
1745  {
1746  return iterator( pcl::LastThat( Begin(), End(), f ).it );
1747  }
1748 
1752  size_type Count( const T& v ) const
1753  {
1754  return pcl::Count( Begin(), End(), v );
1755  }
1756 
1764  size_type Count( const T* p ) const
1765  {
1766  return m_array.Count( p );
1767  }
1768 
1773  template <class BP>
1774  size_type Count( const T& v, BP p ) const
1775  {
1776  return pcl::Count( Begin(), End(), v, p );
1777  }
1778 
1783  template <class UP>
1784  size_type CountIf( UP p ) const
1785  {
1786  return pcl::CountIf( Begin(), End(), p );
1787  }
1788 
1792  {
1793  return const_iterator( pcl::MinItem( Begin(), End() ).it );
1794  }
1795 
1799  {
1800  return iterator( pcl::MinItem( Begin(), End() ).it );
1801  }
1802 
1805  template <class BP>
1806  const_iterator MinItem( BP p ) const
1807  {
1808  return const_iterator( pcl::MinItem( Begin(), End(), p ).it );
1809  }
1810 
1813  template <class BP>
1815  {
1816  return iterator( pcl::MinItem( Begin(), End(), p ).it );
1817  }
1818 
1822  {
1823  return const_iterator( pcl::MaxItem( Begin(), End() ).it );
1824  }
1825 
1829  {
1830  return iterator( pcl::MaxItem( Begin(), End() ).it );
1831  }
1832 
1835  template <class BP>
1836  const_iterator MaxItem( BP p ) const
1837  {
1838  return const_iterator( pcl::MaxItem( Begin(), End(), p ).it );
1839  }
1840 
1843  template <class BP>
1845  {
1846  return iterator( pcl::MaxItem( Begin(), End(), p ).it );
1847  }
1848 
1851  void Reverse()
1852  {
1853  m_array.Reverse();
1854  }
1855 
1859  {
1860  m_array.Rotate( n );
1861  }
1862 
1865  void ShiftLeft( const T* p, size_type n = 1 )
1866  {
1867  m_array.ShiftLeft( p, n );
1868  }
1869 
1872  void ShiftRight( const T* p, size_type n = 1 )
1873  {
1874  m_array.ShiftRight( p, n );
1875  }
1876 
1879  const_iterator Search( const T& v ) const
1880  {
1881  return const_iterator( pcl::LinearSearch( Begin(), End(), v ).it );
1882  }
1883 
1886  iterator Search( const T& v )
1887  {
1888  return iterator( pcl::LinearSearch( Begin(), End(), v ).it );
1889  }
1890 
1893  const_iterator Search( const T* p ) const
1894  {
1895  return const_iterator( m_array.Search( p ) );
1896  }
1897 
1900  iterator Search( const T* p )
1901  {
1902  return iterator( m_array.Search( p ) );
1903  }
1904 
1907  template <class BP>
1908  const_iterator Search( const T& v, BP p ) const
1909  {
1910  return const_iterator( pcl::LinearSearch( Begin(), End(), v, p ).it );
1911  }
1912 
1915  template <class BP>
1916  iterator Search( const T& v, BP p )
1917  {
1918  return iterator( pcl::LinearSearch( Begin(), End(), v, p ).it );
1919  }
1920 
1923  const_iterator SearchLast( const T& v ) const
1924  {
1925  return const_iterator( pcl::LinearSearchLast( Begin(), End(), v ).it );
1926  }
1927 
1930  iterator SearchLast( const T& v )
1931  {
1932  return iterator( pcl::LinearSearchLast( Begin(), End(), v ).it );
1933  }
1934 
1937  const_iterator SearchLast( const T* p ) const
1938  {
1939  return const_iterator( m_array.SearchLast( p ) );
1940  }
1941 
1944  iterator SearchLast( const T* p )
1945  {
1946  return iterator( m_array.SearchLast( p ) );
1947  }
1948 
1951  template <class BP>
1952  const_iterator SearchLast( const T& v, BP p ) const
1953  {
1954  return const_iterator( pcl::LinearSearchLast( Begin(), End(), v, p ).it );
1955  }
1956 
1959  template <class BP>
1960  iterator SearchLast( const T& v, BP p )
1961  {
1962  return iterator( pcl::LinearSearchLast( Begin(), End(), v, p ).it );
1963  }
1964 
1967  template <class FI>
1968  const_iterator SearchSubset( FI i, FI j ) const
1969  {
1970  return const_iterator( pcl::Search( Begin(), End(), i, j ).it );
1971  }
1972 
1975  template <class FI>
1976  iterator SearchSubset( FI i, FI j )
1977  {
1978  return iterator( pcl::Search( Begin(), End(), i, j ).it );
1979  }
1980 
1983  template <class FI, class BP>
1984  const_iterator SearchSubset( FI i, FI j, BP p ) const
1985  {
1986  return const_iterator( pcl::Search( Begin(), End(), i, j, p ).it );
1987  }
1988 
1991  template <class FI, class BP>
1992  iterator SearchSubset( FI i, FI j, BP p )
1993  {
1994  return iterator( pcl::Search( Begin(), End(), i, j, p ).it );
1995  }
1996 
1999  template <class C>
2000  const_iterator SearchSubset( const C& c ) const
2001  {
2002  return const_iterator( pcl::Search( Begin(), End(), c.Begin(), c.End() ).it );
2003  }
2004 
2007  template <class C>
2008  iterator SearchSubset( const C& c )
2009  {
2010  return iterator( pcl::Search( Begin(), End(), c.Begin(), c.End() ).it );
2011  }
2012 
2015  template <class C, class BP>
2016  const_iterator SearchSubset( const C& c, BP p ) const
2017  {
2018  return const_iterator( pcl::Search( Begin(), End(), c.Begin(), c.End(), p ).it );
2019  }
2020 
2023  template <class C, class BP>
2024  iterator SearchSubset( const C& c, BP p )
2025  {
2026  return iterator( pcl::Search( Begin(), End(), c.Begin(), c.End(), p ).it );
2027  }
2028 
2031  template <class BI>
2032  const_iterator SearchLastSubset( BI i, BI j ) const
2033  {
2034  return const_iterator( pcl::SearchLast( Begin(), End(), i, j ).it );
2035  }
2036 
2039  template <class BI>
2041  {
2042  return iterator( pcl::SearchLast( Begin(), End(), i, j ).it );
2043  }
2044 
2047  template <class BI, class BP>
2048  const_iterator SearchLastSubset( BI i, BI j, BP p ) const
2049  {
2050  return const_iterator( pcl::SearchLast( Begin(), End(), i, j, p ).it );
2051  }
2052 
2055  template <class BI, class BP>
2056  iterator SearchLastSubset( BI i, BI j, BP p )
2057  {
2058  return iterator( pcl::SearchLast( Begin(), End(), i, j, p ).it );
2059  }
2060 
2063  template <class C>
2064  const_iterator SearchLastSubset( const C& c ) const
2065  {
2066  return const_iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End() ).it );
2067  }
2068 
2071  template <class C>
2073  {
2074  return iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End() ).it );
2075  }
2076 
2079  template <class C, class BP>
2080  const_iterator SearchLastSubset( const C& c, BP p ) const
2081  {
2082  return const_iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), p ).it );
2083  }
2084 
2087  template <class C, class BP>
2088  iterator SearchLastSubset( const C& c, BP p )
2089  {
2090  return iterator( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), p ).it );
2091  }
2092 
2095  bool Contains( const T& v ) const
2096  {
2097  return Search( v ) != End();
2098  }
2099 
2102  bool Contains( const T* p ) const
2103  {
2104  return m_array.Contains( p );
2105  }
2106 
2109  template <class BP>
2110  bool Contains( const T& v, BP p ) const
2111  {
2112  return Search( v, p ) != End();
2113  }
2114 
2117  template <class FI>
2118  iterator ContainsSubset( FI i, FI j ) const
2119  {
2120  return SearchSubset( i, j ) != End();
2121  }
2122 
2125  template <class FI, class BP>
2126  iterator ContainsSubset( FI i, FI j, BP p ) const
2127  {
2128  return SearchSubset( i, j, p ) != End();
2129  }
2130 
2133  template <class C>
2134  iterator ContainsSubset( const C& c ) const
2135  {
2136  return m_array.ContainsSubset( c );
2137  }
2138 
2141  template <class C, class BP>
2142  iterator ContainsSubset( const C& c, BP p ) const
2143  {
2144  return SearchSubset( c ) != End();
2145  }
2146 
2149  void Sort()
2150  {
2151  pcl::QuickSort( m_array.Begin(), m_array.End(),
2152  []( const T* a, const T* b ){ return *a < *b; } );
2153  }
2154 
2157  template <class BP>
2158  void Sort( BP p )
2159  {
2160  pcl::QuickSort( m_array.Begin(), m_array.End(),
2161  [p]( const T* a, const T* b ){ return p( *a, *b ); } );
2162  }
2163 
2167  friend void Swap( ReferenceArray& x1, ReferenceArray& x2 )
2168  {
2169  pcl::Swap( x1.m_array, x2.m_array );
2170  }
2171 
2188  template <class S, typename SP>
2189  S& ToSeparated( S& s, SP separator ) const
2190  {
2191  const_iterator i = Begin();
2192  if ( i < End() )
2193  {
2194  s.Append( S( *i ) );
2195  if ( ++i < End() )
2196  do
2197  {
2198  s.Append( separator );
2199  s.Append( S( *i ) );
2200  }
2201  while ( ++i < End() );
2202  }
2203  return s;
2204  }
2205 
2228  template <class S, typename SP, class AF>
2229  S& ToSeparated( S& s, SP separator, AF append ) const
2230  {
2231  const_iterator i = Begin();
2232  if ( i < End() )
2233  {
2234  append( s, S( *i ) );
2235  if ( ++i < End() )
2236  {
2237  S p( separator );
2238  do
2239  {
2240  append( s, p );
2241  append( s, S( *i ) );
2242  }
2243  while ( ++i < End() );
2244  }
2245  }
2246  return s;
2247  }
2248 
2257  template <class S>
2258  S& ToCommaSeparated( S& s ) const
2259  {
2260  return ToSeparated( s, ',' );
2261  }
2262 
2271  template <class S>
2272  S& ToSpaceSeparated( S& s ) const
2273  {
2274  return ToSeparated( s, ' ' );
2275  }
2276 
2285  template <class S>
2286  S& ToTabSeparated( S& s ) const
2287  {
2288  return ToSeparated( s, '\t' );
2289  }
2290 
2299  template <class S>
2300  S& ToNewLineSeparated( S& s ) const
2301  {
2302  return ToSeparated( s, '\n' );
2303  }
2304 
2315  uint64 Hash64( uint64 seed = 0 ) const
2316  {
2317  return m_array.Hash64( seed );
2318  }
2319 
2330  uint32 Hash32( uint32 seed = 0 ) const
2331  {
2332  return m_array.Hash32( seed );
2333  }
2334 
2339  uint64 Hash( uint64 seed = 0 ) const
2340  {
2341  return Hash64( seed );
2342  }
2343 
2344 private:
2345 
2346  array_implementation m_array;
2347 
2348  template <class C>
2349  void CloneObjects( const C& x, DirectContainer<T>* )
2350  {
2351  m_array.CloneAssign( x );
2352  }
2353 
2354  template <class C>
2355  void CloneObjects( const C& x, IndirectContainer<T>* )
2356  {
2357  m_array.Clear();
2358  m_array.Reserve( x.Length() );
2359  allocator a;
2360  for ( typename C::const_iterator p = x.Begin(); p != x.End(); ++p )
2361  if ( *p != nullptr )
2362  {
2363  T* o = a.Allocate( 1 );
2364  pcl::Construct( o, **p, a );
2365  m_array.Append( o );
2366  }
2367  }
2368 };
2369 
2370 // ----------------------------------------------------------------------------
2371 
2378 template <class T, class A> inline
2380 {
2381  return x1.Length() == x2.Length() && pcl::Equal( x1.Begin(), x2.Begin(), x2.End() );
2382 }
2383 
2390 template <class T, class A> inline
2392 {
2393  return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End() ) < 0;
2394 }
2395 
2403 template <class T, class A, class V> inline
2404 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>& x, const V* p )
2405 {
2406  x.Append( static_cast<const T*>( p ) );
2407  return x;
2408 }
2409 
2417 template <class T, class A, class V> inline
2418 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>&& x, const V* p )
2419 {
2420  x.Append( static_cast<const T*>( p ) );
2421  return x;
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 
2441 template <class T, class A> inline
2442 ReferenceArray<T,A>& operator <<( ReferenceArray<T,A>&& x1, const ReferenceArray<T,A>& x2 )
2443 {
2444  x1.Append( x2 );
2445  return x1;
2446 }
2447 
2448 // ----------------------------------------------------------------------------
2449 
2450 } // pcl
2451 
2452 #endif // __PCL_ReferenceArray_h
2453 
2454 // ----------------------------------------------------------------------------
2455 // EOF pcl/ReferenceArray.h - Released 2024-12-28T16:53:48Z
Provides memory allocation for PCL containers.
Definition: Allocator.h:132
Root base class of all PCL containers of objects.
Definition: Container.h:78
const T const_item_type
Definition: Container.h:89
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:2313
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2285
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2) noexcept
Definition: Array.h:2296
Complex< T1 > operator-(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:518
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:562
Complex< T1 > operator+(const Complex< T1 > &c1, const Complex< T2 > &c2) noexcept
Definition: Complex.h:478
uint64 Hash64(const void *data, size_type size, uint64 seed=0) noexcept
Definition: Math.h:4830
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