PCL
IndirectArray.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.8.4
6 // ----------------------------------------------------------------------------
7 // pcl/IndirectArray.h - Released 2024-12-23T11:32:56Z
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 
98 
102 
106 
109  using block_allocator = A;
110 
114 
117  using iterator = T**;
118 
121  using const_iterator = T* const*;
122 
126 
130 
134 
138 
142 
146 
150 
151  // -------------------------------------------------------------------------
152 
156  IndirectArray() = default;
157 
162  explicit
164  {
165  m_array.Append( (void*)nullptr, n );
166  }
167 
171  IndirectArray( size_type n, const T* p )
172  {
173  m_array.Append( (void*)p, n );
174  }
175 
180  template <class FI>
181  IndirectArray( FI i, FI j )
182  : m_array( i, j )
183  {
184  }
185 
189  IndirectArray( const IndirectArray& ) = default;
190 
194  IndirectArray( IndirectArray&& ) = default;
195 
204  {
205  }
206 
211  bool IsUnique() const
212  {
213  return m_array.IsUnique();
214  }
215 
223  bool IsAliasOf( const IndirectArray& x ) const
224  {
225  return m_array.IsAliasOf( x.m_array );
226  }
227 
237  {
238  m_array.EnsureUnique();
239  }
240 
245  size_type Size() const
246  {
247  return m_array.Size();
248  }
249 
254  {
255  return m_array.Length();
256  }
257 
264  {
265  return m_array.Capacity();
266  }
267 
276  {
277  return m_array.Available();
278  }
279 
295  bool IsValid() const
296  {
297  return m_array.IsValid();
298  }
299 
303  bool IsEmpty() const
304  {
305  return m_array.IsEmpty();
306  }
307 
313  {
314  return m_array.LowerBound();
315  }
316 
322  {
323  return m_array.UpperBound();
324  }
325 
329  const allocator& Allocator() const
330  {
331  return m_array.Allocator();
332  }
333 
337  void SetAllocator( const allocator& a )
338  {
339  m_array.SetAllocator( a );
340  }
341 
346  {
347  return iterator( m_array.At( i ) );
348  }
349 
354  {
355  return const_iterator( m_array.At( i ) );
356  }
357 
369  {
370  return iterator( m_array.MutableIterator( (const_array_iterator)i ) );
371  }
372 
377  T*& operator []( size_type i )
378  {
379  return (T*&)m_array[i];
380  }
381 
386  const T* operator []( size_type i ) const
387  {
388  return (const T*)m_array[i];
389  }
390 
395  {
396  return (T*&)*Begin();
397  }
398 
403  const T* operator *() const
404  {
405  return (T*)*Begin();
406  }
407 
412  {
413  return iterator( m_array.Begin() );
414  }
415 
420  {
421  return const_iterator( m_array.Begin() );
422  }
423 
428  {
429  return const_iterator( m_array.ConstBegin() );
430  }
431 
436  {
437  return iterator( m_array.End() );
438  }
439 
444  {
445  return const_iterator( m_array.End() );
446  }
447 
452  {
453  return const_iterator( m_array.ConstEnd() );
454  }
455 
463  {
464  return iterator( (array_iterator)m_array.ReverseBegin() );
465  }
466 
474  {
475  return const_iterator( (const_array_iterator)m_array.ReverseBegin() );
476  }
477 
485  {
486  return const_iterator( (const_array_iterator)m_array.ConstReverseBegin() );
487  }
488 
497  {
498  return iterator( (array_iterator)m_array.ReverseEnd() );
499  }
500 
509  {
510  return const_iterator( (const_array_iterator)m_array.ReverseEnd() );
511  }
512 
521  {
522  return const_iterator( (const_array_iterator)m_array.ConstReverseEnd() );
523  }
524 
529  T* First()
530  {
531  return IsEmpty() ? nullptr : *Begin();
532  }
533 
538  const T* First() const
539  {
540  return IsEmpty() ? nullptr : *Begin();
541  }
542 
547  T* Last()
548  {
549  return IsEmpty() ? nullptr : *ReverseBegin();
550  }
551 
556  const T* Last() const
557  {
558  return IsEmpty() ? nullptr : *ReverseBegin();
559  }
560 
570  {
571  m_array.UniquifyIterator( (array_iterator&)i );
572  }
573 
584  {
585  m_array.UniquifyIterators( (array_iterator&)i, (array_iterator&)j );
586  }
587 
588 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
593  {
594  return Begin();
595  }
596 
601  {
602  return Begin();
603  }
604 
609  {
610  return End();
611  }
612 
617  {
618  return End();
619  }
620 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
621 
628  IndirectArray& operator =( const IndirectArray& x )
629  {
630  Assign( x );
631  return *this;
632  }
633 
643  void Assign( const IndirectArray& x )
644  {
645  m_array.Assign( x.m_array );
646  }
647 
651  IndirectArray& operator =( IndirectArray&& x )
652  {
653  Transfer( x );
654  return *this;
655  }
656 
667  {
668  m_array.Transfer( x.m_array );
669  }
670 
681  {
682  m_array.Transfer( x.m_array );
683  }
684 
689  void Assign( const T* p, size_type n = 1 )
690  {
691  m_array.Assign( (void*)p, n );
692  }
693 
700  template <class FI>
701  void Assign( FI i, FI j )
702  {
703  m_array.Assign( i, j );
704  }
705 
717  template <class C>
718  void CloneAssign( const C& x )
719  {
720  PCL_ASSERT_CONTAINER( C, T );
721  CloneObjects( x, (C*)nullptr );
722  }
723 
730  void Import( iterator i, iterator j )
731  {
732  m_array.Import( (array_iterator)i, (array_iterator)j );
733  }
734 
747  {
748  return iterator( m_array.Release() );
749  }
750 
762  {
763  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), (void*)nullptr, n ) );
764  }
765 
776  {
777  return Grow( ConstEnd(), n );
778  }
779 
784  void Shrink( size_type n = 1 )
785  {
786  m_array.Shrink( n );
787  }
788 
804  void Resize( size_type n )
805  {
806  size_type l = Length();
807  if ( n > l )
808  Expand( n - l );
809  else
810  Shrink( l - n );
811  }
812 
825  {
826  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), x.m_array ) );
827  }
828 
839  iterator Insert( const_iterator i, const T* p, size_type n = 1 )
840  {
841  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), (void*)p, n ) );
842  }
843 
856  template <class FI>
857  iterator Insert( const_iterator i, FI p, FI q )
858  {
859  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), p, q ) );
860  }
861 
866  void Append( const IndirectArray& x )
867  {
868  m_array.Append( x.m_array );
869  }
870 
875  void Append( const T* p, size_type n = 1 )
876  {
877  m_array.Append( (void*)p, n );
878  }
879 
886  template <class FI>
887  void Append( FI p, FI q )
888  {
889  m_array.Append( p, q );
890  }
891 
896  void Prepend( const IndirectArray& x )
897  {
898  m_array.Prepend( x.m_array );
899  }
900 
905  void Prepend( const T* p, size_type n = 1 )
906  {
907  m_array.Prepend( (void*)p, n );
908  }
909 
916  template <class FI>
917  void Prepend( FI p, FI q )
918  {
919  m_array.Prepend( p, q );
920  }
921 
925  void Add( const IndirectArray& x )
926  {
927  Append( x );
928  }
929 
933  void Add( const T* p, size_type n = 1 )
934  {
935  Append( p, n );
936  }
937 
941  template <class FI>
942  void Add( FI i, FI j )
943  {
944  Append( i, j );
945  }
946 
959  void Remove( const_iterator i, size_type n = 1 )
960  {
961  m_array.Remove( (array_iterator)const_cast<iterator>( i ), n );
962  }
963 
977  {
978  m_array.Remove( (array_iterator)const_cast<iterator>( i ),
979  (array_iterator)const_cast<iterator>( j ) );
980  }
981 
994  void RemoveFirst( size_type n = 1 )
995  {
996  m_array.RemoveFirst( n );
997  }
998 
1011  void RemoveLast( size_type n = 1 )
1012  {
1013  m_array.RemoveLast( n );
1014  }
1015 
1030  {
1031  m_array.Truncate( (array_iterator)const_cast<iterator>( i ) );
1032  }
1033 
1041  void Remove( const T& v )
1042  {
1044  for ( const_iterator i = ConstBegin(); i < ConstEnd(); ++i )
1045  if ( *i == nullptr || **i != v )
1046  r.Add( (void*)*i );
1047  if ( r.Length() < m_array.Length() )
1048  m_array.Transfer( r );
1049  }
1050 
1058  template <class BP>
1059  void Remove( const T& v, BP p )
1060  {
1062  for ( const_iterator i = ConstBegin(); i < ConstEnd(); ++i )
1063  if ( *i == nullptr || !p( **i, v ) )
1064  r.Add( (void*)*i );
1065  if ( r.Length() < m_array.Length() )
1066  m_array.Transfer( r );
1067  }
1068 
1075  void Remove( const T* p )
1076  {
1077  m_array.Remove( (void*)p );
1078  }
1079 
1094  void Clear()
1095  {
1096  m_array.Clear();
1097  }
1098 
1111  void Delete( iterator i, size_type n = 1 )
1112  {
1113  Delete( i, i+n );
1114  }
1115 
1134  void Delete( iterator i, iterator j )
1135  {
1136  // NB: Copy-on-write must *not* happen in this function.
1137  if ( i < ConstEnd() )
1138  {
1139  i = pcl::Max( const_cast<iterator>( ConstBegin() ), i );
1140  j = pcl::Min( j, const_cast<iterator>( ConstEnd() ) );
1141  allocator a;
1142  for ( ; i < j; ++i )
1143  if ( *i != nullptr )
1144  DeleteObject( i, a );
1145  }
1146  }
1147 
1159  void Delete( const T& v )
1160  {
1161  // NB: Copy-on-write must *not* happen in this function.
1162  allocator a;
1163  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1164  if ( *i != nullptr && **i == v )
1165  DeleteObject( i, a );
1166  }
1167 
1179  template <class BP>
1180  void Delete( const T& v, BP p )
1181  {
1182  // NB: Copy-on-write must *not* happen in this function.
1183  allocator a;
1184  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1185  if ( *i != nullptr && p( **i, v ) )
1186  DeleteObject( i, a );
1187  }
1188 
1197  void Delete()
1198  {
1199  // NB: Copy-on-write must *not* happen in this function.
1200  allocator a;
1201  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1202  if ( *i != nullptr )
1203  DeleteObject( i, a );
1204  }
1205 
1218  void Destroy( iterator i, size_type n = 1 )
1219  {
1220  Delete( i, n );
1221  Remove( i, n );
1222  }
1223 
1236  {
1237  Delete( i, j );
1238  Remove( i, j );
1239  }
1240 
1252  void Destroy( const T& v )
1253  {
1255  allocator a;
1256  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1257  if ( *i != nullptr && **i == v )
1258  DeleteObject( i, a );
1259  else
1260  r.Add( (void*)*i );
1261  // NB: Copy-on-write must *not* happen before this point.
1262  if ( r.Length() < m_array.Length() )
1263  m_array.Transfer( r );
1264  }
1265 
1277  template <class BP>
1278  void Destroy( const T& v, BP p )
1279  {
1281  allocator a;
1282  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1283  if ( *i != nullptr && p( **i, v ) )
1284  DeleteObject( i, a );
1285  else
1286  r.Add( (void*)*i );
1287  // NB: Copy-on-write must *not* happen before this point.
1288  if ( r.Length() < m_array.Length() )
1289  m_array.Transfer( r );
1290  }
1291 
1299  void Destroy()
1300  {
1301  Delete();
1302  Clear();
1303  }
1304 
1308  void Pack()
1309  {
1310  m_array.Remove( (void*)nullptr );
1311  }
1312 
1327  {
1328  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1329  (array_iterator)const_cast<iterator>( j ), x.m_array ) );
1330  }
1331 
1346  {
1347  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1348  (array_iterator)const_cast<iterator>( j ), (void*)p, n ) );
1349  }
1350 
1367  template <class FI>
1369  {
1370  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1371  (array_iterator)const_cast<iterator>( j ), p, q ) );
1372  }
1373 
1381  void Reserve( size_type n )
1382  {
1383  m_array.Reserve( n );
1384  }
1385 
1398  void Squeeze()
1399  {
1400  m_array.Squeeze();
1401  }
1402 
1406  void Fill( const T& v )
1407  {
1408  Apply( [v]( T* x ){ *x = v; } );
1409  }
1410 
1415  template <class F>
1416  void Apply( F f )
1417  {
1418  pcl::Apply( Begin(), End(), IndirectUnaryFunction<T*, F>( f ) );
1419  }
1420 
1425  template <class F>
1426  void Apply( F f ) const
1427  {
1428  pcl::Apply( Begin(), End(), IndirectUnaryFunction<const T*, F>( f ) );
1429  }
1430 
1436  template <class F>
1438  {
1439  return pcl::FirstThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1440  }
1441 
1447  template <class F>
1449  {
1450  return pcl::FirstThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1451  }
1452 
1458  template <class F>
1460  {
1461  return pcl::LastThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1462  }
1463 
1469  template <class F>
1471  {
1472  return pcl::LastThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) );
1473  }
1474 
1479  size_type Count( const T& v ) const
1480  {
1481  return pcl::Count( Begin(), End(), &v, equal() );
1482  }
1483 
1488  size_type Count( const T* p ) const
1489  {
1490  return m_array.Count( (void*)p );
1491  }
1492 
1498  template <class BP>
1499  size_type Count( const T& v, BP p ) const
1500  {
1501  return pcl::Count( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1502  }
1503 
1509  template <class UP>
1510  size_type CountIf( UP p ) const
1511  {
1512  return pcl::CountIf( Begin(), End(), IndirectUnaryPredicate<const T*, UP>( p ) );
1513  }
1514 
1518  {
1519  return pcl::MinItem( Begin(), End(), less() );
1520  }
1521 
1525  {
1526  return pcl::MinItem( Begin(), End(), less() );
1527  }
1528 
1531  template <class BP>
1532  const_iterator MinItem( BP p ) const
1533  {
1534  return pcl::MinItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1535  }
1536 
1539  template <class BP>
1541  {
1542  return pcl::MinItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1543  }
1544 
1548  {
1549  return pcl::MaxItem( Begin(), End(), less() );
1550  }
1551 
1555  {
1556  return pcl::MaxItem( Begin(), End(), less() );
1557  }
1558 
1561  template <class BP>
1562  const_iterator MaxItem( BP p ) const
1563  {
1564  return pcl::MaxItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1565  }
1566 
1569  template <class BP>
1571  {
1572  return pcl::MaxItem( Begin(), End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1573  }
1574 
1577  void Reverse()
1578  {
1579  m_array.Reverse();
1580  }
1581 
1585  {
1586  m_array.Rotate( n );
1587  }
1588 
1591  void ShiftLeft( const T* p, size_type n = 1 )
1592  {
1593  m_array.ShiftLeft( (void*)p, n );
1594  }
1595 
1598  void ShiftRight( const T* p, size_type n = 1 )
1599  {
1600  m_array.ShiftRight( (void*)p, n );
1601  }
1602 
1605  const_iterator Search( const T& v ) const
1606  {
1607  return pcl::LinearSearch( Begin(), End(), &v, equal() );
1608  }
1609 
1612  iterator Search( const T& v )
1613  {
1614  return pcl::LinearSearch( Begin(), End(), &v, equal() );
1615  }
1616 
1619  const_iterator Search( const T* p ) const
1620  {
1621  return const_iterator( m_array.Search( (void*)p ) );
1622  }
1623 
1626  iterator Search( const T* p )
1627  {
1628  return iterator( m_array.Search( (void*)p ) );
1629  }
1630 
1633  template <class BP>
1634  const_iterator Search( const T& v, BP p ) const
1635  {
1636  return pcl::LinearSearch( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1637  }
1638 
1641  template <class BP>
1642  iterator Search( const T& v, BP p )
1643  {
1644  return pcl::LinearSearch( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1645  }
1646 
1649  const_iterator SearchLast( const T& v ) const
1650  {
1651  return pcl::LinearSearchLast( Begin(), End(), &v, equal() );
1652  }
1653 
1656  iterator SearchLast( const T& v )
1657  {
1658  return pcl::LinearSearchLast( Begin(), End(), &v, equal() );
1659  }
1660 
1663  const_iterator SearchLast( const T* p ) const
1664  {
1665  return const_iterator( m_array.SearchLast( (void*)p ) );
1666  }
1667 
1670  iterator SearchLast( const T* p )
1671  {
1672  return iterator( m_array.SearchLast( (void*)p ) );
1673  }
1674 
1677  template <class BP>
1678  const_iterator SearchLast( const T& v, BP p ) const
1679  {
1681  }
1682 
1685  template <class BP>
1686  iterator SearchLast( const T& v, BP p )
1687  {
1689  }
1690 
1693  template <class FI>
1694  const_iterator SearchSubset( FI i, FI j ) const
1695  {
1696  return pcl::Search( Begin(), End(), i, j, equal() );
1697  }
1698 
1701  template <class FI>
1702  iterator SearchSubset( FI i, FI j )
1703  {
1704  return pcl::Search( Begin(), End(), i, j, equal() );
1705  }
1706 
1709  template <class FI, class BP>
1710  const_iterator SearchSubset( FI i, FI j, BP p ) const
1711  {
1712  return pcl::Search( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1713  }
1714 
1717  template <class FI, class BP>
1718  iterator SearchSubset( FI i, FI j, BP p )
1719  {
1720  return pcl::Search( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1721  }
1722 
1725  template <class C>
1726  const_iterator SearchSubset( const C& c ) const
1727  {
1728  return pcl::Search( Begin(), End(), c.Begin(), c.End(), equal() );
1729  }
1730 
1733  template <class C>
1734  iterator SearchSubset( const C& c )
1735  {
1736  return pcl::Search( Begin(), End(), c.Begin(), c.End(), equal() );
1737  }
1738 
1741  template <class C, class BP>
1742  const_iterator SearchSubset( const C& c, BP p ) const
1743  {
1744  return pcl::Search( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1745  }
1746 
1749  template <class C, class BP>
1750  iterator SearchSubset( const C& c, BP p )
1751  {
1752  return pcl::Search( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1753  }
1754 
1757  template <class BI>
1758  const_iterator SearchLastSubset( BI i, BI j ) const
1759  {
1760  return pcl::SearchLast( Begin(), End(), i, j, equal() );
1761  }
1762 
1765  template <class BI>
1767  {
1768  return pcl::SearchLast( Begin(), End(), i, j, equal() );
1769  }
1770 
1773  template <class BI, class BP>
1774  const_iterator SearchLastSubset( BI i, BI j, BP p ) const
1775  {
1776  return pcl::SearchLast( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1777  }
1778 
1781  template <class BI, class BP>
1782  iterator SearchLastSubset( BI i, BI j, BP p )
1783  {
1784  return pcl::SearchLast( Begin(), End(), i, j, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1785  }
1786 
1789  template <class C>
1790  const_iterator SearchLastSubset( const C& c ) const
1791  {
1792  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), equal() );
1793  }
1794 
1797  template <class C>
1799  {
1800  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), equal() );
1801  }
1802 
1805  template <class C, class BP>
1806  const_iterator SearchLastSubset( const C& c, BP p ) const
1807  {
1808  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1809  }
1810 
1813  template <class C, class BP>
1814  iterator SearchLastSubset( const C& c, BP p )
1815  {
1816  return pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1817  }
1818 
1821  bool Contains( const T& v ) const
1822  {
1823  return Search( v ) != End();
1824  }
1825 
1828  bool Contains( const T* p ) const
1829  {
1830  return m_array.Contains( (void*)p );
1831  }
1832 
1835  template <class BP>
1836  bool Contains( const T& v, BP p ) const
1837  {
1838  return Search( v, p ) != End();
1839  }
1840 
1843  template <class FI>
1844  iterator ContainsSubset( FI i, FI j ) const
1845  {
1846  return SearchSubset( i, j ) != End();
1847  }
1848 
1851  template <class FI, class BP>
1852  iterator ContainsSubset( FI i, FI j, BP p ) const
1853  {
1854  return SearchSubset( i, j, p ) != End();
1855  }
1856 
1859  template <class C>
1860  iterator ContainsSubset( const C& c ) const
1861  {
1862  return SearchSubset( c ) != End();
1863  }
1864 
1867  template <class C, class BP>
1868  iterator ContainsSubset( const C& c, BP p ) const
1869  {
1870  return SearchSubset( c, p ) != End();
1871  }
1872 
1875  void Sort()
1876  {
1877  pcl::QuickSort( Begin(), End(), less() );
1878  }
1879 
1882  template <class BP>
1883  void Sort( BP p )
1884  {
1886  }
1887 
1891  friend void Swap( IndirectArray& x1, IndirectArray& x2 )
1892  {
1893  pcl::Swap( x1.m_array, x2.m_array );
1894  }
1895 
1912  template <class S, typename SP>
1913  S& ToSeparated( S& s, SP separator ) const
1914  {
1915  const_iterator i = Begin();
1916  if ( i < End() )
1917  {
1918  while ( *i == nullptr )
1919  if ( ++i == End() )
1920  return s;
1921  s.Append( S( **i ) );
1922  if ( ++i < End() )
1923  do
1924  if ( *i != nullptr )
1925  {
1926  s.Append( separator );
1927  s.Append( S( **i ) );
1928  }
1929  while ( ++i < End() );
1930  }
1931  return s;
1932  }
1933 
1956  template <class S, typename SP, class AF>
1957  S& ToSeparated( S& s, SP separator, AF append ) const
1958  {
1959  const_iterator i = Begin();
1960  if ( i < End() )
1961  {
1962  while ( *i == nullptr )
1963  if ( ++i == End() )
1964  return s;
1965  append( s, S( **i ) );
1966  if ( ++i < End() )
1967  {
1968  S p( separator );
1969  do
1970  if ( *i != nullptr )
1971  {
1972  append( s, p );
1973  append( s, S( **i ) );
1974  }
1975  while ( ++i < End() );
1976  }
1977  }
1978  return s;
1979  }
1980 
1989  template <class S>
1990  S& ToCommaSeparated( S& s ) const
1991  {
1992  return ToSeparated( s, ',' );
1993  }
1994 
2003  template <class S>
2004  S& ToSpaceSeparated( S& s ) const
2005  {
2006  return ToSeparated( s, ' ' );
2007  }
2008 
2017  template <class S>
2018  S& ToTabSeparated( S& s ) const
2019  {
2020  return ToSeparated( s, '\t' );
2021  }
2022 
2031  template <class S>
2032  S& ToNewLineSeparated( S& s ) const
2033  {
2034  return ToSeparated( s, '\n' );
2035  }
2036 
2047  uint64 Hash64( uint64 seed = 0 ) const
2048  {
2049  return m_array.Hash64( seed );
2050  }
2051 
2062  uint32 Hash32( uint32 seed = 0 ) const
2063  {
2064  return m_array.Hash32( seed );
2065  }
2066 
2071  uint64 Hash( uint64 seed = 0 ) const
2072  {
2073  return Hash64( seed );
2074  }
2075 
2076  // -------------------------------------------------------------------------
2077 
2078 private:
2079 
2080  array_implementation m_array;
2081 
2082  void DeleteObject( iterator i, allocator& a )
2083  {
2084  pcl::Destroy( *i );
2085  a.Deallocate( *i );
2086  *i = nullptr;
2087  }
2088 
2089  template <class C>
2090  void CloneObjects( const C& x, DirectContainer<T>* )
2091  {
2092  Clear();
2093  Reserve( x.Length() );
2094  Append( static_cast<T*>( nullptr ), x.Length() );
2095  iterator i = Begin(), j = End();
2096  typename C::const_iterator p = x.Begin(), q = x.End();
2097  for ( allocator a; i < j && p != q; ++i, ++p )
2098  {
2099  *i = a.Allocate( 1 );
2100  pcl::Construct( *i, *p, a );
2101  }
2102  }
2103 
2104  template <class C>
2105  void CloneObjects( const C& x, IndirectContainer<T>* )
2106  {
2107  Clear();
2108  Reserve( x.Length() );
2109  Append( static_cast<T*>( nullptr ), x.Length() );
2110  iterator i = Begin(), j = End();
2111  typename C::const_iterator p = x.Begin(), q = x.End();
2112  for ( allocator a; i < j && p != q; ++i, ++p )
2113  if ( *p != nullptr )
2114  {
2115  *i = a.Allocate( 1 );
2116  pcl::Construct( *i, **p, a );
2117  }
2118  }
2119 };
2120 
2121 // ----------------------------------------------------------------------------
2122 
2129 template <class T, class A> inline
2131 {
2132  return x1.Length() == x2.Length() && pcl::Equal( x1.Begin(), x2.Begin(), x2.End(), IndirectArray<T,A>::equal() );
2133 }
2134 
2141 template <class T, class A> inline
2143 {
2144  return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End(), IndirectArray<T,A>::less() ) < 0;
2145 }
2146 
2154 template <class T, class A, class V> inline
2155 IndirectArray<T,A>& operator <<( IndirectArray<T,A>& x, const V* p )
2156 {
2157  x.Append( static_cast<const T*>( p ) );
2158  return x;
2159 }
2160 
2168 template <class T, class A, class V> inline
2169 IndirectArray<T,A>& operator <<( IndirectArray<T,A>&& x, const V* p )
2170 {
2171  x.Append( static_cast<const T*>( p ) );
2172  return x;
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 
2192 template <class T, class A> inline
2193 IndirectArray<T,A>& operator <<( IndirectArray<T,A>&& x1, const IndirectArray<T,A>& x2 )
2194 {
2195  x1.Append( x2 );
2196  return x1;
2197 }
2198 
2199 // ----------------------------------------------------------------------------
2200 
2201 } // pcl
2202 
2203 #endif // __PCL_IndirectArray_h
2204 
2205 // ----------------------------------------------------------------------------
2206 // EOF pcl/IndirectArray.h - Released 2024-12-23T11:32:56Z
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:278
void Add(const Array &x)
Definition: Array.h:1017
T * iterator
Definition: Array.h:125
const T * const_iterator
Definition: Array.h:129
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:98
const T * const_item_type
Definition: Container.h:109
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: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:562
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 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