PCL
IndirectArray.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/IndirectArray.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_IndirectArray_h
53 #define __PCL_IndirectArray_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/Array.h>
61 #include <pcl/Indirect.h>
62 
63 namespace pcl
64 {
65 
66 // ----------------------------------------------------------------------------
67 
90 template <class T, class A = StandardAllocator>
91 class PCL_CLASS IndirectArray : public IndirectContainer<T>
92 {
93 public:
94 
97  using block_allocator = A;
98 
102 
105  using iterator = T**;
106 
109  using const_iterator = T* const*;
110 
114 
118 
122 
126 
130 
134 
138 
139  // -------------------------------------------------------------------------
140 
144  IndirectArray() = default;
145 
150  explicit
152  {
153  m_array.Append( (void*)nullptr, n );
154  }
155 
159  IndirectArray( size_type n, const T* p )
160  {
161  m_array.Append( (void*)p, n );
162  }
163 
168  template <class FI>
169  IndirectArray( FI i, FI j )
170  : m_array( i, j )
171  {
172  }
173 
177  IndirectArray( const IndirectArray& ) = default;
178 
182  IndirectArray( IndirectArray&& ) = default;
183 
192  {
193  }
194 
199  bool IsUnique() const
200  {
201  return m_array.IsUnique();
202  }
203 
211  bool IsAliasOf( const IndirectArray& x ) const
212  {
213  return m_array.IsAliasOf( x.m_array );
214  }
215 
225  {
226  m_array.EnsureUnique();
227  }
228 
233  size_type Size() const
234  {
235  return m_array.Size();
236  }
237 
242  {
243  return m_array.Length();
244  }
245 
252  {
253  return m_array.Capacity();
254  }
255 
264  {
265  return m_array.Available();
266  }
267 
283  bool IsValid() const
284  {
285  return m_array.IsValid();
286  }
287 
291  bool IsEmpty() const
292  {
293  return m_array.IsEmpty();
294  }
295 
301  {
302  return m_array.LowerBound();
303  }
304 
310  {
311  return m_array.UpperBound();
312  }
313 
317  const allocator& Allocator() const
318  {
319  return m_array.Allocator();
320  }
321 
325  void SetAllocator( const allocator& a )
326  {
327  m_array.SetAllocator( a );
328  }
329 
334  {
335  return iterator( m_array.At( i ) );
336  }
337 
342  {
343  return const_iterator( m_array.At( i ) );
344  }
345 
357  {
358  return iterator( m_array.MutableIterator( (const_array_iterator)i ) );
359  }
360 
365  T*& operator []( size_type i )
366  {
367  return (T*&)m_array[i];
368  }
369 
374  const T* operator []( size_type i ) const
375  {
376  return (const T*)m_array[i];
377  }
378 
383  {
384  return (T*&)*Begin();
385  }
386 
391  const T* operator *() const
392  {
393  return (T*)*Begin();
394  }
395 
400  {
401  return iterator( m_array.Begin() );
402  }
403 
408  {
409  return const_iterator( m_array.Begin() );
410  }
411 
416  {
417  return const_iterator( m_array.ConstBegin() );
418  }
419 
424  {
425  return iterator( m_array.End() );
426  }
427 
432  {
433  return const_iterator( m_array.End() );
434  }
435 
440  {
441  return const_iterator( m_array.ConstEnd() );
442  }
443 
451  {
452  return iterator( (array_iterator)m_array.ReverseBegin() );
453  }
454 
462  {
463  return const_iterator( (const_array_iterator)m_array.ReverseBegin() );
464  }
465 
473  {
474  return const_iterator( (const_array_iterator)m_array.ConstReverseBegin() );
475  }
476 
485  {
486  return iterator( (array_iterator)m_array.ReverseEnd() );
487  }
488 
497  {
498  return const_iterator( (const_array_iterator)m_array.ReverseEnd() );
499  }
500 
509  {
510  return const_iterator( (const_array_iterator)m_array.ConstReverseEnd() );
511  }
512 
517  T* First()
518  {
519  return IsEmpty() ? nullptr : *Begin();
520  }
521 
526  const T* First() const
527  {
528  return IsEmpty() ? nullptr : *Begin();
529  }
530 
535  T* Last()
536  {
537  return IsEmpty() ? nullptr : *ReverseBegin();
538  }
539 
544  const T* Last() const
545  {
546  return IsEmpty() ? nullptr : *ReverseBegin();
547  }
548 
558  {
559  m_array.UniquifyIterator( (array_iterator&)i );
560  }
561 
572  {
573  m_array.UniquifyIterators( (array_iterator&)i, (array_iterator&)j );
574  }
575 
576 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
581  {
582  return Begin();
583  }
584 
589  {
590  return Begin();
591  }
592 
597  {
598  return End();
599  }
600 
605  {
606  return End();
607  }
608 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
609 
616  IndirectArray& operator =( const IndirectArray& x )
617  {
618  Assign( x );
619  return *this;
620  }
621 
631  void Assign( const IndirectArray& x )
632  {
633  m_array.Assign( x.m_array );
634  }
635 
639  IndirectArray& operator =( IndirectArray&& x )
640  {
641  Transfer( x );
642  return *this;
643  }
644 
655  {
656  m_array.Transfer( x.m_array );
657  }
658 
669  {
670  m_array.Transfer( x.m_array );
671  }
672 
677  void Assign( const T* p, size_type n = 1 )
678  {
679  m_array.Assign( (void*)p, n );
680  }
681 
688  template <class FI>
689  void Assign( FI i, FI j )
690  {
691  m_array.Assign( i, j );
692  }
693 
705  template <class C>
706  void CloneAssign( const C& x )
707  {
708  PCL_ASSERT_CONTAINER( C, T );
709  CloneObjects( x, (C*)nullptr );
710  }
711 
718  void Import( iterator i, iterator j )
719  {
720  m_array.Import( (array_iterator)i, (array_iterator)j );
721  }
722 
735  {
736  return iterator( m_array.Release() );
737  }
738 
750  {
751  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), (void*)nullptr, n ) );
752  }
753 
764  {
765  return Grow( ConstEnd(), n );
766  }
767 
772  void Shrink( size_type n = 1 )
773  {
774  m_array.Shrink( n );
775  }
776 
792  void Resize( size_type n )
793  {
794  size_type l = Length();
795  if ( n > l )
796  Expand( n - l );
797  else
798  Shrink( l - n );
799  }
800 
813  {
814  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), x.m_array ) );
815  }
816 
827  iterator Insert( const_iterator i, const T* p, size_type n = 1 )
828  {
829  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), (void*)p, n ) );
830  }
831 
844  template <class FI>
845  iterator Insert( const_iterator i, FI p, FI q )
846  {
847  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), p, q ) );
848  }
849 
854  void Append( const IndirectArray& x )
855  {
856  m_array.Append( x.m_array );
857  }
858 
863  void Append( const T* p, size_type n = 1 )
864  {
865  m_array.Append( (void*)p, n );
866  }
867 
874  template <class FI>
875  void Append( FI p, FI q )
876  {
877  m_array.Append( p, q );
878  }
879 
884  void Prepend( const IndirectArray& x )
885  {
886  m_array.Prepend( x.m_array );
887  }
888 
893  void Prepend( const T* p, size_type n = 1 )
894  {
895  m_array.Prepend( (void*)p, n );
896  }
897 
904  template <class FI>
905  void Prepend( FI p, FI q )
906  {
907  m_array.Prepend( p, q );
908  }
909 
913  void Add( const IndirectArray& x )
914  {
915  Append( x );
916  }
917 
921  void Add( const T* p, size_type n = 1 )
922  {
923  Append( p, n );
924  }
925 
929  template <class FI>
930  void Add( FI i, FI j )
931  {
932  Append( i, j );
933  }
934 
947  void Remove( const_iterator i, size_type n = 1 )
948  {
949  m_array.Remove( (array_iterator)const_cast<iterator>( i ), n );
950  }
951 
965  {
966  m_array.Remove( (array_iterator)const_cast<iterator>( i ),
967  (array_iterator)const_cast<iterator>( j ) );
968  }
969 
982  void RemoveFirst( size_type n = 1 )
983  {
984  m_array.RemoveFirst( n );
985  }
986 
999  void RemoveLast( size_type n = 1 )
1000  {
1001  m_array.RemoveLast( n );
1002  }
1003 
1018  {
1019  m_array.Truncate( (array_iterator)const_cast<iterator>( i ) );
1020  }
1021 
1029  void Remove( const T& v )
1030  {
1032  for ( const_iterator i = ConstBegin(); i < ConstEnd(); ++i )
1033  if ( *i == nullptr || **i != v )
1034  r.Add( (void*)*i );
1035  if ( r.Length() < m_array.Length() )
1036  m_array.Transfer( r );
1037  }
1038 
1046  template <class BP>
1047  void Remove( const T& v, BP p )
1048  {
1050  for ( const_iterator i = ConstBegin(); i < ConstEnd(); ++i )
1051  if ( *i == nullptr || !p( **i, v ) )
1052  r.Add( (void*)*i );
1053  if ( r.Length() < m_array.Length() )
1054  m_array.Transfer( r );
1055  }
1056 
1063  void Remove( const T* p )
1064  {
1065  m_array.Remove( (void*)p );
1066  }
1067 
1082  void Clear()
1083  {
1084  m_array.Clear();
1085  }
1086 
1099  void Delete( iterator i, size_type n = 1 )
1100  {
1101  Delete( i, i+n );
1102  }
1103 
1122  void Delete( iterator i, iterator j )
1123  {
1124  // NB: Copy-on-write must *not* happen in this function.
1125  if ( i < ConstEnd() )
1126  {
1127  i = pcl::Max( const_cast<iterator>( ConstBegin() ), i );
1128  j = pcl::Min( j, const_cast<iterator>( ConstEnd() ) );
1129  allocator a;
1130  for ( ; i < j; ++i )
1131  if ( *i != nullptr )
1132  DeleteObject( i, a );
1133  }
1134  }
1135 
1147  void Delete( const T& v )
1148  {
1149  // NB: Copy-on-write must *not* happen in this function.
1150  allocator a;
1151  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1152  if ( *i != nullptr && **i == v )
1153  DeleteObject( i, a );
1154  }
1155 
1167  template <class BP>
1168  void Delete( const T& v, BP p )
1169  {
1170  // NB: Copy-on-write must *not* happen in this function.
1171  allocator a;
1172  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1173  if ( *i != nullptr && p( **i, v ) )
1174  DeleteObject( i, a );
1175  }
1176 
1185  void Delete()
1186  {
1187  // NB: Copy-on-write must *not* happen in this function.
1188  allocator a;
1189  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1190  if ( *i != nullptr )
1191  DeleteObject( i, a );
1192  }
1193 
1206  void Destroy( iterator i, size_type n = 1 )
1207  {
1208  Delete( i, n );
1209  Remove( i, n );
1210  }
1211 
1224  {
1225  Delete( i, j );
1226  Remove( i, j );
1227  }
1228 
1240  void Destroy( const T& v )
1241  {
1243  allocator a;
1244  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1245  if ( *i != nullptr && **i == v )
1246  DeleteObject( i, a );
1247  else
1248  r.Add( (void*)*i );
1249  // NB: Copy-on-write must *not* happen before this point.
1250  if ( r.Length() < m_array.Length() )
1251  m_array.Transfer( r );
1252  }
1253 
1265  template <class BP>
1266  void Destroy( const T& v, BP p )
1267  {
1269  allocator a;
1270  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1271  if ( *i != nullptr && p( **i, v ) )
1272  DeleteObject( i, a );
1273  else
1274  r.Add( (void*)*i );
1275  // NB: Copy-on-write must *not* happen before this point.
1276  if ( r.Length() < m_array.Length() )
1277  m_array.Transfer( r );
1278  }
1279 
1287  void Destroy()
1288  {
1289  Delete();
1290  Clear();
1291  }
1292 
1296  void Pack()
1297  {
1298  m_array.Remove( (void*)nullptr );
1299  }
1300 
1315  {
1316  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1317  (array_iterator)const_cast<iterator>( j ), x.m_array ) );
1318  }
1319 
1334  {
1335  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1336  (array_iterator)const_cast<iterator>( j ), (void*)p, n ) );
1337  }
1338 
1355  template <class FI>
1357  {
1358  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1359  (array_iterator)const_cast<iterator>( j ), p, q ) );
1360  }
1361 
1369  void Reserve( size_type n )
1370  {
1371  m_array.Reserve( n );
1372  }
1373 
1386  void Squeeze()
1387  {
1388  m_array.Squeeze();
1389  }
1390 
1394  void Fill( const T& v )
1395  {
1396  Apply( [v]( T* x ){ *x = v; } );
1397  }
1398 
1403  template <class F>
1404  void Apply( F f )
1405  {
1406  pcl::Apply( Begin(), End(), IndirectUnaryFunction<T*, F>( f ) );
1407  }
1408 
1413  template <class F>
1414  void Apply( F f ) const
1415  {
1416  pcl::Apply( Begin(), End(), IndirectUnaryFunction<const T*, F>( f ) );
1417  }
1418 
1424  template <class F>
1426  {
1427  return pcl::FirstThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1428  }
1429 
1435  template <class F>
1437  {
1438  return pcl::FirstThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1439  }
1440 
1446  template <class F>
1448  {
1449  return pcl::LastThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1450  }
1451 
1457  template <class F>
1459  {
1460  return pcl::LastThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1461  }
1462 
1467  size_type Count( const T& v ) const
1468  {
1469  return pcl::Count( Begin(), End(), &v, equal() );
1470  }
1471 
1476  size_type Count( const T* p ) const
1477  {
1478  return m_array.Count( (void*)p );
1479  }
1480 
1486  template <class BP>
1487  size_type Count( const T& v, BP p ) const
1488  {
1489  return pcl::Count( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1490  }
1491 
1497  template <class UP>
1498  size_type CountIf( UP p ) const
1499  {
1500  return pcl::CountIf( Begin(), End(), IndirectUnaryPredicate<const T*, UP>( p ) );
1501  }
1502 
1506  {
1507  return pcl::MinItem( Begin(), End(), less() );
1508  }
1509 
1513  {
1514  return pcl::MinItem( Begin(), End(), less() );
1515  }
1516 
1519  template <class BP>
1520  const_iterator MinItem( BP p ) const
1521  {
1522  return pcl::MinItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1523  }
1524 
1527  template <class BP>
1529  {
1530  return pcl::MinItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1531  }
1532 
1536  {
1537  return pcl::MaxItem( Begin(), End(), less() );
1538  }
1539 
1543  {
1544  return pcl::MaxItem( Begin(), End(), less() );
1545  }
1546 
1549  template <class BP>
1550  const_iterator MaxItem( BP p ) const
1551  {
1552  return pcl::MaxItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1553  }
1554 
1557  template <class BP>
1559  {
1560  return pcl::MaxItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1561  }
1562 
1565  void Reverse()
1566  {
1567  m_array.Reverse();
1568  }
1569 
1573  {
1574  m_array.Rotate( n );
1575  }
1576 
1579  void ShiftLeft( const T* p, size_type n = 1 )
1580  {
1581  m_array.ShiftLeft( (void*)p, n );
1582  }
1583 
1586  void ShiftRight( const T* p, size_type n = 1 )
1587  {
1588  m_array.ShiftRight( (void*)p, n );
1589  }
1590 
1593  const_iterator Search( const T& v ) const
1594  {
1595  return pcl::LinearSearch( Begin(), End(), &v, equal() );
1596  }
1597 
1600  iterator Search( const T& v )
1601  {
1602  return pcl::LinearSearch( Begin(), End(), &v, equal() );
1603  }
1604 
1607  const_iterator Search( const T* p ) const
1608  {
1609  return const_iterator( m_array.Search( (void*)p ) );
1610  }
1611 
1614  iterator Search( const T* p )
1615  {
1616  return iterator( m_array.Search( (void*)p ) );
1617  }
1618 
1621  template <class BP>
1622  const_iterator Search( const T& v, BP p ) const
1623  {
1624  return pcl::LinearSearch( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1625  }
1626 
1629  template <class BP>
1630  iterator Search( const T& v, BP p )
1631  {
1632  return pcl::LinearSearch( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1633  }
1634 
1637  const_iterator SearchLast( const T& v ) const
1638  {
1639  return pcl::LinearSearchLast( Begin(), End(), &v, equal() );
1640  }
1641 
1644  iterator SearchLast( const T& v )
1645  {
1646  return pcl::LinearSearchLast( Begin(), End(), &v, equal() );
1647  }
1648 
1651  const_iterator SearchLast( const T* p ) const
1652  {
1653  return const_iterator( m_array.SearchLast( (void*)p ) );
1654  }
1655 
1658  iterator SearchLast( const T* p )
1659  {
1660  return iterator( m_array.SearchLast( (void*)p ) );
1661  }
1662 
1665  template <class BP>
1666  const_iterator SearchLast( const T& v, BP p ) const
1667  {
1669  }
1670 
1673  template <class BP>
1674  iterator SearchLast( const T& v, BP p )
1675  {
1677  }
1678 
1681  template <class FI>
1682  const_iterator SearchSubset( FI i, FI j ) const
1683  {
1684  return pcl::Search( Begin(), End(), i, j, equal() );
1685  }
1686 
1689  template <class FI>
1690  iterator SearchSubset( FI i, FI j )
1691  {
1692  return pcl::Search( Begin(), End(), i, j, equal() );
1693  }
1694 
1697  template <class FI, class BP>
1698  const_iterator SearchSubset( FI i, FI j, BP p ) const
1699  {
1700  return pcl::Search( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1701  }
1702 
1705  template <class FI, class BP>
1706  iterator SearchSubset( FI i, FI j, BP p )
1707  {
1708  return pcl::Search( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1709  }
1710 
1713  template <class C>
1714  const_iterator SearchSubset( const C& c ) const
1715  {
1716  return pcl::Search( Begin(), End(), c.Begin(), c.End(), equal() );
1717  }
1718 
1721  template <class C>
1722  iterator SearchSubset( const C& c )
1723  {
1724  return pcl::Search( Begin(), End(), c.Begin(), c.End(), equal() );
1725  }
1726 
1729  template <class C, class BP>
1730  const_iterator SearchSubset( const C& c, BP p ) const
1731  {
1732  return pcl::Search( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1733  }
1734 
1737  template <class C, class BP>
1738  iterator SearchSubset( const C& c, BP p )
1739  {
1740  return pcl::Search( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1741  }
1742 
1745  template <class BI>
1746  const_iterator SearchLastSubset( BI i, BI j ) const
1747  {
1748  return pcl::SearchLast( Begin(), End(), i, j, equal() );
1749  }
1750 
1753  template <class BI>
1755  {
1756  return pcl::SearchLast( Begin(), End(), i, j, equal() );
1757  }
1758 
1761  template <class BI, class BP>
1762  const_iterator SearchLastSubset( BI i, BI j, BP p ) const
1763  {
1764  return pcl::SearchLast( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1765  }
1766 
1769  template <class BI, class BP>
1770  iterator SearchLastSubset( BI i, BI j, BP p )
1771  {
1772  return pcl::SearchLast( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1773  }
1774 
1777  template <class C>
1778  const_iterator SearchLastSubset( const C& c ) const
1779  {
1780  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), equal() );
1781  }
1782 
1785  template <class C>
1787  {
1788  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), equal() );
1789  }
1790 
1793  template <class C, class BP>
1794  const_iterator SearchLastSubset( const C& c, BP p ) const
1795  {
1796  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1797  }
1798 
1801  template <class C, class BP>
1802  iterator SearchLastSubset( const C& c, BP p )
1803  {
1804  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1805  }
1806 
1809  bool Contains( const T& v ) const
1810  {
1811  return Search( v ) != End();
1812  }
1813 
1816  bool Contains( const T* p ) const
1817  {
1818  return m_array.Contains( (void*)p );
1819  }
1820 
1823  template <class BP>
1824  bool Contains( const T& v, BP p ) const
1825  {
1826  return Search( v, p ) != End();
1827  }
1828 
1831  template <class FI>
1832  iterator ContainsSubset( FI i, FI j ) const
1833  {
1834  return SearchSubset( i, j ) != End();
1835  }
1836 
1839  template <class FI, class BP>
1840  iterator ContainsSubset( FI i, FI j, BP p ) const
1841  {
1842  return SearchSubset( i, j, p ) != End();
1843  }
1844 
1847  template <class C>
1848  iterator ContainsSubset( const C& c ) const
1849  {
1850  return SearchSubset( c ) != End();
1851  }
1852 
1855  template <class C, class BP>
1856  iterator ContainsSubset( const C& c, BP p ) const
1857  {
1858  return SearchSubset( c, p ) != End();
1859  }
1860 
1863  void Sort()
1864  {
1865  pcl::QuickSort( Begin(), End(), less() );
1866  }
1867 
1870  template <class BP>
1871  void Sort( BP p )
1872  {
1874  }
1875 
1879  friend void Swap( IndirectArray& x1, IndirectArray& x2 )
1880  {
1881  pcl::Swap( x1.m_array, x2.m_array );
1882  }
1883 
1900  template <class S, typename SP>
1901  S& ToSeparated( S& s, SP separator ) const
1902  {
1903  const_iterator i = Begin();
1904  if ( i < End() )
1905  {
1906  while ( *i == nullptr )
1907  if ( ++i == End() )
1908  return s;
1909  s.Append( S( **i ) );
1910  if ( ++i < End() )
1911  do
1912  if ( *i != nullptr )
1913  {
1914  s.Append( separator );
1915  s.Append( S( **i ) );
1916  }
1917  while ( ++i < End() );
1918  }
1919  return s;
1920  }
1921 
1944  template <class S, typename SP, class AF>
1945  S& ToSeparated( S& s, SP separator, AF append ) const
1946  {
1947  const_iterator i = Begin();
1948  if ( i < End() )
1949  {
1950  while ( *i == nullptr )
1951  if ( ++i == End() )
1952  return s;
1953  append( s, S( **i ) );
1954  if ( ++i < End() )
1955  {
1956  S p( separator );
1957  do
1958  if ( *i != nullptr )
1959  {
1960  append( s, p );
1961  append( s, S( **i ) );
1962  }
1963  while ( ++i < End() );
1964  }
1965  }
1966  return s;
1967  }
1968 
1977  template <class S>
1978  S& ToCommaSeparated( S& s ) const
1979  {
1980  return ToSeparated( s, ',' );
1981  }
1982 
1991  template <class S>
1992  S& ToSpaceSeparated( S& s ) const
1993  {
1994  return ToSeparated( s, ' ' );
1995  }
1996 
2005  template <class S>
2006  S& ToTabSeparated( S& s ) const
2007  {
2008  return ToSeparated( s, '\t' );
2009  }
2010 
2019  template <class S>
2020  S& ToNewLineSeparated( S& s ) const
2021  {
2022  return ToSeparated( s, '\n' );
2023  }
2024 
2035  uint64 Hash64( uint64 seed = 0 ) const
2036  {
2037  return m_array.Hash64( seed );
2038  }
2039 
2050  uint32 Hash32( uint32 seed = 0 ) const
2051  {
2052  return m_array.Hash32( seed );
2053  }
2054 
2059  uint64 Hash( uint64 seed = 0 ) const
2060  {
2061  return Hash64( seed );
2062  }
2063 
2064  // -------------------------------------------------------------------------
2065 
2066 private:
2067 
2068  array_implementation m_array;
2069 
2070  void DeleteObject( iterator i, allocator& a )
2071  {
2072  pcl::Destroy( *i );
2073  a.Deallocate( *i );
2074  *i = nullptr;
2075  }
2076 
2077  template <class C>
2078  void CloneObjects( const C& x, DirectContainer<T>* )
2079  {
2080  Clear();
2081  Reserve( x.Length() );
2082  Append( static_cast<T*>( nullptr ), x.Length() );
2083  iterator i = Begin(), j = End();
2084  typename C::const_iterator p = x.Begin(), q = x.End();
2085  for ( allocator a; i < j && p != q; ++i, ++p )
2086  {
2087  *i = a.Allocate( 1 );
2088  pcl::Construct( *i, *p, a );
2089  }
2090  }
2091 
2092  template <class C>
2093  void CloneObjects( const C& x, IndirectContainer<T>* )
2094  {
2095  Clear();
2096  Reserve( x.Length() );
2097  Append( static_cast<T*>( nullptr ), x.Length() );
2098  iterator i = Begin(), j = End();
2099  typename C::const_iterator p = x.Begin(), q = x.End();
2100  for ( allocator a; i < j && p != q; ++i, ++p )
2101  if ( *p != nullptr )
2102  {
2103  *i = a.Allocate( 1 );
2104  pcl::Construct( *i, **p, a );
2105  }
2106  }
2107 };
2108 
2109 // ----------------------------------------------------------------------------
2110 
2117 template <class T, class A> inline
2119 {
2120  return x1.Length() == x2.Length() && pcl::Equal( x1.Begin(), x2.Begin(), x2.End(), IndirectArray<T,A>::equal() );
2121 }
2122 
2129 template <class T, class A> inline
2131 {
2132  return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End(), IndirectArray<T,A>::less() ) < 0;
2133 }
2134 
2142 template <class T, class A, class V> inline
2143 IndirectArray<T,A>& operator <<( IndirectArray<T,A>& x, const V* p )
2144 {
2145  x.Append( static_cast<const T*>( p ) );
2146  return x;
2147 }
2148 
2156 template <class T, class A, class V> inline
2157 IndirectArray<T,A>& operator <<( IndirectArray<T,A>&& x, const V* p )
2158 {
2159  x.Append( static_cast<const T*>( p ) );
2160  return x;
2161 }
2162 
2168 template <class T, class A> inline
2169 IndirectArray<T,A>& operator <<( IndirectArray<T,A>& x1, const IndirectArray<T,A>& x2 )
2170 {
2171  x1.Append( x2 );
2172  return x1;
2173 }
2174 
2180 template <class T, class A> inline
2181 IndirectArray<T,A>& operator <<( IndirectArray<T,A>&& x1, const IndirectArray<T,A>& x2 )
2182 {
2183  x1.Append( x2 );
2184  return x1;
2185 }
2186 
2187 // ----------------------------------------------------------------------------
2188 
2189 } // pcl
2190 
2191 #endif // __PCL_IndirectArray_h
2192 
2193 // ----------------------------------------------------------------------------
2194 // EOF pcl/IndirectArray.h - Released 2024-06-18T15:48:54Z
Provides memory allocation for PCL containers.
Definition: Allocator.h:132
Allocator()=default
Generic dynamic array.
Definition: Array.h:100
size_type Length() const noexcept
Definition: Array.h:266
void Add(const Array &x)
Definition: Array.h:999
T * iterator
Definition: Array.h:113
const T * const_iterator
Definition: Array.h:117
Generic dynamic array of pointers to objects.
Definition: IndirectArray.h:92
const_iterator LastThat(F f) const
void Assign(FI i, FI j)
void Destroy(iterator i, size_type n=1)
size_type UpperBound() const
void Assign(const T *p, size_type n=1)
const_iterator SearchSubset(const C &c) const
size_type Length() const
void Transfer(IndirectArray &x)
reverse_iterator ReverseEnd()
bool IsValid() const
void Append(FI p, FI q)
void Add(const IndirectArray &x)
iterator SearchLastSubset(const C &c, BP p)
void Truncate(const_iterator i)
void Remove(const T &v)
T *const * const_iterator
IndirectArray(size_type n, const T *p)
size_type Size() const
iterator SearchSubset(FI i, FI j, BP p)
const_iterator ConstBegin() const
void Delete(const T &v, BP p)
IndirectArray(FI i, FI j)
bool IsEmpty() const
iterator Replace(const_iterator i, const_iterator j, FI p, FI q)
const_iterator SearchLastSubset(const C &c) const
IndirectArray()=default
void UniquifyIterators(iterator &i, iterator &j)
iterator SearchLastSubset(BI i, BI j, BP p)
void Reserve(size_type n)
const_iterator MinItem() const
const allocator & Allocator() const
iterator ContainsSubset(FI i, FI j) const
friend void Swap(IndirectArray &x1, IndirectArray &x2)
bool Contains(const T &v, BP p) const
IndirectArray(IndirectArray &&)=default
typename array_implementation::const_iterator const_array_iterator
const_iterator ConstEnd() const
size_type Available() const
iterator Expand(size_type n=1)
void Remove(const T &v, BP p)
void Remove(const T *p)
const_iterator SearchSubset(FI i, FI j) const
const_iterator SearchLastSubset(const C &c, BP p) const
uint32 Hash32(uint32 seed=0) const
iterator SearchLast(const T *p)
iterator ContainsSubset(const C &c) const
void Remove(const_iterator i, const_iterator j)
void Destroy(const T &v, BP p)
void ShiftRight(const T *p, size_type n=1)
void UniquifyIterator(iterator &i)
iterator Insert(const_iterator i, FI p, FI q)
void SetAllocator(const allocator &a)
const_reverse_iterator ReverseBegin() const
const_iterator Search(const T &v) const
bool Contains(const T *p) const
iterator MinItem(BP p)
const_iterator Search(const T *p) const
size_type Count(const T &v, BP p) const
reverse_iterator ReverseBegin()
const_iterator Search(const T &v, BP p) const
iterator Search(const T &v)
const_iterator FirstThat(F f) const
void Fill(const T &v)
const_iterator SearchLastSubset(BI i, BI j, BP p) const
const_iterator SearchSubset(FI i, FI j, BP p) const
void Destroy(iterator i, iterator j)
const_iterator At(size_type i) const
void Prepend(FI p, FI q)
void Delete(iterator i, size_type n=1)
iterator Grow(const_iterator i, size_type n=1)
iterator SearchLastSubset(const C &c)
iterator SearchSubset(const C &c, BP p)
uint64 Hash64(uint64 seed=0) const
size_type CountIf(UP p) const
size_type Capacity() const
const_reverse_iterator ConstReverseBegin() const
iterator At(size_type i)
const_iterator SearchLast(const T &v) const
void Add(FI i, FI j)
void Rotate(distance_type n)
void Assign(const IndirectArray &x)
iterator MaxItem(BP p)
const_iterator MinItem(BP p) const
bool IsAliasOf(const IndirectArray &x) const
const_iterator MaxItem(BP p) const
bool Contains(const T &v) const
void Resize(size_type n)
void Transfer(IndirectArray &&x)
const_reverse_iterator ReverseEnd() const
iterator Replace(const_iterator i, const_iterator j, const IndirectArray &x)
const_iterator SearchLast(const T &v, BP p) const
void Append(const T *p, size_type n=1)
const_iterator MaxItem() const
size_type LowerBound() const
iterator SearchLast(const T &v)
void Add(const T *p, size_type n=1)
IndirectArray(const IndirectArray &)=default
void Prepend(const IndirectArray &x)
void Import(iterator i, iterator j)
void Apply(F f) const
const_iterator SearchLastSubset(BI i, BI j) const
void ShiftLeft(const T *p, size_type n=1)
void Delete(const T &v)
const_iterator begin() const
iterator SearchSubset(FI i, FI j)
iterator ContainsSubset(const C &c, BP p) const
iterator Insert(const_iterator i, const T *p, size_type n=1)
const_iterator end() const
iterator FirstThat(F f)
uint64 Hash(uint64 seed=0) const
void Remove(const_iterator i, size_type n=1)
iterator ContainsSubset(FI i, FI j, BP p) const
void RemoveLast(size_type n=1)
IndirectArray(size_type n)
iterator Insert(const_iterator i, const IndirectArray &x)
void Shrink(size_type n=1)
const_iterator Begin() const
const_iterator End() const
iterator SearchSubset(const C &c)
typename array_implementation::iterator array_iterator
void Append(const IndirectArray &x)
iterator SearchLast(const T &v, BP p)
size_type Count(const T &v) const
const_iterator SearchLast(const T *p) const
iterator SearchLastSubset(BI i, BI j)
iterator Search(const T &v, BP p)
bool IsUnique() const
void Prepend(const T *p, size_type n=1)
iterator LastThat(F f)
void RemoveFirst(size_type n=1)
iterator MutableIterator(const_iterator i)
iterator Replace(const_iterator i, const_iterator j, const T *p, size_type n=1)
const_iterator SearchSubset(const C &c, BP p) const
iterator Search(const T *p)
void CloneAssign(const C &x)
const_reverse_iterator ConstReverseEnd() const
void Destroy(const T &v)
size_type Count(const T *p) const
void Delete(iterator i, iterator j)
A wrapper class that applies a binary predicate to pointers to objects.
Definition: Indirect.h:236
Root base class of all PCL containers of pointers to objects.
Definition: Container.h:90
A wrapper class that applies a unary function to pointers to objects.
Definition: Indirect.h:80
A wrapper class that applies a unary predicate to pointers to objects.
Definition: Indirect.h:185
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:548
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 Destroy(T *p)
Definition: Allocator.h:277
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
constexpr const T & Min(const T &a, const T &b) noexcept
Definition: Utility.h:90
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
constexpr const T & Max(const T &a, const T &b) noexcept
Definition: Utility.h:119
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
A functional class that tests two pointers for equality of the pointed objects.
Definition: Indirect.h:278
A functional class that applies the less than relational operator to the objects pointed to by two po...
Definition: Indirect.h:300