PCL
IndirectArray.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/IndirectArray.h - Released 2019-11-07T10:59:34Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2019 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_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  typedef A block_allocator;
98 
102 
105  typedef T** iterator;
106 
109  typedef T* const* const_iterator;
110 
114 
117  typedef typename array_implementation::iterator
119 
122  typedef typename array_implementation::const_iterator
124 
129 
134 
138 
142 
143  // -------------------------------------------------------------------------
144 
148  IndirectArray() : m_array()
149  {
150  }
151 
156  explicit
157  IndirectArray( size_type n ) : m_array()
158  {
159  m_array.Append( (void*)nullptr, n );
160  }
161 
165  IndirectArray( size_type n, const T* p ) : m_array()
166  {
167  m_array.Append( (void*)p, n );
168  }
169 
174  template <class FI>
175  IndirectArray( FI i, FI j ) : m_array( i, j )
176  {
177  }
178 
182  IndirectArray( const IndirectArray& x ) : m_array( x.m_array )
183  {
184  }
185 
189  IndirectArray( IndirectArray&& x ) : m_array( std::move( x.m_array ) )
190  {
191  }
192 
201  {
202  }
203 
208  bool IsUnique() const
209  {
210  return m_array.IsUnique();
211  }
212 
220  bool IsAliasOf( const IndirectArray& x ) const
221  {
222  return m_array.IsAliasOf( x.m_array );
223  }
224 
234  {
235  m_array.EnsureUnique();
236  }
237 
242  size_type Size() const
243  {
244  return m_array.Size();
245  }
246 
251  {
252  return m_array.Length();
253  }
254 
261  {
262  return m_array.Capacity();
263  }
264 
273  {
274  return m_array.Available();
275  }
276 
292  bool IsValid() const
293  {
294  return m_array.IsValid();
295  }
296 
300  bool IsEmpty() const
301  {
302  return m_array.IsEmpty();
303  }
304 
310  {
311  return m_array.LowerBound();
312  }
313 
319  {
320  return m_array.UpperBound();
321  }
322 
326  const allocator& GetAllocator() const
327  {
328  return m_array.GetAllocator();
329  }
330 
334  void SetAllocator( const allocator& a )
335  {
336  m_array.SetAllocator( a );
337  }
338 
342  iterator At( size_type i )
343  {
344  return iterator( m_array.At( i ) );
345  }
346 
350  const_iterator At( size_type i ) const
351  {
352  return const_iterator( m_array.At( i ) );
353  }
354 
365  iterator MutableIterator( const_iterator i )
366  {
367  return iterator( m_array.MutableIterator( (const_array_iterator)i ) );
368  }
369 
374  T*& operator []( size_type i )
375  {
376  return (T*&)m_array[i];
377  }
378 
383  const T* operator []( size_type i ) const
384  {
385  return (const T*)m_array[i];
386  }
387 
392  {
393  return (T*&)*Begin();
394  }
395 
400  const T* operator *() const
401  {
402  return (T*)*Begin();
403  }
404 
408  iterator Begin()
409  {
410  return iterator( m_array.Begin() );
411  }
412 
416  const_iterator Begin() const
417  {
418  return const_iterator( m_array.Begin() );
419  }
420 
424  const_iterator ConstBegin() const
425  {
426  return const_iterator( m_array.ConstBegin() );
427  }
428 
432  iterator End()
433  {
434  return iterator( m_array.End() );
435  }
436 
440  const_iterator End() const
441  {
442  return const_iterator( m_array.End() );
443  }
444 
448  const_iterator ConstEnd() const
449  {
450  return const_iterator( m_array.ConstEnd() );
451  }
452 
460  {
461  return iterator( (array_iterator)m_array.ReverseBegin() );
462  }
463 
471  {
472  return const_iterator( (const_array_iterator)m_array.ReverseBegin() );
473  }
474 
482  {
483  return const_iterator( (const_array_iterator)m_array.ConstReverseBegin() );
484  }
485 
494  {
495  return iterator( (array_iterator)m_array.ReverseEnd() );
496  }
497 
506  {
507  return const_iterator( (const_array_iterator)m_array.ReverseEnd() );
508  }
509 
518  {
519  return const_iterator( (const_array_iterator)m_array.ConstReverseEnd() );
520  }
521 
526  T* First()
527  {
528  return IsEmpty() ? nullptr : *Begin();
529  }
530 
535  const T* First() const
536  {
537  return IsEmpty() ? nullptr : *Begin();
538  }
539 
544  T* Last()
545  {
546  return IsEmpty() ? nullptr : *ReverseBegin();
547  }
548 
553  const T* Last() const
554  {
555  return IsEmpty() ? nullptr : *ReverseBegin();
556  }
557 
566  void UniquifyIterator( iterator& i )
567  {
568  m_array.UniquifyIterator( (array_iterator&)i );
569  }
570 
580  void UniquifyIterators( iterator& i, iterator& j )
581  {
582  m_array.UniquifyIterators( (array_iterator&)i, (array_iterator&)j );
583  }
584 
585 #ifndef __PCL_NO_STL_COMPATIBLE_ITERATORS
586 
589  iterator begin()
590  {
591  return Begin();
592  }
593 
597  const_iterator begin() const
598  {
599  return Begin();
600  }
601 
605  iterator end()
606  {
607  return End();
608  }
609 
613  const_iterator end() const
614  {
615  return End();
616  }
617 #endif // !__PCL_NO_STL_COMPATIBLE_ITERATORS
618 
625  IndirectArray& operator =( const IndirectArray& x )
626  {
627  Assign( x );
628  return *this;
629  }
630 
640  void Assign( const IndirectArray& x )
641  {
642  m_array.Assign( x.m_array );
643  }
644 
648  IndirectArray& operator =( IndirectArray&& x )
649  {
650  Transfer( x );
651  return *this;
652  }
653 
664  {
665  m_array.Transfer( x.m_array );
666  }
667 
678  {
679  m_array.Transfer( x.m_array );
680  }
681 
686  void Assign( const T* p, size_type n = 1 )
687  {
688  m_array.Assign( (void*)p, n );
689  }
690 
697  template <class FI>
698  void Assign( FI i, FI j )
699  {
700  m_array.Assign( i, j );
701  }
702 
714  template <class C>
715  void CloneAssign( const C& x )
716  {
717  PCL_ASSERT_CONTAINER( C, T );
718  CloneObjects( x, (C*)nullptr );
719  }
720 
727  void Import( iterator i, iterator j )
728  {
729  m_array.Import( (array_iterator)i, (array_iterator)j );
730  }
731 
743  iterator Release()
744  {
745  return iterator( m_array.Release() );
746  }
747 
758  iterator Grow( const_iterator i, size_type n = 1 )
759  {
760  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), (void*)nullptr, n ) );
761  }
762 
772  iterator Expand( size_type n = 1 )
773  {
774  return Grow( ConstEnd(), n );
775  }
776 
789  void Shrink( size_type n = 1 )
790  {
791  if ( n < Length() )
792  Truncate( ConstEnd() - n );
793  else
794  Clear();
795  }
796 
812  void Resize( size_type n )
813  {
814  size_type l = Length();
815  if ( n > l )
816  Expand( n - l );
817  else
818  Shrink( l - n );
819  }
820 
832  iterator Insert( const_iterator i, const IndirectArray& x )
833  {
834  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), x.m_array ) );
835  }
836 
847  iterator Insert( const_iterator i, const T* p, size_type n = 1 )
848  {
849  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), (void*)p, n ) );
850  }
851 
864  template <class FI>
865  iterator Insert( const_iterator i, FI p, FI q )
866  {
867  return iterator( m_array.Insert( (array_iterator)const_cast<iterator>( i ), p, q ) );
868  }
869 
874  void Append( const IndirectArray& x )
875  {
876  m_array.Append( x.m_array );
877  }
878 
883  void Append( const T* p, size_type n = 1 )
884  {
885  m_array.Append( (void*)p, n );
886  }
887 
894  template <class FI>
895  void Append( FI p, FI q )
896  {
897  m_array.Append( p, q );
898  }
899 
904  void Prepend( const IndirectArray& x )
905  {
906  m_array.Prepend( x.m_array );
907  }
908 
913  void Prepend( const T* p, size_type n = 1 )
914  {
915  m_array.Prepend( (void*)p, n );
916  }
917 
924  template <class FI>
925  void Prepend( FI p, FI q )
926  {
927  m_array.Prepend( p, q );
928  }
929 
933  void Add( const IndirectArray& x )
934  {
935  Append( x );
936  }
937 
941  void Add( const T* p, size_type n = 1 )
942  {
943  Append( p, n );
944  }
945 
949  template <class FI>
950  void Add( FI i, FI j )
951  {
952  Append( i, j );
953  }
954 
967  void Remove( const_iterator i, size_type n = 1 )
968  {
969  m_array.Remove( (array_iterator)const_cast<iterator>( i ), n );
970  }
971 
984  void Remove( const_iterator i, const_iterator j )
985  {
986  m_array.Remove( (array_iterator)const_cast<iterator>( i ),
987  (array_iterator)const_cast<iterator>( j ) );
988  }
989 
1003  void Truncate( const_iterator i )
1004  {
1005  m_array.Truncate( (array_iterator)const_cast<iterator>( i ) );
1006  }
1007 
1015  void Remove( const T& v )
1016  {
1017  array_implementation r;
1018  for ( const_iterator i = ConstBegin(); i < ConstEnd(); ++i )
1019  if ( *i == nullptr || **i != v )
1020  r.Add( (void*)*i );
1021  if ( r.Length() < m_array.Length() )
1022  m_array.Transfer( r );
1023  }
1024 
1032  template <class BP>
1033  void Remove( const T& v, BP p )
1034  {
1035  array_implementation r;
1036  for ( const_iterator i = ConstBegin(); i < ConstEnd(); ++i )
1037  if ( *i == nullptr || !p( **i, v ) )
1038  r.Add( (void*)*i );
1039  if ( r.Length() < m_array.Length() )
1040  m_array.Transfer( r );
1041  }
1042 
1049  void Remove( const T* p )
1050  {
1051  m_array.Remove( (void*)p );
1052  }
1053 
1068  void Clear()
1069  {
1070  m_array.Clear();
1071  }
1072 
1085  void Delete( iterator i, size_type n = 1 )
1086  {
1087  Delete( i, i+n );
1088  }
1089 
1108  void Delete( iterator i, iterator j )
1109  {
1110  // NB: Copy-on-write must *not* happen in this function.
1111  if ( i < ConstEnd() )
1112  {
1113  i = pcl::Max( const_cast<iterator>( ConstBegin() ), i );
1114  j = pcl::Min( j, const_cast<iterator>( ConstEnd() ) );
1115  allocator a;
1116  for ( ; i < j; ++i )
1117  if ( *i != nullptr )
1118  DeleteObject( i, a );
1119  }
1120  }
1121 
1133  void Delete( const T& v )
1134  {
1135  // NB: Copy-on-write must *not* happen in this function.
1136  allocator a;
1137  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1138  if ( *i != nullptr && **i == v )
1139  DeleteObject( i, a );
1140  }
1141 
1153  template <class BP>
1154  void Delete( const T& v, BP p )
1155  {
1156  // NB: Copy-on-write must *not* happen in this function.
1157  allocator a;
1158  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1159  if ( *i != nullptr && p( **i, v ) )
1160  DeleteObject( i, a );
1161  }
1162 
1171  void Delete()
1172  {
1173  // NB: Copy-on-write must *not* happen in this function.
1174  allocator a;
1175  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1176  if ( *i != nullptr )
1177  DeleteObject( i, a );
1178  }
1179 
1192  void Destroy( iterator i, size_type n = 1 )
1193  {
1194  Delete( i, n );
1195  Remove( i, n );
1196  }
1197 
1209  void Destroy( iterator i, iterator j )
1210  {
1211  Delete( i, j );
1212  Remove( i, j );
1213  }
1214 
1226  void Destroy( const T& v )
1227  {
1228  array_implementation r;
1229  allocator a;
1230  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1231  if ( *i != nullptr && **i == v )
1232  DeleteObject( i, a );
1233  else
1234  r.Add( (void*)*i );
1235  // NB: Copy-on-write must *not* happen before this point.
1236  if ( r.Length() < m_array.Length() )
1237  m_array.Transfer( r );
1238  }
1239 
1251  template <class BP>
1252  void Destroy( const T& v, BP p )
1253  {
1254  array_implementation r;
1255  allocator a;
1256  for ( iterator i = const_cast<iterator>( ConstBegin() ); i < ConstEnd(); ++i )
1257  if ( *i != nullptr && p( **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 
1273  void Destroy()
1274  {
1275  Delete();
1276  Clear();
1277  }
1278 
1282  void Pack()
1283  {
1284  m_array.Remove( (void*)nullptr );
1285  }
1286 
1300  iterator Replace( const_iterator i, const_iterator j, const IndirectArray& x )
1301  {
1302  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1303  (array_iterator)const_cast<iterator>( j ), x.m_array ) );
1304  }
1305 
1319  iterator Replace( const_iterator i, const_iterator j, const T* p, size_type n = 1 )
1320  {
1321  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1322  (array_iterator)const_cast<iterator>( j ), (void*)p, n ) );
1323  }
1324 
1341  template <class FI>
1342  iterator Replace( const_iterator i, const_iterator j, FI p, FI q )
1343  {
1344  return iterator( m_array.Replace( (array_iterator)const_cast<iterator>( i ),
1345  (array_iterator)const_cast<iterator>( j ), p, q ) );
1346  }
1347 
1355  void Reserve( size_type n )
1356  {
1357  m_array.Reserve( n );
1358  }
1359 
1372  void Squeeze()
1373  {
1374  m_array.Squeeze();
1375  }
1376 
1380  void Fill( const T& v )
1381  {
1382  Apply( [v]( T* x ){ *x = v; } );
1383  }
1384 
1389  template <class F>
1390  void Apply( F f )
1391  {
1392  pcl::Apply( Begin(), End(), IndirectUnaryFunction<T*, F>( f ) );
1393  }
1394 
1399  template <class F>
1400  void Apply( F f ) const
1401  {
1402  pcl::Apply( Begin(), End(), IndirectUnaryFunction<const T*, F>( f ) );
1403  }
1404 
1410  template <class F>
1411  iterator FirstThat( F f ) const
1412  {
1413  return const_cast<iterator>( pcl::FirstThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) ) );
1414  }
1415 
1421  template <class F>
1422  iterator LastThat( F f ) const
1423  {
1424  return const_cast<iterator>( pcl::LastThat( Begin(), End(), IndirectUnaryPredicate<const T*, F>( f ) ) );
1425  }
1426 
1431  size_type Count( const T& v ) const
1432  {
1433  return pcl::Count( Begin(), End(), &v, equal() );
1434  }
1435 
1440  size_type Count( const T* p ) const
1441  {
1442  return m_array.Count( (void*)p );
1443  }
1444 
1450  template <class BP>
1451  size_type Count( const T& v, BP p ) const
1452  {
1453  return pcl::Count( Begin(), End(), &v, IndirectBinaryPredicate<const T*, const T*, BP>( p ) );
1454  }
1455 
1461  template <class UP>
1462  size_type CountIf( UP p ) const
1463  {
1464  return pcl::CountIf( Begin(), End(), IndirectUnaryPredicate<const T*, UP>( p ) );
1465  }
1466 
1469  iterator MinItem() const
1470  {
1471  return const_cast<iterator>( pcl::MinItem( Begin(), End(), less() ) );
1472  }
1473 
1476  template <class BP>
1477  iterator MinItem( BP p ) const
1478  {
1479  return const_cast<iterator>( pcl::MinItem( Begin(), End(),
1481  }
1482 
1485  iterator MaxItem() const
1486  {
1487  return const_cast<iterator>( pcl::MaxItem( Begin(), End(), less() ) );
1488  }
1489 
1492  template <class BP>
1493  iterator MaxItem( BP p ) const
1494  {
1495  return const_cast<iterator>( pcl::MaxItem( Begin(), End(),
1497  }
1498 
1501  void Reverse()
1502  {
1503  m_array.Reverse();
1504  }
1505 
1509  {
1510  m_array.Rotate( n );
1511  }
1512 
1515  void ShiftLeft( const T* p, size_type n = 1 )
1516  {
1517  m_array.ShiftLeft( (void*)p, n );
1518  }
1519 
1522  void ShiftRight( const T* p, size_type n = 1 )
1523  {
1524  m_array.ShiftRight( (void*)p, n );
1525  }
1526 
1529  iterator Search( const T& v ) const
1530  {
1531  return const_cast<iterator>( pcl::LinearSearch( Begin(), End(), &v, equal() ) );
1532  }
1533 
1536  iterator Search( const T* p ) const
1537  {
1538  return iterator( m_array.Search( (void*)p ) );
1539  }
1540 
1543  template <class BP>
1544  iterator Search( const T& v, BP p ) const
1545  {
1546  return const_cast<iterator>( pcl::LinearSearch( Begin(), End(), &v,
1548  }
1549 
1552  iterator SearchLast( const T& v ) const
1553  {
1554  return const_cast<iterator>( pcl::LinearSearchLast( Begin(), End(), &v, equal() ) );
1555  }
1556 
1559  iterator SearchLast( const T* p ) const
1560  {
1561  return iterator( m_array.SearchLast( (void*)p ) );
1562  }
1563 
1566  template <class BP>
1567  iterator SearchLast( const T& v, BP p ) const
1568  {
1569  return const_cast<iterator>( pcl::LinearSearchLast( Begin(), End(), &v,
1571  }
1572 
1575  template <class FI>
1576  iterator SearchSubset( FI i, FI j ) const
1577  {
1578  return const_cast<iterator>( pcl::Search( Begin(), End(), i, j, equal() ) );
1579  }
1580 
1583  template <class FI, class BP>
1584  iterator SearchSubset( FI i, FI j, BP p ) const
1585  {
1586  return const_cast<iterator>( pcl::Search( Begin(), End(), i, j,
1588  }
1589 
1592  template <class C>
1593  iterator SearchSubset( const C& c ) const
1594  {
1595  return const_cast<iterator>( pcl::Search( Begin(), End(), c.Begin(), c.End(), equal() ) );
1596  }
1597 
1600  template <class C, class BP>
1601  iterator SearchSubset( const C& c, BP p ) const
1602  {
1603  return const_cast<iterator>( pcl::Search( Begin(), End(), c.Begin(), c.End(),
1605  }
1606 
1609  template <class BI>
1610  iterator SearchLastSubset( BI i, BI j ) const
1611  {
1612  return const_cast<iterator>( pcl::SearchLast( Begin(), End(), i, j, equal() ) );
1613  }
1614 
1617  template <class BI, class BP>
1618  iterator SearchLastSubset( BI i, BI j, BP p ) const
1619  {
1620  return const_cast<iterator>( pcl::SearchLast( Begin(), End(), i, j,
1622  }
1623 
1626  template <class C>
1627  iterator SearchLastSubset( const C& c ) const
1628  {
1629  return const_cast<iterator>( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(), equal() ) );
1630  }
1631 
1634  template <class C, class BP>
1635  iterator SearchLastSubset( const C& c, BP p ) const
1636  {
1637  return const_cast<iterator>( pcl::SearchLast( Begin(), End(), c.Begin(), c.End(),
1639  }
1640 
1643  bool Contains( const T& v ) const
1644  {
1645  return Search( v ) != End();
1646  }
1647 
1650  bool Contains( const T* p ) const
1651  {
1652  return m_array.Contains( (void*)p );
1653  }
1654 
1657  template <class BP>
1658  bool Contains( const T& v, BP p ) const
1659  {
1660  return Search( v, p ) != End();
1661  }
1662 
1665  template <class FI>
1666  iterator ContainsSubset( FI i, FI j ) const
1667  {
1668  return SearchSubset( i, j ) != End();
1669  }
1670 
1673  template <class FI, class BP>
1674  iterator ContainsSubset( FI i, FI j, BP p ) const
1675  {
1676  return SearchSubset( i, j, p ) != End();
1677  }
1678 
1681  template <class C>
1682  iterator ContainsSubset( const C& c ) const
1683  {
1684  return SearchSubset( c ) != End();
1685  }
1686 
1689  template <class C, class BP>
1690  iterator ContainsSubset( const C& c, BP p ) const
1691  {
1692  return SearchSubset( c, p ) != End();
1693  }
1694 
1697  void Sort()
1698  {
1699  pcl::QuickSort( Begin(), End(), less() );
1700  }
1701 
1704  template <class BP>
1705  void Sort( BP p )
1706  {
1708  }
1709 
1713  friend void Swap( IndirectArray& x1, IndirectArray& x2 )
1714  {
1715  pcl::Swap( x1.m_array, x2.m_array );
1716  }
1717 
1734  template <class S, typename SP>
1735  S& ToSeparated( S& s, SP separator ) const
1736  {
1737  const_iterator i = Begin();
1738  if ( i < End() )
1739  {
1740  while ( *i == nullptr )
1741  if ( ++i == End() )
1742  return s;
1743  s.Append( S( **i ) );
1744  if ( ++i < End() )
1745  do
1746  if ( *i != nullptr )
1747  {
1748  s.Append( separator );
1749  s.Append( S( **i ) );
1750  }
1751  while ( ++i < End() );
1752  }
1753  return s;
1754  }
1755 
1778  template <class S, typename SP, class AF>
1779  S& ToSeparated( S& s, SP separator, AF append ) const
1780  {
1781  const_iterator i = Begin();
1782  if ( i < End() )
1783  {
1784  while ( *i == nullptr )
1785  if ( ++i == End() )
1786  return s;
1787  append( s, S( **i ) );
1788  if ( ++i < End() )
1789  {
1790  S p( separator );
1791  do
1792  if ( *i != nullptr )
1793  {
1794  append( s, p );
1795  append( s, S( **i ) );
1796  }
1797  while ( ++i < End() );
1798  }
1799  }
1800  return s;
1801  }
1802 
1811  template <class S>
1812  S& ToCommaSeparated( S& s ) const
1813  {
1814  return ToSeparated( s, ',' );
1815  }
1816 
1825  template <class S>
1826  S& ToSpaceSeparated( S& s ) const
1827  {
1828  return ToSeparated( s, ' ' );
1829  }
1830 
1839  template <class S>
1840  S& ToTabSeparated( S& s ) const
1841  {
1842  return ToSeparated( s, '\t' );
1843  }
1844 
1855  uint64 Hash64( uint64 seed = 0 ) const
1856  {
1857  return m_array.Hash64( seed );
1858  }
1859 
1870  uint32 Hash32( uint32 seed = 0 ) const
1871  {
1872  return m_array.Hash32( seed );
1873  }
1874 
1879  uint64 Hash( uint64 seed = 0 ) const
1880  {
1881  return Hash64( seed );
1882  }
1883 
1884  // -------------------------------------------------------------------------
1885 
1886 private:
1887 
1888  array_implementation m_array;
1889 
1890  void DeleteObject( iterator i, allocator& a )
1891  {
1892  pcl::Destroy( *i );
1893  a.Deallocate( *i );
1894  *i = nullptr;
1895  }
1896 
1897  template <class C>
1898  void CloneObjects( const C& x, DirectContainer<T>* )
1899  {
1900  Clear();
1901  Reserve( x.Length() );
1902  Append( static_cast<T*>( nullptr ), x.Length() );
1903  iterator i = Begin(), j = End();
1904  typename C::const_iterator p = x.Begin(), q = x.End();
1905  for ( allocator a; i < j && p != q; ++i, ++p )
1906  {
1907  *i = a.Allocate( 1 );
1908  pcl::Construct( *i, *p, a );
1909  }
1910  }
1911 
1912  template <class C>
1913  void CloneObjects( const C& x, IndirectContainer<T>* )
1914  {
1915  Clear();
1916  Reserve( x.Length() );
1917  Append( static_cast<T*>( nullptr ), x.Length() );
1918  iterator i = Begin(), j = End();
1919  typename C::const_iterator p = x.Begin(), q = x.End();
1920  for ( allocator a; i < j && p != q; ++i, ++p )
1921  if ( *p != nullptr )
1922  {
1923  *i = a.Allocate( 1 );
1924  pcl::Construct( *i, **p, a );
1925  }
1926  }
1927 };
1928 
1929 // ----------------------------------------------------------------------------
1930 
1937 template <class T, class A> inline
1939 {
1940  return x1.Length() == x2.Length() && pcl::Equal( x1.Begin(), x2.Begin(), x2.End(), IndirectArray<T,A>::equal() );
1941 }
1942 
1949 template <class T, class A> inline
1950 bool operator <( const IndirectArray<T,A>& x1, const IndirectArray<T,A>& x2 )
1951 {
1952  return pcl::Compare( x1.Begin(), x1.End(), x2.Begin(), x2.End(), IndirectArray<T,A>::less() ) < 0;
1953 }
1954 
1962 template <class T, class A, class V> inline
1963 IndirectArray<T,A>& operator <<( IndirectArray<T,A>& x, const V* p )
1964 {
1965  x.Append( static_cast<const T*>( p ) );
1966  return x;
1967 }
1968 
1976 template <class T, class A, class V> inline
1977 IndirectArray<T,A>& operator <<( IndirectArray<T,A>&& x, const V* p )
1978 {
1979  x.Append( static_cast<const T*>( p ) );
1980  return x;
1981 }
1982 
1988 template <class T, class A> inline
1989 IndirectArray<T,A>& operator <<( IndirectArray<T,A>& x1, const IndirectArray<T,A>& x2 )
1990 {
1991  x1.Append( x2 );
1992  return x1;
1993 }
1994 
2000 template <class T, class A> inline
2001 IndirectArray<T,A>& operator <<( IndirectArray<T,A>&& x1, const IndirectArray<T,A>& x2 )
2002 {
2003  x1.Append( x2 );
2004  return x1;
2005 }
2006 
2007 // ----------------------------------------------------------------------------
2008 
2009 } // pcl
2010 
2011 #endif // __PCL_IndirectArray_h
2012 
2013 // ----------------------------------------------------------------------------
2014 // EOF pcl/IndirectArray.h - Released 2019-11-07T10:59:34Z
size_type Length() const
const_iterator Begin() const
const_reverse_iterator ReverseBegin() const
void Remove(const T &v, BP p)
A wrapper class that applies a unary predicate to pointers to objects.
Definition: Indirect.h:182
Root base class for all PixInsight module components.
Definition: MetaObject.h:85
iterator SearchLastSubset(BI i, BI j) const
const_reverse_iterator ConstReverseEnd() const
size_type Size() const
reverse_iterator ReverseBegin()
uint64 Hash64(const void *data, size_type size, uint64 seed=0)
Definition: Math.h:3551
void Assign(const T *p, size_type n=1)
void Append(const T *p, size_type n=1)
iterator Grow(const_iterator i, size_type n=1)
const_iterator end() const
Complex< T1 > operator*(const Complex< T1 > &c1, const Complex< T2 > &c2)
Definition: Complex.h:539
A functional class that tests two pointers for equality of the pointed objects.
Definition: Indirect.h:273
void Append(const IndirectArray &x)
BI LinearSearchLast(BI i, BI j, const T &v)
Definition: Search.h:129
void Remove(const T &v)
const_iterator ConstBegin() const
iterator MutableIterator(const_iterator i)
void Deallocate(T *p)
Definition: Allocator.h:176
void Swap(GenericPoint< T > &p1, GenericPoint< T > &p2)
Definition: Point.h:1402
iterator Insert(const_iterator i, const IndirectArray &x)
size_type Count(FI i, FI j, const T &v)
Definition: Utility.h:384
void Assign(FI i, FI j)
iterator ContainsSubset(FI i, FI j) const
int Compare(FI1 i1, FI1 j1, FI2 i2, FI2 j2)
Definition: Utility.h:639
PCL root namespace.
Definition: AbstractImage.h:76
void Truncate(const_iterator i)
Array< void *, A > array_implementation
void Delete(iterator i, iterator j)
BI LastThat(BI i, BI j, UP p)
Definition: Utility.h:350
iterator SearchSubset(FI i, FI j) const
iterator LastThat(F f) const
bool IsEmpty() const
size_type LowerBound() const
FI LinearSearch(FI i, FI j, const T &v)
Definition: Search.h:91
void Transfer(IndirectArray &&x)
bool IsAliasOf(const IndirectArray &x) const
uint64 Hash64(uint64 seed=0) const
iterator MaxItem() const
iterator SearchLastSubset(BI i, BI j, BP p) const
iterator SearchLast(const T *p) const
FI MaxItem(FI i, FI j)
Definition: Utility.h:479
iterator Replace(const_iterator i, const_iterator j, const IndirectArray &x)
ReverseRandomAccessIterator< iterator, T * > reverse_iterator
void Transfer(IndirectArray &x)
iterator SearchSubset(const C &c) const
void Construct(T *p, A &a)
Definition: Allocator.h:246
IndirectLess< const T * > less
iterator Replace(const_iterator i, const_iterator j, const T *p, size_type n=1)
bool Contains(const T &v) const
A functional class that applies the less than relational operator to the objects pointed to by two po...
Definition: Indirect.h:295
bool Equal(FI1 i1, FI2 i2, FI2 j2)
Definition: Utility.h:592
friend void Swap(IndirectArray &x1, IndirectArray &x2)
size_type Count(const T &v, BP p) const
Generic dynamic array of pointers to objects.
Definition: IndirectArray.h:91
iterator MaxItem(BP p) const
MetaObject *const * const_iterator
void Append(FI p, FI q)
uint64 Hash(uint64 seed=0) const
iterator SearchLast(const T &v) const
A wrapper class that applies a unary function to pointers to objects.
Definition: Indirect.h:79
iterator Expand(size_type n=1)
IndirectArray(size_type n)
BI1 SearchLast(BI1 i1, BI1 j1, FI2 i2, FI2 j2)
Definition: Search.h:449
void Resize(size_type n)
size_t size_type
Definition: Defs.h:543
iterator SearchLast(const T &v, BP p) const
Provides memory allocation for PCL containers.
Definition: Allocator.h:131
iterator Insert(const_iterator i, FI p, FI q)
size_type CountIf(UP p) const
void ShiftRight(const T *p, size_type n=1)
iterator MinItem() const
void Destroy(T *p)
Definition: Allocator.h:276
void Apply(FI i, FI j, F f)
Definition: Utility.h:249
iterator FirstThat(F f) const
const_iterator begin() const
bool IsUnique() const
Root base class of all PCL containers of pointers to objects.
Definition: Container.h:88
void Destroy(iterator i, size_type n=1)
T * Allocate(size_type n, size_type extra=0)
Definition: Allocator.h:162
unsigned long long uint64
Definition: Defs.h:616
constexpr const T & Max(const T &a, const T &b)
Definition: Utility.h:119
A wrapper class that applies a binary predicate to pointers to objects.
Definition: Indirect.h:232
iterator Insert(const_iterator i, const T *p, size_type n=1)
array_implementation::const_iterator const_array_iterator
constexpr const T & Min(const T &a, const T &b)
Definition: Utility.h:90
void UniquifyIterator(iterator &i)
iterator Search(const T &v, BP p) const
size_type CountIf(FI i, FI j, UP p)
Definition: Utility.h:423
void Delete(iterator i, size_type n=1)
bool Contains(const T *p) const
Allocator< T, A > allocator
void Remove(const_iterator i, const_iterator j)
void Assign(const IndirectArray &x)
void ShiftLeft(const T *p, size_type n=1)
void Shrink(size_type n=1)
ReverseRandomAccessIterator< const_iterator, const T * > const_reverse_iterator
void Add(const Array &x)
Definition: Array.h:1006
reverse_iterator ReverseEnd()
void Remove(const T *p)
size_type Count(const T *p) const
void Prepend(const IndirectArray &x)
iterator Replace(const_iterator i, const_iterator j, FI p, FI q)
array_implementation::iterator array_iterator
void Prepend(FI p, FI q)
uint32 Hash32(uint32 seed=0) const
size_type Length() const
Definition: Array.h:265
const_iterator End() const
iterator SearchLastSubset(const C &c) const
const allocator & GetAllocator() const
void QuickSort(RI i, RI j)
Definition: Sort.h:250
size_type Capacity() const
void Destroy(iterator i, iterator j)
Root base class of all PCL containers of objects.
Definition: Container.h:77
void Add(FI i, FI j)
iterator SearchSubset(const C &c, BP p) const
iterator At(size_type i)
iterator ContainsSubset(const C &c) const
Reverse random access iterator.
Definition: Iterator.h:414
const_iterator At(size_type i) const
A block allocator class that uses the standard new and delete operators.
Definition: StdAlloc.h:81
void Rotate(distance_type n)
iterator MinItem(BP p) const
FI MinItem(FI i, FI j)
Definition: Utility.h:441
iterator Search(const T *p) const
void Prepend(const T *p, size_type n=1)
FI1 Search(FI1 i1, FI1 j1, FI2 i2, FI2 j2)
Definition: Search.h:397
void SetAllocator(const allocator &a)
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2)
Definition: Array.h:2075
void Import(iterator i, iterator j)
IndirectArray(FI i, FI j)
size_type Available() const
iterator SearchLastSubset(const C &c, BP p) const
void Add(const IndirectArray &x)
const_reverse_iterator ReverseEnd() const
IndirectArray(const IndirectArray &x)
void Destroy(const T &v, BP p)
void Reserve(size_type n)
void Fill(const T &v)
void Destroy(const T &v)
void Remove(const_iterator i, size_type n=1)
void UniquifyIterators(iterator &i, iterator &j)
size_type Count(const T &v) const
ptrdiff_t distance_type
Definition: Defs.h:549
IndirectArray(IndirectArray &&x)
IndirectEqual< const T * > equal
IndirectArray(size_type n, const T *p)
FI FirstThat(FI i, FI j, UP p)
Definition: Utility.h:316
iterator Search(const T &v) const
iterator ContainsSubset(const C &c, BP p) const
void Delete(const T &v)
size_type UpperBound() const
const_iterator ConstEnd() const
bool IsValid() const
iterator SearchSubset(FI i, FI j, BP p) const
unsigned int uint32
Definition: Defs.h:600
void CloneAssign(const C &x)
const_reverse_iterator ConstReverseBegin() const
void Apply(F f) const
void Delete(const T &v, BP p)
bool Contains(const T &v, BP p) const
iterator ContainsSubset(FI i, FI j, BP p) const
void Add(const T *p, size_type n=1)